# smlimonparvez/medi-store-back-end architecture

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

- Interactive diagram: https://gitdiagram.com/smlimonparvez/medi-store-back-end
- Repository: https://github.com/smlimonparvez/medi-store-back-end

## Overview

1. **Overall shape**
   - This is a layered Node.js backend built with **Express + TypeScript**.
   - The main execution path is: **entrypoint → Express app → middleware → route → controller → service → Prisma → PostgreSQL**.

2. **Entrypoints and deployment boundary**
   - `src/server.ts` is the normal server startup entrypoint.
   - `api/index.ts` suggests a **serverless/Vercel-compatible entrypoint**, and `vercel.json` confirms the repo is prepared for that deployment model.
   - `src/app.ts` likely contains the Express app configuration shared by both startup paths.

3. **API composition**
   - The API is split into feature modules under `src/modules/*`.
   - Each module has a consistent three-part structure: `*.route.ts`, `*.controller.ts`, and `*.service.ts`.
   - This creates a clear boundary between HTTP concerns, request handling, and business logic.

4. **Feature domains**
   - The main domains are **auth, admin, seller, medicine, category, order, payment, review**.
   - The README’s route list matches this modular structure, with endpoints mounted under `/api/auth`, `/api/medicines`, `/api/categories`, `/api/orders`, `/api/payments`, `/api/reviews`, `/api/sellers`, and `/api/admin`.

5. **Business logic layer**
   - Services are the core business boundary.
   - Controllers should be thin: they parse the request, call a service, and return a standardized response.
   - The service layer is where domain rules such as role-specific behavior, ordering, and payment handling are likely centralized.

6. **Persistence layer**
   - Data access is handled through **Prisma ORM** in `src/config/prisma.ts` and the `prisma/` directory.
   - `prisma/schema.prisma` defines the database model, while `prisma/migrations/` manages schema evolution.
   - The primary backing store is **PostgreSQL**.

7. **Authentication and authorization**
   - Authentication is based on **JWT**.
   - `src/middlewares/auth.middleware.ts` likely enforces protected routes and role checks.
   - The app supports role-based access for **Customer, Seller, and Admin**, so authorization is an architectural concern, not just a feature.

8. **Cross-cutting middleware**
   - `src/middlewares/error.middleware.ts` centralizes error handling.
   - `src/middlewares/rateLimiter.middleware.ts` protects the API from abuse.
   - Security-related concerns also include **CORS** and password hashing via **bcrypt**, both called out in the README.

9. **Validation and response handling**
   - Request validation is handled with **Zod**, via `src/utils/schemas.ts` and `src/utils/validate.ts`.
   - `src/utils/AppError.ts`, `catchAsync.ts`, and `sendResponse.ts` indicate a standardized error/async/response pattern across modules.
   - This means the API likely returns consistent envelopes and error shapes regardless of module.

10. **Payment boundary**
   - Payments are isolated in `src/modules/payment/*`.
   - The README says **Stripe integration with webhooks**, so the payment module is the main boundary to an external payment provider.
   - Order/payment state changes probably flow through this module rather than directly from order handling.

11. **Domain data flow**
   - Typical flow: client request enters a route, passes auth/rate-limit/validation, reaches a controller, then a service reads/writes via Prisma, and the result is formatted back to the client.
   - For payment-related flows, an additional asynchronous path exists through **Stripe webhooks**, which can update order/payment state after the initial request.

12. **Database lifecycle and bootstrap data**
   - `prisma/migrations` shows schema changes are managed explicitly and versioned.
   - `prisma/seed.ts` provides initial or demo data, which is useful for bootstrapping categories, medicines, roles, or test users.

13. **What to draw in an architecture diagram**
   - A good diagram should show:
     - Clients calling the Express API
     - Shared middleware around every request
     - Separate feature modules with controller/service layers
     - Prisma as the sole persistence gateway
     - PostgreSQL as the database
     - Stripe as an external payment system with webhook callbacks
     - JWT-based auth and role checks as a cross-cutting control layer

