# leduonng/radiovietnam architecture

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

- Interactive diagram: https://gitdiagram.com/leduonng/radiovietnam
- Repository: https://github.com/leduonng/radiovietnam

## Overview

##### Main Components
- User Interface Layer (Flutter Screens): Represent the key screens such as Home, Favorites, Radio, News, News Detail, and Settings. These screens are in the lib/screens folder.
- State Management Layer: Illustrate the Provider components (news_provider, radio_provider, and settings_provider in lib/providers) that manage the application state and business logic.
- Service Layer: Show separate service components that handle different functionalities:
- Audio Service (lib/services/audio_service.dart) to manage the streaming of radio channels using just_audio.
- Radio Service (lib/services/radio_service.dart) for fetching and handling radio channel data.
- News Service (lib/services/news_service.dart) for managing news-related API calls.
- Data Models: Indicate data structures (in lib/models) such as app_settings, news_article, and radio_station that are used throughout the application.
- External Dependencies & APIs:
- External libraries like just_audio, provider, http, shared_preferences, cached_network_image, url_launcher, and fluttertoast.
- API interactions for both radio (with a primary and backup API for redundancy) and news (using NewsAPI or sample data).

##### Relationships & Interactions
- From UI components sending user actions to the providers.
- Providers communicate with the underlying services (audio, radio, news) to fetch or update data.
- The Services invoke external APIs and use shared_preferences for storage and caching.
- Data models are used to pass structured data between providers, services, and UI.
- That the providers (using the Provider package) act as glue between the UI and service layers, ensuring a clean separation of concerns.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Differentiate clearly between UI, business logic, and service/data access layers.
- MVVM/MVC-like Pattern: Although Flutter is flexible, your use of providers and separate UI widgets/models hints at utilizing these patterns.
- Cross-platform Considerations: Although the Flutter code in the lib folder is central, the project structure includes platform-specific directories (android, ios, etc.) that indicate native wrappers for different platforms.

##### Final Advice
- Do not hesitate to break down the system into as many components as possible to capture all essential architectural elements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        UI_Home["Home Screen"]:::ui
        UI_Favorites["Favorites Screen"]:::ui
        UI_Radio["Radio Screen"]:::ui
        UI_News["News Screen"]:::ui
        UI_NewsDetail["News Detail Screen"]:::ui
        UI_Settings["Settings Screen"]:::ui
    end

    %% State Management (Providers) Layer
    subgraph "State Management Layer"
        Provider_News["News Provider"]:::provider
        Provider_Radio["Radio Provider"]:::provider
        Provider_Settings["Settings Provider"]:::provider
    end

    %% Service Layer
    subgraph "Service Layer"
        S_Audio["Audio Service"]:::service
        S_Radio["Radio Service"]:::service
        S_News["News Service"]:::service
    end

    %% Data Models
    subgraph "Data Models"
        DM_AppSettings["App Settings Model"]:::data
        DM_NewsArticle["News Article Model"]:::data
        DM_RadioStation["Radio Station Model"]:::data
    end

    %% External Dependencies & APIs
    subgraph "External Dependencies & APIs"
        External["pubspec.yaml"]:::external
    end

    %% UI to Providers
    UI_Home       -->|"triggers"| Provider_News
    UI_Favorites  -->|"triggers"| Provider_News
    UI_Radio      -->|"triggers"| Provider_Radio
    UI_News       -->|"triggers"| Provider_News
    UI_NewsDetail -->|"triggers"| Provider_News
    UI_Settings   -->|"triggers"| Provider_Settings

    %% Providers to Services
    Provider_News    -->|"calls"| S_News
    Provider_Radio   -->|"calls"| S_Radio
    Provider_Radio   -->|"calls"| S_Audio

    %% Providers and Services using Data Models
    Provider_News     -->|"uses"| DM_NewsArticle
    Provider_Radio    -->|"uses"| DM_RadioStation
    Provider_Settings -->|"uses"| DM_AppSettings

    S_News    -->|"maps"| DM_NewsArticle
    S_Radio   -->|"maps"| DM_RadioStation
    S_Audio   -->|"streams"| DM_RadioStation

    %% Services to External Dependencies
    S_News    -->|"API_call"| External
    S_Radio   -->|"API_call"| External
    S_Audio   -->|"shared_prefs"| External

    %% Click Events for User Interface Layer
    click UI_Home "https://github.com/leduonng/radiovietnam/blob/main/lib/screens/home_screen.dart"
    click UI_Favorites "https://github.com/leduonng/radiovietnam/blob/main/lib/screens/favorites_screen.dart"
    click UI_Radio "https://github.com/leduonng/radiovietnam/blob/main/lib/screens/radio_screen.dart"
    click UI_News "https://github.com/leduonng/radiovietnam/blob/main/lib/screens/news_screen.dart"
    click UI_NewsDetail "https://github.com/leduonng/radiovietnam/blob/main/lib/screens/news_detail_screen.dart"
    click UI_Settings "https://github.com/leduonng/radiovietnam/blob/main/lib/screens/settings_screen.dart"

    %% Click Events for State Management Layer
    click Provider_News "https://github.com/leduonng/radiovietnam/blob/main/lib/providers/news_provider.dart"
    click Provider_Radio "https://github.com/leduonng/radiovietnam/blob/main/lib/providers/radio_provider.dart"
    click Provider_Settings "https://github.com/leduonng/radiovietnam/blob/main/lib/providers/settings_provider.dart"

    %% Click Events for Service Layer
    click S_Audio "https://github.com/leduonng/radiovietnam/blob/main/lib/services/audio_service.dart"
    click S_Radio "https://github.com/leduonng/radiovietnam/blob/main/lib/services/radio_service.dart"
    click S_News "https://github.com/leduonng/radiovietnam/blob/main/lib/services/news_service.dart"

    %% Click Events for Data Models
    click DM_AppSettings "https://github.com/leduonng/radiovietnam/blob/main/lib/models/app_settings.dart"
    click DM_NewsArticle "https://github.com/leduonng/radiovietnam/blob/main/lib/models/news_article.dart"
    click DM_RadioStation "https://github.com/leduonng/radiovietnam/blob/main/lib/models/radio_station.dart"

    %% Click Event for External Dependencies
    click External "https://github.com/leduonng/radiovietnam/blob/main/pubspec.yaml"

    %% Styles
    classDef ui fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef provider fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef service fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef data fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:2px;
```
