# lucaslimaaz/soloyugioh architecture

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

- Interactive diagram: https://gitdiagram.com/lucaslimaaz/soloyugioh
- Repository: https://github.com/lucaslimaaz/soloyugioh

## Overview

Based on your file tree and the README, the project is clearly a single-page application designed to simulate a Yu-Gi-Oh! duel and help players build and test their physical decks. It leverages React for building UI components, using a clear separation between presentational (JSX) components and their accompanying business logic (custom hooks). The project also places a premium on clean code and SOLID principles, with a further division into shared hooks using Jotai for global state, services for handling calls to the Yu-Gi-Oh! API and reading local JSON card lists, and helpers (like sound management with HowlerJS).

##### Main Components
- UI / Presentation Layer:
- Components: These include card, container, deck, enemy-turn (with its sub-phases), field, graveyard, hand, modals (attack, change-stats, search-card, settings), scoreboard, and tool-bar.
- Each component has its presentational part (JSX file) and its logic hook (named use-componentName).
- Shared Hooks and Global State:
- Located in src/shared/hooks
- Uses Jotai atoms (in src/shared/atoms.jsx) to provide a consistent global state across the application.
- Services:
- API communication with the Yu-Gi-Oh! API.
- Reading and managing local cardList JSON files.
- Found in src/shared/services.
- Helpers:
- Utility functions such as playSound (using HowlerJS) for playing sound effects.
- External Libraries & Frameworks:
- React for UI, MUI for styling components, Jotai for global state, and HowlerJS for audio.

##### Relationships and Interactions
- UI components invoke their corresponding hooks to handle logic encompassing state management, complex behaviors, or even local computations.
- Shared hooks update/read Jotai atoms, meaning that many UI components (like the deck, hand, and scoreboard) will interact via these shared state containers.
- Service modules act as mediators between the UI and external data sources (the external API as well as local JSON datasets).
- Helper functions, such as the one that manages sound effects, are used by multiple components to enhance interactivity.
- The directional data flow is essentially: User Interactions → UI Components → Hooks (logic) → Services (data/API calls) → Global State Updates → UI Re-render.

##### Architectural Patterns & Design Principles to Highlight
- Emphasis on separation of concerns: UI (presentation) is kept separate from business logic (hooks) and data sourcing (services).
- Global state management with Jotai ensuring consistency across components.
- Clean Code and SOLID principles achieved via modularization of each concern (components, hooks, services, etc.).
- Coupling between components is minimized by keeping shared functionality within dedicated modules (e.g., shared hooks, helpers).

