# michaai/ctmtuci-schedule architecture

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

- Interactive diagram: https://gitdiagram.com/michaai/ctmtuci-schedule
- Repository: https://github.com/michaai/ctmtuci-schedule

## Overview

##### Main Components

a) Core Bot Components:
- Main Bot Service (src/main.rs)
- Telegram Interface Layer (src/tg.rs)
- Data Processing Components
- Sheet Parser (src/sheet_parser.rs)
- Sheet Updater (src/sheet_updater.rs)

b) Supporting Systems:
- Dialog Management System (src/dialoge/)
- Data Types Layer (src/datatypes.rs)
- Utility Functions (src/utils.rs)

**┌─ External Services Layer ─┐**
- Telegram API          │
- Google Sheets API     │
- ┘
- ↕
**┌─ Interface Layer ────────┐**
- Telegram Handler      │
- Sheet Operations      │
- ┘
- ↕
**┌─ Core Logic Layer ───────┐**
- Dialog Management     │
- Data Processing       │
- ┘
- ↕
**┌─ Data Layer ────────────┐**
- Data Types           │
- Utils               │
- ┘

##### Component Relationships

- Blue: External service connections
- Green: Internal component communications
- Orange: Data flow paths

Key relationships to highlight:
- Main service orchestrating all components
- Dialog system managing conversation flow
- Sheet parser/updater interacting with Google Sheets
- Telegram interface handling bot communications

##### Specific Implementation Details

Technical aspects:
- Docker container boundary (indicated by Dockerfile presence)
- CI/CD pipeline connection (shown by .github/workflows)
- Binary outputs (src/bin directory)
- Module dependencies and interactions

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Services Layer
    subgraph External
        TelegramAPI["Telegram API\n(teloxide crate)\nHandles bot commands\nWebhook integration"]
        GSheetsAPI["Google Sheets API\n(google_sheets4)\nOAuth2 authentication\nRESTful operations"]
    end

    %% Interface Layer
    subgraph Interface
        TGHandler["Telegram Handler\nteloxide::prelude::*\nAsync message processing\nError handling with anyhow"]:::interface
        SheetOps["Sheet Operations\ngoogle_sheets4::Sheets\nBatch updates\nRange operations"]:::interface
    end

    %% Core Logic Layer
    subgraph CoreLogic
        MainService["Main Bot Service\ntokio runtime\nConfig management\nError propagation"]:::core
        DialogSystem["Dialog Management System\nState machines\nConversation tracking\nUser session handling"]:::core
        SheetParser["Sheet Parser\ncsv parsing\nData validation\nError recovery"]:::core
        SheetUpdater["Sheet Updater\nBatch operations\nRetry logic\nConsistency checks"]:::core
    end

    %% Data Layer
    subgraph DataLayer
        DataTypes["Data Types\nSerde serialization\nCustom implementations\nValidation traits"]:::data
        Utils["Utility Functions\nLogging (env_logger)\nError handling\nDate/time operations"]:::data
    end

    %% Infrastructure
    subgraph Infrastructure
        Docker["Docker Container\nAlpine Linux base\nMulti-stage build\nVolume mounts"]:::infra
        CICD["CI/CD Pipeline\nGitHub Actions\nCargo build/test\nDocker publish"]:::infra
    end

    %% Relationships
    TelegramAPI <--> |"Bot API calls\nWebhook events"| TGHandler
    GSheetsAPI <--> |"OAuth2 requests\nJSON responses"| SheetOps
    TGHandler <--> |"Command routing\nResponse handling"| MainService
    SheetOps <--> |"Read operations"| SheetParser
    SheetOps <--> |"Write operations"| SheetUpdater
    MainService --> |"State transitions"| DialogSystem
    DialogSystem --> |"Type conversion"| DataTypes
    SheetParser --> |"Data mapping"| DataTypes
    SheetUpdater --> |"Validation"| DataTypes
    DataTypes --> |"Helper functions"| Utils
    MainService --> |"Error handling"| Utils

    %% Infrastructure Connections
    Docker --- |"Runtime environment"| MainService
    CICD --- |"Build process"| Docker

    %% Click Events
    click MainService "https://github.com/MichaAI/ctmtuci-schedule/blob/master/src/main.rs"
    click TGHandler "https://github.com/MichaAI/ctmtuci-schedule/blob/master/src/tg.rs"
    click SheetParser "https://github.com/MichaAI/ctmtuci-schedule/blob/master/src/sheet_parser.rs"
    click SheetUpdater "https://github.com/MichaAI/ctmtuci-schedule/blob/master/src/sheet_updater.rs"
    click DialogSystem "https://github.com/MichaAI/ctmtuci-schedule/tree/master/src/dialoge/"
    click DataTypes "https://github.com/MichaAI/ctmtuci-schedule/blob/master/src/datatypes.rs"
    click Utils "https://github.com/MichaAI/ctmtuci-schedule/blob/master/src/utils.rs"
    click Docker "https://github.com/MichaAI/ctmtuci-schedule/tree/master/Dockerfile"
    click CICD "https://github.com/MichaAI/ctmtuci-schedule/blob/master/.github/workflows/rust.yml"

    %% Styles
    classDef interface fill:#a8d08d
    classDef core fill:#91c3f2
    classDef data fill:#f4b183
    classDef infra fill:#b4a7d6
    
    %% Legend
    subgraph Legend
        L1["Interface Components"]:::interface
        L2["Core Components"]:::core
        L3["Data Components"]:::data
        L4["Infrastructure"]:::infra
    end
```
