# someoneex/naru_-final architecture

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

- Interactive diagram: https://gitdiagram.com/someoneex/naru_-final
- Repository: https://github.com/someoneex/naru_-final

## Overview

##### Project type and purpose
- This is a Python‐based Telegram bot (“Txt Extractor Bot”) whose sole purpose is to receive text files or APKs from users, scan them for URLs, and then log or relay those URLs. It is not a user‐facing web app but a backend microservice that runs continuously, reacts to Telegram events, and persists data to MongoDB.

##### File structure
- Top level
- Dockerfile, app.json, heroku.yml → containerization and Heroku deployment configs
- main.py → entrypoint, sets up Telegram client, dispatcher, and starts event loop
- config.py → environment variable loader for BOT_TOKEN, API_ID/HASH, DB credentials, channel IDs, etc.
- buttom.py, msg.py → utility modules for bot messages, UI text, maybe keyboard layouts
- database/appx_token.py → database wrapper to store/retrieve tokens or URLs in MongoDB
- module/
- ~40 files named by service/app + “free” suffix → each module implements URL‐extraction logic for a particular target (e.g., “khanfree” handles free URLs from Khan academy content).
- plugins/
- helper.py → shared utility functions, middleware or decorators for modular plug‐ins
- README.md describes deployment steps and required configuration

##### Key insights from README
- The bot uses Pyrogram or Telethon under the hood (implied by API_ID/HASH)
- Persists URL hits and other metadata in MongoDB (“DB_URL/DB_NAME”)
- Logs to 5 different Telegram channels (TXT_LOG, AUTH_LOG, etc.)
- Deployable to Heroku or Docker

##### Main components
a. Telegram Bot Service
– Entry point: main.py
– Load configuration (config.py)
– Telegram API client (Pyrogram/Telethon)
b. Module Manager
– module/ directory: individual URL‐extractor plugins
– plugins/helper.py: shared utilities
– msg.py & buttom.py: message templates, keyboards
c. Database Layer
– database/appx_token.py for token storage
– MongoDB Atlas or whatever DB_URL points to
d. Logging & Notification Channels
– Internal logging to: TXT_LOG, AUTH_LOG, HIT_LOG, DRM_DUMP channels
– Output back to users or designated Telegram channels
e. External Dependencies
– Telegram Bot API endpoints
– MongoDB server
– Heroku build/deploy environment or Docker container

##### Relationships & Data Flow
1) Incoming update from user → Telegram API → Bot Service
2) Bot Service passes raw input to Module Manager
3) Module Manager picks the correct extractor module based on user command or file type
4) Extractor module scans text/APK for URLs, returns list
5) Bot Service writes results to MongoDB via Database Layer
6) Bot Service pushes logs or results to appropriate Telegram channels
7) Bot Service replies back to user via Telegram API

##### Architectural patterns and principles
- Plugin architecture: each module independent, loaded dynamically
- Single responsibility: modules do extraction, database code is separate, config is externalized
- Event‐driven: responds to Telegram updates
- Infrastructure as code: Dockerfile, heroku.yml, app.json

##### Technologies & frameworks
- Python 3.x
- Pyrogram or Telethon (Telegram API client)
- PyMongo (MongoDB driver)
- Heroku / Docker for deployment
- Possibly APScheduler or asyncio for concurrency

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Docker/Heroku Runtime"
        BotService["Bot Service<br/>(main.py)"]:::core
        Config["Environment & Secrets<br/>(config.py)"]:::config

        subgraph "Module Manager (Plugins)"
            Extractor["Extractor Modules<br/>(module/*.py)"]:::plugin
            Helper["Shared Utilities<br/>(plugins/helper.py)"]:::plugin
            Msg["Message Templates<br/>(msg.py)"]:::plugin
            Button["Keyboard Layouts<br/>(buttom.py)"]:::plugin
        end

        DBLayer["Database Layer<br/>(database/appx_token.py)"]:::core
    end

    Telegram["Telegram API (Updates & Messaging)"]:::external
    MongoDB["MongoDB"]:::external

    subgraph "Deployment & Infrastructure"
        DockerfileNode["Dockerfile"]:::infra
        HerokuYML["heroku.yml"]:::infra
        AppJSON["app.json"]:::infra
        README["README.md"]:::infra
    end

    Telegram -->|"Incoming Update"| BotService
    BotService -->|"Load Config"| Config
    BotService -->|"Dispatch to Plugins"| Extractor
    Extractor -->|"Extracted URLs"| BotService
    BotService -->|"Write Results"| DBLayer
    DBLayer -->|"Store Data"| MongoDB
    BotService -->|"Send Logs/Responses"| Telegram

    Config --> BotService
    Config --> Extractor
    Config --> DBLayer

    classDef core fill:#cce5ff,stroke:#004085,color:#004085;
    classDef plugin fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#fff3cd,stroke:#856404,color:#856404;
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef infra fill:#f5c6cb,stroke:#721c24,color:#721c24;

    click BotService "https://github.com/someoneex/naru_-final/blob/main/main.py"
    click Config "https://github.com/someoneex/naru_-final/blob/main/config.py"
    click Extractor "https://github.com/someoneex/naru_-final/tree/main/module/"
    click Helper "https://github.com/someoneex/naru_-final/blob/main/plugins/helper.py"
    click Msg "https://github.com/someoneex/naru_-final/blob/main/msg.py"
    click Button "https://github.com/someoneex/naru_-final/blob/main/buttom.py"
    click DBLayer "https://github.com/someoneex/naru_-final/blob/main/database/appx_token.py"
    click DockerfileNode "https://github.com/someoneex/naru_-final/tree/main/Dockerfile"
    click HerokuYML "https://github.com/someoneex/naru_-final/blob/main/heroku.yml"
    click AppJSON "https://github.com/someoneex/naru_-final/blob/main/app.json"
    click README "https://github.com/someoneex/naru_-final/blob/main/README.md"
```
