# ngletuan-dev/pokeapp-swiftui architecture

> Architecture diagram of the GitHub repository ngletuan-dev/pokeapp-swiftui, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ngletuan-dev/pokeapp-swiftui
- Repository: https://github.com/ngletuan-dev/pokeapp-swiftui

## Overview

##### Project type and purpose
- This is a SwiftUI‐based iOS application (“PokéApp”) that fetches Pokémon data from an external RESTful service (https://pokeapi.co/) and displays it in a list. Users can search, favorite, and view details of Pokémon.

##### File structure
- Top‐level: Xcode project and workspace, Assets folder, README, tests.
- iOS_PokeApp folder subdivided by feature-layer:
- Model: data structures (PokeModel.swift)
- PokemonAPI: networking layer (Downloader.swift, LoadingAPI.swift, PokemonAPI.swift)
- ViewModel: MVVM presentation logic (PokeViewModel.swift, PokeDetailViewModel.swift, PokeEffectViewModel.swift)
- View: SwiftUI views (PokeView, PokemonViewDetail, AbilityView, etc.)
- App entry: iOS_PokeAppApp.swift
- Testing targets: unit and UI tests.

##### README for additional insights
- Confirms MVVM with SwiftUI (targeting iOS 15+)
- Relies on PokéAPI, no local database yet (favorites are in‐memory or ephemeral)
- Core flows: list all Pokémon, search by name, slide‐to‐favorite, view detail with stats and abilities.

##### Main components and interactions
a. Components
1. UI Layer (Views)
2. Presentation Layer (ViewModels)
3. Domain/Data Layer (Models + Networking)
4. External Service (PokéAPI REST)
5. (Optional future) Local Storage for favorites (e.g., UserDefaults or CoreData)
b. Relationships & Data Flow
- UI → binds to → ViewModel
- ViewModel → calls → PokemonAPI (via LoadingAPI/Downloader)
- PokemonAPI → performs HTTP GET → PokéAPI → returns JSON
- JSON → decoded into → PokeModel
- ViewModel → publishes → PokeModel to UI
- UI → renders → List, Detail, Search, Favorite toggle
c. Architectural patterns
- MVVM (Views ←→ ViewModels ←→ Models + Network)
- Single Activity/Coordinator pattern is implicit in App entry (iOS_PokeAppApp.swift)
- Dependency inversion: ViewModels depend on protocol abstractions of network loader
d. Key technologies
- SwiftUI (all UI components)
- Combine or async/await (depending on implementation in LoadingAPI/Downloader)
- URLSession for networking
- Codable for JSON parsing

##### Essential details to capture
- All SwiftUI views and their hierarchical relationship (List view, Detail view, subviews)
- ViewModel responsibilities and which API calls they make
- Model definitions for Pokémon entities and effects
- The networking flow from app → URLSession → PokéAPI → JSON → Codable → ViewModel → UI
- Where tests fit in (pointing at the ViewModel and Networking modules)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        PokeView["PokeView"]:::ui
        PokemonViewDetail["PokemonViewDetail"]:::ui
        AbilityView["AbilityView"]:::ui
        StatsView["StatsView"]:::ui
        StatusHPView["StatusHPView"]:::ui
        TypeElementView["TypeElementView"]:::ui
        SplashView["SplashView"]:::ui
        LoadableImageContentView["LoadableImageContentView"]:::ui
        LoadableImageViewDetail["LoadableImageViewDetail"]:::ui
        ColorExtensions["ColorExtensions"]:::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        direction TB
        PokeViewModel["PokeViewModel"]:::vm
        PokeDetailViewModel["PokeDetailViewModel"]:::vm
        PokeEffectViewModel["PokeEffectViewModel"]:::vm
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        PokeModel["PokeModel"]:::data
    end

    %% Networking Layer
    subgraph "Networking Layer"
        direction TB
        LoadingAPI["LoadingAPI"]:::data
        Downloader["Downloader"]:::data
        PokemonAPI["PokemonAPI"]:::data
    end

    %% External Service
    subgraph "External Service"
        direction TB
        PokéAPI["PokéAPI Service"]:::external
    end

    %% App Entry
    iOSApp["iOS_PokeAppApp.swift"]:::data

    %% Tests
    subgraph "Tests"
        direction TB
        UnitTests["Unit Tests"]:::external
        UITests["UI Tests"]:::external
    end

    %% Connections UI → ViewModel
    PokeView -->|"bindsTo"| PokeViewModel
    PokemonViewDetail -->|"bindsTo"| PokeDetailViewModel
    AbilityView -->|"bindsTo"| PokeEffectViewModel
    StatsView -->|"bindsTo"| PokeDetailViewModel
    StatusHPView -->|"bindsTo"| PokeDetailViewModel
    TypeElementView -->|"bindsTo"| PokeDetailViewModel
    SplashView -->|"bindsTo"| PokeViewModel
    LoadableImageContentView -->|"bindsTo"| PokeViewModel
    LoadableImageViewDetail -->|"bindsTo"| PokeDetailViewModel

    %% ViewModel → Networking
    PokeViewModel -->|"fetchAllPokemons()"| LoadingAPI
    PokeDetailViewModel -->|"fetchPokemonDetail()"| LoadingAPI
    PokeEffectViewModel -->|"fetchEffects()"| LoadingAPI

    LoadingAPI -->|"uses URLSession"| Downloader
    Downloader -->|"request()"| PokemonAPI
    PokemonAPI -->|"HTTP GET /pokemon"| PokéAPI

    PokéAPI -->|"JSON"| PokemonAPI
    PokemonAPI -->|"decode() → PokeModel"| PokeModel

    PokeModel -->|"published"| PokeViewModel
    PokeModel -->|"published"| PokeDetailViewModel
    PokeModel -->|"published"| PokeEffectViewModel

    %% App entry coordination
    iOSApp -->|"launches"| PokeView
    iOSApp -->|"launches"| SplashView

    %% Tests relationships
    UnitTests -->|"tests"| PokeViewModel
    UnitTests -->|"tests"| LoadingAPI
    UITests -->|"drives UI flows"| PokeView

    %% Click Events for component mapping
    click PokeView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/PokeView.swift"
    click PokemonViewDetail "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/PokemonViewDetail.swift"
    click AbilityView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/AbilityView.swift"
    click StatsView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/StatsView.swift"
    click StatusHPView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/StatusHPView.swift"
    click TypeElementView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/TypeElementView.swift"
    click SplashView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/SplashView.swift"
    click LoadableImageContentView "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/LoadableImageContentView.swift"
    click LoadableImageViewDetail "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/LoadableImageViewDetail.swift"
    click ColorExtensions "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/View/ColorExtensions.swift"

    click PokeViewModel "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/ViewModel/PokeViewModel.swift"
    click PokeDetailViewModel "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/ViewModel/PokeDetailViewModel.swift"
    click PokeEffectViewModel "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/ViewModel/PokeEffectViewModel.swift"

    click PokeModel "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/Model/PokeModel.swift"

    click Downloader "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/PokemonAPI/Downloader.swift"
    click LoadingAPI "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/PokemonAPI/LoadingAPI.swift"
    click PokemonAPI "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/PokemonAPI/PokemonAPI.swift"

    click iOSApp "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeApp/iOS_PokeAppApp.swift"

    click UnitTests "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeAppTests/iOS_PokeAppTests.swift"
    click UITests "https://github.com/ngletuan-dev/pokeapp-swiftui/blob/main/iOS_PokeAppUITests/iOS_PokeAppUITests.swift"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef vm fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
