# mdaamir2001/billing-system architecture

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

- Interactive diagram: https://gitdiagram.com/mdaamir2001/billing-system
- Repository: https://github.com/mdaamir2001/billing-system

## Overview

This is a small server-rendered billing application. The main workflow is cashier bill entry, product/stock validation, totals and change calculation, purchase persistence and stock/drawer updates, followed by an invoice result and background email. Separate branches manage products and retrieve purchase history. The excerpts show router ownership of these calls; README documents template pages, configurable database and asynchronous email. The template files and some route implementations were not sampled, so their internal behavior is not expanded.

Main entry points: [`app/routers/billing.py`](https://github.com/mdaamir2001/billing-system/blob/main/app/routers/billing.py) (Bill generation), [`app/main.py`](https://github.com/mdaamir2001/billing-system/blob/main/app/main.py) (FastAPI app), [`app/routers/products.py`](https://github.com/mdaamir2001/billing-system/blob/main/app/routers/products.py) (Product management), [`app/routers/purchases.py`](https://github.com/mdaamir2001/billing-system/blob/main/app/routers/purchases.py) (Purchase history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workflows"]
  node_app["FastAPI app<br/>[main.py]"]
  node_products["Product management<br/>[products.py]"]
  node_billing_route["Bill generation<br/>[billing.py]"]
  node_history["Purchase history<br/>[purchases.py]"]
  node_schemas["Data schemas<br/>[schemas.py]"]
  node_templates["HTML views"]
end

subgraph group_billing["Billing services"]
  node_calc["Bill and change math<br/>[billing.py]"]
end

subgraph group_data["Persistence"]
  node_crud["Data access<br/>[crud.py]"]
  node_models["Billing records<br/>[models.py]"]
  node_database["Database sessions<br/>[database.py]"]
  node_store[("SQL database")]
end

subgraph group_delivery["Invoice delivery"]
  node_email["Invoice email<br/>[email.py]"]
end

node_cashier(("Cashier"))
node_customer(("Customer"))
node_smtp["SMTP server"]

node_app -->|"registers"| node_products
node_app -->|"registers"| node_billing_route
node_app -->|"registers"| node_history
node_cashier -.->|"manages products"| node_products
node_cashier -.->|"submits bill"| node_billing_route
node_customer -.->|"requests history"| node_history
node_products -->|"uses"| node_crud
node_billing_route -->|"uses"| node_crud
node_history -->|"uses"| node_crud
node_billing_route -->|"calculates totals and change"| node_calc
node_billing_route -->|"schedules invoice"| node_email
node_products -.->|"renders pages"| node_templates
node_billing_route -->|"renders bill pages"| node_templates
node_history -->|"renders history"| node_templates
node_billing_route -.->|"emails invoice"| node_customer
node_email -.->|"sends through"| node_smtp
node_crud -->|"queries and updates"| node_models
node_models -->|"uses base"| node_database
node_database -.->|"connects"| node_store
node_app -->|"creates tables"| node_database
node_billing_route -->|"returns bill result"| node_templates

click node_app "https://github.com/mdaamir2001/billing-system/blob/main/app/main.py"
click node_products "https://github.com/mdaamir2001/billing-system/blob/main/app/routers/products.py"
click node_billing_route "https://github.com/mdaamir2001/billing-system/blob/main/app/routers/billing.py"
click node_history "https://github.com/mdaamir2001/billing-system/blob/main/app/routers/purchases.py"
click node_schemas "https://github.com/mdaamir2001/billing-system/blob/main/app/schemas.py"
click node_templates "https://github.com/mdaamir2001/billing-system/tree/main/app/templates"
click node_calc "https://github.com/mdaamir2001/billing-system/blob/main/app/services/billing.py"
click node_email "https://github.com/mdaamir2001/billing-system/blob/main/app/services/email.py"
click node_crud "https://github.com/mdaamir2001/billing-system/blob/main/app/crud.py"
click node_models "https://github.com/mdaamir2001/billing-system/blob/main/app/models.py"
click node_database "https://github.com/mdaamir2001/billing-system/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_products,node_billing_route,node_history,node_schemas,node_templates toneBlue
class node_calc toneAmber
class node_crud,node_models,node_database,node_store,node_smtp toneMint
class node_email toneRose
class node_cashier,node_customer toneIndigo
```

## Components

### Web workflows

- [FastAPI app](https://github.com/mdaamir2001/billing-system/blob/main/app/main.py): `app/main.py`
- [Product management](https://github.com/mdaamir2001/billing-system/blob/main/app/routers/products.py): `app/routers/products.py`
- [Bill generation](https://github.com/mdaamir2001/billing-system/blob/main/app/routers/billing.py): `app/routers/billing.py`
- [Purchase history](https://github.com/mdaamir2001/billing-system/blob/main/app/routers/purchases.py): `app/routers/purchases.py`
- [Data schemas](https://github.com/mdaamir2001/billing-system/blob/main/app/schemas.py): `app/schemas.py`
- [HTML views](https://github.com/mdaamir2001/billing-system/tree/main/app/templates): `app/templates`

### Billing services

- [Bill and change math](https://github.com/mdaamir2001/billing-system/blob/main/app/services/billing.py): `app/services/billing.py`

### Persistence

- [Data access](https://github.com/mdaamir2001/billing-system/blob/main/app/crud.py): `app/crud.py`
- [Billing records](https://github.com/mdaamir2001/billing-system/blob/main/app/models.py): `app/models.py`
- [Database sessions](https://github.com/mdaamir2001/billing-system/blob/main/app/database.py): `app/database.py`
- **SQL database**

### Invoice delivery

- [Invoice email](https://github.com/mdaamir2001/billing-system/blob/main/app/services/email.py): `app/services/email.py`

### Other components

- **Cashier**
- **Customer**
- **SMTP server**

## Connections

- FastAPI app → Product management: registers (evidence: `app/main.py`)
- FastAPI app → Bill generation: registers (evidence: `app/main.py`)
- FastAPI app → Purchase history: registers (evidence: `app/main.py`)
- Cashier → Product management: manages products (evidence: `README.md`)
- Cashier → Bill generation: submits bill (evidence: `README.md`)
- Customer → Purchase history: requests history (evidence: `README.md`)
- Product management → Data access: uses (evidence: `app/routers/products.py`)
- Bill generation → Data access: uses (evidence: `app/routers/billing.py`)
- Purchase history → Data access: uses (evidence: `app/routers/purchases.py`)
- Bill generation → Bill and change math: calculates totals and change (evidence: `app/routers/billing.py`)
- Bill generation → Invoice email: schedules invoice (evidence: `app/routers/billing.py`)
- Product management → HTML views: renders pages (evidence: `README.md`)
- Bill generation → HTML views: renders bill pages (evidence: `app/routers/billing.py`)
- Purchase history → HTML views: renders history (evidence: `app/routers/purchases.py`)
- Bill generation → Customer: emails invoice (evidence: `README.md`)
- Invoice email → SMTP server: sends through (evidence: `README.md`)
- Data access → Billing records: queries and updates (evidence: `app/crud.py`)
- Billing records → Database sessions: uses base (evidence: `app/models.py`)
- Database sessions → SQL database: connects (evidence: `README.md`)
- FastAPI app → Database sessions: creates tables (evidence: `app/main.py`)
- Bill generation → HTML views: returns bill result (evidence: `app/routers/billing.py`)
