# easylive1989/puzzle architecture

> Architecture diagram of the GitHub repository easylive1989/puzzle, 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/easylive1989/puzzle
- Repository: https://github.com/easylive1989/puzzle

## Overview

##### Main Components
- Mobile Client (Flutter App): Represent the client that runs on both Android (android folder) and iOS (ios folder). This is the primary interface where users interact with the game.
- Presentation Layer:
- UI Modules: Includes pages for game play (play puzzle), login (authentication pages), and game list (puzzle list pages). Note the state management implemented with BLoC in the lib/puzzle/presentation and lib/authentication/presentation directories.
- Blocs and Views: Separate components in the presentation package (for instance “login/bloc”, “play_puzzle/bloc”) indicate the use of bloc for state management.
- Domain Layer:
- Game Logic: Components such as create_puzzle_use_case, move_tile_use_case, get_ongoing_puzzles_use_case, and entities like puzzle, puzzle_user, etc.
- Authentication Logic: Domain entities and interfaces defined under the authentication folder.
- Data Layer:
- Data Sources: Local database interactions under lib/puzzle/data/source (app_database, puzzle_games, DAOs), as well as remote data via Firebase (firebase_authentication_repository.dart).
- Repositories: Files like puzzle_repository.dart serve as data abstraction points for business logic.
- External Services & Infrastructure:
- Firebase: Configuration files like firebase.json, .firebaserc, and firebase_options.dart indicate integration with Firebase services for authentication and possibly storage.
- Emulators: The README instructions and Firebase CLI scripts indicate the use of Firebase emulators during testing.
- Testing: Unit, widget, and integration tests are defined under the test and integration_test directories.

##### Relationships and Interactions
- BLoCs interact with Use Cases in the domain layer to fetch or update game state.
- Use Cases call upon Repositories in the data layer to retrieve or persist data, whether it is from a local SQLite DB (via DAOs) or remote Firebase.
- External services such as Firebase facilitate authentication and can be drawn as a separate component that the authentication repository communicates with.
- Mobile native components: Highlight the integration between Flutter and native project configuration on Android and iOS (to support platform-specific features).

##### Architectural Patterns and Design Principles
- Use of BLoC Pattern: Emphasize that the state management heavily relies on the BLoC (business logic component) pattern, connecting UI and business logic.
- Modular Design: Modules like authentication and puzzle are separated in the lib directory, showcasing modular design for reusability and testing.
- Integration with External Services: The Firebase modules are clearly separated and integrated via the dedicated configuration and repository files.

##### Relevant Technologies and Tools
- Flutter: For the cross-platform mobile app development.
- Firebase: For authentication and backend integration.
- BLoC: For state management in the presentation layer.
- SQLite or similar local databases: Represented by the app_database implementation for storage.
- Testing Frameworks: Flutter’s test framework, and integration testing through Firebase emulators.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client
    subgraph "Mobile Client"
        A1("Android"):::native
        A2("iOS"):::native
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        P1("Authentication UI & BLoC"):::presentation
        P2("Puzzle UI & BLoC"):::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        D1("Authentication Domain (Entities&UseCases)"):::domain
        D2("Puzzle Domain (Entities&UseCases)"):::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        DB1("Firebase Authentication Repository"):::data
        DB2("Puzzle Repository & Local Data Source"):::data
    end

    %% External Services & Native Configurations
    subgraph "External Services & Native Configurations"
        E1("Firebase Service & Configurations"):::external
    end

    %% Testing Framework
    subgraph "Testing Framework"
        T1("Unit/Widget/Integration Tests"):::testing
    end

    %% Connections between layers
    A1 -->|"runs_client"| P1
    A2 -->|"runs_client"| P2
    P1 -->|"triggers"| D1
    P2 -->|"triggers"| D2
    D1 -->|"accesses"| DB1
    D2 -->|"accesses"| DB2
    DB1 -->|"connects"| E1
    DB2 -->|"connects"| E1

    %% Testing connections to Mobile Client and Presentation Layer
    T1 -->|"tests"| A1
    T1 -->|"tests"| A2
    T1 -->|"verifies"| P1
    T1 -->|"verifies"| P2

    %% Click Events
    click A1 "https://github.com/easylive1989/puzzle/tree/master/android/"
    click A2 "https://github.com/easylive1989/puzzle/tree/master/ios/"
    click P1 "https://github.com/easylive1989/puzzle/tree/master/lib/authentication/presentation/"
    click P2 "https://github.com/easylive1989/puzzle/tree/master/lib/puzzle/presentation/"
    click D1 "https://github.com/easylive1989/puzzle/tree/master/lib/authentication/domain/"
    click D2 "https://github.com/easylive1989/puzzle/tree/master/lib/puzzle/domain/"
    click DB1 "https://github.com/easylive1989/puzzle/tree/master/lib/authentication/data/"
    click DB2 "https://github.com/easylive1989/puzzle/tree/master/lib/puzzle/data/"
    click E1 "https://github.com/easylive1989/puzzle/blob/master/lib/firebase_options.dart"
    click T1 "https://github.com/easylive1989/puzzle/tree/master/test/"

    %% Styles
    classDef native fill:#ffd1dc,stroke:#ff1493,stroke-width:2px,color:#000;
    classDef presentation fill:#add8e6,stroke:#0000ff,stroke-width:2px,color:#000;
    classDef domain fill:#90ee90,stroke:#008000,stroke-width:2px,color:#000;
    classDef data fill:#ffa500,stroke:#ff4500,stroke-width:2px,color:#000;
    classDef external fill:#dda0dd,stroke:#800080,stroke-width:2px,color:#000;
    classDef testing fill:#d3d3d3,stroke:#a9a9a9,stroke-width:2px,color:#000;
```
