# lakshaycodes08/stripe-payment-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/lakshaycodes08/stripe-payment-gateway
- Repository: https://github.com/lakshaycodes08/stripe-payment-gateway

## Overview

This is a Fastify/MySQL payment backend. Clients can manage products and carts, create payments whose amounts are calculated server-side, and retrieve payment history; Stripe webhooks verify payment outcomes and update payment/cart state. The graph separates routing, controllers, domain services, persistence, and Stripe integration. Service internals are partly unsampled, so some service-to-database relationships rely on the SOURCE INDEX or README rather than inspected implementations.

Main entry points: [`src/app.ts`](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/app.ts) (Fastify bootstrap), [`src/db/connection.ts`](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/db/connection.ts) (MySQL database), [`src/modules/payments/payment.service.ts`](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.service.ts) (Payment service), [`src/modules/products/product.routes.ts`](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.routes.ts) (Product routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_app["Fastify bootstrap<br/>[app.ts]"]
end

subgraph group_catalog_cart["Catalog and cart"]
  node_product_routes["Product routes<br/>[product.routes.ts]"]
  node_product_controller["Product controller"]
  node_product_service["Product service<br/>[product.service.ts]"]
  node_cart_routes["Cart routes<br/>[cart.routes.ts]"]
  node_cart_controller["Cart controller<br/>[cart.controller.ts]"]
  node_cart_service["Cart service<br/>[cart.service.ts]"]
end

subgraph group_payment["Payment processing"]
  node_payment_routes["Payment routes<br/>[payment.routes.ts]"]
  node_payment_controller["Payment controller"]
  node_payment_service["Payment service<br/>[payment.service.ts]"]
  node_stripe_client["Stripe REST client<br/>[stripe.client.ts]"]
end

subgraph group_webhooks["Webhook processing"]
  node_webhook_routes["Webhook routes<br/>[webhook.routes.ts]"]
  node_webhook_controller["Webhook controller"]
  node_webhook_service["Webhook service<br/>[webhook.service.ts]"]
end

subgraph group_infrastructure["Shared infrastructure"]
  node_database[("MySQL database<br/>[connection.ts]")]
  node_config["Environment config<br/>[env.ts]"]
  node_errors["Error handler<br/>[errorHandler.ts]"]
end

node_client(("API client"))
node_stripe(("Stripe"))

node_app -->|"reads config"| node_config
node_app -->|"connects at startup"| node_database
node_app -->|"registers handler"| node_errors
node_app -->|"registers routes"| node_product_routes
node_app -->|"registers routes"| node_cart_routes
node_app -->|"registers routes"| node_payment_routes
node_app -->|"registers routes"| node_webhook_routes
node_client -->|"requests products"| node_product_routes
node_product_routes -->|"dispatches requests"| node_product_controller
node_product_controller -->|"calls service"| node_product_service
node_product_service -->|"queries products"| node_database
node_client -->|"requests cart"| node_cart_routes
node_cart_routes -->|"dispatches requests"| node_cart_controller
node_cart_controller -->|"calls service"| node_cart_service
node_cart_service -->|"queries cart"| node_database
node_client -->|"creates or lists payments"| node_payment_routes
node_payment_routes -->|"dispatches requests"| node_payment_controller
node_payment_controller -->|"calls service"| node_payment_service
node_payment_service -->|"reads and writes"| node_database
node_payment_service -->|"creates intent"| node_stripe_client
node_stripe_client -->|"calls REST API"| node_stripe
node_stripe -->|"sends events"| node_webhook_routes
node_webhook_routes -->|"dispatches event"| node_webhook_controller
node_webhook_controller -->|"verifies and processes"| node_webhook_service
node_webhook_service -->|"updates payment and cart"| node_database
node_database -->|"uses connection settings"| node_config

click node_app "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/app.ts"
click node_product_routes "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.routes.ts"
click node_product_controller "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.controller.ts"
click node_product_service "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.service.ts"
click node_cart_routes "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/cart/cart.routes.ts"
click node_cart_controller "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/cart/cart.controller.ts"
click node_cart_service "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/cart/cart.service.ts"
click node_payment_routes "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.routes.ts"
click node_payment_controller "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.controller.ts"
click node_payment_service "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.service.ts"
click node_stripe_client "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/stripe.client.ts"
click node_webhook_routes "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/webhooks/webhook.routes.ts"
click node_webhook_controller "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/webhooks/webhook.controller.ts"
click node_webhook_service "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/webhooks/webhook.service.ts"
click node_database "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/db/connection.ts"
click node_config "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/config/env.ts"
click node_errors "https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/plugins/errorHandler.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_app,node_client toneBlue
class node_product_routes,node_product_controller,node_product_service,node_cart_routes,node_cart_controller,node_cart_service toneAmber
class node_payment_routes,node_payment_controller,node_payment_service,node_stripe_client toneMint
class node_webhook_routes,node_webhook_controller,node_webhook_service toneRose
class node_database,node_config,node_errors,node_stripe toneIndigo
```

## Components

### API runtime

- [Fastify bootstrap](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/app.ts): `src/app.ts`

### Catalog and cart

- [Product routes](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.routes.ts): `src/modules/products/product.routes.ts`
- [Product controller](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.controller.ts): `src/modules/products/product.controller.ts`
- [Product service](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/products/product.service.ts): `src/modules/products/product.service.ts`
- [Cart routes](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/cart/cart.routes.ts): `src/modules/cart/cart.routes.ts`
- [Cart controller](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/cart/cart.controller.ts): `src/modules/cart/cart.controller.ts`
- [Cart service](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/cart/cart.service.ts): `src/modules/cart/cart.service.ts`

### Payment processing

- [Payment routes](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.routes.ts): `src/modules/payments/payment.routes.ts`
- [Payment controller](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.controller.ts): `src/modules/payments/payment.controller.ts`
- [Payment service](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/payment.service.ts): `src/modules/payments/payment.service.ts`
- [Stripe REST client](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/payments/stripe.client.ts): `src/modules/payments/stripe.client.ts`

### Webhook processing

- [Webhook routes](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/webhooks/webhook.routes.ts): `src/modules/webhooks/webhook.routes.ts`
- [Webhook controller](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/webhooks/webhook.controller.ts): `src/modules/webhooks/webhook.controller.ts`
- [Webhook service](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/modules/webhooks/webhook.service.ts): `src/modules/webhooks/webhook.service.ts`

### Shared infrastructure

- [MySQL database](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/db/connection.ts): `src/db/connection.ts`
- [Environment config](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/config/env.ts): `src/config/env.ts`
- [Error handler](https://github.com/lakshaycodes08/stripe-payment-gateway/blob/main/src/plugins/errorHandler.ts): `src/plugins/errorHandler.ts`

### Other components

- **API client**
- **Stripe**

## Connections

- Fastify bootstrap → Environment config: reads config (evidence: `src/app.ts`)
- Fastify bootstrap → MySQL database: connects at startup (evidence: `src/app.ts`)
- Fastify bootstrap → Error handler: registers handler (evidence: `src/app.ts`)
- Fastify bootstrap → Product routes: registers routes (evidence: `src/app.ts`)
- Fastify bootstrap → Cart routes: registers routes (evidence: `src/app.ts`)
- Fastify bootstrap → Payment routes: registers routes (evidence: `src/app.ts`)
- Fastify bootstrap → Webhook routes: registers routes (evidence: `src/app.ts`)
- API client → Product routes: requests products (evidence: `src/modules/products/product.routes.ts`)
- Product routes → Product controller: dispatches requests (evidence: `src/modules/products/product.routes.ts`)
- Product controller → Product service: calls service (evidence: `src/modules/products/product.controller.ts`)
- Product service → MySQL database: queries products (evidence: `src/modules/products/product.service.ts`)
- API client → Cart routes: requests cart
- Cart routes → Cart controller: dispatches requests (evidence: `src/modules/cart/cart.routes.ts`)
- Cart controller → Cart service: calls service (evidence: `src/modules/cart/cart.controller.ts`)
- Cart service → MySQL database: queries cart (evidence: `src/modules/cart/cart.service.ts`)
- API client → Payment routes: creates or lists payments (evidence: `README.md`)
- Payment routes → Payment controller: dispatches requests (evidence: `src/modules/payments/payment.routes.ts`)
- Payment controller → Payment service: calls service (evidence: `src/modules/payments/payment.controller.ts`)
- Payment service → MySQL database: reads and writes (evidence: `src/modules/payments/payment.service.ts`)
- Payment service → Stripe REST client: creates intent (evidence: `src/modules/payments/payment.service.ts`)
- Stripe REST client → Stripe: calls REST API (evidence: `README.md`)
- Stripe → Webhook routes: sends events (evidence: `README.md`)
- Webhook routes → Webhook controller: dispatches event (evidence: `src/modules/webhooks/webhook.routes.ts`)
- Webhook controller → Webhook service: verifies and processes (evidence: `src/modules/webhooks/webhook.controller.ts`)
- Webhook service → MySQL database: updates payment and cart (evidence: `src/modules/webhooks/webhook.service.ts`)
- MySQL database → Environment config: uses connection settings (evidence: `src/db/connection.ts`)
