# mdik0n/fastapi-ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/mdik0n/fastapi-ecommerce
- Repository: https://github.com/mdik0n/fastapi-ecommerce

## Overview

This is a FastAPI e-commerce API. Its visible customer workflow is to browse and search the catalog, inspect product reviews, authenticate, and manage a cart; sellers manage products, while admins manage categories. The sampled routers directly query and mutate the async database through SQLAlchemy models. The users router and several model files are present in the tree but were not sampled, so their internal behavior is not inferred here.

Main entry points: [`app/database.py`](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/database.py) (SQL database), [`app/db_depends.py`](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/db_depends.py) (DB sessions), [`app/main.py`](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/main.py) (FastAPI app), [`app/auth.py`](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/auth.py) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry"]
  node_app["FastAPI app<br/>[main.py]"]
  node_users["User routes<br/>[users.py]"]
  node_auth["Authentication<br/>[auth.py]"]
end

subgraph group_catalog["Catalog management"]
  node_categories["Category routes<br/>[categories.py]"]
  node_products["Product routes<br/>[products.py]"]
end

subgraph group_commerce["Customer commerce"]
  node_cart["Cart routes<br/>[cart.py]"]
  node_reviews["Review routes<br/>[reviews.py]"]
end

subgraph group_data["Persistence"]
  node_category_model["Category model<br/>[categories.py]"]
  node_product_model["Product model<br/>[products.py]"]
  node_cart_model["Cart item model<br/>[cart_items.py]"]
  node_review_model["Review model<br/>[reviews.py]"]
  node_user_model["User model<br/>[users.py]"]
  node_sessions["DB sessions<br/>[db_depends.py]"]
  node_database[("SQL database<br/>[database.py]")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"dispatches"| node_users
node_app -->|"dispatches"| node_categories
node_app -->|"dispatches"| node_products
node_app -->|"dispatches"| node_cart
node_app -->|"dispatches"| node_reviews
node_categories -->|"requires user"| node_auth
node_products -->|"requires seller"| node_auth
node_cart -->|"requires user"| node_auth
node_reviews -->|"requires user"| node_auth
node_auth -->|"gets session"| node_sessions
node_categories -->|"gets session"| node_sessions
node_products -->|"gets session"| node_sessions
node_cart -->|"gets session"| node_sessions
node_reviews -->|"gets session"| node_sessions
node_sessions -->|"opens session"| node_database
node_auth -->|"looks up user"| node_database
node_categories -->|"reads and writes"| node_database
node_products -->|"reads and writes"| node_database
node_cart -->|"reads and writes"| node_database
node_reviews -->|"reads and writes"| node_database
node_users -->|"gets session"| node_sessions
node_category_model -->|"maps category data"| node_database
node_product_model -->|"maps product data"| node_database
node_cart_model -->|"maps cart data"| node_database
node_review_model -->|"maps review data"| node_database
node_user_model -->|"maps user data"| node_database

click node_app "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/main.py"
click node_users "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/users.py"
click node_auth "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/auth.py"
click node_categories "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/categories.py"
click node_category_model "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/categories.py"
click node_products "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/products.py"
click node_product_model "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/products.py"
click node_cart "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/cart.py"
click node_cart_model "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/cart_items.py"
click node_reviews "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/reviews.py"
click node_review_model "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/reviews.py"
click node_user_model "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/users.py"
click node_sessions "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/db_depends.py"
click node_database "https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/database.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_app,node_users,node_auth,node_client toneBlue
class node_categories,node_products toneAmber
class node_cart,node_reviews toneMint
class node_category_model,node_product_model,node_cart_model,node_review_model,node_user_model,node_sessions,node_database toneRose
```

## Components

### API entry

- [FastAPI app](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/main.py): `app/main.py`
- [User routes](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/users.py): `app/routers/users.py`
- [Authentication](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/auth.py): `app/auth.py`

### Catalog management

- [Category routes](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/categories.py): `app/routers/categories.py`
- [Product routes](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/products.py): `app/routers/products.py`

### Customer commerce

- [Cart routes](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/cart.py): `app/routers/cart.py`
- [Review routes](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/routers/reviews.py): `app/routers/reviews.py`

### Persistence

- [Category model](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/categories.py): `app/models/categories.py`
- [Product model](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/products.py): `app/models/products.py`
- [Cart item model](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/cart_items.py): `app/models/cart_items.py`
- [Review model](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/reviews.py): `app/models/reviews.py`
- [User model](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/models/users.py): `app/models/users.py`
- [DB sessions](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/db_depends.py): `app/db_depends.py`
- [SQL database](https://github.com/mdik0n/fastapi-ecommerce/blob/main/app/database.py): `app/database.py`

### Other components

- **API client**

## Connections

- API client → FastAPI app: sends requests
- FastAPI app → User routes: dispatches
- FastAPI app → Category routes: dispatches
- FastAPI app → Product routes: dispatches
- FastAPI app → Cart routes: dispatches
- FastAPI app → Review routes: dispatches
- Category routes → Authentication: requires user
- Product routes → Authentication: requires seller
- Cart routes → Authentication: requires user
- Review routes → Authentication: requires user
- Authentication → DB sessions: gets session
- Category routes → DB sessions: gets session
- Product routes → DB sessions: gets session
- Cart routes → DB sessions: gets session
- Review routes → DB sessions: gets session
- DB sessions → SQL database: opens session
- Authentication → SQL database: looks up user
- Category routes → SQL database: reads and writes
- Product routes → SQL database: reads and writes
- Cart routes → SQL database: reads and writes
- Review routes → SQL database: reads and writes
- User routes → DB sessions: gets session
- Category model → SQL database: maps category data
- Product model → SQL database: maps product data
- Cart item model → SQL database: maps cart data
- Review model → SQL database: maps review data
- User model → SQL database: maps user data
