# misterfrukt3/oborudsh architecture

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

- Interactive diagram: https://gitdiagram.com/misterfrukt3/oborudsh
- Repository: https://github.com/misterfrukt3/oborudsh

## Overview

#### Purpose and entry points
Оборудыш is a Telegram Mini App for reserving filming equipment and room 626 at Media BMSTU. The browser client starts at `prototype/index.html`; its Telegram-facing backend and bot process are combined in `bot/main.py`. The system is deployed as one production service and one SQLite-backed instance.

#### Mini App client
The static Mini App provides catalog browsing, reservation flow, navigation, screens, and visual presentation:
- `prototype/index.html`
- `prototype/style.css`
- `prototype/catalog.js`
- `prototype/texts.js`

It runs inside Telegram Web Apps and calls backend HTTP endpoints. The catalog is also shipped client-side, making the UI catalog a deliberate boundary from server-side availability and reservation enforcement.

#### API, bot, and authentication boundary
`bot/main.py` hosts aiohttp API routes and an aiogram 3 Telegram bot in the same Python runtime. It validates Telegram Mini App identity, serves application bootstrap/state, accepts booking-related actions, and handles bot commands such as migration. Telegram is the identity and notification channel; browser requests must cross the Telegram init-data authorization boundary before accessing user-specific data.

#### Reservation and availability domain
The backend owns booking state, equipment availability, room scheduling, request lifecycle, and conflict prevention. Its central orchestration is in:
- `bot/main.py`
- `bot/equipment.json`
- `bot/catalog.js`

Equipment metadata is maintained as structured catalog data; `bot/update_catalog_from_csv.py` is the controlled import path for catalog updates. Client and server catalog representations must remain aligned, while the backend remains authoritative for occupied dates and accepted requests.

#### Persistence and operational jobs
SQLite persistence is embedded in the backend process, storing users, registration-derived fields, reservations, and local accrual data. A scheduler in `bot/main.py` handles time-based workflow actions, such as reservation lifecycle transitions and notifications. The architecture is intentionally single-instance: production must not run a second bot or database.

#### External integrations
Telegram Bot API and Mini App runtime are core external dependencies. Google Sheets is optional: registration may be populated from a restricted `люди` sheet, and accruals can be synchronized while retaining local persistence when Sheets is disabled. Server-sent events from `bot/main.py` provide real-time client updates where applicable.

#### Supporting operational interfaces
User-facing Telegram copy is centralized in `bot/texts.py`. Migration from a legacy button bot is a one-way administrative workflow: it reads the old database directly without changing the new database. Runtime dependencies and environment contract are defined in:
- `bot/requirements.txt`
- `bot/.env.example`
- `DEPLOY.md`

