# qarabaierooom/qazaz-apk-boot architecture

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

- Interactive diagram: https://gitdiagram.com/qarabaierooom/qazaz-apk-boot
- Repository: https://github.com/qarabaierooom/qazaz-apk-boot

## Overview

#### Purpose and Entry Point
QazaQsha APK Store is an automated Telegram bot for publishing and distributing modded Android APKs. The entire application is a single Python process launched with `python main.py`; bot configuration, handlers, persistence, FSMs, and media generation are centralized in `main.py`.

Paths: `main.py`, `README.md`

#### Telegram Bot Runtime
The bot runs on Python 3.10+ with Aiogram 3.7+ and Telegram’s Bot API. It uses asynchronous command, message, callback-query, and document/media handlers. Primary public entry points are `/start`, including `/start app_{id}` download deep links, and `/search`; administrator entry points are `/admin`, `/stats`, and `/send`.

Paths: `main.py`

#### Persistence and Domain Model
SQLite is the durable system of record, created locally at runtime as `apk_store.db`. It stores applications and Telegram `file_id`s, users, download history, and dynamically managed mandatory-subscription channels. The bot includes schema initialization/migration behavior for older databases.

Core records connect the publishing and download lifecycle: an uploaded APK becomes an `apps` row; users are registered in `users`; approved downloads are recorded in `downloads`; gating channels come from `mandatory_channels`.

Paths: `main.py`

#### Admin APK Publishing Pipeline
Admin-only controls drive a seven-step in-memory FSM: APK document, icon, app name, description, version, mod features, and category/tags. The pipeline validates APK input, retains its Telegram file reference, computes SHA-256 for files up to 25 MB, derives a VirusTotal report URL, generates a branded preview, persists the app, and posts it to the configured Telegram channel with an HTML caption and deep-link download button.

FSM state is backed by Aiogram `MemoryStorage`, so in-progress submissions are lost on restart.

Paths: `main.py`, `assets/logo.png`, `assets/badge.png`

#### Media Generation Boundary
Pillow generates a 1920×1080 JPEG promotional preview from the submitted icon. Branding assets and a TrueType font are runtime dependencies: the icon is composed with the badge and logo, while app-name typography uses the font. This is local image processing; Telegram is responsible for storing and delivering the resulting media.

Paths: `main.py`, `assets/logo.png`, `assets/badge.png`, `assets/font.ttf`

#### User Download and Access Control Flow
A channel post’s deep link routes a user to `/start app_{id}`. Before returning the APK using the stored Telegram `file_id`, the bot checks membership in every mandatory channel through Telegram APIs. Non-members receive subscription links and a verification action; members receive the APK and create a download-history record. Search retrieves matching app records by name or description, and users can submit mod requests to administrators.

Paths: `main.py`

#### Operations, Broadcasts, and External Dependencies
Administrators can inspect aggregate statistics, manage mandatory channels, and broadcast text, photos, videos, or GIFs either to the publishing channel or all stored users. Bulk delivery is rate-limited with failure tracking. Required infrastructure is minimal: a long-running Python host, a writable local filesystem for SQLite/assets, Telegram bot credentials, a configured admin ID and channel ID, and network access to Telegram. VirusTotal is not called as an API; generated links point users to reports based on computed hashes.

Paths: `main.py`

