# mdrakibmia99/swiftcart-apis architecture

> Architecture diagram of the GitHub repository mdrakibmia99/swiftcart-apis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mdrakibmia99/swiftcart-apis
- Repository: https://github.com/mdrakibmia99/swiftcart-apis

## Overview

#### Purpose and Runtime
SwiftCart is a TypeScript Node.js/Express REST backend for an e-commerce platform. It exposes APIs for catalog, shops, customer accounts, orders, reviews, promotions, and payments. MongoDB/Mongoose is the persistent store; it is deployable with Docker and Vercel configuration. Process entry is `src/server.ts`, which starts the Express application assembled in `src/app.ts`.

#### Application Composition and HTTP Boundary
The Express app centralizes middleware, route registration, missing-route handling, and global error translation in `src/app.ts`. The route aggregator is `src/app/routes/index.ts`; it mounts module route files, keeping transport concerns separate from domain implementations. Requests commonly traverse authentication, request parsing/validation, controller, service, and Mongoose model layers.
- `src/app.ts`
- `src/app/routes/index.ts`
- `src/app/middleware/globalErrorHandler.ts`

#### Authentication and Authorization
The auth domain owns registration/login and JWT-oriented credential flows, while the auth middleware protects downstream routes and likely establishes request identity/roles. User records are the account authority, with customer/shop concepts modeled separately for commerce-specific profiles and operations.
- `src/app/modules/auth/auth.routes.ts`
- `src/app/modules/auth/auth.service.ts`
- `src/app/middleware/auth.ts`
- `src/app/modules/user/user.model.ts`

#### Catalog and Seller Domain
Product discovery and management are centered on products, categories, brands, and shops. Each domain follows a consistent route → controller → service → model structure. Product query behavior is abstracted through a reusable query builder, establishing the search/filter/pagination boundary rather than embedding query logic in controllers.
- `src/app/modules/product/product.service.ts`
- `src/app/modules/shop/shop.service.ts`
- `src/app/modules/category/category.model.ts`
- `src/app/builder/QueryBuilder.ts`

#### Commerce Lifecycle
Order processing is the core transactional domain, backed by order persistence and service logic. Coupons and flash sales contribute pricing/promotion rules; reviews connect customers back to purchased/discovered products. Invoice PDF generation is an outbound artifact associated with order completion.
- `src/app/modules/order/order.service.ts`
- `src/app/modules/order/order.model.ts`
- `src/app/modules/coupon/coupon.service.ts`
- `src/app/modules/flashSell/flashSale.service.ts`
- `src/app/utils/generateOrderInvoicePDF.ts`

#### Payments and External Integrations
Payment behavior is split between a general payment module and an SSLCommerz-specific gateway module, including callback-facing routes. The configured external dependencies are Stripe/SSLCommerz for payments, Cloudinary for image storage/upload handling, and Nodemailer for email. These form integration boundaries around otherwise MongoDB-backed domain services.
- `src/app/modules/payment/payment.service.ts`
- `src/app/modules/sslcommerz/sslcommerz.service.ts`
- `src/app/config/cloudinary.config.ts`
- `src/app/config/multer.config.ts`
- `src/app/utils/emailHelper.ts`

#### Validation, Errors, and API Contracts
Module-specific validation files enforce input contracts before services operate. Typed application errors and dedicated Mongo/Mongoose/Zod error mappers converge at the global error handler, providing a consistent client-facing failure boundary. Controllers use shared async and response utilities to normalize successful and failed request execution.
- `src/app/middleware/validateRequest.ts`
- `src/app/errors/appError.ts`
- `src/app/errors/handleValidationError.ts`
- `src/app/utils/catchAsync.ts`
- `src/app/utils/sendResponse.ts`

