# linyi102/anime_trace architecture

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

- Interactive diagram: https://gitdiagram.com/linyi102/anime_trace
- Repository: https://github.com/linyi102/anime_trace

## Overview

##### Project type and purpose
- This is a cross‑platform Flutter application (“anime_trace”) that runs on Android, iOS, Windows and Web.
- Purpose: let users track anime watch history, take episode notes (with images), backup/restore data (locally or via WebDAV), and fetch metadata from online sources.

##### File structure
- Top‑level platform folders: android, ios, windows, web – hold native embedding, build scripts, platform channels.
- lib/ directory: the heart of the app, subdivided into:
- main.dart + global.dart – entry point and app‐wide initialization
- models/ – domain data classes (Anime, Episode, Note, Settings)
- controllers/ – state‑management logic using GetX (anime_display_controller, backup_service, theme_controller, etc.)
- dao/ – data access objects encapsulating SQLite operations (sqflite)
- repositories/ – higher‑level wrappers (e.g. bangumi_repository)
- utils/ – network clients (Dio), crawling modules for multiple anime websites, file and WebDAV utilities
- pages/ & modules/ & widgets/ & components/ – UI layer: screens, reusable widgets, dialogs
- routes/ – GetX route definitions
- values/ – constants, theme, assets
- Configuration files: pubspec.yaml (dependencies), Android/iOS/Windows build scripts, test/ folder with unit tests.

##### README for additional insights
- Confirms local SQLite storage + optional WebDAV backup
- Uses multiple third‑party packages (GetX for state, Dio for HTTP, sqflite for DB, webdav_client)
- Describes platform‑specific behaviors (Android only WebDAV backup, Windows local+WebDAV backup)

