# saydullin/bsuir_schedule architecture

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

- Interactive diagram: https://gitdiagram.com/saydullin/bsuir_schedule
- Repository: https://github.com/saydullin/bsuir_schedule

## Overview

##### Project Overview and Purpose
- This project is an Android application designed to display schedules for BSUIR University students and teachers. It supports multiple schedule types (teachers, students, exams), custom subject additions, history tracking, sharing capabilities, and various settings (language, theme, auto update, etc.).
- The app also includes rich features like local notifications, app widgets, and an offline database for managing schedule data.

##### Main Architectural Layers and Components
a. Presentation Layer (UI)
- Activities, Fragments, and Dialogs (located in app/src/main/java/com/bsuir/bsuirschedule/presentation) provide the user interface.
- ViewModels (in app/src/main/java/com/bsuir/bsuirschedule/presentation/viewModels) that interact with the UI logic.
- Adapters, Views, and Widgets (e.g., app/src/main/java/com/bsuir/bsuirschedule/presentation/adapters, widgets, and views) handle visual rendering and user input.
- Android Services, Receivers, and Workers (in the service, receiver, and worker folders) manage background tasks such as schedule updates, notifications, and widget updates.

b. Domain Layer (Business Logic)
- Use Cases (in app/src/main/java/com/bsuir/bsuirschedule/domain/usecase) encapsulate the business logic like fetching schedules, updating schedule history, and applying custom schedule settings.
- Domain Models (in app/src/main/java/com/bsuir/bsuirschedule/domain/models) represent the key entities for schedule, teacher, faculty, etc.
- Schedule Management components (managers in app/src/main/java/com/bsuir/bsuirschedule/domain/manager) handle schedule building, updating, and related business rules.

c. Data Layer (Data Access and Repositories)
- API Services (located under app/src/main/java/com/bsuir/bsuirschedule/api) implemented with Retrofit (e.g., RetrofitBuilder.kt and various Get…Service.kt files) handle network requests.
- Local Database and DAOs (in app/src/main/java/com/bsuir/bsuirschedule/data/db) manage on-device persistence using Room (from the database entities, dao, and migration folders). JSON schema files in app/schemas hint at keeping database versions.
- Repositories (both in the data layer and mirrored in the domain layer under repository folders) abstract data fetching and caching, integrating both remote API and local DB sources.

d. Dependency Injection (DI)
- DI modules (located in app/src/main/java/com/bsuir/bsuirschedule/di) such as AppModule, DataModule, and DomainModule manage dependency injection, ensuring decoupling and testability.

e. External Components/Services
- Notification components (in app/src/main/java/com/bsuir/bsuirschedule/notification) handle schedule notifications.
- Widget components (in app/src/main/java/com/bsuir/bsuirschedule/presentation/widgets) provide app widget functionality.
- Android-specific components such as AndroidManifest, Gradle build scripts, and resource files under app/src/main/res contributing to overall application packaging and configuration.

- At the top, show the Presentation/UI layer which includes Activities, Fragments, ViewModels, and Widgets.
- An “Infrastructure” block that houses the Dependency Injection (DI) containers used by all layers.
- Integrations with external components such as:

##### Architectural Patterns and Design Principles
- The project follows a layered, clean architecture pattern separating presentation, domain, and data responsibilities.
- MVVM (Model-View-ViewModel) appears in the presentation layer with ViewModels interacting with Domain use cases.
- Use of dependency injection promotes loose coupling.
- The repository pattern abstracts data sources, enabling interchangeability between remote and local data.
- The architecture supports extensibility with clearly separated responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        S1["UI Components (Activities, Fragments, Dialogs, Adapters, Views)"]:::presentation
        S2["ViewModels"]:::presentation
        subgraph "Background Processes"
            S3a["Services"]:::presentation
            S3b["Receivers"]:::presentation
            S3c["Workers"]:::presentation
        end
        S4["Widgets"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        D1["Use Cases"]:::domain
        D2["Domain Models"]:::domain
        D3["Schedule Management"]:::domain
        D4["Domain Repositories"]:::domain
        D5["Domain Utils"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        L1["API Services"]:::data
        L2["Local Database & DAOs"]:::data
        L3["Migrations"]:::data
        L4["Repository Implementations"]:::data
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        I1["Dependency Injection"]:::infra
    end

    %% External Components
    subgraph "External Components"
        E1["Notification Components"]:::external
    end

    %% Connections between layers
    S1 -->|"triggers"| S2
    S2 -->|"calls"| D1
    D1 -->|"invokes"| D3
    D1 -->|"utilizes"| D2
    D1 -->|"accesses"| D4
    D1 -->|"uses"| D5
    D4 -->|"fetches data from"| L4
    L1 -->|"supplies data to"| L4
    L2 -->|"supplies data to"| L4
    L3 -->|"supplies migrations to"| L4

    %% Background Processes invoking business logic
    S3a -->|"updates schedule"| D1
    S3b -->|"updates schedule"| D1
    S3c -->|"updates schedule"| D1

    %% Widgets interact with UI
    S4 -->|"renders"| S1

    %% Dependency Injection connections
    I1 --> S1
    I1 --> D1
    I1 --> L1

    %% External Notifications triggered by Services
    S3a -->|"triggers notification"| E1

    %% Style classes
    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef domain fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef data fill:#FFD580,stroke:#333,stroke-width:2px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#D8BFD8,stroke:#333,stroke-width:2px;

    %% Click Events for Presentation Layer
    click S1 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/presentation"
    click S2 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/presentation/viewModels"
    click S3a "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/service"
    click S3b "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/receiver"
    click S3c "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/worker"
    click S4 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/presentation/widgets"

    %% Click Events for Domain Layer
    click D1 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/domain/usecase"
    click D2 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/domain/models"
    click D3 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/domain/manager/schedule"
    click D4 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/domain/repository"
    click D5 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/domain/utils"

    %% Click Events for Data Layer
    click L1 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/api"
    click L2 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/data/db"
    click L3 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/data/db/migration"
    click L4 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/data/repository"

    %% Click Event for Infrastructure
    click I1 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/di"

    %% Click Event for External Components
    click E1 "https://github.com/saydullin/bsuir_schedule/tree/master/app/src/main/java/com/bsuir/bsuirschedule/notification"
```
