Architecture Conventions
Architecture Conventions
Section titled “Architecture Conventions”Where code lives and which direction dependencies flow. Full rationale:
plans/ARCHITECTURE.md §1.
Module map
Section titled “Module map”apps/*— deployment targets (@apps/web,@apps/cron-*). Thin.packages/*— shared libraries (@packages/db,@packages/auth,@packages/service).- Import aliases:
@packages/*,@apps/*.
Dependency direction (do not violate)
Section titled “Dependency direction (do not violate)”apps/* → packages/service → packages/{db, auth} packages/auth → packages/db@packages/dbdepends on nothing internal. Never importservice/authintodb.- Business logic lives in
@packages/service, NOT in@apps/webroute handlers or TanStack server functions. Handlers are thin: validate → authorize → call service. - Cron jobs (
@apps/cron-*) call@packages/servicedirectly (trusted internal context).
Service boundary (critical)
Section titled “Service boundary (critical)”@packages/serviceis auth-agnostic: it receives already-authorized input plus anAuditContext. It NEVER checks permissions.requirePermission(...)is called by the Hono route handler BEFORE the service function runs.- Service functions that may run in a transaction accept
db: DB | TX.
DB client
Section titled “DB client”- Access the DB via the
createDB(env)factory +DB/TXtypes from@packages/db. There is NO module-leveldbsingleton — the connection comes from per-requestenv(Hyperdrive in prod,NEON_DATABASE_URLin dev).
Code organization
Section titled “Code organization”- One service operation per file, composed via the mixin pattern — see
service-conventions.md. - DB schema is domain-split under
packages/db/src/schema/, re-exported fromschema/index.ts— seeschema.md. - Relations live only in
packages/db/src/relations.ts, never inline in table files.