# anarnurayev0/doner-calc-api architecture

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

- Interactive diagram: https://gitdiagram.com/anarnurayev0/doner-calc-api
- Repository: https://github.com/anarnurayev0/doner-calc-api

## Overview

Doner-Calc is a FastAPI service and receipt-style web app for calculating how many doners a budget buys in Azerbaijan. The main flow selects a doner and meat type, reads its AZN price, converts the budget to AZN, computes the count and remainder, then converts the change back to the input currency. Separate public branches provide options and currencies; authenticated admin endpoints maintain the catalog. PostgreSQL stores doners, Redis caches results and lists, and fxratesapi supplies currency data. The graph follows shown calls and README-documented behavior; the frontend source was not sampled, so its API interactions rely on README evidence.

Main entry points: [`app/routers/public.py`](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/routers/public.py) (Public routes), [`app/routers/admin.py`](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/routers/admin.py) (Admin routes), [`app/database.py`](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/database.py) (Database access), [`app/redis.py`](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/redis.py) (Redis client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App and web"]
  node_app["FastAPI app<br/>[main.py]"]
  node_web["Receipt page<br/>[index.html]"]
end

subgraph group_public["Public calculation"]
  node_public_api["Public routes<br/>[public.py]"]
end

subgraph group_catalog["Admin catalog"]
  node_admin_api["Admin routes<br/>[admin.py]"]
  node_auth["Basic auth<br/>[auth.py]"]
  node_doner_model["Doner model<br/>[models.py]"]
  node_schemas["Admin schemas<br/>[schemas.py]"]
end

subgraph group_services["Services and state"]
  node_calculator["Doner calculator<br/>[calculator.py]"]
  node_currency["Currency service<br/>[currency.py]"]
  node_db_access["Database access<br/>[database.py]"]
  node_cache_client["Redis client<br/>[redis.py]"]
  node_settings["Settings<br/>[settings.py]"]
end

node_visitor(("Visitor"))
node_administrator(("Administrator"))
node_postgres[("PostgreSQL")]
node_redis_store[("Redis store")]
node_fxrates["fxratesapi"]

node_visitor -->|"opens page"| node_web
node_visitor -->|"requests calculations"| node_public_api
node_administrator -->|"manages catalog"| node_admin_api
node_app -->|"registers routes"| node_public_api
node_app -->|"registers routes"| node_admin_api
node_app -->|"serves page"| node_web
node_web -->|"loads options"| node_public_api
node_public_api -->|"queries catalog"| node_db_access
node_public_api -->|"queries doners"| node_doner_model
node_public_api -->|"reads and writes"| node_cache_client
node_public_api -->|"converts amounts"| node_currency
node_public_api -->|"calculates count"| node_calculator
node_currency -->|"requests rates"| node_fxrates
node_admin_api -->|"requires credentials"| node_auth
node_admin_api -->|"reads and writes"| node_db_access
node_admin_api -->|"manages records"| node_doner_model
node_admin_api -->|"validates payloads"| node_schemas
node_admin_api -->|"clears cache"| node_cache_client
node_db_access -->|"connects to"| node_postgres
node_cache_client -->|"connects to"| node_redis_store
node_auth -->|"checks credentials"| node_settings
node_db_access -->|"reads connection config"| node_settings
node_cache_client -->|"reads Redis config"| node_settings

click node_app "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/main.py"
click node_web "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/static/index.html"
click node_public_api "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/routers/public.py"
click node_admin_api "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/routers/admin.py"
click node_auth "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/auth.py"
click node_calculator "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/services/calculator.py"
click node_currency "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/services/currency.py"
click node_db_access "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/database.py"
click node_doner_model "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/models.py"
click node_schemas "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/schemas.py"
click node_cache_client "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/redis.py"
click node_settings "https://github.com/anarnurayev0/doner-calc-api/blob/main/app/settings.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_web toneBlue
class node_public_api,node_postgres,node_redis_store toneAmber
class node_admin_api,node_auth,node_doner_model,node_schemas,node_fxrates toneMint
class node_calculator,node_currency,node_db_access,node_cache_client,node_settings toneRose
class node_visitor,node_administrator toneIndigo
```

## Components

### App and web

- [FastAPI app](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/main.py): `app/main.py`
- [Receipt page](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/static/index.html): `app/static/index.html`

### Public calculation

- [Public routes](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/routers/public.py): `app/routers/public.py`

### Admin catalog

- [Admin routes](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/routers/admin.py): `app/routers/admin.py`
- [Basic auth](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/auth.py): `app/auth.py`
- [Doner model](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/models.py): `app/models.py`
- [Admin schemas](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/schemas.py): `app/schemas.py`

### Services and state

- [Doner calculator](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/services/calculator.py): `app/services/calculator.py`
- [Currency service](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/services/currency.py): `app/services/currency.py`
- [Database access](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/database.py): `app/database.py`
- [Redis client](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/redis.py): `app/redis.py`
- [Settings](https://github.com/anarnurayev0/doner-calc-api/blob/main/app/settings.py): `app/settings.py`

### Other components

- **Visitor**
- **Administrator**
- **PostgreSQL**
- **Redis store**
- **fxratesapi**

## Connections

- Visitor → Receipt page: opens page (evidence: `README.md`)
- Visitor → Public routes: requests calculations (evidence: `README.md`)
- Administrator → Admin routes: manages catalog (evidence: `README.md`)
- FastAPI app → Public routes: registers routes (evidence: `app/main.py`)
- FastAPI app → Admin routes: registers routes (evidence: `app/main.py`)
- FastAPI app → Receipt page: serves page (evidence: `app/main.py`)
- Receipt page → Public routes: loads options (evidence: `README.md`)
- Public routes → Database access: queries catalog (evidence: `app/routers/public.py`)
- Public routes → Doner model: queries doners (evidence: `app/routers/public.py`)
- Public routes → Redis client: reads and writes (evidence: `app/routers/public.py`)
- Public routes → Currency service: converts amounts (evidence: `app/routers/public.py`)
- Public routes → Doner calculator: calculates count (evidence: `app/routers/public.py`)
- Currency service → fxratesapi: requests rates (evidence: `app/services/currency.py`)
- Admin routes → Basic auth: requires credentials (evidence: `app/routers/admin.py`)
- Admin routes → Database access: reads and writes (evidence: `app/routers/admin.py`)
- Admin routes → Doner model: manages records (evidence: `app/routers/admin.py`)
- Admin routes → Admin schemas: validates payloads (evidence: `app/routers/admin.py`)
- Admin routes → Redis client: clears cache (evidence: `app/routers/admin.py`)
- Database access → PostgreSQL: connects to (evidence: `app/database.py`)
- Redis client → Redis store: connects to (evidence: `app/redis.py`)
- Basic auth → Settings: checks credentials (evidence: `app/auth.py`)
- Database access → Settings: reads connection config (evidence: `app/database.py`)
- Redis client → Settings: reads Redis config (evidence: `app/redis.py`)
