# ritik-gusain/indentron architecture

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

- Interactive diagram: https://gitdiagram.com/ritik-gusain/indentron
- Repository: https://github.com/ritik-gusain/indentron

## Overview

##### Project Type & Purpose
- Full-stack web application: a single-page front-end (public/index.html + vanilla JS) served by a Node.js/Express backend.
- Purpose: real-time code formatting across 12+ languages, plus code sharing and analytics.

##### High-Level Components
a. Client/UI Layer
- Browser running the static HTML/JS/CSS in public/
- Glassmorphic editor UI, language dropdown, format/share buttons
b. Server/API Layer (Express)
- server.js (entry point)
- Routes (src/routes/*)
- Middleware (src/middleware/*)
- Controllers (src/controllers/*)
- Services (src/services/*, including AIFormatterService, FormatterService, ShareService, AnalyticsService)
- Formatters (src/services/formatters/*.js)
- Utils (src/utils/logger.js, formatUtils.js)
- Config (config/config.js, config/ai-config.js)
c. External Services
- OpenAI API (for advanced formatting)
- Vercel (static + serverless hosting)
- (Optional) In-memory or file-based store for shared code

##### Data Flow & Interactions
- User action in browser → HTTP request to Express (e.g., POST /format)
- Request passes through rateLimiter & validation middleware
- Route handler (formatRoutes.js) dispatches to FormatController
- FormatController invokes AIFormatterService or FormatterService
– FormatterService delegates to language-specific formatter modules
– AIFormatterService calls OpenAI API, applies ai-config settings
- Controller assembles response → sends JSON back to UI
- AnalyticsService logs usage (could POST to external or write locally)
- For sharing: ShareController ↔ ShareService → persist share record → return share ID

##### Architectural Patterns & Principles
- MVC (Routes → Controllers → Services → Views/Responses)
- Modular organization: one folder per concern (routes, controllers, services, utils)
- Single responsibility: each formatter module handles one language
- Centralized configuration & environment management (config/)

##### Detail Level
- Do not collapse too aggressively: the value is in illustrating each moving part (controllers vs. services vs. utils).
- Config files and environment variables (PORT, OPENAI_API_KEY) are called out.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/UI Layer
    subgraph "Client/UI Layer"
        direction TB
        UI["public/index.html"]:::client
    end

    %% Server/API Layer
    subgraph "Server/API Layer"
        direction TB
        ServerEntry["server.js"]:::api
        App["src/app.js"]:::api

        subgraph "Routes & Middleware"
            direction TB
            RoutesIndex["src/routes/index.js"]:::api
            FormatRoutes["src/routes/formatRoutes.js"]:::api
            FileUploadRoutes["src/routes/fileUploadRoutes.js"]:::api
            ShareRoutes["src/routes/shareRoutes.js"]:::api
            HealthRoutes["src/routes/healthRoutes.js"]:::api
            RateLimiter["src/middleware/rateLimiter.js"]:::api
            Validation["src/middleware/validation.js"]:::api
        end

        subgraph "Controllers"
            direction TB
            FormatController["src/controllers/FormatController.js"]:::api
            FileUploadController["src/controllers/FileUploadController.js"]:::api
            ShareController["src/controllers/ShareController.js"]:::api
        end

        subgraph "Services & Formatters"
            direction TB
            AIFormatterService["src/services/AIFormatterService.js"]:::logic
            FormatterService["src/services/FormatterService.js"]:::logic
            ShareService["src/services/ShareService.js"]:::logic
            AnalyticsService["src/services/AnalyticsService.js"]:::logic

            subgraph "Formatters"
                direction TB
                CSSFormatter["src/services/formatters/css-formatter.js"]:::logic
                CStyleFormatter["src/services/formatters/cstyle-formatter.js"]:::logic
                GenericFormatter["src/services/formatters/generic-formatter.js"]:::logic
                HTMLFormatter["src/services/formatters/html-formatter.js"]:::logic
                JSFormatter["src/services/formatters/js-formatter.js"]:::logic
                JSONFormatter["src/services/formatters/json-formatter.js"]:::logic
                PythonFormatter["src/services/formatters/python-formatter.js"]:::logic
            end
        end

        subgraph "Utils & Config"
            direction TB
            FormatUtils["src/utils/formatUtils.js"]:::api
            Logger["src/utils/logger.js"]:::api
            GeneralConfig["config/config.js"]:::api
            AIConfig["config/ai-config.js"]:::api
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI API"]:::external
        Vercel["Vercel Hosting"]:::external
        DataStore["In-Memory Store\nor File System"]:::external
    end

    %% Connections
    UI -->|"POST /format"| ServerEntry
    ServerEntry --> App
    App --> RoutesIndex
    RoutesIndex --> FormatRoutes
    RoutesIndex --> FileUploadRoutes
    RoutesIndex --> ShareRoutes
    RoutesIndex --> HealthRoutes

    FormatRoutes -->|middleware| RateLimiter
    FormatRoutes -->|middleware| Validation
    FormatRoutes -->|"handle /format"| FormatController

    FileUploadRoutes -->|"handle /upload"| FileUploadController
    ShareRoutes -->|"handle /share"| ShareController
    HealthRoutes -->|"handle /health"| ServerEntry

    FormatController -->|calls| AIFormatterService
    FormatController -->|calls| FormatterService
    FormatController -->|logs| AnalyticsService
    ShareController -->|calls| ShareService
    ShareController -->|logs| AnalyticsService

    FormatterService -->|delegates| CSSFormatter
    FormatterService -->|delegates| CStyleFormatter
    FormatterService -->|delegates| GenericFormatter
    FormatterService -->|delegates| HTMLFormatter
    FormatterService -->|delegates| JSFormatter
    FormatterService -->|delegates| JSONFormatter
    FormatterService -->|delegates| PythonFormatter

    AIFormatterService -->|uses config| AIConfig
    AIFormatterService -->|API call| OpenAI
    ShareService -->|persist| DataStore
    AnalyticsService -->|persist| DataStore

    FormatController -->|utilizes| FormatUtils
    FileUploadController -->|utilizes| Logger
    AIFormatterService -->|utilizes| Logger

    %% Click Events
    click UI "https://github.com/ritik-gusain/indentron/blob/master/public/index.html"
    click ServerEntry "https://github.com/ritik-gusain/indentron/blob/master/server.js"
    click App "https://github.com/ritik-gusain/indentron/blob/master/src/app.js"
    click RoutesIndex "https://github.com/ritik-gusain/indentron/blob/master/src/routes/index.js"
    click FormatRoutes "https://github.com/ritik-gusain/indentron/blob/master/src/routes/formatRoutes.js"
    click FileUploadRoutes "https://github.com/ritik-gusain/indentron/blob/master/src/routes/fileUploadRoutes.js"
    click ShareRoutes "https://github.com/ritik-gusain/indentron/blob/master/src/routes/shareRoutes.js"
    click HealthRoutes "https://github.com/ritik-gusain/indentron/blob/master/src/routes/healthRoutes.js"
    click RateLimiter "https://github.com/ritik-gusain/indentron/blob/master/src/middleware/rateLimiter.js"
    click Validation "https://github.com/ritik-gusain/indentron/blob/master/src/middleware/validation.js"
    click FormatController "https://github.com/ritik-gusain/indentron/blob/master/src/controllers/FormatController.js"
    click FileUploadController "https://github.com/ritik-gusain/indentron/blob/master/src/controllers/FileUploadController.js"
    click ShareController "https://github.com/ritik-gusain/indentron/blob/master/src/controllers/ShareController.js"
    click AIFormatterService "https://github.com/ritik-gusain/indentron/blob/master/src/services/AIFormatterService.js"
    click FormatterService "https://github.com/ritik-gusain/indentron/blob/master/src/services/FormatterService.js"
    click ShareService "https://github.com/ritik-gusain/indentron/blob/master/src/services/ShareService.js"
    click AnalyticsService "https://github.com/ritik-gusain/indentron/blob/master/src/services/AnalyticsService.js"
    click CSSFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/css-formatter.js"
    click CStyleFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/cstyle-formatter.js"
    click GenericFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/generic-formatter.js"
    click HTMLFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/html-formatter.js"
    click JSFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/js-formatter.js"
    click JSONFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/json-formatter.js"
    click PythonFormatter "https://github.com/ritik-gusain/indentron/blob/master/src/services/formatters/python-formatter.js"
    click FormatUtils "https://github.com/ritik-gusain/indentron/blob/master/src/utils/formatUtils.js"
    click Logger "https://github.com/ritik-gusain/indentron/blob/master/src/utils/logger.js"
    click GeneralConfig "https://github.com/ritik-gusain/indentron/blob/master/config/config.js"
    click AIConfig "https://github.com/ritik-gusain/indentron/blob/master/config/ai-config.js"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,color:#004085;
    classDef api fill:#d4edda,stroke:#155724,color:#155724;
    classDef logic fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#d6d8db,stroke:#1b1e21,color:#1b1e21;
```
