# mdyhakash/prisma-press architecture

> Architecture diagram of the GitHub repository mdyhakash/prisma-press, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mdyhakash/prisma-press
- Repository: https://github.com/mdyhakash/prisma-press

## Overview

1. **What this repo is**
   - This is a **TypeScript Node.js backend API** built around **Prisma ORM** and **JWT-based authentication**.
   - The repository is organized as a small, feature-oriented server with two main domains: **auth** and **user**.

2. **Application bootstrap**
   - `src/server.ts` is the process entrypoint: it starts the HTTP server.
   - `src/app.ts` is the application assembly layer: it wires middleware, routes, and shared app-level configuration before the server listens.

3. **Feature-module structure**
   - Business logic is split into modules under `src/modules/`.
   - Each module follows the same shape:
     - `*.route.ts` for endpoint definitions
     - `*.controller.ts` for request/response handling
     - `*.service.ts` for business logic and data access coordination
     - `*.interface.ts` for module-specific TypeScript contracts

4. **Auth subsystem**
   - `src/modules/auth` handles authentication concerns: likely login, token issuance, and related auth flows.
   - It depends on:
     - `src/utils/jwt.ts` for JWT creation/verification
     - `src/middlewares/auth.ts` for protecting routes
   - This makes auth a boundary that sits between public routes and protected application logic.

5. **User subsystem**
   - `src/modules/user` encapsulates user-facing CRUD or profile-related operations.
   - It is separate from auth, which suggests a clean split between **identity/session management** and **user data operations**.

6. **Request flow**
   - Incoming requests go from route handlers to controllers, then to services.
   - Services interact with the persistence layer through Prisma.
   - Responses are normalized through `src/utils/sendResponse.ts`, and async errors are centralized via `src/utils/catchAsync.ts`.

7. **Persistence layer**
   - `src/lib/prisma.ts` is the Prisma client singleton/connector used by services.
   - The database model is defined in `prisma/schema/` and evolved through `prisma/migrations/`.
   - This means the application relies on Prisma as the only direct database boundary, rather than raw SQL in the app layer.

8. **Schema organization**
   - Prisma schema is split into focused files:
     - `user.prisma`
     - `profile.prisma`
     - `enums.prisma`
     - `schema.prisma`
   - That separation indicates the domain model is intentionally modular, with user/profile as core entities and enums extracted for reuse.

9. **Configuration boundary**
   - `src/config/index.ts` centralizes environment/runtime configuration.
   - `prisma.config.ts` handles Prisma-specific configuration outside the app runtime.
   - This keeps deployment/runtime concerns separate from domain code.

10. **Cross-cutting middleware and utilities**
   - `src/middlewares/auth.ts` is the primary request boundary for authorization.
   - `catchAsync.ts` and `sendResponse.ts` standardize error handling and API output shape across modules.
   - These utilities reduce duplication and keep controllers thin.

11. **Documentation and ERD**
   - The README points to an ERD and includes an image in `public/prisma-press-erd.jpg`.
   - The diagram is the source of truth for the data model, which is especially important here because the codebase is schema-driven through Prisma.

12. **Overall architecture**
   - The system is a **layered backend**: HTTP layer → controller layer → service layer → Prisma/database.
   - Its main architectural boundaries are:
     - **API transport** (`app.ts`, `server.ts`, routes/controllers)
     - **Domain modules** (`auth`, `user`)
     - **Persistence** (`lib/prisma.ts`, Prisma schemas, migrations)
     - **Shared infrastructure** (`config`, middleware, utils)

