# shaulincito/tarea_separada_bot architecture

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

- Interactive diagram: https://gitdiagram.com/shaulincito/tarea_separada_bot
- Repository: https://github.com/shaulincito/tarea_separada_bot

## Overview

#### Purpose and Runtime

HEROE is a modular Python Telegram bot for monitoring border-post logistics. Operators query inventory and guard shifts through Telegram; a background process proactively alerts a configured chat when stock falls below thresholds. The runtime starts with `python main.py`.

Core runtime paths:
- `main.py`
- `requirements.txt`
- `config.example.py`

#### Entry Points and Telegram Interface

`main.py` is the application orchestrator and Telegram-facing boundary. It initializes the bot using locally supplied credentials, registers reactive commands, starts background monitoring, and keeps the bot receiving updates.

Operator commands:
- `/start` and `/estado`: current resource status.
- `/guardia`: current duty team.
- `/ayuda`: command guidance.

Paths:
- `main.py`
- `config.example.py`

#### Inventory Data Boundary

`database.py` owns the inventory-facing data layer. The repository describes this as simulated logistics data, including inventory access and PDF reading/segmentation capability. It supplies the inventory state consumed by command handlers and scheduled checks, isolating data representation from Telegram interaction.

Paths:
- `database.py`
- `main.py`

#### Proactive Alerting Stage

`scheduler.py` runs scheduled work on a secondary thread. Its primary job is to periodically inspect inventory—documented as every 30 seconds—and identify items whose quantity is below their configured minimum threshold. Detected shortages are sent as proactive Telegram alerts to the configured monitoring chat.

Control flow: scheduler thread → inventory query → threshold evaluation → Telegram message to monitoring chat.

Paths:
- `scheduler.py`
- `database.py`
- `main.py`

#### Guard-Shift Capability

`guardia.py` is an independent domain module for determining the active guard rotation from the host computer’s current time. It maps three daily eight-hour windows to Equipo Alfa, Bravo, or Charlie. `main.py` delegates `/guardia` handling to this module rather than embedding schedule logic in the bot orchestrator.

Paths:
- `guardia.py`
- `main.py`

#### Configuration and Security Boundary

Telegram API credentials and the alert destination chat ID are expected in a local `config.py`, which is intentionally absent from the repository and excluded by `.gitignore`. `config.example.py` defines the distributable configuration shape without real secrets.

External service boundary: Telegram Bot API, accessed from the Python bot runtime using the configured BotFather token.

Paths:
- `config.example.py`
- `.gitignore`
- `main.py`

#### Primary Execution Flow

At startup, `main.py` loads configuration, connects the Telegram bot, registers command handlers, and launches the scheduler. Telegram updates invoke inventory or guard-shift workflows synchronously through the relevant module. Independently, the scheduler evaluates stock levels and emits alerts, allowing monitoring to continue without operator commands.

