# wicked-bunny/e-commercetelegrambot architecture

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

- Interactive diagram: https://gitdiagram.com/wicked-bunny/e-commercetelegrambot
- Repository: https://github.com/wicked-bunny/e-commercetelegrambot

## Overview

E-commerceBot is a Telegram shop: customers browse categories and product details, then initiate purchases through the bot; Stripe webhook handling completes successful payments, updates stock, and notifies the customer. The runtime is organized around aiogram handlers and a repository/unit-of-work persistence layer backed by SQLite/SQLAlchemy. The graph includes the documented catalog, ordering, and payment capabilities. Some handler and payment-service internals were not excerpted, so uncertain relationships are omitted or marked dashed.

Main entry points: [`repositories/implementations/sql_alchemy_unit_of_work.py`](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_unit_of_work.py) (Unit of work), [`main.py`](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/main.py) (App runtime), [`api/stripe_webhook.py`](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/api/stripe_webhook.py) (Stripe webhook), [`handlers/сatalog.py`](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/%D1%81atalog.py) (Catalog browsing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bot["Telegram bot"]
  node_main["App runtime<br/>[main.py]"]
  node_routers["Router registration<br/>[__init__.py]"]
  node_middleware["Session middleware<br/>[session.py]"]
  node_start["Start and profile<br/>[start.py]"]
end

subgraph group_commerce["Shopping flow"]
  node_catalog["Catalog browsing<br/>[сatalog.py]"]
  node_categories["Category browsing<br/>[categories.py]"]
  node_buy["Purchase handler<br/>[buy.py]"]
  node_orders["Order handling<br/>[orders.py]"]
  node_keyboards["Shop keyboards"]
  node_callbacks["Callback data<br/>[callbacks.py]"]
end

subgraph group_payments["Payment processing"]
  node_stripe_service["Checkout service<br/>[stripe_service.py]"]
  node_webhook["Stripe webhook<br/>[stripe_webhook.py]"]
end

subgraph group_persistence["Persistence"]
  node_uow["Unit of work"]
  node_repositories["SQLAlchemy repositories"]
  node_item_repo["Item repository"]
  node_user_repo["User repository"]
  node_database[("Database sessions<br/>[connection.py]")]
  node_items["Product model<br/>[items.py]"]
  node_category_model["Category model<br/>[category.py]"]
  node_user_model["User model<br/>[user.py]"]
end

node_customer(("Customer"))
node_stripe(("Stripe"))

node_customer -->|"uses bot"| node_main
node_main -->|"registers"| node_routers
node_main -->|"registers"| node_middleware
node_main -->|"initializes"| node_database
node_main -->|"configures route"| node_webhook
node_routers -->|"registers"| node_start
node_customer -->|"browses"| node_catalog
node_customer -->|"orders"| node_buy
node_catalog -->|"uses"| node_keyboards
node_categories -->|"uses"| node_keyboards
node_catalog -->|"uses"| node_callbacks
node_categories -->|"uses"| node_callbacks
node_buy -->|"calls"| node_stripe_service
node_buy -->|"uses"| node_uow
node_stripe -.->|"sends events"| node_webhook
node_webhook -->|"updates stock"| node_uow
node_webhook -->|"sends notification"| node_customer
node_middleware -->|"creates sessions"| node_uow
node_uow -->|"constructs"| node_item_repo
node_uow -->|"constructs"| node_repositories
node_uow -->|"constructs"| node_user_repo
node_uow -->|"opens session"| node_database
node_item_repo -->|"queries"| node_items
node_user_repo -->|"queries"| node_user_model
node_repositories -.->|"queries"| node_category_model

click node_main "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/main.py"
click node_routers "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/__init__.py"
click node_middleware "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/middlewares/session.py"
click node_start "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/start.py"
click node_catalog "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/%D1%81atalog.py"
click node_categories "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/categories.py"
click node_buy "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/buy.py"
click node_orders "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/orders.py"
click node_keyboards "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/Keyboards/inline_category_kb.py"
click node_callbacks "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/callbacks.py"
click node_stripe_service "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/services/stripe_service.py"
click node_webhook "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/api/stripe_webhook.py"
click node_uow "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_unit_of_work.py"
click node_repositories "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_repo.py"
click node_item_repo "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_item_repo.py"
click node_user_repo "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_user_repo.py"
click node_database "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/connection.py"
click node_items "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/models/items.py"
click node_category_model "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/models/category.py"
click node_user_model "https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/models/user.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_main,node_routers,node_middleware,node_start toneBlue
class node_catalog,node_categories,node_buy,node_orders,node_keyboards,node_callbacks toneAmber
class node_stripe_service,node_webhook toneMint
class node_uow,node_repositories,node_item_repo,node_user_repo,node_database,node_items,node_category_model,node_user_model toneRose
class node_customer,node_stripe toneIndigo
```

## Components

### Telegram bot

- [App runtime](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/main.py): `main.py`
- [Router registration](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/__init__.py): `handlers/__init__.py`
- [Session middleware](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/middlewares/session.py): `middlewares/session.py`
- [Start and profile](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/start.py): `handlers/start.py`

### Shopping flow

- [Catalog browsing](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/%D1%81atalog.py): `handlers/сatalog.py`
- [Category browsing](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/categories.py): `handlers/categories.py`
- [Purchase handler](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/buy.py): `handlers/buy.py`
- [Order handling](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/handlers/orders.py): `handlers/orders.py`
- [Shop keyboards](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/Keyboards/inline_category_kb.py): `Keyboards/inline_category_kb.py`
- [Callback data](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/callbacks.py): `callbacks.py`

### Payment processing

- [Checkout service](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/services/stripe_service.py): `services/stripe_service.py`
- [Stripe webhook](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/api/stripe_webhook.py): `api/stripe_webhook.py`

### Persistence

- [Unit of work](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_unit_of_work.py): `repositories/implementations/sql_alchemy_unit_of_work.py`
- [SQLAlchemy repositories](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_repo.py): `repositories/implementations/sql_alchemy_repo.py`
- [Item repository](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_item_repo.py): `repositories/implementations/sql_alchemy_item_repo.py`
- [User repository](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/repositories/implementations/sql_alchemy_user_repo.py): `repositories/implementations/sql_alchemy_user_repo.py`
- [Database sessions](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/connection.py): `database/connection.py`
- [Product model](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/models/items.py): `database/models/items.py`
- [Category model](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/models/category.py): `database/models/category.py`
- [User model](https://github.com/wicked-bunny/e-commercetelegrambot/blob/master/database/models/user.py): `database/models/user.py`

### Other components

- **Customer**
- **Stripe**

## Connections

- Customer → App runtime: uses bot
- App runtime → Router registration: registers (evidence: `main.py`)
- App runtime → Session middleware: registers (evidence: `main.py`)
- App runtime → Database sessions: initializes (evidence: `main.py`)
- App runtime → Stripe webhook: configures route (evidence: `main.py`)
- Router registration → Start and profile: registers (evidence: `handlers/__init__.py`)
- Customer → Catalog browsing: browses
- Customer → Purchase handler: orders
- Catalog browsing → Shop keyboards: uses (evidence: `handlers/сatalog.py`)
- Category browsing → Shop keyboards: uses (evidence: `handlers/categories.py`)
- Catalog browsing → Callback data: uses (evidence: `handlers/сatalog.py`)
- Category browsing → Callback data: uses (evidence: `handlers/categories.py`)
- Purchase handler → Checkout service: calls (evidence: `handlers/buy.py`)
- Purchase handler → Unit of work: uses (evidence: `handlers/buy.py`)
- Stripe → Stripe webhook: sends events
- Stripe webhook → Unit of work: updates stock (evidence: `api/stripe_webhook.py`)
- Stripe webhook → Customer: sends notification (evidence: `api/stripe_webhook.py`)
- Session middleware → Unit of work: creates sessions (evidence: `middlewares/session.py`)
- Unit of work → Item repository: constructs (evidence: `repositories/implementations/sql_alchemy_unit_of_work.py`)
- Unit of work → SQLAlchemy repositories: constructs (evidence: `repositories/implementations/sql_alchemy_unit_of_work.py`)
- Unit of work → User repository: constructs (evidence: `repositories/implementations/sql_alchemy_unit_of_work.py`)
- Unit of work → Database sessions: opens session (evidence: `repositories/implementations/sql_alchemy_unit_of_work.py`)
- Item repository → Product model: queries (evidence: `repositories/implementations/sql_alchemy_item_repo.py`)
- User repository → User model: queries (evidence: `repositories/implementations/sql_alchemy_user_repo.py`)
- SQLAlchemy repositories → Category model: queries
