# tranducvu1/eggduckhunt architecture

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

- Interactive diagram: https://gitdiagram.com/tranducvu1/eggduckhunt
- Repository: https://github.com/tranducvu1/eggduckhunt

## Overview

##### Project Type and Purpose
- This project is the frontend part of a blockchain NFT "play-to-earn" game. Its main purpose is to provide an interactive game experience where players control a duck to collect eggs that can later be exchanged into ETH or tokens. Note that the blockchain smart contract (backend) is deployed separately.
- The README confirms that this project is specifically focused on the game’s frontend and includes guides for running a development server and instructions for connecting MetaMask, which is essential for blockchain interactions.

##### File Structure
- Look at top-level files and directories:
- The root includes standard files (README.md, index.html, style.css, tsconfig.json, vite.config.js, package.json, etc.) which indicate this is a Node.js project developed with TypeScript and built using Vite.
- The assets folder contains media (images and sounds) that are used by the game (e.g., duck images and sound effects).
- The src folder is structured into subdirectories that encapsulate core game modules:
- Basket: Contains logic for baskets, likely for catching or collecting eggs.
- DuckManager: Contains the module managing duck behavior.
- Egg: Houses modules for egg laying and scheduling, indicating core gameplay mechanics.
- Constant, State, Types, and UI: Provide configuration, state management, type definitions, and user interface logic.
- Ultils: General utility functions that support game operations.
- Additional top-level files like duсks.ts, game.ts, and a secondary index.html in src hint at the key game entry point and main logic.

##### Main Components to be Diagrammed
- Frontend UI Component:
- Represented by the HTML files (index.html in the root and in src), styles (style.css in both root and src/styles), and assets (assets folder for duck animations and sound effects).
- Game Logic Layer:
- Modularized into several parts within the src directory:
- DuckManager: Manages the duck’s behavior and movements.
- Egg: Handles the egg laying process and scheduling.
- Basket: Controls basket-related functionality.
- State: Possibly governs game states (like duck movement, game status, etc.).
- Constant, Types, and Ultils: Provide shared constants, type definitions, and helper functions that support the overall game operations.
- External Interaction:
- Integration with MetaMask and Blockchain: Although the blockchain smart contracts reside on a separate backend system, include a component to represent blockchain interaction (for token exchange). This module connects via MetaMask, as mentioned in the README.

##### Relationships and Data Flow
- How the browser (using index.html) loads the frontend and applies the UI assets.
- From the UI (user inputs) to game logic for handling game events.
- From game logic back to UI for rendering game states and updating animations.
- A directional connection from the frontend to the blockchain integration module (via MetaMask) for actions such as token and ETH exchange. This reinforces that while the frontend hosts the game logic, the smart contract deployment exists separately.

##### Architectural Patterns and Design Principles
- Modularity: The structure demonstrates separation of concerns, grouping related functionalities into distinct directories (e.g., Egg, Basket, DuckManager).
- Integration Points: Mark the integration with external blockchain services using MetaMask.

##### Essential Elements
- Each component should have a clear label (e.g., “UI Layer”, “DuckManager Module”, “Egg Scheduler”, “Blockchain Integration via MetaMask”).
- User Input → Game Logic
- Game State Updates → UI Rendering
- UI → Blockchain for transactions or token exchanges
- Optional details: you may add a note indicating that while the blockchain part is external, it is crucial for the token exchange mechanics in the game.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend UI Layer
    subgraph "Frontend UI"
        HTML1["\"index.html\""] 
        HTML2["\"src/index.html\""] 
        CSS1["\"style.css\""]
        CSS2["\"src/styles/style.css\""]
        Assets["\"assets/\""]
    end

    %% Game Logic Layer
    subgraph "Game Logic Layer"
        DM["\"DuckManager Module\""]
        EL["\"Egg Laying\""]
        ES["\"Egg Scheduler\""]
        Basket["\"Basket Module\""]
        StateMgmt["\"State Management\""]
    end

    %% Shared Services
    subgraph "Shared Services"
        Constants["\"Constants\""]
        Types["\"Types\""]
        Utilities["\"Utilities\""]
        Storage["\"Storage Utility\""]
    end

    %% External Integration
    External["\"Blockchain Integration via MetaMask\""]:::external

    %% UI to Game Logic (User input flows)
    HTML1 -->|"input"| DM
    HTML1 -->|"input"| EL
    HTML1 -->|"input"| ES
    HTML1 -->|"input"| Basket
    HTML1 -->|"input"| StateMgmt

    %% Game Logic to UI (Update flows)
    DM -->|"update_UI"| HTML2
    EL -->|"update_UI"| HTML2
    ES -->|"update_UI"| HTML2
    Basket -->|"update_UI"| HTML2
    StateMgmt -->|"update_UI"| HTML2

    %% Game Logic dependencies on Shared Services
    Constants -->|"provides"| DM
    Constants -->|"provides"| EL
    Constants -->|"provides"| ES
    Constants -->|"provides"| Basket
    Constants -->|"provides"| StateMgmt

    Types -->|"defines"| DM
    Types -->|"defines"| EL
    Types -->|"defines"| ES
    Types -->|"defines"| Basket
    Types -->|"defines"| StateMgmt

    Utilities -->|"assists"| DM
    Utilities -->|"assists"| EL
    Utilities -->|"assists"| ES
    Utilities -->|"assists"| Basket
    Utilities -->|"assists"| StateMgmt

    Storage -->|"assists"| DM
    Storage -->|"assists"| EL
    Storage -->|"assists"| ES
    Storage -->|"assists"| Basket
    Storage -->|"assists"| StateMgmt

    %% Game Logic interaction with Blockchain/External Integration
    DM -->|"chain_interaction"| External
    EL -->|"chain_interaction"| External
    ES -->|"chain_interaction"| External

    %% Click Events for Frontend UI
    click HTML1 "https://github.com/tranducvu1/eggduckhunt/blob/main/index.html"
    click HTML2 "https://github.com/tranducvu1/eggduckhunt/blob/main/src/index.html"
    click CSS1 "https://github.com/tranducvu1/eggduckhunt/blob/main/style.css"
    click CSS2 "https://github.com/tranducvu1/eggduckhunt/blob/main/src/styles/style.css"
    click Assets "https://github.com/tranducvu1/eggduckhunt/tree/main/assets/"

    %% Click Events for Game Logic Layer
    click DM "https://github.com/tranducvu1/eggduckhunt/blob/main/src/DuckManager/duckManager.ts"
    click EL "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Egg/eggLaying.ts"
    click ES "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Egg/eggScheduler.ts"
    click Basket "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Basket/baskets.ts"
    click StateMgmt "https://github.com/tranducvu1/eggduckhunt/blob/main/src/State/duckMovement.ts"

    %% Click Events for Shared Services
    click Constants "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Constant/constant.ts"
    click Types "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Types/types.ts"
    click Utilities "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Ultils/Ultils.ts"
    click Storage "https://github.com/tranducvu1/eggduckhunt/blob/main/src/Ultils/storage.ts"

    %% Styles
    classDef ui fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef logic fill:#cce6ff,stroke:#333,stroke-width:2px;
    classDef shared fill:#e6ccff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffe6cc,stroke:#333,stroke-width:2px;

    class HTML1,HTML2,CSS1,CSS2,Assets ui;
    class DM,EL,ES,Basket,StateMgmt logic;
    class Constants,Types,Utilities,Storage shared;
    class External external;
```