Main entry points: [`main.py`](https://github.com/shaulincito/tarea_separada_bot/blob/main/main.py) (Application orchestrator), [`scheduler.py`](https://github.com/shaulincito/tarea_separada_bot/blob/main/scheduler.py) (Stock scheduler), [`database.py`](https://github.com/shaulincito/tarea_separada_bot/blob/main/database.py) (Inventory data), [`config.example.py`](https://github.com/shaulincito/tarea_separada_bot/blob/main/config.example.py) (Configuration template)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Python bot runtime"]
  node_main["Application orchestrator<br/>Python entry point<br/>[main.py]"]
  node_handlers["Command handlers<br/>Telegram commands<br/>[main.py]"]
  node_scheduler["Stock scheduler<br/>Background thread<br/>[scheduler.py]"]
  node_config["Local configuration<br/>Secret runtime config"]
  node_config_example["Configuration template<br/>Example config<br/>[config.example.py]"]
  node_gitignore["Secret exclusion<br/>Git ignore rules<br/>[.gitignore]"]
end

subgraph group_domain["Domain modules"]
  node_database[("Inventory data<br/>Logistics data layer<br/>[database.py]")]
  node_thresholds["Threshold evaluation<br/>Shortage detection<br/>[scheduler.py]"]
  node_guardia["Guard rotation<br/>Time-based domain module<br/>[guardia.py]"]
end

subgraph group_external["External boundary"]
  node_telegram{{"Telegram Bot API<br/>External messaging service"}}
  node_operators(("Operators<br/>Telegram users"))
  node_monitoring_chat(("Monitoring chat<br/>Alert destination"))
end

node_config_example -.->|"copied and populated as"| node_config
node_gitignore -.->|"excludes"| node_config
node_config -->|"credentials and chat ID"| node_main
node_main -->|"registers"| node_handlers
node_main -->|"starts"| node_scheduler
node_main -->|"connects with bot token"| node_telegram
node_operators -->|"send commands"| node_telegram
node_telegram -->|"delivers updates"| node_handlers
node_handlers -->|"status queries"| node_database
node_handlers -->|"/guardia"| node_guardia
node_scheduler -->|"periodic inventory query"| node_database
node_scheduler -->|"evaluates"| node_thresholds
node_database -->|"inventory quantities"| node_thresholds
node_thresholds -->|"shortage alert"| node_telegram
node_telegram -->|"proactive message"| node_monitoring_chat

click node_main "https://github.com/shaulincito/tarea_separada_bot/blob/main/main.py"
click node_handlers "https://github.com/shaulincito/tarea_separada_bot/blob/main/main.py"
click node_scheduler "https://github.com/shaulincito/tarea_separada_bot/blob/main/scheduler.py"
click node_database "https://github.com/shaulincito/tarea_separada_bot/blob/main/database.py"
click node_thresholds "https://github.com/shaulincito/tarea_separada_bot/blob/main/scheduler.py"
click node_guardia "https://github.com/shaulincito/tarea_separada_bot/blob/main/guardia.py"
click node_config_example "https://github.com/shaulincito/tarea_separada_bot/blob/main/config.example.py"
click node_gitignore "https://github.com/shaulincito/tarea_separada_bot/blob/main/.gitignore"

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_scheduler,node_config,node_config_example,node_gitignore toneBlue
class node_database,node_thresholds,node_guardia toneAmber
class node_telegram,node_operators,node_monitoring_chat toneMint
```

## Components

### Python bot runtime

- [Application orchestrator](https://github.com/shaulincito/tarea_separada_bot/blob/main/main.py): Python entry point · Starts polling, registers commands, and launches monitoring. · `main.py`
- [Command handlers](https://github.com/shaulincito/tarea_separada_bot/blob/main/main.py): Telegram commands · Handles status, guard duty, and help requests. · `main.py`
- [Stock scheduler](https://github.com/shaulincito/tarea_separada_bot/blob/main/scheduler.py): Background thread · Checks inventory every 30 seconds. · `scheduler.py`
- **Local configuration**: Secret runtime config · Provides bot token and alert chat ID; excluded from source control.
- [Configuration template](https://github.com/shaulincito/tarea_separada_bot/blob/main/config.example.py): Example config · Defines the distributable configuration shape. · `config.example.py`
- [Secret exclusion](https://github.com/shaulincito/tarea_separada_bot/blob/main/.gitignore): Git ignore rules · Keeps local config out of the repository. · `.gitignore`

### Domain modules

- [Inventory data](https://github.com/shaulincito/tarea_separada_bot/blob/main/database.py): Logistics data layer · Provides simulated inventory and document-reading capability. · `database.py`
- [Threshold evaluation](https://github.com/shaulincito/tarea_separada_bot/blob/main/scheduler.py): Shortage detection · Identifies stock below configured minimums. · `scheduler.py`
- [Guard rotation](https://github.com/shaulincito/tarea_separada_bot/blob/main/guardia.py): Time-based domain module · Maps eight-hour windows to Alfa, Bravo, or Charlie. · `guardia.py`

### External boundary

- **Telegram Bot API**: External messaging service
- **Operators**: Telegram users
- **Monitoring chat**: Alert destination

## Connections

- Configuration template → Local configuration: copied and populated as
- Secret exclusion → Local configuration: excludes
- Local configuration → Application orchestrator: credentials and chat ID
- Application orchestrator → Command handlers: registers
- Application orchestrator → Stock scheduler: starts
- Application orchestrator → Telegram Bot API: connects with bot token
- Operators → Telegram Bot API: send commands
- Telegram Bot API → Command handlers: delivers updates
- Command handlers → Inventory data: status queries
- Command handlers → Guard rotation: /guardia
- Stock scheduler → Inventory data: periodic inventory query
- Stock scheduler → Threshold evaluation: evaluates
- Inventory data → Threshold evaluation: inventory quantities
- Threshold evaluation → Telegram Bot API: shortage alert
- Telegram Bot API → Monitoring chat: proactive message
