# doonmad/reactplayground architecture

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

- Interactive diagram: https://gitdiagram.com/doonmad/reactplayground
- Repository: https://github.com/doonmad/reactplayground

## Overview

##### Project type and purpose
- This is a **React SPA** scaffolded by **Vite**, featuring multiple small “project” demos under `src/projects/`.
- Purpose: demonstrate React components, state management, and HMR using either Babel (plugin-react) or SWC (plugin-react-swc).

##### File structure
- Top-level files
– `index.html`: SPA entry point
– `package.json` / `vite.config.js`: build & dev-server config; NPM scripts
– `eslint.config.js`: linting rules
- `public/`: static assets (favicon, images…) served “as-is”
- `src/`:
– `main.jsx`: mounts `<App />` into `div#root`
– `App.jsx` + `App.css`: core layout, routing to individual demos
– `components/`: reusable presentational units (e.g., `ProjectCard.jsx`)
– `projects/[01ViteReact…05LOLScript]`: five demo apps, each self-contained with its own `index.jsx`, optional hooks, subcomponents

##### Extract additional insights from README
- Emphasizes **Vite** for fast refresh + HMR
- Optional Babel vs SWC plugin for compilation
- Encouraged TypeScript + type-aware ESLint for production, though this template is plain JS

##### Main components & boundaries
a. Developer workstation
– IDE / source code
– NPM scripts (`npm run dev`, `npm run build`)
b. Build & Dev pipeline
– **Vite Dev Server**
- Reads `vite.config.js`, watches `src/` + `public/`
- Applies `@vitejs/plugin-react` or `@vitejs/plugin-react-swc` (Babel/SWC transforms, HMR)
– **ESLint** (pre-commit or editor integration)
c. Source layers
– **Public assets** served statically
– **index.html**: root shell (div#root) + script injection
– **Module graph** under `src/`:
- `main.jsx` → `App.jsx` → child components & demo entrypoints
- `components/` & `projects/*` folders
d. Browser runtime
– Bundled modules delivered via Vite’s module server (ESM)
– **React reconciliation** & Virtual DOM
– Rendered UI in the DOM
e. Individual project demos (01…05)
– Each is a sub-module:
- e.g. `05LOLScript` uses custom hook `useGetJoke` to fetch data

##### Interactions & data flow
- On load: Browser requests `index.html` → Vite injects script tags → modules load
- React bootstraps at `#root` → `App.jsx` renders navigation + `<ProjectCard>` list → clicking a card loads corresponding demo component
- Demo components may fetch data (e.g. jokes) via hooks → update component state → UI refresh

##### Architectural patterns & principles
- **Component-based UI**: All UI divided into small, reusable React components
- **SPA routing/navigation** (implicit in `App.jsx`)
- **Modular demos**: each project folder is a pluggable module
- **HMR & ESM**: Vite leverages native ES modules for lightning-fast hot updates
- **Separation of concerns**: Static assets vs source code vs config vs build pipeline

##### Detail level
- Every folder and major file as a node in the “Source Code” zone
- HMR loop: Dev → Vite → Browser → React → back to Dev upon save

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Developer Workstation"
        DevIDE["IDE / Source Code"]:::dev
        DevNPM["package.json (NPM Scripts)"]:::code
    end

    subgraph "Build & Dev Pipeline"
        Vite["Vite Dev Server"]:::tool
        ESLint["ESLint"]:::tool
        ViteConfig["vite.config.js"]:::code
        ESLintConfig["eslint.config.js"]:::code
    end

    subgraph "Source Code"
        Public["public/"]:::code
        HTML["index.html"]:::code
        subgraph "src/"
            Main["src/main.jsx"]:::code
            App["src/App.jsx"]:::code
            AppCSS["src/App.css"]:::code
            IndexCSS["src/index.css"]:::code
            Components["src/components/"]:::code
            ProjectCard["src/components/ProjectCard.jsx"]:::code
            Assets["src/assets/"]:::code
            subgraph "projects/"
                P1["src/projects/01ViteReact/index.jsx"]:::code
                P1Comp["src/projects/01ViteReact/Comp.jsx"]:::code
                P2["src/projects/02BgChanger/index.jsx"]:::code
                P3["src/projects/03ReactProps/index.jsx"]:::code
                P3Card["src/projects/03ReactProps/components/Card.jsx"]:::code
                P4["src/projects/04PasswordGenerator/index.jsx"]:::code
                P5["src/projects/05LOLScript/index.jsx"]:::code
                P5Hook["src/projects/05LOLScript/hooks/useGetJoke.js"]:::code
            end
        end
    end

    subgraph "Browser Runtime"
        Browser["Browser"]:::runtime
        ReactVM["React Reconciler & Virtual DOM"]:::runtime
        DOM["DOM (div#root)"]:::runtime
    end

    DevIDE -->|edits code| Vite
    DevNPM -->|npm run dev| Vite
    ViteConfig --> Vite
    ESLintConfig --> ESLint
    ESLint --> Vite
    Public -->|watched| Vite
    HTML -->|served| Vite
    src -->|watched| Vite
    Vite -->|serve modules & HMR| Browser
    Browser -->|HTTP GET index.html| HTML
    HTML -->|loads| Main
    Main -->|renders| App
    App -->|imports| Components
    Components -->|provides| ProjectCard
    App -->|imports| Assets
    App -->|navigates to demo| P1
    App -->|navigates to demo| P2
    App -->|navigates to demo| P3
    App -->|navigates to demo| P4
    App -->|navigates to demo| P5
    Browser -->|React bootstrap| ReactVM
    ReactVM -->|reconciles| DOM

    click HTML "https://github.com/doonmad/reactplayground/blob/master/index.html"
    click ViteConfig "https://github.com/doonmad/reactplayground/blob/master/vite.config.js"
    click ESLintConfig "https://github.com/doonmad/reactplayground/blob/master/eslint.config.js"
    click Public "https://github.com/doonmad/reactplayground/tree/master/public/"
    click DevNPM "https://github.com/doonmad/reactplayground/blob/master/package.json"
    click Main "https://github.com/doonmad/reactplayground/blob/master/src/main.jsx"
    click App "https://github.com/doonmad/reactplayground/blob/master/src/App.jsx"
    click AppCSS "https://github.com/doonmad/reactplayground/blob/master/src/App.css"
    click IndexCSS "https://github.com/doonmad/reactplayground/blob/master/src/index.css"
    click Components "https://github.com/doonmad/reactplayground/tree/master/src/components/"
    click ProjectCard "https://github.com/doonmad/reactplayground/blob/master/src/components/ProjectCard.jsx"
    click Assets "https://github.com/doonmad/reactplayground/tree/master/src/assets/"
    click P1 "https://github.com/doonmad/reactplayground/blob/master/src/projects/01ViteReact/index.jsx"
    click P1Comp "https://github.com/doonmad/reactplayground/blob/master/src/projects/01ViteReact/Comp.jsx"
    click P2 "https://github.com/doonmad/reactplayground/blob/master/src/projects/02BgChanger/index.jsx"
    click P3 "https://github.com/doonmad/reactplayground/blob/master/src/projects/03ReactProps/index.jsx"
    click P3Card "https://github.com/doonmad/reactplayground/blob/master/src/projects/03ReactProps/components/Card.jsx"
    click P4 "https://github.com/doonmad/reactplayground/blob/master/src/projects/04PasswordGenerator/index.jsx"
    click P5 "https://github.com/doonmad/reactplayground/blob/master/src/projects/05LOLScript/index.jsx"
    click P5Hook "https://github.com/doonmad/reactplayground/blob/master/src/projects/05LOLScript/hooks/useGetJoke.js"

    classDef tool fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef code fill:#98FB98,stroke:#333,stroke-width:1px
    classDef runtime fill:#FFA500,stroke:#333,stroke-width:1px
    classDef dev fill:#D3D3D3,stroke:#333,stroke-width:1px
```
