# s-madii/ecommerce-api architecture

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

- Interactive diagram: https://gitdiagram.com/s-madii/ecommerce-api
- Repository: https://github.com/s-madii/ecommerce-api

## Overview

Commerce API is a FastAPI storefront backend. The main workflow runs from account authentication and catalog browsing through a persistent cart, locked-stock checkout, Stripe payment confirmation, and asynchronous confirmation email. The graph preserves documented caching, role controls, category management, and payment integration. Some router-to-service links are supported only by the README or module references; these are marked unverified where the exact call is not shown.

Main entry points: [`app/db/session.py`](https://github.com/s-madii/ecommerce-api/blob/main/app/db/session.py) (Async DB sessions), [`app/routers/payments.py`](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/payments.py) (Payment webhook), [`app/routers/auth.py`](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/auth.py) (Authentication routes), [`app/core/security.py`](https://github.com/s-madii/ecommerce-api/blob/main/app/core/security.py) (JWT and access control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_api_routes["API routes"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_security["JWT and access control<br/>[security.py]"]
  node_user_model["User accounts<br/>[user.py]"]
  node_schemas["Request and response schemas"]
end

subgraph group_commerce["Storefront domain"]
  node_catalog_routes["Catalog routes<br/>[products.py]"]
  node_catalog_service["Catalog service<br/>[product.py]"]
  node_categories["Category management<br/>[categories.py]"]
  node_cart_routes["Cart routes<br/>[cart.py]"]
  node_cart_service["Cart service<br/>[cart.py]"]
  node_product_model["Product inventory<br/>[product.py]"]
  node_cart_model["Cart state<br/>[cart.py]"]
  node_checkout_routes["Checkout routes<br/>[orders.py]"]
  node_order_service["Checkout and orders<br/>[order.py]"]
end

subgraph group_data["Persistence and cache"]
  node_database[("PostgreSQL")]
  node_redis[("Redis cache and broker")]
  node_session["Async DB sessions<br/>[session.py]"]
end

subgraph group_payments["Payments and tasks"]
  node_order_model["Orders and payments<br/>[order.py]"]
  node_payment_routes["Payment webhook<br/>[payments.py]"]
  node_payment_service["Stripe payment service<br/>[payment.py]"]
  node_worker["Email task worker<br/>[worker.py]"]
end

subgraph group_foundation["Shared foundations"]
  node_config["Application settings<br/>[config.py]"]
  node_errors["Domain errors<br/>[exceptions.py]"]
end

node_customer(("Storefront user"))
node_stripe{{"Stripe"}}

node_customer -->|"signs up"| node_auth_routes
node_auth_routes -->|"queries and creates"| node_user_model
node_auth_routes -->|"creates token"| node_security
node_customer -->|"browses"| node_catalog_routes
node_catalog_routes -->|"delegates"| node_catalog_service
node_catalog_service -->|"reads and caches"| node_redis
node_catalog_service -->|"queries products"| node_product_model
node_customer -->|"views categories"| node_categories
node_customer -->|"manages cart"| node_cart_routes
node_cart_routes -->|"delegates"| node_cart_service
node_cart_service -->|"reads and updates"| node_cart_model
node_cart_service -->|"checks stock"| node_product_model
node_customer -->|"checks out"| node_checkout_routes
node_checkout_routes -.->|"delegates"| node_order_service
node_order_service -->|"locks stock"| node_product_model
node_order_service -->|"creates order"| node_order_model
node_order_service -->|"creates intent"| node_payment_service
node_payment_service -->|"creates intent"| node_stripe
node_stripe -->|"sends webhook"| node_payment_routes
node_payment_routes -->|"verifies signature"| node_payment_service
node_payment_routes -->|"confirms payment"| node_order_model
node_payment_routes -->|"dispatches email"| node_worker
node_worker -->|"uses broker"| node_redis
node_api_routes -.->|"validates and serializes"| node_schemas
node_auth_routes -->|"uses DB session"| node_session
node_catalog_routes -->|"uses DB session"| node_session
node_cart_routes -->|"uses DB session"| node_session
node_payment_routes -->|"uses DB session"| node_session
node_session -->|"opens sessions"| node_database
node_security -->|"loads user"| node_session
node_security -->|"queries account"| node_user_model
node_security -->|"reads secrets"| node_config
node_catalog_service -->|"raises domain errors"| node_errors
node_cart_service -->|"raises domain errors"| node_errors

click node_api_routes "https://github.com/s-madii/ecommerce-api/tree/main/app/routers"
click node_auth_routes "https://github.com/s-madii/ecommerce-api/blob/main/app/routers/auth.py"
click node_security "https://github.com/s-madii/ecommerce-api/blob/main/app/core/security.py"
click node_user_model "https://github.com/s-madii/ecommerce-api/blob/main/app/models/user.py"
click node_schemas "https://github.com/s-madii/ecommerce-api/tree/main/app/schemas"
click node_catalog_routes "https://github.com/s-madii/ecommerce-api/blob/main/app/routers/products.py"
click node_catalog_service "https://github.com/s-madii/ecommerce-api/blob/main/app/services/product.py"
click node_categories "https://github.com/s-madii/ecommerce-api/blob/main/app/routers/categories.py"
click node_cart_routes "https://github.com/s-madii/ecommerce-api/blob/main/app/routers/cart.py"
click node_cart_service "https://github.com/s-madii/ecommerce-api/blob/main/app/services/cart.py"
click node_product_model "https://github.com/s-madii/ecommerce-api/blob/main/app/models/product.py"
click node_cart_model "https://github.com/s-madii/ecommerce-api/blob/main/app/models/cart.py"
click node_checkout_routes "https://github.com/s-madii/ecommerce-api/blob/main/app/routers/orders.py"
click node_order_service "https://github.com/s-madii/ecommerce-api/blob/main/app/services/order.py"
click node_order_model "https://github.com/s-madii/ecommerce-api/blob/main/app/models/order.py"
click node_payment_routes "https://github.com/s-madii/ecommerce-api/blob/main/app/routers/payments.py"
click node_payment_service "https://github.com/s-madii/ecommerce-api/blob/main/app/services/payment.py"
click node_worker "https://github.com/s-madii/ecommerce-api/blob/main/app/worker.py"
click node_session "https://github.com/s-madii/ecommerce-api/blob/main/app/db/session.py"
click node_config "https://github.com/s-madii/ecommerce-api/blob/main/app/core/config.py"
click node_errors "https://github.com/s-madii/ecommerce-api/blob/main/app/core/exceptions.py"

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_api_routes,node_auth_routes,node_security,node_user_model,node_schemas,node_customer toneBlue
class node_catalog_routes,node_catalog_service,node_categories,node_cart_routes,node_cart_service,node_product_model,node_cart_model,node_checkout_routes,node_order_service toneAmber
class node_database,node_redis,node_session toneMint
class node_order_model,node_payment_routes,node_payment_service,node_worker toneRose
class node_config,node_errors,node_stripe toneIndigo
```

## Components

### API and identity

- [API routes](https://github.com/s-madii/ecommerce-api/tree/main/app/routers): `app/routers`
- [Authentication routes](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/auth.py): `app/routers/auth.py`
- [JWT and access control](https://github.com/s-madii/ecommerce-api/blob/main/app/core/security.py): `app/core/security.py`
- [User accounts](https://github.com/s-madii/ecommerce-api/blob/main/app/models/user.py): `app/models/user.py`
- [Request and response schemas](https://github.com/s-madii/ecommerce-api/tree/main/app/schemas): `app/schemas`

### Storefront domain

- [Catalog routes](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/products.py): `app/routers/products.py`
- [Catalog service](https://github.com/s-madii/ecommerce-api/blob/main/app/services/product.py): `app/services/product.py`
- [Category management](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/categories.py): `app/routers/categories.py`
- [Cart routes](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/cart.py): `app/routers/cart.py`
- [Cart service](https://github.com/s-madii/ecommerce-api/blob/main/app/services/cart.py): `app/services/cart.py`
- [Product inventory](https://github.com/s-madii/ecommerce-api/blob/main/app/models/product.py): `app/models/product.py`
- [Cart state](https://github.com/s-madii/ecommerce-api/blob/main/app/models/cart.py): `app/models/cart.py`
- [Checkout routes](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/orders.py): `app/routers/orders.py`
- [Checkout and orders](https://github.com/s-madii/ecommerce-api/blob/main/app/services/order.py): `app/services/order.py`

### Persistence and cache

- **PostgreSQL**
- **Redis cache and broker**
- [Async DB sessions](https://github.com/s-madii/ecommerce-api/blob/main/app/db/session.py): `app/db/session.py`

### Payments and tasks

- [Orders and payments](https://github.com/s-madii/ecommerce-api/blob/main/app/models/order.py): `app/models/order.py`
- [Payment webhook](https://github.com/s-madii/ecommerce-api/blob/main/app/routers/payments.py): `app/routers/payments.py`
- [Stripe payment service](https://github.com/s-madii/ecommerce-api/blob/main/app/services/payment.py): `app/services/payment.py`
- [Email task worker](https://github.com/s-madii/ecommerce-api/blob/main/app/worker.py): `app/worker.py`

### Shared foundations

- [Application settings](https://github.com/s-madii/ecommerce-api/blob/main/app/core/config.py): `app/core/config.py`
- [Domain errors](https://github.com/s-madii/ecommerce-api/blob/main/app/core/exceptions.py): `app/core/exceptions.py`

### Other components

- **Storefront user**
- **Stripe**

## Connections

- Storefront user → Authentication routes: signs up (evidence: `README.md`)
- Authentication routes → User accounts: queries and creates (evidence: `app/routers/auth.py`)
- Authentication routes → JWT and access control: creates token (evidence: `app/routers/auth.py`)
- Storefront user → Catalog routes: browses (evidence: `README.md`)
- Catalog routes → Catalog service: delegates (evidence: `app/routers/products.py`)
- Catalog service → Redis cache and broker: reads and caches (evidence: `app/services/product.py`)
- Catalog service → Product inventory: queries products (evidence: `app/services/product.py`)
- Storefront user → Category management: views categories (evidence: `README.md`)
- Storefront user → Cart routes: manages cart (evidence: `README.md`)
- Cart routes → Cart service: delegates (evidence: `app/routers/cart.py`)
- Cart service → Cart state: reads and updates (evidence: `app/services/cart.py`)
- Cart service → Product inventory: checks stock (evidence: `app/services/cart.py`)
- Storefront user → Checkout routes: checks out (evidence: `README.md`)
- Checkout routes → Checkout and orders: delegates
- Checkout and orders → Product inventory: locks stock (evidence: `README.md`)
- Checkout and orders → Orders and payments: creates order (evidence: `README.md`)
- Checkout and orders → Stripe payment service: creates intent (evidence: `README.md`)
- Stripe payment service → Stripe: creates intent (evidence: `README.md`)
- Stripe → Payment webhook: sends webhook (evidence: `README.md`)
- Payment webhook → Stripe payment service: verifies signature (evidence: `app/routers/payments.py`)
- Payment webhook → Orders and payments: confirms payment (evidence: `app/routers/payments.py`)
- Payment webhook → Email task worker: dispatches email (evidence: `app/routers/payments.py`)
- Email task worker → Redis cache and broker: uses broker (evidence: `app/worker.py`)
- API routes → Request and response schemas: validates and serializes (evidence: `app/routers/auth.py`)
- Authentication routes → Async DB sessions: uses DB session (evidence: `app/routers/auth.py`)
- Catalog routes → Async DB sessions: uses DB session (evidence: `app/routers/products.py`)
- Cart routes → Async DB sessions: uses DB session (evidence: `app/routers/cart.py`)
- Payment webhook → Async DB sessions: uses DB session (evidence: `app/routers/payments.py`)
- Async DB sessions → PostgreSQL: opens sessions (evidence: `app/db/session.py`)
- JWT and access control → Async DB sessions: loads user (evidence: `app/core/security.py`)
- JWT and access control → User accounts: queries account (evidence: `app/core/security.py`)
- JWT and access control → Application settings: reads secrets (evidence: `app/core/security.py`)
- Catalog service → Domain errors: raises domain errors (evidence: `app/services/product.py`)
- Cart service → Domain errors: raises domain errors (evidence: `app/services/cart.py`)
