← ClaudeAtlas

structure-a-shared-backend-liblisted

Use when organizing a shared backend infrastructure library that many services depend on (e.g. @org/infra-*) — how to split it into focused packages by dependency weight, expose one barrel per package, avoid dependency cycles with peer deps, version/publish it, decide what belongs in the lib vs a service, and the canonical primitives it should provide (a base entity with soft-delete + audit columns, base pagination/response DTOs, column transformers, type helpers). NestJS/TypeORM reference, framework-flexible. The backend twin of structure-a-shared-ui-lib.
kennguyen887/agent-foundation · ★ 1 · API & Backend · score 77
Install: claude install-skill kennguyen887/agent-foundation
# Structure a shared backend library A library of cross-cutting infrastructure (`@org/infra-*`) that every backend service imports, so the fleet is consistent and DRY. This is the *where & how it's packaged*; the framework primitives inside it are in `write-cross-cutting-code` and `design-an-error-model`. Frontend equivalent: `structure-a-shared-ui-lib`. ## When to use You're starting or reorganizing the shared lib behind a fleet of services, deciding which package a new primitive goes in, or pulling duplicated infra out of services into one place. ## 1. Split into focused packages by dependency weight - **Several small packages, not one mega-package** — each owns one concern and pulls only the deps it needs, so a service that wants typed errors doesn't drag in the whole AWS/cache stack. - **Order packages from zero-dep core → heavier**, and let the light ones be depended on by the heavy ones (never the reverse), so there are **no cycles**: - `infra-exception` / `infra-types` — **zero framework deps**; the error model + shared types. Anything can import it. - `infra-auth` — guards/decorators; depends on the error package (peer), nothing heavier. - `infra-cqrs` — base command/query/event classes; orthogonal, used by event-driven services. - `infra-common` — the workhorse (pipes, interceptors, middleware, DTOs, base entity, utils, cache, messaging clients). Highest reuse; may depend on the lighter packages. ``` @org/infra-exception (0 deps) ←─ @org/