Main entry points: [`src/app/routes/index.ts`](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/routes/index.ts) (Route registry), [`src/app/modules/order/order.service.ts`](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/order/order.service.ts) (Orders), [`src/app/modules/product/product.service.ts`](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/product/product.service.ts) (Catalog and shops), [`src/app.ts`](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app.ts) (Express app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_server["Server entry<br/>Node runtime<br/>[server.ts]"]
  node_app["Express app<br/>application composition<br/>[app.ts]"]
  node_routes["Route registry<br/>route aggregator<br/>[index.ts]"]
  node_auth_middleware["Auth middleware<br/>JWT authorization<br/>[auth.ts]"]
  node_validation["Request validation<br/>middleware<br/>[validateRequest.ts]"]
  node_error_handler["Global error handler<br/>error boundary"]
end

subgraph group_domains["Commerce Domains"]
  node_auth["Authentication<br/>auth service<br/>[auth.service.ts]"]
  node_users[("User accounts<br/>Mongoose model<br/>[user.model.ts]")]
  node_catalog["Catalog and shops<br/>domain services<br/>[product.service.ts]"]
  node_categories[("Categories<br/>Mongoose model<br/>[category.model.ts]")]
  node_orders["Orders<br/>order service<br/>[order.service.ts]"]
  node_order_store[("Order records<br/>Mongoose model<br/>[order.model.ts]")]
  node_promotions["Promotions<br/>pricing services<br/>[coupon.service.ts]"]
  node_payments["Payments<br/>payment services<br/>[payment.service.ts]"]
end

subgraph group_platform["Platform Services"]
  node_query_builder["Query builder<br/>query abstraction<br/>[QueryBuilder.ts]"]
  node_invoice["Invoice PDF<br/>document generator"]
end

subgraph group_integrations["External Integrations"]
  node_mongodb[("MongoDB<br/>persistent store")]
  node_payment_gateways{{"Stripe / SSLCommerz<br/>payment providers"}}
  node_media{{"Cloudinary uploads<br/>media storage"}}
  node_email{{"Email delivery<br/>Nodemailer integration<br/>[emailHelper.ts]"}}
end

node_server -->|"starts"| node_app
node_app -->|"registers"| node_routes
node_app -->|"uses"| node_error_handler
node_routes -->|"validates requests"| node_validation
node_routes -->|"protects routes"| node_auth_middleware
node_routes -->|"auth endpoints"| node_auth
node_routes -->|"catalog endpoints"| node_catalog
node_routes -->|"order endpoints"| node_orders
node_routes -->|"payment callbacks"| node_payments
node_auth_middleware -->|"resolves identity"| node_users
node_auth -->|"manages accounts"| node_users
node_catalog -->|"organizes products"| node_categories
node_catalog -->|"builds discovery queries"| node_query_builder
node_catalog -->|"persists"| node_mongodb
node_orders -->|"persists"| node_order_store
node_orders -->|"applies pricing rules"| node_promotions
node_orders -->|"collects payment"| node_payments
node_orders -->|"generates on completion"| node_invoice
node_order_store -->|"stored in"| node_mongodb
node_payments -->|"charges via"| node_payment_gateways
node_catalog -->|"stores product images"| node_media
node_orders -->|"sends notifications"| node_email
node_validation -.->|"validation failures"| node_error_handler

click node_server "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/server.ts"
click node_app "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app.ts"
click node_routes "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/routes/index.ts"
click node_auth_middleware "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/middleware/auth.ts"
click node_validation "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/middleware/validateRequest.ts"
click node_error_handler "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/middleware/globalErrorHandler.ts"
click node_auth "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/auth/auth.service.ts"
click node_users "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/user/user.model.ts"
click node_catalog "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/product/product.service.ts"
click node_categories "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/category/category.model.ts"
click node_query_builder "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/builder/QueryBuilder.ts"
click node_orders "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/order/order.service.ts"
click node_order_store "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/order/order.model.ts"
click node_promotions "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/coupon/coupon.service.ts"
click node_payments "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/payment/payment.service.ts"
click node_invoice "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/utils/generateOrderInvoicePDF.ts"
click node_media "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/config/cloudinary.config.ts"
click node_email "https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/utils/emailHelper.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_server,node_app,node_routes,node_auth_middleware,node_validation,node_error_handler toneBlue
class node_auth,node_users,node_catalog,node_categories,node_orders,node_order_store,node_promotions,node_payments toneAmber
class node_query_builder,node_invoice toneMint
class node_mongodb,node_payment_gateways,node_media,node_email toneRose
```

## Components

### HTTP API

- [Server entry](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/server.ts): Node runtime · Starts the Express application. · `src/server.ts`
- [Express app](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app.ts): application composition · Configures middleware, routes, and error handling. · `src/app.ts`
- [Route registry](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/routes/index.ts): route aggregator · Mounts module HTTP routes. · `src/app/routes/index.ts`
- [Auth middleware](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/middleware/auth.ts): JWT authorization · Protects routes and establishes request identity. · `src/app/middleware/auth.ts`
- [Request validation](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/middleware/validateRequest.ts): middleware · Enforces module input contracts. · `src/app/middleware/validateRequest.ts`
- [Global error handler](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/middleware/globalErrorHandler.ts): error boundary · Translates application and validation failures to API responses. · `src/app/middleware/globalErrorHandler.ts`

### Commerce Domains

- [Authentication](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/auth/auth.service.ts): auth service · Registration, login, and credential flows. · `src/app/modules/auth/auth.service.ts`
- [User accounts](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/user/user.model.ts): Mongoose model · Account authority for identities and roles. · `src/app/modules/user/user.model.ts`
- [Catalog and shops](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/product/product.service.ts): domain services · Product discovery and seller/shop management. · `src/app/modules/product/product.service.ts`
- [Categories](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/category/category.model.ts): Mongoose model · `src/app/modules/category/category.model.ts`
- [Orders](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/order/order.service.ts): order service · Core transactional commerce lifecycle. · `src/app/modules/order/order.service.ts`
- [Order records](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/order/order.model.ts): Mongoose model · `src/app/modules/order/order.model.ts`
- [Promotions](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/coupon/coupon.service.ts): pricing services · Coupon and flash-sale pricing rules. · `src/app/modules/coupon/coupon.service.ts`
- [Payments](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/modules/payment/payment.service.ts): payment services · General payment processing and SSLCommerz gateway handling. · `src/app/modules/payment/payment.service.ts`

### Platform Services

- [Query builder](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/builder/QueryBuilder.ts): query abstraction · Applies catalog search, filters, and pagination. · `src/app/builder/QueryBuilder.ts`
- [Invoice PDF](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/utils/generateOrderInvoicePDF.ts): document generator · Produces order-completion invoice artifacts. · `src/app/utils/generateOrderInvoicePDF.ts`

### External Integrations

- **MongoDB**: persistent store · Mongoose-backed domain persistence.
- **Stripe / SSLCommerz**: payment providers · External payment gateway boundary.
- [Cloudinary uploads](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/config/cloudinary.config.ts): media storage · Image upload and storage boundary. · `src/app/config/cloudinary.config.ts`
- [Email delivery](https://github.com/mdrakibmia99/swiftcart-apis/blob/main/src/app/utils/emailHelper.ts): Nodemailer integration · `src/app/utils/emailHelper.ts`

## Connections

- Server entry → Express app: starts
- Express app → Route registry: registers
- Express app → Global error handler: uses
- Route registry → Request validation: validates requests
- Route registry → Auth middleware: protects routes
- Route registry → Authentication: auth endpoints
- Route registry → Catalog and shops: catalog endpoints
- Route registry → Orders: order endpoints
- Route registry → Payments: payment callbacks
- Auth middleware → User accounts: resolves identity
- Authentication → User accounts: manages accounts
- Catalog and shops → Categories: organizes products
- Catalog and shops → Query builder: builds discovery queries
- Catalog and shops → MongoDB: persists
- Orders → Order records: persists
- Orders → Promotions: applies pricing rules
- Orders → Payments: collects payment
- Orders → Invoice PDF: generates on completion
- Order records → MongoDB: stored in
- Payments → Stripe / SSLCommerz: charges via
- Catalog and shops → Cloudinary uploads: stores product images
- Orders → Email delivery: sends notifications
- Request validation → Global error handler: validation failures
