## Foundation — Initial Scaffold **Status:** ✅ Complete ### Completed - [x] Move existing files into `src/` structure (app/, shared/, features/) - [x] Install Drizzle ORM + Neon serverless driver + Drizzle Kit - [x] Create `tenants` table schema (status enum, soft delete) - [x] Create `tasks` table schema (FK to tenants) - [x] Create `audit_logs` + `access_logs` table schemas - [x] Schema barrel (`shared/db/schema.ts`) re-exporting all feature schemas - [x] Drizzle connection (`shared/db/index.ts`) - [x] `drizzle.config.ts` with `.env.local` support - [x] Push schema to Neon (`npm run db:push`) - [x] Permission constants (`shared/lib/permissions.ts`) - [x] Subdomain middleware (`src/middleware.ts`) - [x] Tenant resolution helpers (`shared/lib/tenant.ts`) - [x] API auth helpers (`shared/api/auth.ts`) - [x] Account-locked page (frozen/suspended/deactivated) - [x] Updated `.env.local.example`, `tsconfig.json`, `components.json`, `tailwind.config.ts` ### Architecture - Feature-sliced: `app/ → features/* → shared/*` (one-way deps) - Schema barrel pattern: features define tables, `shared/db/schema.ts` re-exports all - Subdomain routing: `acme.localhost:3000` → rewrite to `/tenant/*` with `x-tenant-slug` header - 4-tier RBAC: admin > manager > member > viewer (via Stack Auth team permissions) ### Key Files - `src/middleware.ts` — subdomain routing - `src/shared/db/schema.ts` — barrel schema - `src/shared/lib/permissions.ts` — role/permission constants - `src/shared/api/auth.ts` — resolveRequestContext, requireSuperAdmin - `drizzle.config.ts` — Drizzle Kit config
Foundation — Initial Scaffold
Status: ✅ Complete
Completed
src/structure (app/, shared/, features/)tenantstable schema (status enum, soft delete)taskstable schema (FK to tenants)audit_logs+access_logstable schemasshared/db/schema.ts) re-exporting all feature schemasshared/db/index.ts)drizzle.config.tswith.env.localsupportnpm run db:push)shared/lib/permissions.ts)src/middleware.ts)shared/lib/tenant.ts)shared/api/auth.ts).env.local.example,tsconfig.json,components.json,tailwind.config.tsArchitecture
app/ → features/* → shared/*(one-way deps)shared/db/schema.tsre-exports allacme.localhost:3000→ rewrite to/tenant/*withx-tenant-slugheaderKey Files
src/middleware.ts— subdomain routingsrc/shared/db/schema.ts— barrel schemasrc/shared/lib/permissions.ts— role/permission constantssrc/shared/api/auth.ts— resolveRequestContext, requireSuperAdmindrizzle.config.ts— Drizzle Kit config