##### Final Checklist for the Principal Software Engineer
- Component is clearly labeled with its name and role (e.g., “card (Presentation)” and “use-card (Logic)”).
- UI components and their hooks.
- Hooks and the services module (illustrating API and JSON processing).
- Hooks and shared state (using Jotai atoms), reflecting the global state management.
- External technology usages (React, MUI, Jotai, HowlerJS, Yu-Gi-Oh! API).
- Notes or call-outs for important architectural principles like separation of concerns and adherence to SOLID principles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Libraries
    EXTERNAL["External: React, MUI, Jotai, HowlerJS, Yu-Gi-Oh! API"]:::external

    %% UI/Presentation Layer Subgraph
    subgraph "UI Presentation"
        UICARD["card (Presentation)"]:::ui
        UICONTAINER["container (Presentation)"]:::ui
        UIDECK["deck (Presentation)"]:::ui
        UIENEMY["enemy-turn (Presentation)"]:::ui
        UIBATTLE["battle-phase (Presentation)"]:::ui
        UIDRAW["draw-phase (Presentation)"]:::ui
        UIMAIN["main-phase (Presentation)"]:::ui
        UIMAIN2["main-phase-two (Presentation)"]:::ui
        UISTANDBY["standby-phase (Presentation)"]:::ui
        UIFIELD["field (Presentation)"]:::ui
        UIGRAVEYARD["graveyard (Presentation)"]:::ui
        UIHAND["hand (Presentation)"]:::ui
        UIATTACK["attack-card modal (Presentation)"]:::ui
        UICHANGE["change-stats modal (Presentation)"]:::ui
        UISEARCH["search-card modal (Presentation)"]:::ui
        UISETTINGS["settings modal (Presentation)"]:::ui
        UISCOREBOARD["scoreboard (Presentation)"]:::ui
        UITOOLBAR["tool-bar (Presentation)"]:::ui
    end

    %% UI Logic Hooks Subgraph
    subgraph "UI Logic Hooks"
        UICARD_LOGIC["use-card (Logic)"]:::logic
        UISTANDBY_LOGIC["use-standby-phase (Logic)"]:::logic
        UIATTACK_LOGIC["use-attack-card (Logic)"]:::logic
        UICHANGE_LOGIC["use-change-stats (Logic)"]:::logic
        UISEARCH_LOGIC["use-search-card (Logic)"]:::logic
        UISETTINGS_LOGIC["use-settings (Logic)"]:::logic
        UISCOREBOARD_LOGIC["use-scoreboard (Logic)"]:::logic
        UITOOLBAR_LOGIC["use-tool-bar (Logic)"]:::logic
    end

    %% Shared Hooks and Global State
    subgraph "Shared State"
        HOOKS_DIR["Shared Hooks Directory"]:::state
        ATOMS["Jotai Atoms"]:::state
    end

    %% Services Subgraph
    subgraph "Services"
        SERVICE_CARDS["Cards Service"]:::service
    end

    %% Helpers Subgraph
    subgraph "Helpers"
        HELPER["Sound Helper"]:::helper
    end

    %% Connections: External to UI Presentation
    EXTERNAL --> UICONTAINER

    %% Connections between UI Presentation and their Logic Hooks
    UICARD -->|"triggers"| UICARD_LOGIC
    UISTANDBY -->|"triggers"| UISTANDBY_LOGIC
    UIATTACK -->|"triggers"| UIATTACK_LOGIC
    UICHANGE -->|"triggers"| UICHANGE_LOGIC
    UISEARCH -->|"triggers"| UISEARCH_LOGIC
    UISETTINGS -->|"triggers"| UISETTINGS_LOGIC
    UISCOREBOARD -->|"triggers"| UISCOREBOARD_LOGIC
    UITOOLBAR -->|"triggers"| UITOOLBAR_LOGIC

    %% Connections from UI Logic Hooks to Shared State & Services
    UICARD_LOGIC -->|"updates"| ATOMS
    UICARD_LOGIC -->|"calls"| SERVICE_CARDS

    UISTANDBY_LOGIC -->|"updates"| ATOMS
    UISTANDBY_LOGIC -->|"calls"| SERVICE_CARDS

    UIATTACK_LOGIC -->|"updates"| ATOMS
    UIATTACK_LOGIC -->|"calls"| SERVICE_CARDS

    UICHANGE_LOGIC -->|"updates"| ATOMS
    UICHANGE_LOGIC -->|"calls"| SERVICE_CARDS

    UISEARCH_LOGIC -->|"updates"| ATOMS
    UISEARCH_LOGIC -->|"calls"| SERVICE_CARDS

    UISETTINGS_LOGIC -->|"updates"| ATOMS
    UISETTINGS_LOGIC -->|"calls"| SERVICE_CARDS

    UISCOREBOARD_LOGIC -->|"updates"| ATOMS
    UISCOREBOARD_LOGIC -->|"calls"| SERVICE_CARDS

    UITOOLBAR_LOGIC -->|"updates"| ATOMS
    UITOOLBAR_LOGIC -->|"calls"| SERVICE_CARDS

    %% Connection from UI Presentation components to Helpers for sound management
    UICARD ---|"plays sound"| HELPER
    UIATTACK ---|"plays sound"| HELPER
    UICHANGE ---|"plays sound"| HELPER
    UISEARCH ---|"plays sound"| HELPER
    UISETTINGS ---|"plays sound"| HELPER
    UISCOREBOARD ---|"plays sound"| HELPER
    UITOOLBAR ---|"plays sound"| HELPER

    %% Click Events for UI Components and their Hooks
    click UICARD "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/card/card.jsx"
    click UICARD_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/card/use-card.js"
    click UICONTAINER "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/container/container.jsx"
    click UIDECK "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/deck/deck.jsx"
    click UIENEMY "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/enemy-turn.jsx"
    click UIBATTLE "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/phases/battle-phase.jsx"
    click UIDRAW "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/phases/draw-phase.jsx"
    click UIMAIN "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/phases/main-phase.jsx"
    click UIMAIN2 "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/phases/main-phase-two.jsx"
    click UISTANDBY "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/phases/standby-phase.jsx"
    click UISTANDBY_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/enemy-turn/phases/use-standby-phase.js"
    click UIFIELD "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/field/field.jsx"
    click UIGRAVEYARD "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/graveyard/graveyard.jsx"
    click UIHAND "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/hand/hand.jsx"
    click UIATTACK "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/attack-card/attack-card.jsx"
    click UIATTACK_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/attack-card/use-attack-card.js"
    click UICHANGE "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/change-stats/change-stats.jsx"
    click UICHANGE_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/change-stats/use-change-stats.js"
    click UISEARCH "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/search-card/search-card.jsx"
    click UISEARCH_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/search-card/use-search-card.js"
    click UISETTINGS "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/settings/settings.jsx"
    click UISETTINGS_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/modals/settings/use-settings.js"
    click UISCOREBOARD "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/scoreboard/scoreboard.jsx"
    click UISCOREBOARD_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/scoreboard/use-scoreboard.js"
    click UITOOLBAR "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/tool-bar/tool-bar.jsx"
    click UITOOLBAR_LOGIC "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/components/tool-bar/use-tool-bar.js"
    click HOOKS_DIR "https://github.com/lucaslimaaz/soloyugioh/tree/master/src/shared/hooks"
    click ATOMS "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/shared/atoms.jsx"
    click SERVICE_CARDS "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/shared/services/cards.jsx"
    click HELPER "https://github.com/lucaslimaaz/soloyugioh/blob/master/src/shared/helper.jsx"

    %% Styles
    classDef ui fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef logic fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef state fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef service fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef helper fill:#FFCCFF,stroke:#333,stroke-width:2px;
    classDef external fill:#EFEFEF,stroke:#333,stroke-width:2px;
```
