# sai-pratham05/code-mania architecture

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

- Interactive diagram: https://gitdiagram.com/sai-pratham05/code-mania
- Repository: https://github.com/sai-pratham05/code-mania

## Overview

##### Project Type and Purpose
- Code-Mania is a single-page application (SPA) built in React.
- It provides a playground for writing, theming, and compiling code in 40+ languages via the external Judge0 API (hosted through RapidAPI).

##### File Structure
- public/: Static assets and HTML shell (index.html, manifest.json, demo image).
- src/:
– components/: UI building blocks (CodeEditorWindow, LanguagesDropdown, ThemeDropdown, CustomInput, OutputWindow, Landing, Footer).
– constants/: Configs for styles, languages, and statuses.
– hooks/: Custom React hooks (useKeyPress).
– lib/: Theme-definition logic (defineTheme.js).
– utils/: General helpers (API calls, debounce, etc.).
– App.js & index.js: App orchestration and mount point.
- tailwind.config.js & postcss.config.js: Styling pipeline.
- package.json/lock & .env (for RapidAPI keys): Dependency and configuration.

##### Key Insights from README
- UI rendered entirely in the browser using React + Monaco Editor.
- Communication with remote Judge0 service over HTTP (compile/execute).
- Theming handled via Tailwind CSS + customStyles.
- Notifications via React-Toastify.

##### Main Architectural Components
a. Browser / User
b. React SPA
– UI Layer: Components (Editor, Dropdowns, Buttons, Windows)
– State & Theme Layer: App state, contexts, custom hooks
– Utils & API Layer: HTTP client calling Judge0 endpoints, environment config
c. External Service
– Judge0 compilation engine (via RapidAPI gateway)
d. Optional Dev/Build Tools
– Node.js dev server (npm start)
– Build pipeline (webpack via Create React App)

##### Interactions & Data Flow
1. User enters code / selects language & theme in CodeEditorWindow.
2. App state updates (useState, custom hooks).
3. On “Compile” click, UI triggers API call in utils/general.js → Judge0 (RapidAPI).
4. Judge0 processes code, returns JSON (stdout, stderr, status).
5. App receives response → OutputWindow & OutputDetails render result/status.
6. Notifications (success/error) via React-Toastify.

##### Architectural Patterns & Principles
- Component-Based Design: Each UI block is a self-contained React component.
- Separation of Concerns:
– components/ for presentation
– utils/ & hooks/ for business logic and behaviors
– constants/ & lib/ for configuration
- Single Source of Truth: App.js orchestrates top-level state, environment variables for credentials.

##### Detailed Elements to Capture
- Editor theming (Tailwind + defineTheme)
- Language options loaded from constants/languageOptions.js
- Custom hooks (useKeyPress) enhancing UX
- Environment variables for API credentials

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser
    B["Browser"]:::external

    %% React SPA
    subgraph "React SPA"
        IN["src/index.js"]:::logic
        AP["src/App.js"]:::logic

        subgraph "UI Components"
            CE["CodeEditorWindow"]:::ui
            LD["LanguagesDropdown"]:::ui
            TDr["ThemeDropdown"]:::ui
            CI["CustomInput"]:::ui
            OW["OutputWindow"]:::ui
            OD["OutputDetails"]:::ui
            LP["Landing"]:::ui
            F["Footer"]:::ui
        end

        subgraph "State & Theme Layer"
            KP["useKeyPress Hook"]:::logic
            DT["defineTheme"]:::logic
            CS["customStyles"]:::logic
        end

        subgraph "Constants & Configuration"
            LO["languageOptions"]:::logic
            ST["statuses"]:::logic
        end

        subgraph "API Layer"
            UG["general.js (Judge0 Client)"]:::logic
            ENV[".env Variables"]:::logic
        end
    end

    %% External Service
    E["Judge0 REST API (RapidAPI)"]:::external

    %% Dev & Build Tools
    subgraph "Dev & Build Tools"
        NPM["Node.js Dev Server / Build Pipeline"]:::tools
    end

    %% Connections
    B --> IN
    IN --> AP
    AP --> CE
    AP --> LD
    AP --> TDr
    AP --> CI
    AP --> OW
    AP --> OD
    AP --> KP
    AP --> DT
    AP --> CS
    AP --> LO
    AP --> ST
    AP --> UG

    CE -->|"Compile Request"| UG
    UG -->|"Uses Env Vars"| ENV
    UG -->|"API Call"| E
    E -->|"Response JSON"| UG
    UG -->|"Return Output"| OW
    OW --> OD

    NPM -.-> IN

    %% Click Events
    click IN "https://github.com/sai-pratham05/code-mania/blob/main/src/index.js"
    click AP "https://github.com/sai-pratham05/code-mania/blob/main/src/App.js"
    click CE "https://github.com/sai-pratham05/code-mania/blob/main/src/components/CodeEditorWindow.js"
    click LD "https://github.com/sai-pratham05/code-mania/blob/main/src/components/LanguagesDropdown.js"
    click TDr "https://github.com/sai-pratham05/code-mania/blob/main/src/components/ThemeDropdown.js"
    click CI "https://github.com/sai-pratham05/code-mania/blob/main/src/components/CustomInput.js"
    click OW "https://github.com/sai-pratham05/code-mania/blob/main/src/components/OutputWindow.js"
    click OD "https://github.com/sai-pratham05/code-mania/blob/main/src/components/OutputDetails.js"
    click LP "https://github.com/sai-pratham05/code-mania/blob/main/src/components/Landing.js"
    click F "https://github.com/sai-pratham05/code-mania/blob/main/src/components/Footer.js"
    click KP "https://github.com/sai-pratham05/code-mania/blob/main/src/hooks/useKeyPress.js"
    click DT "https://github.com/sai-pratham05/code-mania/blob/main/src/lib/defineTheme.js"
    click CS "https://github.com/sai-pratham05/code-mania/blob/main/src/constants/customStyles.js"
    click LO "https://github.com/sai-pratham05/code-mania/blob/main/src/constants/languageOptions.js"
    click ST "https://github.com/sai-pratham05/code-mania/blob/main/src/constants/statuses.js"
    click UG "https://github.com/sai-pratham05/code-mania/blob/main/src/utils/general.js"
    click ENV "https://github.com/sai-pratham05/code-mania/blob/main/.env"
    click NPM "https://github.com/sai-pratham05/code-mania/blob/main/package.json"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085
    classDef logic fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef tools fill:#f8d7da,stroke:#721c24,color:#721c24
```
