# kienminho/anymex architecture

> Architecture diagram of the GitHub repository kienminho/anymex, 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/kienminho/anymex
- Repository: https://github.com/kienminho/anymex

## Overview

##### Main Layers and Components

- User Interface (Presentation) Layer:
- Represented by the “lib/screens” and “lib/widgets” directories.
- This layer manages the visual components including screens (anime, manga, novel, library, profile, settings) and reusable widgets (animations, headers, navigation bars).
- Also includes platform-specific UI configuration present under android, ios, macos, windows, linux, and web directories.

- Business Logic Layer:
- Located in “lib/controllers” and “lib/models.”
- Controllers such as “anilist,” “offline,” “settings,” “source,” and “theme” drive the app’s behavior.
- Models define the data structures for content (anime, manga, novels) and support offline storage (Hive models).

- Data & API Integration Layer:
- Found in “lib/api.”
- This layer contains code for content extraction, API communication, and source handling. Notably, the “Mangayomi” directory under “lib/api” encapsulates various routines:
- Evaluation engine components (subdirectories Eval/dart, Eval/javascript, Eval/compiler, etc.)
- Extensions for fetching sources (extensions providers, anime and manga extractors).
- HTTP clients (in “lib/api/Mangayomi/http”) with specialized submodules such as RHTTP and rust-based API integrations.
- This layer is responsible for interfacing with external data sources, processing content, and handling the necessary parsing and extraction tasks.

- Offline Storage & Persistence:
- Look in “lib/controllers/offline” and “lib/models/Offline.”
- The offline functionality—using Hive-based models—is an essential component enabling local caching of user data and media information.

- External Service Integrations:
- The project integrates with external APIs (for example, AniList sync is mentioned in the README).
- These interactions can be visualized as separate services that interact with the API layer (sending requests and receiving data).

##### Relationships and Data Flow

- Start at the top with the UI layer handling user input and presentation.
- User interactions trigger events in the business logic controllers (for example, a user selects an anime or manga).
- The controllers communicate with the API layer to fetch or update content. In this process, the API integration layer uses custom extraction logic and HTTP clients to fetch information from external sources.
- Data is then passed back to the controllers, which update the UI accordingly and may also save data for offline access.
- Offline storage components are accessed throughout the flow for caching and local data persistence.
- Additionally, platform-specific modules (Android, iOS, etc.) are essentially Flutter “shells” that call into the same shared code in lib/, which can be represented as an underlying cross-platform infrastructure supporting all these components.

##### Important Architectural Patterns and Technologies

- Layered Architecture (Separation of Concerns):
- Clearly separate presentation (UI/screens/widgets), domain logic (controllers/models), and data access (API/extraction services).
- Modular Design:
- The distinct packages under lib (like controllers, api, models, widgets) suggest a modular architecture where each component can be developed and tested independently.
- Multi-platform Support:
- The presence of platform-specific directories indicates that while most code is shared in Flutter (lib/), platform-specific adaptations exist.
- Use of Code Generation:
- Files with “.g.dart” indicate that some models/controllers leverage Dart’s build tools for code generation.
- Custom HTTP Client & Extraction Engines:
- The API substructure (with components like evaluation, extraction, HTTP client integration) is central to obtaining and processing content.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface (Presentation) Layer
    subgraph "User Interface (Presentation) Layer"
        UI1["Screens"]:::ui
        UI2["Widgets"]:::ui
    end

    %% Platform Integration
    subgraph "Platform Integration"
        P1["Android"]:::platform
        P2["iOS"]:::platform
        P3["macOS"]:::platform
        P4["Windows"]:::platform
        P5["Linux"]:::platform
        P6["Web"]:::platform
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BL1["Core Controllers"]:::business
        BL2["Core Models"]:::business
    end

    %% API & Content Extraction Layer
    subgraph "API & Content Extraction Layer"
        API1["Main API"]:::api
        API2["Mangayomi Engine"]:::api
    end

    %% Offline Storage & Persistence
    subgraph "Offline Storage & Persistence"
        OFF1["Offline Controllers"]:::offline
        OFF2["Offline Models"]:::offline
    end

    %% External Service Integration
    subgraph "External Service Integration (AniList)"
        EXT1["AniList Controller"]:::external
        EXT2["AniList Model"]:::external
    end

    %% Interactions
    UI1 -->|"triggers"| BL1
    UI2 -->|"renders updates"| BL2
    BL1 -->|"fetch/update"| API1
    API1 -->|"calls"| API2
    API2 -->|"returns content"| API1
    API1 -->|"delivers data"| BL1
    BL1 -->|"caches data"| OFF1
    OFF1 -->|"persists"| OFF2
    BL1 -->|"sync request"| EXT1
    EXT1 -->|"processes sync"| EXT2
    EXT2 -->|"sync data"| BL1

    %% Platform integration support to UI
    P1 ---|"platform config"| UI1
    P2 ---|"platform config"| UI1
    P3 ---|"platform config"| UI1
    P4 ---|"platform config"| UI1
    P5 ---|"platform config"| UI1
    P6 ---|"platform config"| UI1

    %% Click Events for Component Mapping
    click UI1 "https://github.com/kienminho/anymex/tree/main/lib/screens"
    click UI2 "https://github.com/kienminho/anymex/tree/main/lib/widgets"
    click BL1 "https://github.com/kienminho/anymex/tree/main/lib/controllers"
    click BL2 "https://github.com/kienminho/anymex/tree/main/lib/models"
    click API1 "https://github.com/kienminho/anymex/tree/main/lib/api"
    click API2 "https://github.com/kienminho/anymex/tree/main/lib/api/Mangayomi"
    click OFF1 "https://github.com/kienminho/anymex/tree/main/lib/controllers/offline"
    click OFF2 "https://github.com/kienminho/anymex/tree/main/lib/models/Offline"
    click EXT1 "https://github.com/kienminho/anymex/tree/main/lib/controllers/anilist"
    click EXT2 "https://github.com/kienminho/anymex/tree/main/lib/models/Anilist"

    %% Styles
    classDef ui fill:#cce,stroke:#333,stroke-width:2px;
    classDef business fill:#dfd,stroke:#333,stroke-width:2px;
    classDef api fill:#fdd,stroke:#333,stroke-width:2px;
    classDef offline fill:#ffd,stroke:#333,stroke-width:2px;
    classDef external fill:#ddf,stroke:#333,stroke-width:2px;
    classDef platform fill:#fed,stroke:#333,stroke-width:2px;
```
