# blnwajith/compiler architecture

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

- Interactive diagram: https://gitdiagram.com/blnwajith/compiler
- Repository: https://github.com/blnwajith/compiler

## Overview

##### Project type and purpose
- This is a full-stack, web-based code editor and compiler with AI-powered assistance.
- Purpose: let users edit, compile, run multi-language code and interact with a local AI model for explanations, bug detection, and improvements.

##### File structure
- Top-level directories:
- client/ – React/Vite frontend and Monaco editor
- server/ – Node.js + Express backend, proxies to Piston API
- compiler/ – Python Flask AI service loading a HuggingFace model
- Other files:
- huggingface.py – model loading & analysis logic
- all_runtimes.json – supported languages list for Piston
- test/version scripts and helper scripts (check_versions.js, verify_mock.js)
- No database or persistent store; stateless request/response architecture with external API calls.

##### Key insights from the README
- Frontend: React, Vite, Monaco Editor, Axios
- Backend: Node.js, Express, Piston API for code execution
- AI service: Python, Flask, HuggingFace Transformers, PyTorch
- Three distinct services start in parallel: AI (port 5000), Backend (port 3000), Frontend (port 5173).

a. Main components
- User’s Browser (UI)
- Frontend App (React + Monaco Editor)
- Backend Service (Node.js + Express)
- AI Service (Python + Flask + HuggingFace model)
- External Code Execution API (Piston)
b. Relationships & interactions
1. User interacts with the React UI in browser.
2. On “Run Code,” UI issues HTTP POST to Backend → Backend calls Piston API → Backend returns compile/run results → UI displays output.
3. On “Chat” or AI request, UI issues HTTP POST to AI Service → Flask loads model (Qwen2.5) → model analysis → AI Service returns explanation/feedback → UI updates chat panel.
c. Architectural patterns & design principles
- Microservices style: three independent services communicating over HTTP.
- Clear separation of concerns: UI vs. business logic vs. AI inference.
- Stateless services: each request is self-contained.
d. Relevant technologies
- Frontend: React, Vite, Monaco Editor, Axios
- Backend: Node.js, Express, Piston API
- AI: Python, Flask, HuggingFace Transformers, PyTorch

## Diagram (Mermaid)

```mermaid
graph TB
    User["User Browser"]:::external

    subgraph "Frontend (React + Vite)"
        FEApp["App.jsx"]:::frontend
        Main["main.jsx"]:::frontend
        ViteConfig["vite.config.js"]:::frontend
        CodeEditor["CodeEditor.jsx"]:::frontend
        ChatPanel["ChatPanel.jsx"]:::frontend
        Controls["Controls.jsx"]:::frontend
        Output["Output.jsx"]:::frontend
        Event1["onEditorChange.js"]:::frontend
        Event2["onChatSend.js"]:::frontend
    end

    subgraph "Backend Service (Node.js + Express)"
        Server["index.js"]:::backend
        Runtimes["all_runtimes.json"]:::backend
        VersionCheck1["check_versions.js"]:::backend
        VersionCheck2["test_version.js"]:::backend
        VersionCheck3["verify_mock.js"]:::backend
    end

    subgraph "AI Service (Python + Flask)"
        AIService["main.py"]:::ai
        ModelLoader["huggingface.py"]:::ai
    end

    Piston["Piston API"]:::external

    %% User interaction
    User --> FEApp
    FEApp --> CodeEditor
    FEApp --> ChatPanel

    CodeEditor --> Controls
    ChatPanel --> Controls

    %% Code execution flow
    Controls -->|"POST /run"| Server
    Server -->|"HTTP POST"| Piston
    Piston -->|Response| Server
    Server -->|Response| Output

    %% AI analysis flow
    Controls -->|"POST /analyze"| AIService
    AIService -->|loads model| ModelLoader
    ModelLoader -->|inference| AIService
    AIService -->|Response| ChatPanel

    %% Click Events
    click FEApp "https://github.com/blnwajith/compiler/blob/main/client/src/App.jsx"
    click Main "https://github.com/blnwajith/compiler/blob/main/client/src/main.jsx"
    click ViteConfig "https://github.com/blnwajith/compiler/blob/main/client/vite.config.js"
    click CodeEditor "https://github.com/blnwajith/compiler/blob/main/client/src/components/CodeEditor.jsx"
    click ChatPanel "https://github.com/blnwajith/compiler/blob/main/client/src/components/ChatPanel.jsx"
    click Controls "https://github.com/blnwajith/compiler/blob/main/client/src/components/Controls.jsx"
    click Output "https://github.com/blnwajith/compiler/blob/main/client/src/components/Output.jsx"
    click Event1 "https://github.com/blnwajith/compiler/blob/main/client/src/events/onEditorChange.js"
    click Event2 "https://github.com/blnwajith/compiler/blob/main/client/src/events/onChatSend.js"
    click Server "https://github.com/blnwajith/compiler/blob/main/server/index.js"
    click Runtimes "https://github.com/blnwajith/compiler/blob/main/server/all_runtimes.json"
    click VersionCheck1 "https://github.com/blnwajith/compiler/blob/main/server/check_versions.js"
    click VersionCheck2 "https://github.com/blnwajith/compiler/blob/main/server/test_version.js"
    click VersionCheck3 "https://github.com/blnwajith/compiler/blob/main/server/verify_mock.js"
    click AIService "https://github.com/blnwajith/compiler/blob/main/compiler/main.py"
    click ModelLoader "https://github.com/blnwajith/compiler/blob/main/huggingface.py"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6;
    classDef backend fill:#D0F0D0,stroke:#228B22;
    classDef ai fill:#FFE4B5,stroke:#FF8C00;
    classDef external fill:#F0F0F0,stroke:#777777,stroke-dasharray: 4 2;
```
