# hfdlys/bjtuselfservice architecture

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

- Interactive diagram: https://gitdiagram.com/hfdlys/bjtuselfservice
- Repository: https://github.com/hfdlys/bjtuselfservice

## Overview

##### Project Type and Purpose
- This is an Android Studio project – a mobile app designed to consolidate numerous student services (automatic MIS login, email viewing without re-login, campus card balance, exam schedules, course table management, local data parsing including captcha recognition, and even a classroom capacity check).
- Its key advantage is local processing for improved security, with a single network interaction for retrieving classroom numbers.
- The app also incorporates email subscription and alert functionality for assignments and courses.

##### Analyzing the File Structure
- The top-level “app” folder indicates the application module.
- Under “app/src/main/java/team/bjtuss/bjtuselfservice”, directories are arranged by functionality:
- “screen” houses UI screens for various features (LoginScreen, HomeScreen, ExamScheduleScreen, etc.).
- “viewmodel” contains the ViewModels (e.g., LoginViewModel, CourseScheduleViewModel) that likely manage UI state and business logic.
- “repository” abstracts data sources with different repositories (DatabaseRepository, NetworkRepository, etc.).
- “dao”, “database”, and “entity” imply a local database layer (potentially using Room) for persisting course data, grades, homework, etc.
- “component” and “ui/theme” support the UI elements and design consistency.
- “utils” provide helper functions (e.g., network operations, file picking, image conversion for ML model).
- “web” and “jsonclass” suggest integration with external services (like classroom capacity or MIS data).
- The “assets” folder contains a machine learning model (model.pt) used for captcha recognition, adding a specialized component for local ML processing.
- The build files (build.gradle.kts, settings.gradle.kts) and gradle wrapper files handle project builds and dependency management.

##### Architectural Patterns and Design Principles
- The structure strongly suggests the Model-View-ViewModel (MVVM) pattern:
- The “screen” (View) layer is separated from the “viewmodel” (logic) layer.
- Repositories form the data/model layer, encapsulating database (dao, database, entity) and network operations.
- There’s a clear separation between UI, business logic, and data access, ensuring modularity and ease of testing.
- The use of repositories and a centralized database abstraction provides single points of access to data, enhancing maintainability.

##### Relationships and Interactions
- UI components sending user interactions to the corresponding ViewModel.
- ViewModels querying or updating data via the Repository layer.
- Data flows between the Database (using DAO) and Repositories.
- Network requests flowing from the Network Repository to external services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        LS("LoginScreen"):::ui
        HS("HomeScreen"):::ui
        CSS("CourseScheduleScreen"):::ui
        ESS("ExamScheduleScreen"):::ui
        UITH("UI Theme"):::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        LV("LoginViewModel"):::vm
        CV("CourseScheduleViewModel"):::vm
        MV("MainViewModel"):::vm
    end

    %% Repository/Data Layer
    subgraph "Repository/Data Layer"
        DR("Database Repository"):::repo
        NR("Network Repository"):::repo
        DAO("DAO Layer"):::repo
        DB("Database"):::repo
        ENT("Entities"):::repo
    end

    %% ML & Assets Component
    subgraph "ML & Assets Component"
        ML("ML Model (model.pt)"):::ml
        ITC("ImageToTensorConverter"):::ml
    end

    %% Web Integration
    subgraph "Web Integration"
        WEB("Web Services"):::web
    end

    %% Utility Functions
    subgraph "Utility Functions"
        UTILS("Utilities"):::util
    end

    %% Relationships between UI and ViewModel Layers
    LS -->|"input"| LV
    HS -->|"input"| MV
    CSS -->|"input"| CV
    ESS -->|"input"| MV
    UITH -->|"applies style"| LS

    %% Relationships between ViewModels and Repository/Data Layer
    LV -->|"query/update"| DR
    LV -->|"APIcall"| NR
    CV -->|"query/update"| DR
    CV -->|"APIcall"| NR
    MV -->|"query/update"| DR
    MV -->|"APIcall"| NR

    %% Internal Data Layer connections
    DR -->|"dataAccess"| DAO
    DR -->|"dataAccess"| DB
    DR -->|"dataAccess"| ENT

    %% Network Repository external call
    NR -->|"externalCall"| WEB

    %% ML Component interactions
    ITC -->|"convertsImage"| ML
    ITC -->|"captchaVerify"| DR

    %% Utility Functions supporting ML and Network operations
    UTILS -->|"helper"| ITC
    UTILS -->|"networkHelper"| NR

    %% Click Events for UI Layer
    click LS "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/screen"
    click HS "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/screen"
    click CSS "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/screen"
    click ESS "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/screen"
    click UITH "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/ui/theme"

    %% Click Events for ViewModel Layer
    click LV "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/viewmodel"
    click CV "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/viewmodel"
    click MV "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/viewmodel"

    %% Click Events for Repository/Data Layer
    click DR "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/repository"
    click NR "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/repository"
    click DAO "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/dao"
    click DB "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/database"
    click ENT "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/entity"

    %% Click Events for ML & Assets Component
    click ML "https://github.com/hfdlys/bjtuselfservice/blob/main/app/src/main/assets/model.pt"
    click ITC "https://github.com/hfdlys/bjtuselfservice/blob/main/app/src/main/java/team/bjtuss/bjtuselfservice/utils/ImageToTensorConverter.java"

    %% Click Event for Web Integration
    click WEB "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/web"

    %% Click Event for Utility Functions
    click UTILS "https://github.com/hfdlys/bjtuselfservice/tree/main/app/src/main/java/team/bjtuss/bjtuselfservice/utils"

    %% Styles
    classDef ui fill:#f9e6ff,stroke:#ad1fea,stroke-width:2px;
    classDef vm fill:#cce5ff,stroke:#3399ff,stroke-width:2px;
    classDef repo fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef ml fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef web fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef util fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
