DEC-AIC-0051: Organize workspace into apps and libs with hexagonal and layered module boundaries
Accepted
Status: accepted · 2026-11-20 · supersedes DEC-AIC-0008
Context
DEC-AIC-0008 structured the coach as ports and adapters inside a flat packages/ directory alongside apps/climb-board and apps/docs (observed: repository @ 2026-11-20). As the workspace grew to include the vault server (vault, vault-server, DEC-AIC-0048) and frontend applications (climb-board, docs), three limitations emerged:
- Runnable applications (
cli,vault-server) lived inpackages/alongside libraries, while frontend apps lived inapps/. - The flat
packages/layout mixed unrelated domains (coachandvault) and gave no clear home for future frontend libraries. - The
@nx/enforce-module-boundariesrules only modeled hexagonal backend layers and lacked support for a layered frontend architecture (feat,ui,data-access,util) or cross-domainscope:*isolation.
Decision
- All executable code and libraries live in
apps/andlibs/. Thepackages/directory is removed. npm workspaces are["apps/*", "libs/*/*"]. Non-code repository content stays at the root (kb/,docs/,README.md,ARCHITECTURE.md,CONTRIBUTING.md, per DEC-AIC-0032 and DEC-AIC-0049). - Applications live in
apps/:apps/cli(@ai-coach/cli) — composition root and terminal entry point forcoach.apps/vault-server(@ai-coach/vault-server) — MCP server andcoach-vaultbinary forvault.apps/climb-board(@ai-coach/climb-board) — Angular drawing board for/climb.apps/docs(@ai-coach/docs) — Docusaurus documentation site.
- Libraries live in
libs/<domain>/<lib>/, grouped by domain:libs/coach/:domain,application,adapter-vault-mcp,adapter-ollama,adapter-gemini,adapter-local-state.libs/vault/:corein stage 1 (migrated frompackages/vault), to be refactored in stage 2 into hexagonal libraries (domain,application,adapter-*) withapps/vault-serveras its composition root.libs/shared/: pure TypeScripttype:utillibraries shared across scopes when needed (no npm dependencies, no Node built-ins).- Frontend domains (such as
libs/climb-board/or future UI domains):feat-*,ui-*,data-access-*,util-*.
- Every project carries three tag dimensions enforced by
@nx/enforce-module-boundaries:- Domain scope (
scope:*):scope:coach,scope:vault,scope:climb-board,scope:docs,scope:shared. Every domain scope may depend only on itself andscope:shared.scope:coachandscope:vaultcannot import each other (preserving DEC-AIC-0048).scope:sharedmay depend only onscope:sharedand allows no external npm imports. - Architecture style (
architecture:*):architecture:hexagonal(may depend onarchitecture:hexagonalandscope:shared) andarchitecture:layered(may depend onarchitecture:layeredandscope:shared). - Layer type (
type:*):- Hexagonal:
type:domain->type:domain,type:util(no external imports);type:application->type:domain,type:application,type:util(no external imports);type:adapter->type:domain,type:application,type:util.type:vaultis a transitional tag forlibs/vault/coreuntil the stage 2 hexagonal refactor removes it. - Layered (frontend):
type:feat->type:ui,type:data-access,type:util(nofeat->feat);type:ui->type:ui,type:util;type:data-access->type:data-access,type:util;type:util->type:util. - Applications:
type:app-> any library type permitted by the app'sscope:*andarchitecture:*tags.
- Hexagonal:
- External import whitelists: per-adapter (
adapter:vault-mcp,adapter:ollama,adapter:gemini,adapter:local-state) and per-app (app:cli,app:vault-server) tags restrict third-party and Node imports.
- Domain scope (
no-restricted-importsbans Node built-ins inlibs/*/domain/src/**/*.ts,libs/*/application/src/**/*.ts, andlibs/shared/*/src/**/*.ts, keeping hexagonal cores and shared utilities pure TypeScript.- Staged rollout: Stage 1 (this change) moves
packages/intoapps/andlibs/, updates ESLint boundaries, project configs, and documentation. Stage 2 refactorslibs/vault/coreinto hexagonal libraries underlibs/vault/and removes the transitionaltype:vaulttag.
This ADR supersedes DEC-AIC-0008. All hexagonal invariants from DEC-AIC-0008 (inward-only dependencies, manual composition root, error translation in adapters, no circular dependencies) remain in force.
Consequences
- Every runnable entry point is in
apps/, and every library is grouped by domain inlibs/<domain>/<lib>. - Backend domains (
coach,vault) and frontend apps (climb-board,docs, future UIs) follow explicit, lint-enforced boundaries without leaking across architectures or domains. - Pure
scope:sharedtype:utillibraries can be imported by any scope, including hexagonaldomainandapplication, without compromising purity. - Paths in
package.json,tsconfig.json,apps/docs,.mcp.example.json, and setup guides change frompackages/toapps/andlibs/. Existing local MCP configurations pointing atpackages/vault-server/dist/main.jsmust be updated toapps/vault-server/dist/main.js.
Alternatives Considered
- Keep
packages/flat and add frontend libs alongside backend packages. Rejected: mixes apps with libs and obscures domain ownership as more domains and frontend libraries are added. - Move
kb/anddocs/intoapps/. Rejected:kb/anddocs/guide/are non-code Markdown content, not runnable applications; keeping them at root preserves GitHub browsability and DEC-AIC-0032 / DEC-AIC-0049. - Keep
libs/vault/corepermanently outside hexagonal architecture. Rejected: applying the same hexagonal pattern tovaultin stage 2 makes backend architecture uniform across the repository.