# timerunis/cloudreve_app architecture

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

- Interactive diagram: https://gitdiagram.com/timerunis/cloudreve_app
- Repository: https://github.com/timerunis/cloudreve_app

## Overview

##### Main Components
- Frontend/UI Layer: Represented mainly by the lib/page and lib/widget directories. This layer contains the various screens (login page, main page, preview pages) and reusable widgets (e.g., the drawer, theme change button, user cart).
- Controller / Business Logic: The lib/controller.dart acts as the bridge between the UI and the underlying data services or API calls.
- Data Models (Entities): Found in lib/entity (e.g., file.dart, group.dart, user.dart). These model the core data structures needed for interacting with Cloudreve.
- API & Utility Services: The lib/common folder (with files like api.dart, constants.dart, and util.dart) is responsible for making network calls and holding app-wide configuration or helper functions.
- Internationalization & Localization: The lib/generated and lib/l10n directories handle internationalization (i18n) and localization resources, enabling the app to support multiple languages.
- External Systems: While not part of the in-app code, the connection to the Cloudreve backend should be shown as an external service the app communicates with.

##### Relationships and Interactions
- The UI layer (pages and widgets) sends user events and requests to the Controller.
- The Controller or business logic layer processes these actions and interacts with the API module (from lib/common/api.dart) to fetch or send data.
- Data received from the API is mapped into Entities (models) located in lib/entity, which then update the UI.
- The app uses utility functions and constants from lib/common to maintain consistency and reduce duplication.
- The i18n and theme switching functionalities are integrated into the UI components to provide responsiveness to user preferences.
- For platform-specific functions (Android, iOS, Windows, macOS, Linux, web), the platform directories serve as native wrappers or integrations that run the Flutter code.

##### Architectural Patterns and Design Principles
- The project loosely follows an MVC or MVVM pattern, splitting responsibilities between the UI (View), Controller (Business Logic), and Model (Entity).
- Clear separation of concerns is visible, making it easier to maintain and extend.
- The design also leverages Flutter’s cross-platform capabilities and includes integration points for native platform code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Layer Subgraph
    subgraph "Frontend/UI Layer"
        UI_Composite("UI Layer"):::ui
        subgraph "Screens"
            login("Login Page"):::ui
            main_page("Main Page"):::ui
            preview_pic("Preview Pic Page"):::ui
            preview_video("Preview Video Page"):::ui
        end
        subgraph "Widgets"
            main_drawer("Main Drawer"):::ui
            theme_change("Theme Change Button"):::ui
            user_cart("User Cart"):::ui
            file_grid_card("File Grid Card"):::ui
            file_grid_view("File Grid View"):::ui
        end
    end

    %% Controller / Business Logic
    controller("Controller"):::controller

    %% API & Utility Services Subgraph
    subgraph "API & Utility Services"
        apiService("API Service"):::api
        constants("Constants"):::api
        utilities("Utilities"):::api
    end

    %% Data Models (Entities) Subgraph
    subgraph "Data Models (Entities)"
        dataModels("Data Models"):::models
        fileModel("File Model"):::models
        groupModel("Group Model"):::models
        userModel("User Model"):::models
    end

    %% Internationalization & Localization Subgraph
    subgraph "Internationalization & Localization"
        intl("Internationalization"):::intl
        intlAll("Intl Messages All"):::intl
        intlEn("Intl Messages EN"):::intl
        localization("Localization"):::intl
    end

    %% External Cloudreve Service
    cloudreve("Cloudreve Service"):::external

    %% Platform Wrappers
    platform("Platform Wrappers (Android,iOS,Desktop,Web)"):::platform

    %% Relationships
    UI_Composite -->|"UserEvents"| controller
    controller -->|"APICalls"| apiService
    apiService -->|"FetchData"| cloudreve
    cloudreve -->|"Response"| apiService
    controller -->|"MapData"| dataModels
    dataModels -->|"UIUpdate"| UI_Composite
    intl -->|"Localizes"| UI_Composite
    platform -->|"Integrates"| UI_Composite
    constants --> apiService
    utilities --> apiService

    %% Class Definitions for Colours
    classDef ui fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef controller fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef models fill:#ffe082,stroke:#f9a825,stroke-width:2px;
    classDef api fill:#ffccbc,stroke:#d84315,stroke-width:2px;
    classDef intl fill:#f8bbd0,stroke:#ad1457,stroke-width:2px;
    classDef external fill:#ef9a9a,stroke:#c62828,stroke-width:2px;
    classDef platform fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;

    %% Click Events for Frontend/UI Layer Screens
    click login "https://github.com/timerunis/cloudreve_app/blob/main/lib/page/login_page.dart"
    click main_page "https://github.com/timerunis/cloudreve_app/blob/main/lib/page/main_page.dart"
    click preview_pic "https://github.com/timerunis/cloudreve_app/blob/main/lib/page/preview_pic_page.dart"
    click preview_video "https://github.com/timerunis/cloudreve_app/blob/main/lib/page/preview_video_page.dart"

    %% Click Events for Frontend/UI Layer Widgets
    click main_drawer "https://github.com/timerunis/cloudreve_app/blob/main/lib/widget/common/main_drawser.dart"
    click theme_change "https://github.com/timerunis/cloudreve_app/blob/main/lib/widget/common/theme_change_btn.dart"
    click user_cart "https://github.com/timerunis/cloudreve_app/blob/main/lib/widget/common/user_cart.dart"
    click file_grid_card "https://github.com/timerunis/cloudreve_app/blob/main/lib/widget/file/file_grid_card.dart"
    click file_grid_view "https://github.com/timerunis/cloudreve_app/blob/main/lib/widget/file/file_grid_view.dart"

    %% Click Event for Controller
    click controller "https://github.com/timerunis/cloudreve_app/blob/main/lib/controller.dart"

    %% Click Events for Data Models (Entities)
    click fileModel "https://github.com/timerunis/cloudreve_app/blob/main/lib/entity/file.dart"
    click groupModel "https://github.com/timerunis/cloudreve_app/blob/main/lib/entity/group.dart"
    click userModel "https://github.com/timerunis/cloudreve_app/blob/main/lib/entity/user.dart"

    %% Click Events for API & Utility Services
    click apiService "https://github.com/timerunis/cloudreve_app/blob/main/lib/common/api.dart"
    click constants "https://github.com/timerunis/cloudreve_app/blob/main/lib/common/constants.dart"
    click utilities "https://github.com/timerunis/cloudreve_app/blob/main/lib/common/util.dart"

    %% Click Events for Internationalization & Localization
    click intlAll "https://github.com/timerunis/cloudreve_app/blob/main/lib/generated/intl/messages_all.dart"
    click intlEn "https://github.com/timerunis/cloudreve_app/blob/main/lib/generated/intl/messages_en.dart"
    click localization "https://github.com/timerunis/cloudreve_app/tree/main/lib/l10n"
```
