# praveenvarshney619/code-forge-online-compiler- architecture

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

- Interactive diagram: https://gitdiagram.com/praveenvarshney619/code-forge-online-compiler-
- Repository: https://github.com/praveenvarshney619/code-forge-online-compiler-

## Overview

##### Project Type & Purpose
- Full-stack online IDE / collaborative code editor
- Frontend built in Next.js + Tailwind CSS
- Backend in Node.js + Express.js, exposing REST endpoints for compile/scrape and a WebSocket channel for real-time collaboration

##### Main Components
A. Frontend (Next.js App)
– UI Layer: editor, language selector, input/output panes (components/FileEditor.jsx, LanguageDropdown.jsx, Output.jsx, etc.)
– Theme and styling (Tailwind + defineTheme.jsx)
– Data/API layer (frontend/services/index.js) for REST calls and WebSocket client
– Static assets (public/images, styles/globals.css)

B. Backend (Express Server)
1. REST API Controllers
- compileControllers.js – writes temp files, invokes system compiler (g++, javac, python), returns stdout/stderr
- scraperController.js – fetches coding problems via HTTP from external sites, parses HTML, returns JSON
2. WebSocket Controller
- socketController.js – socket.io (or ws) server to broadcast editor state changes between clients
3. Temp & Output Storage
- /temp – holds incoming code files and input.txt for each compile request
- /output – stores generated executables and console output
4. Server Entry Point
- server.js – mounts REST routes, initializes WebSocket server

C. External Services
– Code compilation toolchain (system g++, javac, python interpreters)
– Third-party websites for scraping coding questions
– (Optional) Logging/Monitoring, if present

##### Relationships & Data Flows
- User edits code → Frontend WebSocket client emits “code-update” → Backend socketController broadcasts to peers
- User clicks “Run” → Frontend sends POST /compile → compileController writes to /temp, runs compiler, reads /output, responds JSON → Frontend displays output
- User requests a problem → Frontend GET /scrape → scraperController fetches & parses external site, returns problem data → Frontend populates editor/description

##### Architectural Patterns & Principles
– Layered Architecture: UI Layer → API Layer (REST + WebSocket) → Business Logic Layer (compilation, scraping) → System Calls & File I/O
– MVC-style grouping in backend (controllers)
– Separation of concerns: collaboration sync (WebSocket) vs. one-off operations (REST)
– Stateless services: REST endpoints are idempotent aside from file I/O in temp/output

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Frontend Layer
  subgraph "Frontend (Next.js)" 
    subgraph "UI Components" 
      FileEditor["FileEditor.jsx"]:::frontend
      LanguageDropdown["LanguageDropdown.jsx"]:::frontend
      InputComp["Input.jsx"]:::frontend
      OutputComp["Output.jsx"]:::frontend
      ScraperComp["Scraper.jsx"]:::frontend
      ThemeDropdown["ThemeDropdown.jsx"]:::frontend
      LayoutComp["Layout.jsx"]:::frontend
      HeaderComp["Header.jsx"]:::frontend
    end
    subgraph "Theme & Styling"
      DefineTheme["defineTheme.jsx"]:::frontend
      GlobalsCSS["globals.css"]:::frontend
      TailwindJS["tailwind.config.js"]:::frontend
      TailwindTS["tailwind.config.ts"]:::frontend
      CustomStyles["customStyles.jsx"]:::frontend
    end
    subgraph "Data/API Layer"
      Services["index.js"]:::frontend
    end
    subgraph "Static Assets"
      PublicAssets["public/"]:::frontend
      ImageAssets["images/"]:::frontend
    end
  end

  %% API Gateway & Controllers
  subgraph "Backend (Express.js API)" 
    Server["server.js"]:::api
    subgraph "REST Controllers"
      CompileCtrl["compileControllers.js"]:::api
      ScraperCtrl["scraperController.js"]:::api
    end
    subgraph "WebSocket Controller"
      SocketCtrl["socketController.js"]:::realtime
    end
  end

  %% File System
  subgraph "File System" 
    TempFS["/temp"]:::fs
    OutputFS["/output"]:::fs
  end

  %% External Services
  subgraph "External Services"
    CompilerToolchain["System Compilers"]:::external
    ExternalSites["Coding Problem Sites"]:::external
  end

  %% Relationships
  FileEditor --> Services
  LanguageDropdown --> Services
  InputComp --> Services
  OutputComp --> Services
  ScraperComp --> Services
  ThemeDropdown --> Services
  LayoutComp --> Services
  HeaderComp --> Services
  DefineTheme --> Services
  GlobalsCSS --> Services
  TailwindJS --> Services
  TailwindTS --> Services
  CustomStyles --> Services
  PublicAssets --> Services
  ImageAssets --> Services

  Services -->|HTTP/REST| Server
  Services -->|WebSocket| SocketCtrl

  Server --> CompileCtrl
  Server --> ScraperCtrl

  Services -->|POST /compile| CompileCtrl
  Services -->|GET /scrape| ScraperCtrl
  Services -->|socket.emit code-update| SocketCtrl
  SocketCtrl -->|broadcast code-update| Services

  CompileCtrl --> TempFS
  CompileCtrl --> CompilerToolchain
  CompilerToolchain --> OutputFS
  CompileCtrl --> OutputFS

  ScraperCtrl --> ExternalSites

  %% Click Events
  click FileEditor "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/FileEditor.jsx"
  click LanguageDropdown "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/LanguageDropdown.jsx"
  click InputComp "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/Input.jsx"
  click OutputComp "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/Output.jsx"
  click ScraperComp "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/Scraper.jsx"
  click ThemeDropdown "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/ThemeDropdown.jsx"
  click LayoutComp "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/Layout.jsx"
  click HeaderComp "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/components/Header.jsx"
  click DefineTheme "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/lib/defineTheme.jsx"
  click GlobalsCSS "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/styles/globals.css"
  click TailwindJS "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/tailwind.config.js"
  click TailwindTS "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/tailwind.config.ts"
  click CustomStyles "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/constants/customStyles.jsx"
  click Services "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/frontend/services/index.js"
  click PublicAssets "https://github.com/praveenvarshney619/code-forge-online-compiler-/tree/main/frontend/public/"
  click ImageAssets "https://github.com/praveenvarshney619/code-forge-online-compiler-/tree/main/frontend/images/"
  click Server "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/backend/server.js"
  click CompileCtrl "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/backend/controllers/compileControllers.js"
  click ScraperCtrl "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/backend/controllers/scraperController.js"
  click SocketCtrl "https://github.com/praveenvarshney619/code-forge-online-compiler-/blob/main/backend/controllers/socketController.js"
  click TempFS "https://github.com/praveenvarshney619/code-forge-online-compiler-/tree/main/backend/temp/"
  click OutputFS "https://github.com/praveenvarshney619/code-forge-online-compiler-/tree/main/backend/output/"

  %% Styles
  classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
  classDef api fill:#d4edda,stroke:#333,stroke-width:1px
  classDef realtime fill:#ffe5b4,stroke:#333,stroke-width:1px
  classDef fs fill:#e2e3e5,stroke:#333,stroke-width:1px
  classDef external fill:#f3e0ff,stroke:#333,stroke-width:1px
```