##### Detail
- Modules (e.g., note editor, crawling logic, backup service) as separate sub‑components
- That routes/get_route.dart connects navigation events to page widgets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry and Global
    Main["lib/main.dart"]:::entry
    Global["lib/global.dart"]:::entry

    %% Routing
    Routes["get_route.dart"]:::presentation
    click Main "https://github.com/linyi102/anime_trace/blob/master/lib/main.dart"
    click Global "https://github.com/linyi102/anime_trace/blob/master/lib/global.dart"
    click Routes "https://github.com/linyi102/anime_trace/blob/master/lib/routes/get_route.dart"

    %% Presentation Layer
    subgraph "Presentation (UI Layer)"
        direction TB
        Pages["Pages (lib/pages/)"]:::presentation
        Widgets["Widgets (lib/widgets/)"]:::presentation
        Components["Components (lib/components/)"]:::presentation
        Animation["Animation Helpers (lib/animation/)"]:::presentation
        click Pages "https://github.com/linyi102/anime_trace/tree/master/lib/pages/"
        click Widgets "https://github.com/linyi102/anime_trace/tree/master/lib/widgets/"
        click Components "https://github.com/linyi102/anime_trace/tree/master/lib/components/"
        click Animation "https://github.com/linyi102/anime_trace/tree/master/lib/animation/"
    end

    %% State Management Layer
    subgraph "State Management (GetX Controllers)"
        direction TB
        AnimeDisplayCtrl["anime_display_controller.dart"]:::state
        BackupServiceCtrl["backup_service.dart"]:::state
        ThemeCtrl["theme_controller.dart"]:::state
        OtherCtrls["Other Controllers (lib/controllers/)"]:::state
        click AnimeDisplayCtrl "https://github.com/linyi102/anime_trace/blob/master/lib/controllers/anime_display_controller.dart"
        click BackupServiceCtrl "https://github.com/linyi102/anime_trace/blob/master/lib/controllers/backup_service.dart"
        click ThemeCtrl "https://github.com/linyi102/anime_trace/blob/master/lib/controllers/theme_controller.dart"
        click OtherCtrls "https://github.com/linyi102/anime_trace/tree/master/lib/controllers/"
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        subgraph DAOs
            direction TB
            AnimeDAO["anime_dao.dart"]:::data
            EpisodeNoteDAO["episode_note_dao.dart"]:::data
            HistoryDAO["history_dao.dart"]:::data
            ImageDAO["image_dao.dart"]:::data
            NoteDAO["note_dao.dart"]:::data
            click AnimeDAO "https://github.com/linyi102/anime_trace/blob/master/lib/dao/anime_dao.dart"
            click EpisodeNoteDAO "https://github.com/linyi102/anime_trace/blob/master/lib/dao/episode_note_dao.dart"
            click HistoryDAO "https://github.com/linyi102/anime_trace/blob/master/lib/dao/history_dao.dart"
            click ImageDAO "https://github.com/linyi102/anime_trace/blob/master/lib/dao/image_dao.dart"
            click NoteDAO "https://github.com/linyi102/anime_trace/blob/master/lib/dao/note_dao.dart"
        end
        subgraph Repositories & Network
            direction TB
            BangumiRepo["bangumi_repository.dart"]:::data
            NetworkClients["Dio & APIs"]:::data
            click BangumiRepo "https://github.com/linyi102/anime_trace/blob/master/lib/repositories/bangumi_repository.dart"
            click NetworkClients "https://github.com/linyi102/anime_trace/blob/master/lib/utils/network/bangumi_api.dart"
            click NetworkClients "https://github.com/linyi102/anime_trace/blob/master/lib/utils/dio_util.dart"
        end
        subgraph Crawling Services
            direction TB
            Crawlers["lib/utils/climb/"]:::data
            click Crawlers "https://github.com/linyi102/anime_trace/tree/master/lib/utils/climb/"
        end
        subgraph Backup Utilities
            direction TB
            BackupUtil["backup_util.dart"]:::data
            WebDAVUtil["webdav_util.dart"]:::data
            click BackupUtil "https://github.com/linyi102/anime_trace/blob/master/lib/utils/backup_util.dart"
            click WebDAVUtil "https://github.com/linyi102/anime_trace/blob/master/lib/utils/webdav_util.dart"
        end
        DB[(SQLite Database)]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        WebDAVServer["WebDAV Server"]:::external
        AnimeSources["Anime Metadata Sources"]:::external
    end

    %% Platform Embedders
    subgraph "Platform Embedders"
        direction TB
        Android["android/"]:::platform
        iOS["ios/"]:::platform
        Windows["windows/"]:::platform
        WebPlat["web/"]:::platform
    end

    %% Flows
    Main -->|launch| Global
    Global -->|init| Pages
    Global -->|init| Widgets
    Global -->|init| Components
    Global -->|init| Animation
    Pages -->|"user event"| AnimeDisplayCtrl
    Widgets -->|event| AnimeDisplayCtrl
    Components -->|event| AnimeDisplayCtrl
    Animation -->|anim trigger| AnimeDisplayCtrl
    Routes -->|navigation| Pages

    AnimeDisplayCtrl -->|READ/WRITE| AnimeDAO
    AnimeDisplayCtrl -->|READ/WRITE| EpisodeNoteDAO
    AnimeDisplayCtrl -->|READ/WRITE| HistoryDAO
    AnimeDisplayCtrl -->|READ/WRITE| ImageDAO
    AnimeDisplayCtrl -->|READ/WRITE| NoteDAO
    AnimeDisplayCtrl -->|FETCH| BangumiRepo
    AnimeDisplayCtrl -->|FETCH| Crawlers

    BackupServiceCtrl -->|UPLOAD/DOWNLOAD| BackupUtil
    BackupUtil -->|USE| WebDAVUtil
    WebDAVUtil -->|UPLOAD/DOWNLOAD| WebDAVServer
    BackupServiceCtrl -->|ARCHIVE/UNARCHIVE| DB
    BackupServiceCtrl -->|ARCHIVE/UNARCHIVE| WebDAVServer

    BangumiRepo -->|HTTP| NetworkClients
    NetworkClients -->|FETCH| AnimeSources
    Crawlers -->|SCRAPE| AnimeSources

    AnimeDAO -->|STORE/QUERY| DB
    EpisodeNoteDAO -->|STORE/QUERY| DB
    HistoryDAO -->|STORE/QUERY| DB
    ImageDAO -->|STORE/QUERY| DB
    NoteDAO -->|STORE/QUERY| DB

    %% Cross-layer
    OtherCtrls -->|various| DB
    OtherCtrls -->|various| WebDAVServer

    %% Platform injection
    Main -.-> Android
    Main -.-> iOS
    Main -.-> Windows
    Main -.-> WebPlat

    %% Styles
    classDef entry fill:#eef,stroke:#77f,color:#005;
    classDef presentation fill:#ccf,stroke:#88f,color:#004;
    classDef state fill:#cfc,stroke:#8f8,color:#040;
    classDef data fill:#fcf,stroke:#f8f,color:#404;
    classDef external fill:#fdd,stroke:#f55,color:#500;
    classDef platform fill:#ddd,stroke:#888,color:#333;
```
