# erkan3034/nlpminiproject architecture

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

- Interactive diagram: https://gitdiagram.com/erkan3034/nlpminiproject
- Repository: https://github.com/erkan3034/nlpminiproject

## Overview

##### Main Components
a. User’s Telegram Client (Mobile/Desktop)
b. Telegram Bot API (External Service)
c. Bot Application (ItDesk.py)
- Update handler
- Command router
- NLP-style keyword matcher
d. Knowledge Base Module (bilgi_tabani.py)
- Data access functions (read/write)
- In-memory vs. file persistence (e.g., JSON or plain text)
e. Persistent Storage (flat files under the project directory)
f. Environment & Config
- `TELEGRAM_BOT_TOKEN` (env var)
- Third-party library: `python-telegram-bot`

##### Relationships & Data Flows
1) User sends a message in Telegram → goes to Telegram Bot API
2) API forwards Update to ItDesk.py via webhook or polling
3) ItDesk.py parses the Update, routes it to the appropriate handler:
- “Report Issue” → keyword extractor → knowledge base lookup
- “Add Solution” → knowledge base write
- “Unknown Questions” → knowledge base query
4) Handlers call functions in bilgi_tabani.py to fetch or store data
5) The bot assembles a response and sends it back through the Telegram Bot API → to the User

##### Architectural Patterns & Principles
- Separation of Concerns:
- ItDesk.py handles messaging and command logic
- bilgi_tabani.py handles data access and rule-based matching
- Rule-based NLP: keyword matching rather than ML pipeline
- Single Python process (no microservices) but modular code for easy extension

##### Relevant Technologies & Frameworks
- Language: Python 3.7+
- Telegram integration: `python-telegram-bot` library
- Data storage: flat files (no external DB)
- Environment config: OS env vars for secrets

##### Essential Elements Checklist
[ ] User (Telegram client)
[ ] Telegram Bot API (external)
[ ] Bot Application
- Update Receiver
- Command Router
- Response Generator
[ ] Knowledge Base Module
[ ] Persistent Storage (files)
[ ] Environment/Config

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and External
    User["User\n(Telegram Client)"]:::user
    API["Telegram Bot API"]:::external

    %% Bot Service
    subgraph "Bot Service"
        ItDesk["ItDesk.py\n(Update Handler, Command Router, Response Generator)"]:::app
        Config["Env & Config\n(Load TELEGRAM_BOT_TOKEN, python-telegram-bot)"]:::app
        KB["bilgi_tabani.py\n(Knowledge Base Module)"]:::app
    end

    %% Storage
    Storage[(Flat Files\nKnowledge Base)]:::storage

    %% Data Flows
    User -->|"Send Message"| API
    API -->|"Webhook/Polling Update"| ItDesk
    ItDesk -->|"fetch_solution(keyword)"| KB
    ItDesk -->|"write_solution()/add_rule()"| KB
    KB -->|"read/write data"| Storage
    ItDesk -->|"Load Token & Config"| Config
    ItDesk -->|"Send Response"| API
    API -->|"Deliver Message"| User

    %% Click Events
    click ItDesk "https://github.com/erkan3034/nlpminiproject/blob/main/ItDesk.py"
    click KB "https://github.com/erkan3034/nlpminiproject/blob/main/bilgi_tabani.py"

    %% Styles
    classDef app fill:#e0ffe0,stroke:#008000,stroke-width:1px;
    classDef storage fill:#ffffcc,stroke:#cccc00,stroke-width:1px;
    classDef external fill:#ccf2ff,stroke:#3399ff,stroke-width:1px;
    classDef user fill:#f9f9f9,stroke:#666666,stroke-width:1px;
```
