# gorocode/as-react architecture

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

- Interactive diagram: https://gitdiagram.com/gorocode/as-react
- Repository: https://github.com/gorocode/as-react

## Overview

##### Project Overview and Type
- This is a frontend application for an interactive game called “Apocalypse Simulator” built using React with Vite. It communicates with a separate Spring Boot–based backend (as indicated in the README) for game state and user management.
- The game includes question-based decision making (affecting player stats) and combat mechanics. Player authentication is handled via Google OAuth and profile images are managed with Cloudinary.

##### Main Components
a. Frontend (React Application):
- Entry and configuration: index.html, vite.config.js, etc.
- Core application: App.jsx and pages (Home, Game, Login, GameOver, etc.) for different game states and interactions.
- UI components: a comprehensive set of components (ConfirmModal, EnemySprite, Footer, PlayerSprite, etc.) that construct the interactive game interface.
- Context Providers (AuthContext.jsx, LanguageContext.jsx): managing authentication and language state across the application.
- Hooks and Store: custom hooks (e.g., usePlayerControls) and state management via Zustand (files in the "store" directory) to support dynamic game actions/events.
- API Module (src/api/api.js): handles communication with the external backend API.

b. Backend Interaction:

c. External Services:
- Google OAuth for authentication.
- Cloudinary for image storage, especially in user profile functionalities.

##### Relationships and Interactions
- Routing (React Router) as a connector between different pages (Home, Game, Login, etc.). Indicate that pages are composed of components (modals, sprites, texts, etc.).
- Role of the context providers to supply global state (authentication and language); link these providers with the pages and main app.

