# fawwazs17/makanapa architecture

> Architecture diagram of the GitHub repository fawwazs17/makanapa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fawwazs17/makanapa
- Repository: https://github.com/fawwazs17/makanapa

## Overview

##### Main Components
- Telegram Bot Interface:
- Represented by bot.py, which handles incoming messages/commands from users on Telegram.
- It communicates with the Telegram Bot API (an external service) to both receive customer commands (like /start) and send notifications (especially to the runners' Telegram group using RUNNER_GROUP_ID).
- Database Component:
- Represented by database.py which sets up an SQLite database, and the “data” directory that holds the database file (and possibly other JSON files for order or counter tracking).
- This component is responsible for persistent storage and order management.
- Configuration and Environment:
- An important aspect is the management of environment variables (BOT_TOKEN, RUNNER_GROUP_ID) used to authenticate and configure the Telegram bot.
- The .env.example file (to be copied over to .env) acts as a guideline for required configuration.
- Data/Order Management:
- Files such as data/devlist.json and potentially other JSON files (as mentioned in README like order_counter.json) are used to track orders, counters, or additional runtime data.

##### Relationships and Interactions between Components
- The Telegram bot (bot.py) is the central point that interacts directly with the Telegram API.
- When a user sends a command, bot.py:
- Validates and processes the command,
- Interacts with the database (SQLite via database.py) to store or retrieve order details,
- And sends notifications to the appropriate Telegram group (using the RUNNER_GROUP_ID).
- Database interactions are primarily CRUD operations for order management.
- The external dependency on Telegram’s API means network requests both ways (incoming messages and outgoing notifications).

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The bot’s logic (in bot.py) is separated from the database initialization (in database.py) and persistent data storage (in the “data” directory).
- Configuration Management:
- Environment variables (managed via .env file based on .env.example) clearly decouple sensitive information from the code.
- Data Flow:
- Incoming user interactions via Telegram flow into bot.py,
- Which then interacts with the database layer for storing order data
- And sends notifications back through the Telegram API.

##### Relevant Technologies, Frameworks, or Libraries
- Python is the core programming language.
- Telegram Bot API is used to integrate with Telegram.
- SQLite serves as the database backend.
- JSON is utilized for order tracking and other data storage in files within the “data” directory.

- The flow starting from a user interacting on Telegram,
- Proceeding to bot.py that processes the request,
- Followed by interactions with SQLite (database.py and “data” folder),
- And finally, showing the response back to Telegram users and the runners’ group.
- This helps in visualizing how the Telegram bot orchestrates all tasks while ensuring each component’s role is clearly defined.

## Diagram (Mermaid)

```mermaid
flowchart TD
    API("Telegram API"):::external
    Config("Configuration Module"):::config

    subgraph "Application Layer"
        Bot("Telegram Bot Interface"):::app
    end

    subgraph "Data Layer"
        DB("Database Setup & Persistence"):::data
        DataFolder("Data Folder"):::data
        DataMgmt("Data/Order Management Files"):::data
        DB -->|"Uses"| DataFolder
        DataFolder -->|"Contains"| DataMgmt
    end

    API -->|"ReceivesOrder"| Bot
    Bot -->|"OrderCRUD"| DB
    Bot -->|"SendsNotification"| API
    Config -->|"EnvConfig"| Bot

    click Bot "https://github.com/fawwazs17/makanapa/blob/main/bot.py"
    click DB "https://github.com/fawwazs17/makanapa/blob/main/database.py"
    click DataFolder "https://github.com/fawwazs17/makanapa/tree/main/data/"
    click DataMgmt "https://github.com/fawwazs17/makanapa/blob/main/data/devlist.json"
    click Config "https://github.com/fawwazs17/makanapa/blob/main/.env.example"

    classDef external fill:#add8e6,stroke:#000,stroke-width:2px,color:#000
    classDef app fill:#ffcc00,stroke:#000,stroke-width:2px,color:#000
    classDef data fill:#90ee90,stroke:#000,stroke-width:2px,color:#000
    classDef config fill:#dda0dd,stroke:#000,stroke-width:2px,color:#000
```