Main entry points: [`src/app.ts`](https://github.com/mdyhakash/prisma-press/blob/main/src/app.ts) (App), [`src/modules/auth/auth.controller.ts`](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.controller.ts) (Auth Controller), [`src/modules/user/user.controller.ts`](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.controller.ts) (User Controller), [`src/lib/prisma.ts`](https://github.com/mdyhakash/prisma-press/blob/main/src/lib/prisma.ts) (Prisma Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime/API"]
  node_src_server["Server<br/>entrypoint<br/>[server.ts]"]
  node_src_app["App<br/>composition root<br/>[app.ts]"]
end

subgraph group_features["Features"]
  node_auth_route["Auth Routes<br/>route module<br/>[auth.route.ts]"]
  node_auth_controller["Auth Controller<br/>[auth.controller.ts]"]
  node_auth_service["Auth Service<br/>[auth.service.ts]"]
  node_user_route["User Routes<br/>route module<br/>[user.route.ts]"]
  node_user_controller["User Controller<br/>[user.controller.ts]"]
  node_user_service["User Service<br/>[user.service.ts]"]
end

subgraph group_infrastructure["Infrastructure"]
  node_auth_middleware["Auth Middleware<br/>request guard<br/>[auth.ts]"]
  node_jwt_util["JWT Utils<br/>token helper<br/>[jwt.ts]"]
  node_catch_async["Async Wrapper<br/>error helper<br/>[catchAsync.ts]"]
  node_send_response["Response Helper<br/>api helper<br/>[sendResponse.ts]"]
  node_config["Config<br/>[index.ts]"]
end

subgraph group_persistence["Persistence"]
  node_prisma_client[("Prisma Client<br/>db connector<br/>[prisma.ts]")]
  node_prisma_schema["Prisma Schema<br/>data model<br/>[schema.prisma]"]
  node_prisma_migrations["Migrations<br/>schema history<br/>[migration.sql]"]
  node_prisma_config["Prisma Config<br/>tool config<br/>[prisma.config.ts]"]
end

node_src_server -->|"bootstraps"| node_src_app
node_src_app -->|"mounts"| node_auth_route
node_src_app -->|"mounts"| node_user_route
node_auth_route -->|"invokes"| node_auth_controller
node_user_route -->|"invokes"| node_user_controller
node_auth_controller -->|"delegates"| node_auth_service
node_user_controller -->|"delegates"| node_user_service
node_auth_service -->|"uses"| node_jwt_util
node_auth_route -->|"protects"| node_auth_middleware
node_auth_controller -->|"wraps"| node_catch_async
node_user_controller -->|"wraps"| node_catch_async
node_auth_controller -->|"formats"| node_send_response
node_user_controller -->|"formats"| node_send_response
node_auth_service -->|"queries"| node_prisma_client
node_user_service -->|"queries"| node_prisma_client
node_prisma_client -->|"models"| node_prisma_schema
node_prisma_client -->|"migrates"| node_prisma_migrations
node_src_app -->|"reads"| node_config
node_prisma_config -->|"targets"| node_prisma_schema

click node_src_server "https://github.com/mdyhakash/prisma-press/blob/main/src/server.ts"
click node_src_app "https://github.com/mdyhakash/prisma-press/blob/main/src/app.ts"
click node_auth_route "https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.route.ts"
click node_auth_controller "https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.controller.ts"
click node_auth_service "https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.service.ts"
click node_user_route "https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.route.ts"
click node_user_controller "https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.controller.ts"
click node_user_service "https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.service.ts"
click node_auth_middleware "https://github.com/mdyhakash/prisma-press/blob/main/src/middlewares/auth.ts"
click node_jwt_util "https://github.com/mdyhakash/prisma-press/blob/main/src/utils/jwt.ts"
click node_catch_async "https://github.com/mdyhakash/prisma-press/blob/main/src/utils/catchAsync.ts"
click node_send_response "https://github.com/mdyhakash/prisma-press/blob/main/src/utils/sendResponse.ts"
click node_config "https://github.com/mdyhakash/prisma-press/blob/main/src/config/index.ts"
click node_prisma_client "https://github.com/mdyhakash/prisma-press/blob/main/src/lib/prisma.ts"
click node_prisma_schema "https://github.com/mdyhakash/prisma-press/blob/main/prisma/schema/schema.prisma"
click node_prisma_migrations "https://github.com/mdyhakash/prisma-press/blob/main/prisma/migrations/20260622092935_init/migration.sql"
click node_prisma_config "https://github.com/mdyhakash/prisma-press/blob/main/prisma.config.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_server,node_src_app toneBlue
class node_auth_route,node_auth_controller,node_auth_service,node_user_route,node_user_controller,node_user_service toneAmber
class node_auth_middleware,node_jwt_util,node_catch_async,node_send_response,node_config toneMint
class node_prisma_client,node_prisma_schema,node_prisma_migrations,node_prisma_config toneRose
```

## Components

### Runtime/API

HTTP bootstrap and request handling layers

- [Server](https://github.com/mdyhakash/prisma-press/blob/main/src/server.ts): entrypoint · Starts the HTTP process · `src/server.ts`
- [App](https://github.com/mdyhakash/prisma-press/blob/main/src/app.ts): composition root · Assembles middleware and routes · `src/app.ts`

### Features

Domain modules for auth and user operations

- [Auth Routes](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.route.ts): route module · Authentication endpoints · `src/modules/auth/auth.route.ts`
- [Auth Controller](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.controller.ts): controller · Handles auth requests and responses · `src/modules/auth/auth.controller.ts`
- [Auth Service](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/auth/auth.service.ts): service · Auth business logic and token flow · `src/modules/auth/auth.service.ts`
- [User Routes](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.route.ts): route module · User endpoints · `src/modules/user/user.route.ts`
- [User Controller](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.controller.ts): controller · Handles user requests and responses · `src/modules/user/user.controller.ts`
- [User Service](https://github.com/mdyhakash/prisma-press/blob/main/src/modules/user/user.service.ts): service · User business logic and persistence coordination · `src/modules/user/user.service.ts`

### Infrastructure

Shared config, middleware, and utilities

- [Auth Middleware](https://github.com/mdyhakash/prisma-press/blob/main/src/middlewares/auth.ts): request guard · Protects authenticated routes · `src/middlewares/auth.ts`
- [JWT Utils](https://github.com/mdyhakash/prisma-press/blob/main/src/utils/jwt.ts): token helper · Signs and verifies JWTs · `src/utils/jwt.ts`
- [Async Wrapper](https://github.com/mdyhakash/prisma-press/blob/main/src/utils/catchAsync.ts): error helper · Centralized async error handling · `src/utils/catchAsync.ts`
- [Response Helper](https://github.com/mdyhakash/prisma-press/blob/main/src/utils/sendResponse.ts): api helper · Normalizes API responses · `src/utils/sendResponse.ts`
- [Config](https://github.com/mdyhakash/prisma-press/blob/main/src/config/index.ts): runtime config · Environment and app settings · `src/config/index.ts`

### Persistence

Prisma client, schema, and migrations

- [Prisma Client](https://github.com/mdyhakash/prisma-press/blob/main/src/lib/prisma.ts): db connector · Singleton database access layer · `src/lib/prisma.ts`
- [Prisma Schema](https://github.com/mdyhakash/prisma-press/blob/main/prisma/schema/schema.prisma): data model · Domain schema split across Prisma files · `prisma/schema/schema.prisma`
- [Migrations](https://github.com/mdyhakash/prisma-press/blob/main/prisma/migrations/20260622092935_init/migration.sql): schema history · Database migration history · `prisma/migrations/20260622092935_init/migration.sql`
- [Prisma Config](https://github.com/mdyhakash/prisma-press/blob/main/prisma.config.ts): tool config · Prisma tooling configuration · `prisma.config.ts`

## Connections

- Server → App: bootstraps · Server starts the assembled application
- App → Auth Routes: mounts · App registers auth routes
- App → User Routes: mounts · App registers user routes
- Auth Routes → Auth Controller: invokes · Routes dispatch to controller handlers
- User Routes → User Controller: invokes · Routes dispatch to controller handlers
- Auth Controller → Auth Service: delegates · Controller forwards business logic to service
- User Controller → User Service: delegates · Controller forwards business logic to service
- Auth Service → JWT Utils: uses · Auth service issues and validates tokens
- Auth Routes → Auth Middleware: protects · Middleware gates authenticated endpoints
- Auth Controller → Async Wrapper: wraps · Async request handling is centralized
- User Controller → Async Wrapper: wraps · Async request handling is centralized
- Auth Controller → Response Helper: formats · Responses are standardized
- User Controller → Response Helper: formats · Responses are standardized
- Auth Service → Prisma Client: queries · Service reads/writes through Prisma
- User Service → Prisma Client: queries · Service reads/writes through Prisma
- Prisma Client → Prisma Schema: models · Client is generated from schema
- Prisma Client → Migrations: migrates · Database shape is tracked by migrations
- App → Config: reads · App loads runtime configuration
- Prisma Config → Prisma Schema: targets · Tooling is configured around the schema
