# sickmz/microw architecture

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

- Interactive diagram: https://gitdiagram.com/sickmz/microw
- Repository: https://github.com/sickmz/microw

## Overview

##### Main Components

a) Client Layer:
- Telegram Bot Interface
- User Interaction Components (Commands: Add, Delete, Charts, List, Budget, Settings)

b) Application Core:
- Main Bot Service (src/main.py)
- Handler System (src/handlers.py)
- Configuration Management (src/config.py)
- Synchronization Service (src/sync.py)

c) Storage Layer:
- Local Storage (.xlsx file)
- Google Sheets Integration (optional sync)

d) Utility Services:
- Charts Generation (src/charts.py)
- Utility Functions (src/utils.py)

**┌─────────────────────────────────────────────────────────────┐**
- Telegram Platform                         │
- ┘
- ↕️
**┌─────────────────────────────────────────────────────────────┐**
- Bot Interface Layer                       │
- ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐        │
- Add    │  │ Delete  │  │ Charts  │  │ Budget  │        │
- ┘  └─────────┘  └─────────┘  └─────────┘        │
- ┘
- ↕️
**┌─────────────────────────────────────────────────────────────┐**
- Core Application Layer                    │
- ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐        │
- Handlers│  │  Sync   │  │ Charts  │  │ Config  │        │
- ┘  └─────────┘  └─────────┘  └─────────┘        │
- ┘
- ↙️                                    ↘️
**┌────────────────────┐                    ┌─────────────────┐**
- Local Storage    │ ← − − − − − − − → │  Google Sheets  │
- (.xlsx file)    │      Sync         │    (Optional)    │
- ┘                    └─────────────────┘

##### Important Relationships to Highlight

a) Data Flow:
- User interactions through Telegram → Bot Interface
- Command handling through Handlers
- Storage operations (Local → Google Sheets sync)
- Chart generation flow

b) Key Integration Points:
- Telegram Bot API connection
- Google Sheets API integration
- Local file system interaction

##### Technical Details

- Python-based implementation
- Docker container boundary
- Environment configuration dependencies
- Service account authentication for Google Sheets

##### State Management

Remember to:
- Keep components modular and clearly separated
- Both synchronous and asynchronous operations
- Optional components (like Google Sheets sync)
- Error handling paths
- Security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        TP[Telegram Platform]:::external
        GS[Google Sheets]:::external
    end

    subgraph Interface
        UI[Bot Interface]:::interface
        Add[Add Command]:::command
        Del[Delete Command]:::command
        Chart[Charts Command]:::command
        Budget[Budget Command]:::command
        List[List Command]:::command
        Settings[Settings Command]:::command
        UI --> Add & Del & Chart & Budget & List & Settings
    end

    subgraph Core
        Main[Main Bot Service]:::core
        Handler[Command Handler]:::core
        Config[Configuration Manager]:::core
        Sync[Sync Service]:::core
        Charts[Charts Generator]:::core
        Utils[Utility Functions]:::core
        Constants[System Constants]:::core

        Main --> Handler
        Handler --> Config
        Handler --> Sync
        Handler --> Charts
        Handler --> Utils
        Config --> Constants
    end

    subgraph Storage
        Local[(Local Storage<br>.xlsx)]:::storage
        Docker[Docker Container]:::container
    end

    %% Relationships
    TP <--> UI
    UI --> Main
    Sync <--> GS
    Handler --> Local
    Charts --> Local
    Docker --> Main

    %% Click Events
    click Main "https://github.com/sickmz/microw/blob/main/src/main.py"
    click Handler "https://github.com/sickmz/microw/blob/main/src/handlers.py"
    click Config "https://github.com/sickmz/microw/blob/main/src/config.py"
    click Sync "https://github.com/sickmz/microw/blob/main/src/sync.py"
    click Charts "https://github.com/sickmz/microw/blob/main/src/charts.py"
    click Utils "https://github.com/sickmz/microw/blob/main/src/utils.py"
    click Constants "https://github.com/sickmz/microw/blob/main/src/constants.py"
    click Docker "https://github.com/sickmz/microw/tree/main/Dockerfile"

    %% Styling
    classDef external fill:#gray,stroke:#333,stroke-width:2px
    classDef interface fill:#green,stroke:#333,stroke-width:2px
    classDef command fill:#lightgreen,stroke:#333,stroke-width:1px
    classDef core fill:#blue,stroke:#333,stroke-width:2px
    classDef storage fill:#yellow,stroke:#333,stroke-width:2px
    classDef container fill:#purple,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[External Services]:::external
        L2[Interface Layer]:::interface
        L3[Core Components]:::core
        L4[Storage Systems]:::storage
        L5[Container]:::container
    end
```
