# chirag-mukhija/paytmentgateway architecture

> Architecture diagram of the GitHub repository chirag-mukhija/paytmentgateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chirag-mukhija/paytmentgateway
- Repository: https://github.com/chirag-mukhija/paytmentgateway

## Overview

PaytmentGateway is an Express payment API backed by PostgreSQL. A merchant client sends requests to the running server; payment routes authenticate the merchant, then handlers validate and dispatch create, retrieve, or list operations to the payment service. The service reads and writes payment records and creates an initial audit event transactionally. The sampled code shows request logging and centralized error handling as supporting layers. The README describes the project broadly as a backend/database learning project, but gives no additional product capabilities; the graph therefore reflects only evidenced runtime behavior.

Main entry points: [`src/app.js`](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/app.js) (Express app), [`src/routes/payments.js`](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/routes/payments.js) (Payment routes), [`src/middleware/auth.js`](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/auth.js) (Merchant auth), [`src/services/paymentService.js`](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/services/paymentService.js) (Payment service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["HTTP runtime"]
  node_server["Server entry<br/>[index.js]"]
  node_app["Express app<br/>[app.js]"]
  node_logger["Request logger<br/>[requestLogger.js]"]
  node_errors["Error handler<br/>[errorHandler.js]"]
end

subgraph group_security["Merchant access"]
  node_routes["Payment routes<br/>[payments.js]"]
  node_auth["Merchant auth<br/>[auth.js]"]
end

subgraph group_payments["Payment operations"]
  node_controller["Payment handlers"]
  node_service["Payment service<br/>[paymentService.js]"]
end

subgraph group_persistence["Persistence"]
  node_pool["Postgres pool<br/>[db.js]"]
  node_database[("Payment database<br/>[schema.sql]")]
end

node_merchant(("Merchant client"))

node_merchant -->|"sends requests"| node_server
node_server -->|"starts"| node_app
node_app -->|"registers"| node_logger
node_app -->|"mounts"| node_routes
node_app -->|"registers"| node_errors
node_routes -->|"guards routes"| node_auth
node_routes -->|"dispatches"| node_controller
node_auth -->|"looks up merchant"| node_pool
node_controller -->|"calls operations"| node_service
node_service -->|"queries"| node_pool
node_pool -.->|"connects"| node_database
node_auth -->|"checks API key"| node_database
node_service -->|"reads and writes"| node_database

click node_server "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/index.js"
click node_app "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/app.js"
click node_logger "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/requestLogger.js"
click node_errors "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/errorHandler.js"
click node_routes "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/routes/payments.js"
click node_auth "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/auth.js"
click node_controller "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/controllers/paymentController.js"
click node_service "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/services/paymentService.js"
click node_pool "https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/config/db.js"
click node_database "https://github.com/chirag-mukhija/paytmentgateway/blob/main/db/schema.sql"

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_logger,node_errors,node_merchant toneBlue
class node_routes,node_auth toneAmber
class node_controller,node_service toneMint
class node_pool,node_database toneRose
```

## Components

### HTTP runtime

- [Server entry](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/index.js): `src/index.js`
- [Express app](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/app.js): `src/app.js`
- [Request logger](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/requestLogger.js): `src/middleware/requestLogger.js`
- [Error handler](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/errorHandler.js): `src/middleware/errorHandler.js`

### Merchant access

- [Payment routes](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/routes/payments.js): `src/routes/payments.js`
- [Merchant auth](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/middleware/auth.js): `src/middleware/auth.js`

### Payment operations

- [Payment handlers](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/controllers/paymentController.js): `src/controllers/paymentController.js`
- [Payment service](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/services/paymentService.js): `src/services/paymentService.js`

### Persistence

- [Postgres pool](https://github.com/chirag-mukhija/paytmentgateway/blob/main/src/config/db.js): `src/config/db.js`
- [Payment database](https://github.com/chirag-mukhija/paytmentgateway/blob/main/db/schema.sql): `db/schema.sql`

### Other components

- **Merchant client**

## Connections

- Merchant client → Server entry: sends requests
- Server entry → Express app: starts (evidence: `src/index.js`)
- Express app → Request logger: registers (evidence: `src/app.js`)
- Express app → Payment routes: mounts (evidence: `src/app.js`)
- Express app → Error handler: registers (evidence: `src/app.js`)
- Payment routes → Merchant auth: guards routes (evidence: `src/routes/payments.js`)
- Payment routes → Payment handlers: dispatches (evidence: `src/routes/payments.js`)
- Merchant auth → Postgres pool: looks up merchant (evidence: `src/middleware/auth.js`)
- Payment handlers → Payment service: calls operations (evidence: `src/controllers/paymentController.js`)
- Payment service → Postgres pool: queries (evidence: `src/services/paymentService.js`)
- Postgres pool → Payment database: connects (evidence: `src/config/db.js`)
- Merchant auth → Payment database: checks API key (evidence: `src/middleware/auth.js`)
- Payment service → Payment database: reads and writes (evidence: `src/services/paymentService.js`)
