# steve245270533/react-three-egg architecture

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

- Interactive diagram: https://gitdiagram.com/steve245270533/react-three-egg
- Repository: https://github.com/steve245270533/react-three-egg

## Overview

##### Project Type and Purpose
- This is a single-page, client-side 3D game built with React and Three.js (via @react-three/fiber) plus a physics engine (@react-three/rapier).
- The README calls it “react-three-egg,” a third-person Q-style adventure game clone, stripped of multiplayer logic and migrated to Vite.

##### File Structure
- Top-level config & env files (.env.*, tsconfig, vite.config.ts, .eslintrc.cjs, GitHub Actions).
- public/ holds static 3D models (GLB) and index.html.
- src/ contains:
- App.tsx & index.tsx – React entry point and root component.
- components/Character (Character.tsx + model & hooks)
- components/Map (Map.tsx + useMap hook)
- components/Spinner (loading UI)
- hooks/ (useMap, useCharacter)
- Constants.ts, styles.scss, vite-env.d.ts

##### Key Insights from the README
- Tech stack: react, three, @react-three/fiber, @react-three/rapier
- Game controls via keyboard (input → useCharacter hook → physics)
- Assets loaded at runtime from public/

##### Main Components
a. Browser / Client
- index.html → Vite-bundled JS/CSS → React app
b. React App Layer
- <App>
- <Canvas> (react-three-fiber)
- <Spinner> (loading indicator)
- Scene Graph:
– Character component (uses useCharacter hook + CharacterModel)
– Map component (uses useMap hook)
c. 3D Engine & Physics
- Three.js core (renderer, scene, camera)
- Rapier physics engine (rigid bodies, collision)
d. Assets & Configuration
- GLB model files (public/)
- Constants.ts for magic values
- SCSS styles
e. Build & Deployment
- Vite (dev server, bundler)
- GitHub Actions (deploy.yml)

##### Relationships and Data Flows
- User Input (keyboard events) → useCharacter hook → Rapier physics update → Three.js scene graph
- useMap hook → sets up static physics colliders + Map mesh in scene
- Three.js + Canvas → painted to browser viewport
- Public assets loaded via HTTP requests

##### Architectural Patterns & Design Principles
- Component-based decomposition (React functional components + hooks)
- Separation of concerns: rendering (react-three-fiber), physics (rapier), game logic (hooks), assets (public)
- Single responsibility: each hook & component has a distinct role

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Layer
    Browser["Browser / Client"]:::client
    HTML["index.html"]:::client
    Browser -->|loads| HTML
    HTML -->|serves| ReactApp

    %% React Application Layer
    subgraph "React App" 
        direction TB
        ReactApp["Vite-bundled React App"]:::react
        IDX["index.tsx"]:::react
        App["App.tsx"]:::react
        Canvas["<Canvas> (react-three-fiber)"]:::react
        Spinner["Spinner Component"]:::react
        CharacterComp["Character Component"]:::react
        MapComp["Map Component"]:::react
        UseChar["useCharacter Hook"]:::react
        UseMap["useMap Hook"]:::react
        Constants["Constants.ts"]:::asset
        Styles["styles.scss"]:::asset

        ReactApp --> IDX
        IDX --> App
        App --> Canvas
        App --> Spinner
        Canvas --> CharacterComp
        Canvas --> MapComp
        CharacterComp --> UseChar
        MapComp --> UseMap
        ReactApp --> Constants
        ReactApp --> Styles
    end

    %% 3D Engine & Physics Layer
    subgraph "3D Engine & Physics"
        direction TB
        ThreeJS["Three.js Engine"]:::engine
        Rapier["Rapier Physics Engine"]:::physics
    end

    %% Assets Layer
    subgraph "Assets"
        direction TB
        Model1["fella-anim-transformed.glb"]:::asset
        Model2["trip-fellas-map-transformed.glb"]:::asset
    end

    %% Build & Deployment
    subgraph "Build & CI/CD"
        direction TB
        Vite["Vite Config"]:::build
        GHActions["GitHub Actions Deploy"]:::build
    end

    %% Data Flows
    Browser -->|HTTP fetch| Model1
    Browser -->|HTTP fetch| Model2
    Canvas --> ThreeJS
    UseChar --> Rapier
    UseMap --> Rapier
    ThreeJS -->|renders frame| Browser
    Vite --> ReactApp
    GHActions --> Vite

    %% Click events
    click HTML "https://github.com/steve245270533/react-three-egg/blob/master/index.html"
    click IDX "https://github.com/steve245270533/react-three-egg/blob/master/src/index.tsx"
    click App "https://github.com/steve245270533/react-three-egg/blob/master/src/App.tsx"
    click Spinner "https://github.com/steve245270533/react-three-egg/blob/master/src/components/Spinner/Spinner.tsx"
    click CharacterComp "https://github.com/steve245270533/react-three-egg/blob/master/src/components/Character/Character.tsx"
    click CharacterComp "https://github.com/steve245270533/react-three-egg/blob/master/src/components/Character/CharacterModel.tsx"
    click UseChar "https://github.com/steve245270533/react-three-egg/blob/master/src/components/Character/use-character.ts"
    click MapComp "https://github.com/steve245270533/react-three-egg/blob/master/src/components/Map/Map.tsx"
    click UseMap "https://github.com/steve245270533/react-three-egg/blob/master/src/hooks/useMap.ts"
    click Constants "https://github.com/steve245270533/react-three-egg/blob/master/src/Constants.ts"
    click Styles "https://github.com/steve245270533/react-three-egg/blob/master/src/styles.scss"
    click Model1 "https://github.com/steve245270533/react-three-egg/blob/master/public/fella-anim-transformed.glb"
    click Model2 "https://github.com/steve245270533/react-three-egg/blob/master/public/trip-fellas-map-transformed.glb"
    click Vite "https://github.com/steve245270533/react-three-egg/blob/master/vite.config.ts"
    click GHActions "https://github.com/steve245270533/react-three-egg/blob/master/.github/workflows/deploy.yml"

    %% Styles
    classDef client fill:#D4E6F1,stroke:#1B4F72,color:#1B4F72;
    classDef react fill:#AED6F1,stroke:#2874A6,color:#154360;
    classDef engine fill:#ABEBC6,stroke:#229954,color:#1D8348;
    classDef physics fill:#A9DFBF,stroke:#28B463,color:#186A3B;
    classDef asset fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef build fill:#D5D8DC,stroke:#626567,color:#1C2833;
```
