Project Structure
Primary directories and the responsibility of each layer.
High-level layout
src/
├── app/
│ ├── api/
│ ├── (dashboard)/
│ └── (marketing)/
├── lib/
│ ├── services/
│ ├── stripe/
│ ├── db/
│ ├── validators/
│ ├── middleware/
│ └── errors/
└── prisma/
├── schema.prisma
├── seed.ts
└── migrations/
Routing layer
src/app/api/**/route.ts files are thin controllers:
- Authenticate request
- Parse and validate payload with Zod
- Call service function
- Return normalized success or error response
Business layer
src/lib/services/** contains business logic and transactional behavior. This is where group membership checks, billing calculations, and domain constraints live.
Data layer
src/lib/db/client.tsexposes Prisma singleton.prisma/schema.prismadefines relational data model.prisma/seed.tscreates initial subscription catalog entries.
Integration layer
src/lib/stripe/** encapsulates checkout session creation and webhook event handling support.
Validation and errors
src/lib/validators/**defines all request contracts.src/lib/errors/AppError.tscentralizes error code + status semantics.