# shameer99/anagrab architecture

> Architecture diagram of the GitHub repository shameer99/anagrab, 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/shameer99/anagrab
- Repository: https://github.com/shameer99/anagrab

## Overview

##### Main Components
- Frontend: This is found under the “frontend/anagrab-frontend” directory. It includes:
- HTML (index.html)
- JavaScript/React components (App.jsx, various UI components such as AlphabetDisplay, GameControls, WordList, etc.)
- Styling files and hooks (e.g., useSocket.js for real-time communication)
- Vite configuration for development with hot module replacement.
- Backend: Located in the “backend” directory. Its key elements include:
- Server Setup: “server.js” that sets up the server and integrates the other modules.
- Routes: API endpoints (e.g., debug.js for testing game rules like word root comparisons, test cases, etc.)
- Socket Handlers: “socket/handlers.js” to manage real-time communication.
- Game Logic: Business logic in “utils/gameLogic.js” and configuration files (e.g., MongoDB config in “config/mongodb.js”).
- Supporting Data: Files like “dictionary.txt” and JSON configuration files for transformation rules and test cases.
- External Services and Configuration:
- GitHub Actions workflows and husky for code quality/enforcement.

##### Relationships and Data Flow
- Client-Server Communication:
- The frontend communicates with the backend over HTTP (for API endpoints) and via WebSockets for real-time game actions.
- In the backend:
- Routes are defined to handle game-related API calls including debugging and data validation.
- The “socket” module works in tandem with the “gameLogic” module to ensure game rules are applied during real-time play.
- Testing and Debug Tools:
- Endpoints dedicated to debugging (through the /debug routes) as they provide validation tools for game logic and transformation rules.

##### Architectural Patterns and Design Principles
- MVC/Separation of Concerns:
- Although not explicitly named, the separation between frontend presentation, backend business logic, and data configuration suggests a separation of concerns.
- Real-time Communication:
- Usage of socket-based communication to support the real-time multiplayer aspects of the game.
- Development Tooling:
- Use of husky, GitHub workflows, and Vite for development and debugging add layers that ensure code quality and an efficient development cycle.

##### Technologies, Frameworks, and Libraries
- Frontend:
- React (with components, hooks)
- Vite for bundling and HMR (Hot Module Replacement)
- ESLint and Prettier for code linting and formatting.
- Backend:
- Node.js running Express-like servers (given standard “server.js” and routings)
- Socket communication (custom handlers under “socket/handlers.js”)
- nodemon in development for auto-reloading.
- MongoDB configuration (if persistence is active) and JSON-based configuration files for game data.
- Debug/Testing:
- Internal debug endpoints described in the README for testing word transformation and root comparison.

##### Additional Elements
- A node for “Development Tools” with notes about auto-reload (nodemon) and hot module replacement (Vite) that support a smoother development cycle.
- If necessary, include the build and deployment pipelines (GitHub Workflows) as auxiliary modules to show how code is managed and deployed to production.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        FE["Frontend (React/Vite)"]:::client
        DT_FE["Development Tools (Vite, HMR)"]:::client
    end

    %% Server Layer
    subgraph "Server Layer"
        BS["Server Setup (server.js)"]:::server
        AR["API Routes (debug.js)"]:::server
        SH["Socket Handlers (handlers.js)"]:::server
        GL["Game Logic (gameLogic.js)"]:::server
        DT_BE["Development Tools (nodemon)"]:::server
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        Conf["Database Config (mongodb.js)"]:::server
        DB["MongoDB"]:::db
    end

    %% Game Data & Debugging
    subgraph "Game Data & Debugging"
        Dict["Dictionary (dictionary.txt)"]:::data
        TBL["transformationBlacklist.json"]:::data
        TWL["transformationWhitelist.json"]:::data
        WTT["wordTransformationTests.json"]:::data
    end

    %% Connections between Client and Server
    FE -->|"HTTP_API"| AR
    FE -->|"WebSocket"| SH

    %% Internal Server Connections
    BS -->|"integrates"| AR
    BS -->|"integrates"| SH
    AR -->|"calls"| GL
    SH -->|"invokes"| GL

    %% Server to Persistence
    Conf --> DB
    BS -->|"loads config"| Conf

    %% API Routes use Game Data for Debug/Validation
    AR -->|"reads"| Dict
    AR -->|"uses"| TBL
    AR -->|"uses"| TWL
    AR -->|"uses"| WTT

    %% Click Events
    click FE "https://github.com/shameer99/anagrab/tree/main/frontend/anagrab-frontend"
    click BS "https://github.com/shameer99/anagrab/blob/main/backend/server.js"
    click AR "https://github.com/shameer99/anagrab/blob/main/backend/routes/debug.js"
    click SH "https://github.com/shameer99/anagrab/blob/main/backend/socket/handlers.js"
    click GL "https://github.com/shameer99/anagrab/blob/main/backend/utils/gameLogic.js"
    click Conf "https://github.com/shameer99/anagrab/blob/main/backend/config/mongodb.js"
    click Dict "https://github.com/shameer99/anagrab/blob/main/backend/dictionary.txt"
    click TBL "https://github.com/shameer99/anagrab/blob/main/backend/data/transformationBlacklist.json"
    click TWL "https://github.com/shameer99/anagrab/blob/main/backend/data/transformationWhitelist.json"
    click WTT "https://github.com/shameer99/anagrab/blob/main/backend/data/wordTransformationTests.json"

    %% Styles
    classDef client fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef server fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef db fill:#577590,stroke:#fff,stroke-width:2px;
    classDef data fill:#f94144,stroke:#fff,stroke-width:2px;
```