Main entry points: [`src/app.ts`](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/app.ts) (Express app), [`src/config/prisma.ts`](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/config/prisma.ts) (Prisma client), [`src/utils/sendResponse.ts`](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/utils/sendResponse.ts) (Response helpers), [`src/modules/payment/payment.route.ts`](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/payment/payment.route.ts) (Payment module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Entrypoints"]
  node_n1(("Client<br/>consumer"))
  node_n2["Serverless entry<br/>vercel entrypoint<br/>[index.ts]"]
  node_n3["Server startup<br/>node entrypoint<br/>[server.ts]"]
end

subgraph group_g2["API Layer"]
  node_n4["Express app<br/>app composition<br/>[app.ts]"]
  node_n5["Auth guard<br/>middleware<br/>[auth.middleware.ts]"]
  node_n6["Rate limit<br/>middleware"]
  node_n7["Error handler<br/>middleware"]
  node_n8["Response helpers<br/>[sendResponse.ts]"]
end

subgraph group_g3["Domain Modules"]
  node_n9["Auth module<br/>feature module<br/>[auth.route.ts]"]
  node_n10["Admin module<br/>feature module<br/>[admin.route.ts]"]
  node_n11["Seller module<br/>feature module<br/>[seller.route.ts]"]
  node_n12["Catalog module<br/>feature module<br/>[medicine.route.ts]"]
  node_n13["Order module<br/>feature module<br/>[order.route.ts]"]
  node_n14["Payment module<br/>feature module<br/>[payment.route.ts]"]
  node_n15["Review module<br/>feature module<br/>[review.route.ts]"]
end

subgraph group_g4["Data & Integrations"]
  node_n16["Prisma client<br/>orm gateway<br/>[prisma.ts]"]
  node_n17["Schema & migrations<br/>db schema<br/>[schema.prisma]"]
  node_n18[("PostgreSQL<br/>database")]
  node_n19(("Stripe<br/>payment provider"))
end

node_n1 -->|"HTTP requests"| node_n2
node_n1 -->|"HTTP requests"| node_n3
node_n2 -->|"bootstraps"| node_n4
node_n3 -->|"bootstraps"| node_n4
node_n4 -->|"protects routes"| node_n5
node_n4 -->|"throttles"| node_n6
node_n4 -->|"handles failures"| node_n7
node_n4 -->|"mounts"| node_n9
node_n4 -->|"mounts"| node_n10
node_n4 -->|"mounts"| node_n11
node_n4 -->|"mounts"| node_n12
node_n4 -->|"mounts"| node_n13
node_n4 -->|"mounts"| node_n14
node_n4 -->|"mounts"| node_n15
node_n9 -->|"uses"| node_n8
node_n10 -->|"uses"| node_n8
node_n11 -->|"uses"| node_n8
node_n12 -->|"uses"| node_n8
node_n13 -->|"uses"| node_n8
node_n14 -->|"uses"| node_n8
node_n15 -->|"uses"| node_n8
node_n9 -->|"reads/writes"| node_n16
node_n10 -->|"reads/writes"| node_n16
node_n11 -->|"reads/writes"| node_n16
node_n12 -->|"reads/writes"| node_n16
node_n13 -->|"reads/writes"| node_n16
node_n14 -->|"reads/writes"| node_n16
node_n15 -->|"reads/writes"| node_n16
node_n16 -->|"connects to"| node_n18
node_n16 -->|"manages schema"| node_n17
node_n14 -->|"charges via"| node_n19
node_n19 -.->|"webhooks"| node_n14

click node_n2 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/api/index.ts"
click node_n3 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/server.ts"
click node_n4 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/app.ts"
click node_n5 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/middlewares/auth.middleware.ts"
click node_n6 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/middlewares/rateLimiter.middleware.ts"
click node_n7 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/middlewares/error.middleware.ts"
click node_n8 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/utils/sendResponse.ts"
click node_n9 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/auth/auth.route.ts"
click node_n10 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/admin/admin.route.ts"
click node_n11 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/seller/seller.route.ts"
click node_n12 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/medicine/medicine.route.ts"
click node_n13 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/order/order.route.ts"
click node_n14 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/payment/payment.route.ts"
click node_n15 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/review/review.route.ts"
click node_n16 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/config/prisma.ts"
click node_n17 "https://github.com/smlimonparvez/medi-store-back-end/blob/main/prisma/schema.prisma"

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_n1,node_n2,node_n3 toneBlue
class node_n4,node_n5,node_n6,node_n7,node_n8 toneAmber
class node_n9,node_n10,node_n11,node_n12,node_n13,node_n14,node_n15 toneMint
class node_n16,node_n17,node_n18,node_n19 toneRose
```

## Components

### Entrypoints

Runtime startup paths and deployment boundary.

- **Client**: consumer · External HTTP clients calling the API.
- [Serverless entry](https://github.com/smlimonparvez/medi-store-back-end/blob/main/api/index.ts): vercel entrypoint · Serverless-compatible entrypoint for deployment platforms. · `api/index.ts`
- [Server startup](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/server.ts): node entrypoint · Standard Node.js server bootstrap. · `src/server.ts`

### API Layer

Express app composition, middleware, and request handling.

- [Express app](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/app.ts): app composition · Shared Express application setup used by both entrypoints. · `src/app.ts`
- [Auth guard](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/middlewares/auth.middleware.ts): middleware · JWT authentication and role checks. · `src/middlewares/auth.middleware.ts`
- [Rate limit](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/middlewares/rateLimiter.middleware.ts): middleware · API abuse protection layer. · `src/middlewares/rateLimiter.middleware.ts`
- [Error handler](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/middlewares/error.middleware.ts): middleware · Centralized error formatting and handling. · `src/middlewares/error.middleware.ts`
- [Response helpers](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/utils/sendResponse.ts): utility · Shared async, error, validation, and response utilities. · `src/utils/sendResponse.ts`

### Domain Modules

Feature areas implemented as route-controller-service slices.

- [Auth module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/auth/auth.route.ts): feature module · Login, registration, and role-aware auth flows. · `src/modules/auth/auth.route.ts`
- [Admin module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/admin/admin.route.ts): feature module · Admin-only operations and controls. · `src/modules/admin/admin.route.ts`
- [Seller module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/seller/seller.route.ts): feature module · Seller-facing API and workflows. · `src/modules/seller/seller.route.ts`
- [Catalog module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/medicine/medicine.route.ts): feature module · Medicine and category catalog management. · `src/modules/medicine/medicine.route.ts`
- [Order module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/order/order.route.ts): feature module · Order creation and lifecycle management. · `src/modules/order/order.route.ts`
- [Payment module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/payment/payment.route.ts): feature module · Payment processing and webhook handling. · `src/modules/payment/payment.route.ts`
- [Review module](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/modules/review/review.route.ts): feature module · User reviews and product feedback. · `src/modules/review/review.route.ts`

### Data & Integrations

Persistence, schema lifecycle, and external service boundaries.

- [Prisma client](https://github.com/smlimonparvez/medi-store-back-end/blob/main/src/config/prisma.ts): orm gateway · Central database access layer. · `src/config/prisma.ts`
- [Schema & migrations](https://github.com/smlimonparvez/medi-store-back-end/blob/main/prisma/schema.prisma): db schema · Prisma schema, migrations, and seed lifecycle. · `prisma/schema.prisma`
- **PostgreSQL**: database · Primary persistent datastore.
- **Stripe**: payment provider · External payment system with webhook callbacks.

## Connections

- Client → Serverless entry: HTTP requests · Clients can enter through the serverless deployment path.
- Client → Server startup: HTTP requests · Clients can enter through the standard server process.
- Serverless entry → Express app: bootstraps · Serverless entry reuses the shared Express app.
- Server startup → Express app: bootstraps · Server startup initializes the shared Express app.
- Express app → Auth guard: protects routes · Authentication and role checks wrap protected handlers.
- Express app → Rate limit: throttles · Requests may be rate-limited before reaching modules.
- Express app → Error handler: handles failures · Unhandled errors are normalized at the app boundary.
- Express app → Auth module: mounts · Auth routes are mounted into the API.
- Express app → Admin module: mounts · Admin routes are mounted into the API.
- Express app → Seller module: mounts · Seller routes are mounted into the API.
- Express app → Catalog module: mounts · Catalog routes are mounted into the API.
- Express app → Order module: mounts · Order routes are mounted into the API.
- Express app → Payment module: mounts · Payment routes are mounted into the API.
- Express app → Review module: mounts · Review routes are mounted into the API.
- Auth module → Response helpers: uses · Controllers use shared response and validation helpers.
- Admin module → Response helpers: uses · Controllers use shared response and validation helpers.
- Seller module → Response helpers: uses · Controllers use shared response and validation helpers.
- Catalog module → Response helpers: uses · Controllers use shared response and validation helpers.
- Order module → Response helpers: uses · Controllers use shared response and validation helpers.
- Payment module → Response helpers: uses · Controllers use shared response and validation helpers.
- Review module → Response helpers: uses · Controllers use shared response and validation helpers.
- Auth module → Prisma client: reads/writes · Auth services persist through Prisma.
- Admin module → Prisma client: reads/writes · Admin services persist through Prisma.
- Seller module → Prisma client: reads/writes · Seller services persist through Prisma.
- Catalog module → Prisma client: reads/writes · Catalog services persist through Prisma.
- Order module → Prisma client: reads/writes · Order services persist through Prisma.
- Payment module → Prisma client: reads/writes · Payment services persist through Prisma.
- Review module → Prisma client: reads/writes · Review services persist through Prisma.
- Prisma client → PostgreSQL: connects to · Prisma is the gateway to PostgreSQL.
- Prisma client → Schema & migrations: manages schema · The schema and migrations define the database lifecycle.
- Payment module → Stripe: charges via · Payments integrate with Stripe as an external provider.
- Stripe → Payment module: webhooks · Stripe callbacks can update payment and order state asynchronously.