Main entry points: [`bot/main.py`](https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py) (API and bot runtime), [`prototype/index.html`](https://github.com/misterfrukt3/oborudsh/blob/main/prototype/index.html) (Static Mini App), [`bot/equipment.json`](https://github.com/misterfrukt3/oborudsh/blob/main/bot/equipment.json) (Server catalog), [`DEPLOY.md`](https://github.com/misterfrukt3/oborudsh/blob/main/DEPLOY.md) (Production contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Telegram Mini App"]
  node_telegram_miniapp{{"Telegram Mini App runtime<br/>external runtime"}}
  node_web_client["Static Mini App<br/>browser client<br/>[index.html]"]
  node_client_catalog["Client catalog<br/>catalog data<br/>[catalog.js]"]
  node_client_presentation["UI styles and copy<br/>client assets<br/>[style.css]"]
end

subgraph group_backend["Single Python Runtime"]
  node_backend_runtime["API and bot runtime<br/>aiohttp + aiogram<br/>[main.py]"]
  node_telegram_auth{{"Init-data authorization<br/>auth boundary<br/>[main.py]"}}
  node_reservation_domain["Reservations &amp; availability<br/>domain orchestration<br/>[main.py]"]
  node_sse_updates["Real-time updates<br/>SSE endpoint<br/>[main.py]"]
  node_scheduler["Lifecycle scheduler<br/>scheduled workflow<br/>[main.py]"]
  node_bot_copy["Bot copy<br/>message templates<br/>[texts.py]"]
  node_server_catalog["Server catalog<br/>catalog metadata<br/>[equipment.json]"]
  node_catalog_import["Catalog CSV import<br/>admin import"]
end

subgraph group_data["Data &amp; Integrations"]
  node_telegram_api{{"Telegram Bot API<br/>external service"}}
  node_sqlite[("SQLite instance<br/>embedded database")]
  node_google_sheets["Google Sheets<br/>optional integration"]
  node_legacy_database[("Legacy bot database<br/>migration source")]
  node_deployment_contract["Production contract<br/>deployment guidance<br/>[DEPLOY.md]"]
end

node_telegram_miniapp -->|"hosts"| node_web_client
node_web_client -->|"loads"| node_client_catalog
node_web_client -->|"uses"| node_client_presentation
node_web_client -->|"HTTP actions"| node_backend_runtime
node_web_client -->|"sends init data"| node_telegram_auth
node_telegram_auth -->|"authorizes requests"| node_reservation_domain
node_backend_runtime -->|"routes actions"| node_reservation_domain
node_reservation_domain -->|"persists state"| node_sqlite
node_reservation_domain -->|"reads metadata"| node_server_catalog
node_catalog_import -->|"updates"| node_server_catalog
node_client_catalog -.->|"must align"| node_server_catalog
node_backend_runtime -->|"serves"| node_sse_updates
node_sse_updates -->|"pushes changes"| node_web_client
node_scheduler -->|"transitions lifecycle"| node_reservation_domain
node_scheduler -->|"sends notifications"| node_telegram_api
node_backend_runtime -->|"bot commands and identity"| node_telegram_api
node_backend_runtime -->|"formats messages"| node_bot_copy
node_backend_runtime -.->|"optional registration and accrual sync"| node_google_sheets
node_backend_runtime -.->|"one-way migration reads"| node_legacy_database
node_deployment_contract -.->|"deploys as one service"| node_backend_runtime
node_deployment_contract -.->|"requires one instance"| node_sqlite

click node_web_client "https://github.com/misterfrukt3/oborudsh/blob/main/prototype/index.html"
click node_client_catalog "https://github.com/misterfrukt3/oborudsh/blob/main/prototype/catalog.js"
click node_client_presentation "https://github.com/misterfrukt3/oborudsh/blob/main/prototype/style.css"
click node_backend_runtime "https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py"
click node_telegram_auth "https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py"
click node_reservation_domain "https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py"
click node_sse_updates "https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py"
click node_scheduler "https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py"
click node_bot_copy "https://github.com/misterfrukt3/oborudsh/blob/main/bot/texts.py"
click node_server_catalog "https://github.com/misterfrukt3/oborudsh/blob/main/bot/equipment.json"
click node_catalog_import "https://github.com/misterfrukt3/oborudsh/blob/main/bot/update_catalog_from_csv.py"
click node_deployment_contract "https://github.com/misterfrukt3/oborudsh/blob/main/DEPLOY.md"

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_telegram_miniapp,node_web_client,node_client_catalog,node_client_presentation toneBlue
class node_backend_runtime,node_telegram_auth,node_reservation_domain,node_sse_updates,node_scheduler,node_bot_copy,node_server_catalog,node_catalog_import toneAmber
class node_telegram_api,node_sqlite,node_google_sheets,node_legacy_database,node_deployment_contract toneMint
```

## Components

### Telegram Mini App

- **Telegram Mini App runtime**: external runtime · Hosts the browser client and supplies init data.
- [Static Mini App](https://github.com/misterfrukt3/oborudsh/blob/main/prototype/index.html): browser client · Catalog, navigation, and reservation screens. · `prototype/index.html`
- [Client catalog](https://github.com/misterfrukt3/oborudsh/blob/main/prototype/catalog.js): catalog data · Shipped UI catalog; not authoritative for availability. · `prototype/catalog.js`
- [UI styles and copy](https://github.com/misterfrukt3/oborudsh/blob/main/prototype/style.css): client assets · `prototype/style.css`

### Single Python Runtime

One process hosts both the API and Telegram bot.

- [API and bot runtime](https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py): aiohttp + aiogram · Combined HTTP API, Telegram bot, and domain entry point. · `bot/main.py`
- [Init-data authorization](https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py): auth boundary · Validates Telegram identity before user-specific API access. · `bot/main.py`
- [Reservations & availability](https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py): domain orchestration · Enforces conflicts, lifecycle, equipment, and room scheduling. · `bot/main.py`
- [Real-time updates](https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py): SSE endpoint · `bot/main.py`
- [Lifecycle scheduler](https://github.com/misterfrukt3/oborudsh/blob/main/bot/main.py): scheduled workflow · Advances reservations and sends timed notifications. · `bot/main.py`
- [Bot copy](https://github.com/misterfrukt3/oborudsh/blob/main/bot/texts.py): message templates · `bot/texts.py`
- [Server catalog](https://github.com/misterfrukt3/oborudsh/blob/main/bot/equipment.json): catalog metadata · Authoritative equipment metadata used by backend workflows. · `bot/equipment.json`
- [Catalog CSV import](https://github.com/misterfrukt3/oborudsh/blob/main/bot/update_catalog_from_csv.py): admin import · Controlled update path for server catalog data. · `bot/update_catalog_from_csv.py`

### Data & Integrations

- **Telegram Bot API**: external service · Identity, commands, and user notifications.
- **SQLite instance**: embedded database · Stores users, registrations, reservations, and local accruals.
- **Google Sheets**: optional integration · Restricted people-sheet lookup and optional accrual synchronization.
- **Legacy bot database**: migration source · Read-only source for one-way administrative migration.
- [Production contract](https://github.com/misterfrukt3/oborudsh/blob/main/DEPLOY.md): deployment guidance · Defines the single-service, single-database deployment model. · `DEPLOY.md`

## Connections

- Telegram Mini App runtime → Static Mini App: hosts
- Static Mini App → Client catalog: loads
- Static Mini App → UI styles and copy: uses
- Static Mini App → API and bot runtime: HTTP actions
- Static Mini App → Init-data authorization: sends init data
- Init-data authorization → Reservations & availability: authorizes requests
- API and bot runtime → Reservations & availability: routes actions
- Reservations & availability → SQLite instance: persists state
- Reservations & availability → Server catalog: reads metadata
- Catalog CSV import → Server catalog: updates
- Client catalog → Server catalog: must align
- API and bot runtime → Real-time updates: serves
- Real-time updates → Static Mini App: pushes changes
- Lifecycle scheduler → Reservations & availability: transitions lifecycle
- Lifecycle scheduler → Telegram Bot API: sends notifications
- API and bot runtime → Telegram Bot API: bot commands and identity
- API and bot runtime → Bot copy: formats messages
- API and bot runtime → Google Sheets: optional registration and accrual sync
- API and bot runtime → Legacy bot database: one-way migration reads
- Production contract → API and bot runtime: deploys as one service
- Production contract → SQLite instance: requires one instance
