# avishek23fe10cii00021/idempotent-payment-gateway architecture

> Architecture diagram of the GitHub repository avishek23fe10cii00021/idempotent-payment-gateway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/avishek23fe10cii00021/idempotent-payment-gateway
- Repository: https://github.com/avishek23fe10cii00021/idempotent-payment-gateway

## Overview

This is an Express payment gateway centered on retry-safe POST /charges: it validates a request, coordinates an idempotency claim or lease takeover, charges through a key-deduplicating processor, persists the charge, then stores and returns a replayable response. The README also documents conflict, decline, and in-progress outcomes. The schema is represented as the durable state boundary; migration/schema details and any real processor integration were not sampled, so no unsupported implementation links are inferred.

Main entry points: [`src/server.ts`](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/server.ts) (Charge routes), [`src/prismaClient.ts`](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/prismaClient.ts) (Prisma client), [`src/idempotency.ts`](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/idempotency.ts) (Idempotency runner), [`src/errors.ts`](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/errors.ts) (Idempotency errors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["Charge routes<br/>[server.ts]"]
end

subgraph group_coord["Idempotency coordination"]
  node_idem["Idempotency runner<br/>[idempotency.ts]"]
  node_errors["Idempotency errors<br/>[errors.ts]"]
end

subgraph group_payments["Charge processing"]
  node_processor["Fake processor<br/>[processor.ts]"]
end

subgraph group_state["Persistent state"]
  node_charge[("Charge records<br/>[server.ts]")]
  node_idemrecords[("Idempotency records<br/>[schema.prisma]")]
  node_client["Prisma client<br/>[prismaClient.ts]"]
end

node_caller(("API caller"))

node_caller -->|"submits charge"| node_server
node_server -->|"runs safely"| node_idem
node_server -->|"requests charge"| node_processor
node_server -->|"upserts charge"| node_charge
node_server -->|"uses database client"| node_client
node_idem -->|"claims and completes"| node_client
node_client -.->|"accesses records"| node_idemrecords
node_client -.->|"accesses records"| node_charge
node_idem -->|"throws conflicts"| node_errors
node_server -->|"maps outcomes"| node_errors
node_server -->|"returns response"| node_caller

click node_server "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/server.ts"
click node_idem "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/idempotency.ts"
click node_errors "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/errors.ts"
click node_processor "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/processor.ts"
click node_charge "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/server.ts"
click node_idemrecords "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/prisma/schema.prisma"
click node_client "https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/prismaClient.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 toneBlue
class node_idem,node_errors toneAmber
class node_processor,node_caller toneMint
class node_charge,node_idemrecords,node_client toneRose
```

## Components

### HTTP API

- [Charge routes](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/server.ts): `src/server.ts`

### Idempotency coordination

- [Idempotency runner](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/idempotency.ts): `src/idempotency.ts`
- [Idempotency errors](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/errors.ts): `src/errors.ts`

### Charge processing

- [Fake processor](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/processor.ts): `src/processor.ts`

### Persistent state

- [Charge records](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/server.ts): `src/server.ts`
- [Idempotency records](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Prisma client](https://github.com/avishek23fe10cii00021/idempotent-payment-gateway/blob/main/src/prismaClient.ts): `src/prismaClient.ts`

### Other components

- **API caller**

## Connections

- API caller → Charge routes: submits charge (evidence: `README.md`)
- Charge routes → Idempotency runner: runs safely (evidence: `src/server.ts`)
- Charge routes → Fake processor: requests charge (evidence: `src/server.ts`)
- Charge routes → Charge records: upserts charge (evidence: `src/server.ts`)
- Charge routes → Prisma client: uses database client (evidence: `src/server.ts`)
- Idempotency runner → Prisma client: claims and completes (evidence: `src/idempotency.ts`)
- Prisma client → Idempotency records: accesses records
- Prisma client → Charge records: accesses records (evidence: `src/server.ts`)
- Idempotency runner → Idempotency errors: throws conflicts (evidence: `src/idempotency.ts`)
- Charge routes → Idempotency errors: maps outcomes (evidence: `src/server.ts`)
- Charge routes → API caller: returns response (evidence: `README.md`)