##### Architectural Patterns & Design Principles
- The component-based structure reflects a typical modern frontend MVC-like pattern: isolated UI components, dedicated state management (useGameStore, useEvent), and centralized API communications.
- Separation of concerns: UI, state, API interactions, and global context are all separated into different directories.
- Responsive and interactive design, noting that components like EnemySprite and PlayerSprite directly manage gameplay graphics and interactions.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend (Apocalypse Simulator)"
        subgraph "Entry & Config"
            E1["index.html"]:::entry
            E2["vite.config.js"]:::entry
            E3["src/main.jsx"]:::entry
        end
        subgraph "Core Application"
            CA["src/App.jsx"]:::core
        end
        subgraph "Pages"
            P1["Home.jsx"]:::pages
            P2["Game.jsx"]:::pages
            P3["Login.jsx"]:::pages
            P4["GameOver.jsx"]:::pages
            P5["HowToPlay.jsx"]:::pages
            P6["Contact.jsx"]:::pages
            P7["EditUser.jsx"]:::pages
            P8["MyPlayers.jsx"]:::pages
        end
        subgraph "UI Components"
            UC1["ConfirmModal.jsx"]:::components
            UC2["EnemySprite.jsx"]:::components
            UC3["Footer.jsx"]:::components
            UC4["HomeButton.jsx"]:::components
            UC5["MessageModal.jsx"]:::components
            UC6["PageTransition.jsx"]:::components
            UC7["PlayerSprite.jsx"]:::components
            UC8["PlayerStats.jsx"]:::components
            UC9["ProtectedRoute.jsx"]:::components
            UC10["SceneDisplay.jsx"]:::components
            UC11["TextSlides.jsx"]:::components
            UC12["UserSettings.jsx"]:::components
        end
        subgraph "Context Providers"
            CP1["AuthContext.jsx"]:::context
            CP2["LanguageContext.jsx"]:::context
        end
        subgraph "Hooks & Store"
            subgraph "Hooks"
                H1["usePlayerControls.js"]:::hooks
            end
            subgraph "Store"
                S1["useEvent.js"]:::hooks
                S2["useGameStore.js"]:::hooks
            end
        end
        APM["src/api/api.js"]:::api
    end
    BE["Backend (Spring Boot)"]:::backend
    EO1["Google OAuth"]:::external
    EO2["Cloudinary"]:::external

    %% Connections
    E3 --> CA
    CA --> P1
    CA --> P3
    P2 --> APM
    P3 -->|"OAuth"| EO1
    UC12 -->|"ProfileImg"| EO2
    APM -->|"REST_API"| BE
    CP1 -.->|"globalAuth"| CA
    CP2 -.->|"languageState"| CA
    H1 -->|"controls"| UC7

    %% Click Events for Entry & Config
    click E1 "https://github.com/gorocode/as-react/blob/main/index.html"
    click E2 "https://github.com/gorocode/as-react/blob/main/vite.config.js"
    click E3 "https://github.com/gorocode/as-react/blob/main/src/main.jsx"
    
    %% Click Event for Core Application
    click CA "https://github.com/gorocode/as-react/blob/main/src/App.jsx"
    
    %% Click Events for Pages
    click P1 "https://github.com/gorocode/as-react/blob/main/src/pages/Home.jsx"
    click P2 "https://github.com/gorocode/as-react/blob/main/src/pages/Game.jsx"
    click P3 "https://github.com/gorocode/as-react/blob/main/src/pages/Login.jsx"
    click P4 "https://github.com/gorocode/as-react/blob/main/src/pages/GameOver.jsx"
    click P5 "https://github.com/gorocode/as-react/blob/main/src/pages/HowToPlay.jsx"
    click P6 "https://github.com/gorocode/as-react/blob/main/src/pages/Contact.jsx"
    click P7 "https://github.com/gorocode/as-react/blob/main/src/pages/EditUser.jsx"
    click P8 "https://github.com/gorocode/as-react/blob/main/src/pages/MyPlayers.jsx"
    
    %% Click Events for UI Components
    click UC1 "https://github.com/gorocode/as-react/blob/main/src/components/ConfirmModal.jsx"
    click UC2 "https://github.com/gorocode/as-react/blob/main/src/components/EnemySprite.jsx"
    click UC3 "https://github.com/gorocode/as-react/blob/main/src/components/Footer.jsx"
    click UC4 "https://github.com/gorocode/as-react/blob/main/src/components/HomeButton.jsx"
    click UC5 "https://github.com/gorocode/as-react/blob/main/src/components/MessageModal.jsx"
    click UC6 "https://github.com/gorocode/as-react/blob/main/src/components/PageTransition.jsx"
    click UC7 "https://github.com/gorocode/as-react/blob/main/src/components/PlayerSprite.jsx"
    click UC8 "https://github.com/gorocode/as-react/blob/main/src/components/PlayerStats.jsx"
    click UC9 "https://github.com/gorocode/as-react/blob/main/src/components/ProtectedRoute.jsx"
    click UC10 "https://github.com/gorocode/as-react/blob/main/src/components/SceneDisplay.jsx"
    click UC11 "https://github.com/gorocode/as-react/blob/main/src/components/TextSlides.jsx"
    click UC12 "https://github.com/gorocode/as-react/blob/main/src/components/UserSettings.jsx"
    
    %% Click Events for Context Providers
    click CP1 "https://github.com/gorocode/as-react/blob/main/src/context/AuthContext.jsx"
    click CP2 "https://github.com/gorocode/as-react/blob/main/src/context/LanguageContext.jsx"
    
    %% Click Events for Hooks & Store
    click H1 "https://github.com/gorocode/as-react/blob/main/src/hooks/usePlayerControls.js"
    click S1 "https://github.com/gorocode/as-react/blob/main/src/store/useEvent.js"
    click S2 "https://github.com/gorocode/as-react/blob/main/src/store/useGameStore.js"
    
    %% Click Event for API Module
    click APM "https://github.com/gorocode/as-react/blob/main/src/api/api.js"

    %% Styles
    classDef entry fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef core fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef pages fill:#fffacd,stroke:#000,stroke-width:2px;
    classDef components fill:#ffb6c1,stroke:#000,stroke-width:2px;
    classDef context fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef hooks fill:#ffdead,stroke:#000,stroke-width:2px;
    classDef api fill:#ffa07a,stroke:#000,stroke-width:2px;
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef backend fill:#afeeee,stroke:#000,stroke-width:2px;
```