Main entry points: [`main.py`](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py) (Command & Event Handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot Runtime"]
  node_main["Bot Application<br/>Aiogram process<br/>[main.py]"]
  node_handlers["Command &amp; Event Handlers<br/>Aiogram handlers<br/>[main.py]"]
  node_store[("SQLite Store<br/>durable persistence")]
  node_admin_ops["Admin Operations<br/>administration<br/>[main.py]"]
end

subgraph group_publishing["Admin Publishing"]
  node_fsm["Publishing FSM<br/>MemoryStorage FSM<br/>[main.py]"]
  node_apk_input["APK Submission<br/>admin document input<br/>[main.py]"]
  node_metadata["App Metadata<br/>publishing fields<br/>[main.py]"]
  node_hashing["Hash &amp; Report Link<br/>SHA-256 processing<br/>[main.py]"]
  node_preview["Promotional Preview<br/>Pillow renderer<br/>[main.py]"]
  node_branding["Branding Assets<br/>image and font assets"]
  node_channel_post["Publishing Channel Post<br/>Telegram channel content<br/>[main.py]"]
end

subgraph group_delivery["User Delivery"]
  node_deep_link["App Deep Link<br/>/start app_&#123;id&#125;<br/>[main.py]"]
  node_access_gate["Subscription Gate<br/>membership verification<br/>[main.py]"]
  node_apk_delivery["APK Delivery<br/>Telegram document send<br/>[main.py]"]
  node_search_requests["Search &amp; Mod Requests<br/>user interaction<br/>[main.py]"]
end

node_telegram{{"Telegram Bot API<br/>external API"}}

node_telegram -->|"updates and file access"| node_main
node_main -->|"dispatches"| node_handlers
node_handlers -->|"admin publishing flow"| node_fsm
node_fsm -->|"collects"| node_apk_input
node_fsm -->|"collects"| node_metadata
node_apk_input -->|"APK content"| node_hashing
node_metadata -->|"icon and copy"| node_preview
node_branding -->|"logo, badge, font"| node_preview
node_hashing -->|"app hash and report URL"| node_store
node_preview -->|"rendered media"| node_channel_post
node_store -->|"persisted app"| node_channel_post
node_channel_post -->|"download button"| node_deep_link
node_deep_link -->|"requested app"| node_access_gate
node_access_gate -->|"checks memberships"| node_telegram
node_store -->|"mandatory channels"| node_access_gate
node_access_gate -->|"approved member"| node_apk_delivery
node_store -->|"APK file_id; records download"| node_apk_delivery
node_apk_delivery -->|"sends document"| node_telegram
node_handlers -->|"user commands"| node_search_requests
node_search_requests -->|"queries apps and users"| node_store
node_handlers -->|"admin commands"| node_admin_ops
node_admin_ops -->|"stats, users, channels"| node_store
node_admin_ops -->|"broadcasts and channel updates"| node_telegram

click node_main "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_handlers "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_fsm "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_apk_input "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_metadata "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_hashing "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_preview "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_channel_post "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_deep_link "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_access_gate "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_apk_delivery "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_search_requests "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py"
click node_admin_ops "https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.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_handlers,node_store,node_admin_ops toneBlue
class node_fsm,node_apk_input,node_metadata,node_hashing,node_preview,node_branding,node_channel_post toneAmber
class node_deep_link,node_access_gate,node_apk_delivery,node_search_requests toneMint
class node_telegram toneNeutral
```

## Components

### Bot Runtime

- [Bot Application](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): Aiogram process · Single-process entry point containing handlers, domain logic, and initialization. · `main.py`
- [Command & Event Handlers](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): Aiogram handlers · Handles commands, callbacks, documents, and media asynchronously. · `main.py`
- **SQLite Store**: durable persistence · Locally initialized and migrated record store for apps, users, downloads, and channels.
- [Admin Operations](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): administration · Provides stats, channel management, and rate-limited broadcasts with failure tracking. · `main.py`

### Admin Publishing

- [Publishing FSM](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): MemoryStorage FSM · Seven-step in-memory APK submission workflow; resets on restart. · `main.py`
- [APK Submission](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): admin document input · Validates APKs and retains Telegram file references. · `main.py`
- [App Metadata](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): publishing fields · Collects icon, name, description, version, mod features, and tags. · `main.py`
- [Hash & Report Link](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): SHA-256 processing · Hashes APKs up to 25 MB and derives a VirusTotal report URL. · `main.py`
- [Promotional Preview](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): Pillow renderer · Creates a branded 1920×1080 JPEG preview. · `main.py`
- **Branding Assets**: image and font assets · Logo, badge, and font used by preview composition.
- [Publishing Channel Post](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): Telegram channel content · Posts preview, HTML caption, and app deep-link button. · `main.py`

### User Delivery

- [App Deep Link](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): /start app_{id} · Routes channel visitors to the requested app download. · `main.py`
- [Subscription Gate](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): membership verification · Checks every mandatory channel and presents subscription links when needed. · `main.py`
- [APK Delivery](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): Telegram document send · Returns the stored APK file after access approval. · `main.py`
- [Search & Mod Requests](https://github.com/qarabaierooom/qazaz-apk-boot/blob/main/main.py): user interaction · Searches app name/description and forwards mod requests to administrators. · `main.py`

### Other components

- **Telegram Bot API**: external API · Hosts bot interactions, files, channel posts, and membership checks.

## Connections

- Telegram Bot API → Bot Application: updates and file access
- Bot Application → Command & Event Handlers: dispatches
- Command & Event Handlers → Publishing FSM: admin publishing flow
- Publishing FSM → APK Submission: collects
- Publishing FSM → App Metadata: collects
- APK Submission → Hash & Report Link: APK content
- App Metadata → Promotional Preview: icon and copy
- Branding Assets → Promotional Preview: logo, badge, font
- Hash & Report Link → SQLite Store: app hash and report URL
- Promotional Preview → Publishing Channel Post: rendered media
- SQLite Store → Publishing Channel Post: persisted app
- Publishing Channel Post → App Deep Link: download button
- App Deep Link → Subscription Gate: requested app
- Subscription Gate → Telegram Bot API: checks memberships
- SQLite Store → Subscription Gate: mandatory channels
- Subscription Gate → APK Delivery: approved member
- SQLite Store → APK Delivery: APK file_id; records download
- APK Delivery → Telegram Bot API: sends document
- Command & Event Handlers → Search & Mod Requests: user commands
- Search & Mod Requests → SQLite Store: queries apps and users
- Command & Event Handlers → Admin Operations: admin commands
- Admin Operations → SQLite Store: stats, users, channels
- Admin Operations → Telegram Bot API: broadcasts and channel updates
