# carloscg2000/thesimpsonsplaceappandroid architecture

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

- Interactive diagram: https://gitdiagram.com/carloscg2000/thesimpsonsplaceappandroid
- Repository: https://github.com/carloscg2000/thesimpsonsplaceappandroid

## Overview

##### Overall Structure and Main Components
- Application Layer:
– The Android app is bootstrapped by MainActivity.kt and TheSimpsonPlaceApp.kt.
– MainActivity is the entry point that sets up dependency injection (using @AndroidEntryPoint) and launches the Compose UI (MyApp()).
– The application class (TheSimpsonPlaceApp) configures Hilt and initializes the Room database (with migration details).
- Presentation Layer (UI):
– Composables, organized under presentation/ui, including screens (characterSection, episodeSection, quoteSection, gameQuotes, menuSection, and profileSection) and components (e.g., TopBarComponent, BottomBarComponent, character items, etc.).
– Navigation is handled by NavegacionApp.kt which defines routes using NavController and a sealed Screen class.
– ViewModels (found in presentation/viewmodel) manage the UI’s state for characters, episodes, quotes, games, and profiles.
- Domain Layer (Business Logic):
– Contains Domain Models (entities for Character, Episode, Quote, Game, and UserPreferences).
– Use Cases (organized in usecases folders for each feature such as character, episode, quote, game, and user) encapsulate application logic for retrieving and updating data.
– Domain mappers (e.g., CharacterMapper, EpisodeMapper, etc.) for converting data between layers.
– Repository interfaces, with actual implementations in the “impl” folder, that abstract the source of data.
- Data Layer:
- Local Data:
– Room Database: TheSimpsonsDatabase (with converters), and DAOs for Characters, Episodes, and Quotes reside under data/daos/room.
– DataStore: Utilized for saving user preferences and game statistics. The corresponding DAOs (GameDao and UserDao) along with their implementations in “local/datastore” are used here.
- Remote Data:
– Remote data source: Interfaces (CharacterDao, EpisodeDao, QuoteDao) and their implementations that rely on either a JSON source (assets) or use Retrofit for API calls. Note that depending on the build flavor (production or mock), the correct NetworkModule (in remote or mock) is injected.
- Dependency Injection (DI):
– Modules in data/di provide the Room database, the DataStore instances, and the network components (Retrofit for QuoteDao).
– Separate DI modules exist for Data, Domain, and Network; they glue the layers together using Hilt.

##### How to Represent Relationships and Interactions
– Position Presentation (UI and ViewModels) at the top.
– Underneath, include the Domain (Use Cases, Repositories, Domain Models, and Mapping functions).
– At the bottom, show the Data Layer (split into two subsections: Local with Room and DataStore, and Remote with API/JSON data).
– Repositories then fetch data from the Local DAO (Room/DataStore) or from the Remote APIs.
- Dependency injection:
– Create an overlay or annotation for Hilt modules showing how dependencies are injected across these layers.

##### Architectural Patterns and Design Principles
- Clean Architecture / MVVM: Clearly denote the separation between UI, business logic, and data access.
- Repository Pattern: Illustrate that the UI does not care about the source (remote or local) because the Repository abstracts these details.
- Use of reactive programming (Flow) to indicate asynchronous data streams between the DAO (Room/DataStore) and the ViewModel.

##### Additional Elements
- Configurations and testing aspects:
– Optionally mention that there’s a testing layer (androidTest, test, and screenshot tests) that validate UI and integration of use cases.
– A small note on employing flavors (production, mock, remote) which alter which network module (NetworkModule vs. MockModule) is active.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Layer"
        A1["MainActivity.kt"]:::application
        A2["TheSimpsonPlaceApp.kt"]:::application
    end

    subgraph "Presentation Layer"
        P1["UI/Composables (Screens & Components)"]:::presentation
        P2["Navigation (NavegacionApp.kt)"]:::presentation
        P3["ViewModels"]:::presentation
    end

    subgraph "Domain Layer"
        D1["Domain Models"]:::domain
        D2["Use Cases"]:::domain
        D3["Domain Mappers"]:::domain
        D4["Repository Interfaces"]:::domain
    end

    subgraph "Data Layer"
        subgraph "Local Data"
            L1["Room Database & DAOs"]:::data
            L2["DataStore DAOs & Implementations"]:::data
        end
        subgraph "Remote Data"
            R1["Remote DAOs & Implementations"]:::data
        end
        DIm["Dependency Injection (DI Modules)"]:::data
    end

    %% Relationships
    A1 -->|"launches"| P1
    A2 -->|"configures"| DIm
    P2 -->|"navigates"| P1
    P1 -->|"updates"| P3
    P3 -->|"calls"| D2
    D2 -->|"executes"| D4
    D4 -->|"accesses"| L1
    D4 -->|"accesses"| L2
    D4 -->|"accesses"| R1
    D2 -->|"transforms"| D3

    %% DI providing dependencies
    DIm -->|"provides"| L1
    DIm -->|"provides"| L2
    DIm -->|"provides"| R1
    DIm -->|"injects"| P3
    DIm -->|"injects"| D2

    %% Click Events
    click A1 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/blob/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/MainActivity.kt"
    click A2 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/blob/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/TheSimpsonPlaceApp.kt"
    click P1 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/presentation/ui/"
    click P2 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/blob/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/presentation/ui/navigation/NavegacionApp.kt"
    click P3 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/presentation/viewmodel/"
    click D1 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/domain/models/"
    click D2 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/domain/usescases/"
    click D3 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/domain/mappers/"
    click D4 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/domain/repository/"
    click L1 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/data/daos/local/room/"
    click L2 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/data/daos/local/datastore/"
    click R1 "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/data/daos/remote/"
    click DIm "https://github.com/carloscg2000/thesimpsonsplaceappandroid/tree/main/app/src/main/java/es/upsa/mimo/thesimpsonplace/data/di/"

    %% Styles
    classDef application fill:#f39c12,stroke:#333,stroke-width:2px;
    classDef presentation fill:#3498db,stroke:#333,stroke-width:2px;
    classDef domain fill:#2ecc71,stroke:#333,stroke-width:2px;
    classDef data fill:#e74c3c,stroke:#333,stroke-width:2px;
```
