# himera19/english_vocabulary architecture

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

- Interactive diagram: https://gitdiagram.com/himera19/english_vocabulary
- Repository: https://github.com/himera19/english_vocabulary

## Overview

##### Project Type and Purpose
- This project is a mobile application developed in Flutter, targeting both Android and iOS platforms. It focuses on helping users view detailed English word information, including synonyms and meanings, while using local persistence (via Hive) and network calls (HTTP) to fetch data.
- The app leverages key dependencies such as Provider for state management, Hive for local storage of recent searches, and Screen Util for responsive UI design.

##### Main Components
a. User Interface Layer:
- Flutter frontend components found in the lib/view and lib/page directories. These represent various screens (detail_screen.dart, search_screen.dart) and UI widgets (found in lib/view/widget and lib/view/construction).
b. Business Logic and State Management:
- Components within the lib/service/provider directory (e.g., word_provider.dart, synonym_provider.dart) manage the state and serve as bridges between the UI and the underlying data sources.
c. Data Layer:
- Repository classes (lib/service/repository), such as synonym_repository.dart and word_repository.dart, encapsulate the data fetching logic from the external API.
- Model definitions in lib/service/modal hold the data structures for word details, synonyms, etc.
d. External Services and Utilities:
- HTTP dependency for making API calls.
- Hive for local storage, especially for caching the last 5 searched words.
- Responsive design handled by Screen Util.

##### Relationships and Interactions
- The UI layer (views and pages) triggers actions (like searching a word) that are handled by the Providers.
- Providers (state management layer) call Repository components to fetch data from external services (API via HTTP) or local storage (Hive).
- After processing, the data flows back from the Repository to the Provider and then updates the UI.
- Specify that the UI also triggers events (like applying filters on word meanings), which flow to the Provider and process the data accordingly.

##### Architectural Patterns and Key Principles
- The project follows a layered architecture with a clear separation between the presentation (UI), business logic (Providers), and data handling (Repositories and Models).
- The use of Provider for dependency injection and state management emphasizes reactive design and promotes loose coupling.
- Dependency inversion is observed by abstracting data retrieval logic in the Repository layer, allowing for easier testing and substitution of data sources.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        DetailScreen["Detail Screen"]:::ui
        SearchScreen["Search Screen"]:::ui
        UIWidgets["UI Widgets"]:::ui
        UIConstruction["UI Construction"]:::ui
    end

    %% State Management
    subgraph "State Management"
        WordProvider["Word Provider"]:::provider
        SynonymProvider["Synonym Provider"]:::provider
    end

    %% Data Access
    subgraph "Data Access"
        subgraph "Repositories"
            WordRepository["Word Repository"]:::repository
            SynonymRepository["Synonym Repository"]:::repository
        end
        subgraph "Models"
            WordModel["Word Model"]:::model
            WordDefinitionModel["Word Definition Model"]:::model
            SynonymModel["Synonym Model"]:::model
            MeaningModel["Meaning Model"]:::model
        end
    end

    %% External Services
    subgraph "External Services"
        HTTPAPI["HTTP API"]:::external
        HiveStorage["Hive Local Storage"]:::external
    end

    %% Data Flow
    %% UI triggers actions in State Management
    DetailScreen -->|"triggers"| WordProvider
    SearchScreen -->|"triggers"| SynonymProvider

    %% State Management calls Repositories
    WordProvider -->|"calls"| WordRepository
    SynonymProvider -->|"calls"| SynonymRepository

    %% Repositories use Models
    WordRepository -->|"uses"| WordModel
    WordRepository -->|"uses"| WordDefinitionModel
    SynonymRepository -->|"uses"| SynonymModel
    SynonymRepository -->|"uses"| MeaningModel

    %% Repositories interact with External Services
    WordRepository -->|"fetches_from"| HTTPAPI
    WordRepository -->|"caches_at"| HiveStorage
    SynonymRepository -->|"fetches_from"| HTTPAPI
    SynonymRepository -->|"caches_at"| HiveStorage

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef provider fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef repository fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef model fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:2px;

    %% Click Events
    click DetailScreen "https://github.com/himera19/english_vocabulary/blob/master/lib/page/detail_screen.dart"
    click SearchScreen "https://github.com/himera19/english_vocabulary/blob/master/lib/page/search_screen.dart"
    click UIWidgets "https://github.com/himera19/english_vocabulary/tree/master/lib/view/widget"
    click UIConstruction "https://github.com/himera19/english_vocabulary/tree/master/lib/view/construction"
    click WordProvider "https://github.com/himera19/english_vocabulary/blob/master/lib/service/provider/word_provider.dart"
    click SynonymProvider "https://github.com/himera19/english_vocabulary/blob/master/lib/service/provider/synonym_provider.dart"
    click WordRepository "https://github.com/himera19/english_vocabulary/blob/master/lib/service/repository/word_repository.dart"
    click SynonymRepository "https://github.com/himera19/english_vocabulary/blob/master/lib/service/repository/synonym_repository.dart"
    click WordModel "https://github.com/himera19/english_vocabulary/blob/master/lib/service/modal/word_modal.dart"
    click WordDefinitionModel "https://github.com/himera19/english_vocabulary/blob/master/lib/service/modal/word_definition_modal.dart"
    click SynonymModel "https://github.com/himera19/english_vocabulary/blob/master/lib/service/modal/synonym_modal.dart"
    click MeaningModel "https://github.com/himera19/english_vocabulary/blob/master/lib/service/modal/meaning_modal.dart"
```
