How aak-developers/centraleats-backend works
1. Overall shape
This is a transactional Node.js/TypeScript HTTP backend built as a modular monolith. Business capabilities are isolated by domain under src/modules/*, while shared cross-cutting concerns live in src/shared/*.
2. Request entry and runtime
The runtime starts in src/main.ts, which boots the Express application defined in src/app.ts. The app is the composition root: it wires middleware, module routes, error handling, logging, auth checks, and the WebSocket server.
3. Layering inside each module
Each module follows a clean Architecture-style flow:
- presentation/http: Express controllers, routes, and Zod schemas
- application/use-cases: orchestration and business operations
- domain: entities, repository contracts, and business rules
- infrastructure/persistence: Prisma-backed repository implementations
Dependencies flow inward only; controllers call use cases, and use cases depend on repository interfaces rather than Prisma directly.
4. Primary business modules
The implemented domains are:
- users: local user records, Clerk webhook sync, role reset
- vendors: vendor registration and listing
- catalog: categories and products, including product creation/update and public catalog reads
- orders: order creation, student/vendor order queries, order status updates, lifecycle rules
- auth: authenticated identity/me responses and protected route examples
notifications and payments exist as scaffolding but are not yet fully implemented.
5. Data access boundary
Persistence is abstracted through repository interfaces in each domain and implemented with Prisma in src/modules/*/infrastructure/persistence. The shared Prisma client sits in src/infrastructure/database/prismaClient.ts. The backing database is Supabase PostgreSQL, with migrations and seed data under prisma/.
6. Domain model and business rules
The repo emphasizes richer domain logic rather than fat controllers. Notable domain rules include:
- Money value object in src/shared/domain/value-objects/Money.ts
- order lifecycle logic in orders/domain/rules/OrderLifecycle.ts
- stock-related failure handling in orders/domain/rules/StockError.ts
This suggests important invariants are enforced in application/domain rather than only at the API layer.
7. Authentication and authorization flow
Authentication is handled with Clerk. Incoming protected requests go through requireAuth and requireRole middlewares, and token validation is backed by Clerk token verification utilities in src/infrastructure/external-services/clerk/. Roles are enforced at the HTTP boundary, with the API exposing RBAC-sensitive endpoints for student/vendor/admin-style access.
8. Webhook-driven user synchronization
Clerk user lifecycle events are received at the webhook route in the users module. The webhook controller verifies the request signature via Svix, then drives local user synchronization use cases. This is an important boundary: Clerk is the identity source, while the app keeps a local user projection for roles and business permissions.
9. HTTP API surface
Routes are grouped per module, not globally by concern. The catalog, vendors, orders, users, and auth modules each expose their own route files under presentation/http/routes. Validation is done with Zod schemas near the controllers, keeping request parsing close to the transport layer.
10. Shared infrastructure
src/shared contains cross-module utilities that affect architecture:
- centralized error handling
- request logging
- auth/role middleware
- Express type augmentation
- storage abstraction and a Supabase storage adapter
These are shared boundaries, not domain logic, and are reused by multiple modules.
11. External systems
The runtime depends materially on:
- Supabase/PostgreSQL for transactional persistence
- Clerk for authentication and identity events
- Svix for webhook verification
- a WebSocket server scaffold in src/infrastructure/websocket/socketServer.ts for real-time features such as order updates
12. Operational and delivery concerns
The repo is containerized with a Dockerfile and docker-compose.yml, and has GitHub Actions workflows for build, CI, QA, dev, and deploy. Database migrations are first-class via Prisma, indicating schema changes are part of the delivery pipeline.
13. Testing shape
The test suite is focused on unit testing use cases and domain rules, with mocks for repositories under tests/mocks. This reinforces the architecture: application and domain are intended to be testable without the database or HTTP layer.
Main entry points: app.ts app · prismaClient.ts Prisma client · http Users API · use-cases Order use cases
Components 25
Runtime
Process bootstrap and HTTP composition
Shared
Cross-cutting infrastructure and domain primitives
- Middleware · Request logging, auth, roles, and error handling
src/shared/middlewares - Money · Shared monetary value abstraction
src/shared/domain/value-objects/Money.ts - Storage · Shared storage contract and Supabase adapter
src/shared/domain/ports/storage.repository.ts
Users
User sync and role management
- Users API · User registration, sync webhook, and role reset endpoints
src/modules/users/presentation/http - User use cases · Registers, syncs, and resets local users
src/modules/users/application/use-cases - User repo · Prisma-backed user persistence implementation
src/modules/users/infrastructure/persistence/PrismaUserRepository.ts
Catalog
Categories and products
- Catalog API · Catalog read and product write endpoints
src/modules/catalog/presentation/http - Catalog use cases · Creates and updates products through domain rules
src/modules/catalog/application/use-cases - Catalog repo · Prisma-backed category and product repositories
src/modules/catalog/infrastructure/persistence
Orders
Order lifecycle and queries
- Orders API · Order creation, history, and status endpoints
src/modules/orders/presentation/http - Order use cases · Orchestrates order lifecycle and stock checks
src/modules/orders/application/use-cases - Order rules · Order entity plus lifecycle and stock errors
src/modules/orders/domain - Order repo · Prisma-backed order persistence implementation
src/modules/orders/infrastructure/persistence/PrismaOrderRepository.ts
Vendors
Vendor registration and listing
- Vendors API · Vendor registration and listing endpoints
src/modules/vendors/presentation/http - Vendor use cases · Registers vendors through domain rules
src/modules/vendors/application/use-cases - Vendor repo · Prisma-backed vendor persistence implementation
src/modules/vendors/infrastructure/persistence/PrismaVendorRepository.ts
Auth
Identity and protected route surface
- Auth API · Me / protected test route surface
src/modules/auth/presentation/http/routes
External
Outside systems and services
- Clerk verify · Validates Clerk tokens and webhook signatures
src/infrastructure/external-services/clerk - WebSocket · Socket server scaffold for live updates
src/infrastructure/websocket/socketServer.ts - Supabase · Transactional database and object storage backend
- Svix · Webhook signature verification provider
- Postgres · Supabase PostgreSQL backing store
Delivery
Database, migrations, and test support
- Prisma client · Shared Prisma connection used by module repositories
src/infrastructure/database/prismaClient.ts
Connections 29
- main → app: boots · Process entry initializes the Express composition root
- app → Middleware: uses · Applies shared HTTP middleware and error handling
- app → Users API: mounts · Registers module routes
- app → Catalog API: mounts · Registers module routes
- app → Orders API: mounts · Registers module routes
- app → Vendors API: mounts · Registers module routes
- app → Auth API: mounts · Registers module routes
- app → WebSocket: starts · Initializes realtime server scaffold
- Users API → User use cases: calls · HTTP controllers dispatch to use cases
- Users API → Clerk verify: verifies · Webhook controller checks Clerk/Svix signatures
- User use cases → User repo: persists · User orchestration reads and writes local users
- Users API → User repo: reads/writes · Presentation layer stays thin but uses repository-backed flows
- Catalog API → Catalog use cases: calls · Controllers trigger product and category flows
- Catalog use cases → Catalog repo: persists · Use cases depend on repository interfaces and Prisma adapters
- Catalog use cases → Money: uses · Product pricing relies on shared monetary primitive
- Orders API → Order use cases: calls · Controllers orchestrate order workflows
- Order use cases → Order rules: enforces · Application logic depends on domain rules and entities
- Order use cases → Order repo: persists · Order operations read and write through repository contracts
- Order use cases → Money: uses · Order totals use shared monetary primitive
- Vendors API → Vendor use cases: calls · Vendor endpoints dispatch to application layer
- Vendor use cases → Vendor repo: persists · Vendor registration is stored via repository implementation
- Auth API → Clerk verify: trusts · Protected route behavior depends on Clerk-backed auth state
- User repo → Prisma client: uses · Module repositories share the central Prisma client
- Catalog repo → Prisma client: uses · Module repositories share the central Prisma client
- Order repo → Prisma client: uses · Module repositories share the central Prisma client
- Vendor repo → Prisma client: uses · Module repositories share the central Prisma client
- Prisma client → Postgres: connects · Prisma targets the Supabase PostgreSQL database
- Storage → Supabase: adapts · Shared storage abstraction bridges to Supabase storage
- Clerk verify → Svix: verifies · Webhook boundary relies on Svix verification