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.ts exposes Prisma singleton.
  • prisma/schema.prisma defines relational data model.
  • prisma/seed.ts creates 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.ts centralizes error code + status semantics.