# alexisomg/bmstu-free-rooms architecture

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

- Interactive diagram: https://gitdiagram.com/alexisomg/bmstu-free-rooms
- Repository: https://github.com/alexisomg/bmstu-free-rooms

## Overview

##### Main Components Identification
The project appears to be a Telegram bot with the following key components:

a) Bot Interface Layer
- Entry point through Telegram Bot API
- Located in `handlers/bot.go`

b) ICS Processing System
- ICS file loader (`handlers/iscloader.go`)
- ICS parser (`icsparser/icsparser.go`)

c) Core Service Layer
- Business logic handlers in `service/` directory
- Separate services for different entities (audience, group, lesson, schedule, user)

d) Database Layer
- PostgreSQL database (indicated by `init.sql`)
- Database models and operations in `database/` directory

##### Component Relationships

**[Telegram Bot API] (External)**
- ↓
**[Bot Handler Layer]**
- ↓
**[ICS Processing System] ←→ [External ICS Calendar Source]**
- ↓
**[Service Layer]**
- ↓
**[Database Layer]**
- ↓
**[PostgreSQL Database]**

##### Specific Elements

- Telegram Bot API
- ICS Calendar Source (University's schedule system)

b) Core Components (Solid rectangles):
- Bot Handler (handlers/bot.go)
- ICS Processor (icsparser/)
- Service Layer (service/)
- Database Layer (database/)

- User requests → Bot Handler
- Schedule updates → ICS Processor
- Data persistence flows → Database

##### Important Details to Highlight

a) Service Layer Components:
- AudienceService
- GroupService
- LessonService
- ScheduleService
- UserService

b) Database Entities:
- Audience
- Group
- Lesson
- Schedule
- User

##### Architectural Patterns to Emphasize
- Layer separation (handlers → service → database)
- Domain-driven design (separate service files for each domain entity)
- Repository pattern (database layer implementation)

Remember to indicate the asynchronous nature of Telegram bot interactions and any background processes for ICS file processing. This will help other developers understand both the static structure and dynamic behavior of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Systems
    TG[Telegram Bot API]:::external
    ICS[External ICS Calendar Source]:::external

    %% Bot Interface Layer
    subgraph BotLayer[Bot Interface Layer]
        BH[Bot Handler]:::handler
        IL[ICS Loader]:::handler
    end

    %% ICS Processing System
    subgraph ICSLayer[ICS Processing System]
        IP[ICS Parser]:::processor
    end

    %% Service Layer
    subgraph ServiceLayer[Service Layer]
        SI[Service Initialization]:::service
        AS[Audience Service]:::service
        GS[Group Service]:::service
        LS[Lesson Service]:::service
        SS[Schedule Service]:::service
        US[User Service]:::service
        SE[Service Error Handler]:::error
    end

    %% Database Layer
    subgraph DBLayer[Database Layer]
        DI[Database Initialization]:::db
        AR[Audience Repository]:::db
        GR[Group Repository]:::db
        LR[Lesson Repository]:::db
        SR[Schedule Repository]:::db
        UR[User Repository]:::db
        DE[Database Error Handler]:::db
    end

    %% Database
    DB[(PostgreSQL)]:::database

    %% Configuration
    CF[Config]:::config
    ME[Main Entry]:::config

    %% Relationships
    TG --> BH
    ICS --> IL
    
    BH --> SI
    IL --> IP
    IP --> SS
    
    SI --> AS & GS & LS & SS & US
    SI --> SE
    
    AS --> AR
    GS --> GR
    LS --> LR
    SS --> SR
    US --> UR
    
    AR & GR & LR & SR & UR --> DI
    DI --> DE
    DI --> DB
    
    CF --> ME
    ME --> BH

    %% Click Events
    click BH "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/handlers/bot.go"
    click IL "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/handlers/iscloader.go"
    click IP "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/icsparser/icsparser.go"
    click SI "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/service.go"
    click AS "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/audience.go"
    click GS "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/group.go"
    click LS "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/lesson.go"
    click SS "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/schedule.go"
    click US "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/user.go"
    click SE "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/service/errors.go"
    click DI "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/database.go"
    click AR "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/audience.go"
    click GR "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/group.go"
    click LR "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/lesson.go"
    click SR "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/schedule.go"
    click UR "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/user.go"
    click DE "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/database/errors.go"
    click DB "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/init.sql"
    click CF "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/cmd/ics/config.go"
    click ME "https://github.com/AlexisOMG/bmstu-free-rooms/blob/main/cmd/ics/main.go"

    %% Styles
    classDef external fill:#A0D8EF,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef handler fill:#90EE90,stroke:#333,stroke-width:2px
    classDef processor fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef service fill:#98FB98,stroke:#333,stroke-width:2px
    classDef db fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef database fill:#FF8C69,stroke:#333,stroke-width:2px
    classDef error fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef config fill:#DDA0DD,stroke:#333,stroke-width:2px
```
