# chyiiiiiiiiiiii/better-world architecture

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

- Interactive diagram: https://gitdiagram.com/chyiiiiiiiiiiii/better-world
- Repository: https://github.com/chyiiiiiiiiiiii/better-world

## Overview

##### High-Level Architecture Components

a) Client Application Layer (Flutter)
- Frontend UI Components
- Game Engine Components
- State Management
- Local Storage

b) Backend Services
- Firebase Authentication
- Firebase Firestore
- Gemini AI Integration
- Google Wallet Integration

##### Detailed Component Breakdown

Frontend Architecture:
**Client Application**
- Core
- App Initialization
- Routing System
- Internationalization (L10n)
- Features
- Authentication
- Game Modules
- Recycling Game
- Trash Catching Game
- AI Interaction
- Leaderboard
- Collection System
- State Management
- Controllers
- Providers
- Repositories
- Shared
- Assets
- Constants
- Utils

##### Interaction Flows

- User Authentication Flow
- Game Session Flow
- Data Synchronization Flow
- AI Interaction Flow
- Wallet Integration Flow

##### Implementation Details

- Cross-platform support (iOS, Android, Web, macOS)
- Firebase integration points
- State management flow using controllers and providers
- Game feature implementations
- External service integrations

##### Technical Stack Representation

Technologies:
- Flutter/Dart
- Firebase (Auth & Firestore)
- Gemini AI
- Google Wallet API
- ZFlutter (3D UI)

##### Infrastructure Layer (Firebase/Platform-specific code)

This structure reflects the project's nature as a cross-platform educational game with complex integrations while maintaining clarity and educational focus.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application"]
        direction TB
        
        subgraph Core["Core Layer"]
            direction TB
            AppInit["App Initialization"]
            Router["Routing System"]
            I18n["Internationalization"]
        end

        subgraph Features["Features Layer"]
            direction TB
            
            subgraph Games["Game Modules"]
                direction TB
                RecycleGame["Recycling Game"]
                CatchGame["Trash Catching Game"]
                AIGame["AI Interaction"]
            end
            
            Auth["Authentication"]
            Leader["Leaderboard"]
            Collection["Collection System"]
        end

        subgraph State["State Management"]
            direction TB
            Controllers["Controllers"]
            Providers["Providers"]
            Repos["Repositories"]
        end

        subgraph UI["UI Layer"]
            direction TB
            Dialogs["Dialogs"]
            Widgets["Widgets"]
            ZDogs["3D Components"]
        end

        subgraph Data["Data Layer"]
            direction TB
            Models["Data Models"]
            Constants["Constants"]
            LocalStorage["Local Storage"]
        end

        subgraph Assets["Assets"]
            direction TB
            Animations["Animations"]
            Images["Images"]
            Sounds["Sounds"]
        end
    end

    subgraph External["External Services"]
        direction TB
        Firebase["Firebase"]
        Firestore[(Firestore)]
        GeminiAI["Gemini AI"]
        GWallet["Google Wallet"]
    end

    %% Connections
    AppInit --> Router
    Router --> Features
    I18n --> UI

    Games --> Controllers
    Auth --> Controllers
    Leader --> Controllers
    Collection --> Controllers

    Controllers --> Providers
    Providers --> Repos
    Repos --> External

    UI --> Controllers
    
    %% External Service Connections
    Auth <--> Firebase
    Repos <--> Firestore
    AIGame <--> GeminiAI
    Collection <--> GWallet

    %% Styling
    classDef core fill:#2196F3,color:white
    classDef feature fill:#4CAF50,color:white
    classDef state fill:#FF9800,color:white
    classDef ui fill:#9C27B0,color:white
    classDef data fill:#795548,color:white
    classDef external fill:#607D8B,color:white
    classDef asset fill:#FFEB3B,color:black

    class AppInit,Router,I18n core
    class Games,Auth,Leader,Collection feature
    class Controllers,Providers,Repos state
    class Dialogs,Widgets,ZDogs ui
    class Models,Constants,LocalStorage data
    class Firebase,Firestore,GeminiAI,GWallet external
    class Animations,Images,Sounds asset

    %% Click Events
    click AppInit "https://github.com/chyiiiiiiiiiiii/better-world/blob/main/lib/app.dart"
    click Router "https://github.com/chyiiiiiiiiiiii/better-world/blob/main/lib/router/app_router.dart"
    click I18n "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/l10n/"
    click RecycleGame "https://github.com/chyiiiiiiiiiiii/better-world/blob/main/lib/pages/recycle_game_page.dart"
    click CatchGame "https://github.com/chyiiiiiiiiiiii/better-world/blob/main/lib/pages/catch_game_page.dart"
    click Auth "https://github.com/chyiiiiiiiiiiii/better-world/blob/main/lib/firebase/firebase_auth_provider.dart"
    click Controllers "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/controllers/"
    click Providers "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/providers/"
    click Repos "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/repositories/"
    click Dialogs "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/dialogs/"
    click Widgets "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/widgets/"
    click ZDogs "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/zdogs/"
    click Models "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/data/"
    click Constants "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/lib/constants/"
    click Animations "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/assets/animations/"
    click Images "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/assets/images/"
    click Sounds "https://github.com/chyiiiiiiiiiiii/better-world/tree/main/assets/sounds/"
    click GWallet "https://github.com/chyiiiiiiiiiiii/better-world/blob/main/lib/controllers/google_wallet_controller.dart"
```
