# mightywomble/haproxywebui architecture

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

- Interactive diagram: https://gitdiagram.com/mightywomble/haproxywebui
- Repository: https://github.com/mightywomble/haproxywebui

## Overview

##### Project type and purpose
- This is a lightweight full-stack Node.js web application (“proof of concept”) for editing and managing HAProxy configuration files via a browser GUI.
- It serves static HTML/JS in /public, exposes REST-style endpoints in server.js, manipulates haproxy configs on disk, queries HAProxy status, and optionally calls the OpenAI API to perform an “AI check” on a selected config file.

##### File structure
- Top level
- config.js — holds application configuration (port, file paths, etc.)
- server.js — main Express application entrypoint, defines HTTP routes for file listing, editing, AI checks, status, etc.
- openai.js — wrapper module that calls OpenAI’s API for syntax/semantic checks.
- haproxyStatus.js — module that queries HAProxy’s runtime status (e.g., via CLI or socket).
- public/ — frontend assets: index.html and aiCheck.js implement the UI and AJAX calls.
- setup.sh — optional bootstrap script.
- Dependencies (package.json): dotenv, express, cors, openai, util.
- Running on a single port (default 3300) with no external database—uses the server’s file system and external services (OpenAI, HAProxy).

##### Key insights from README
- Self-contained: no traditional webserver like Apache needed—Express serves everything.
- Port configurable in config.js.
- “AI Check” invokes the OpenAI API—response can take ~10 s.
- Goal: minimal fuss, proof-of-concept, not production hardened.

##### Main components
a. Client/User Browser
- Renders HTML/JS from public/index.html
- Initiates REST calls (list files, read/edit file, submit AI check, poll HAProxy status)
b. Frontend Static Layer
- public/index.html
- public/aiCheck.js — UI logic, invokes HTTP endpoints
c. Backend/API Server (Node.js/Express)
- server.js
- config.js (configuration)
- openai.js — communicates with OpenAI cloud API
- haproxyStatus.js — interacts with local HAProxy service
d. File System
- Directory containing HAProxy .cfg files (read/write)
e. External Services
- OpenAI API (cloud)
- HAProxy process or socket (for status queries)

##### Relationships and interactions
- Browser → HTTP GET/POST → Express server (server.js)
- Express → filesystem → read/write .cfg files
- Express → haproxyStatus.js → HAProxy’s stats socket or CLI → status response
- Express → openai.js → OpenAI API → analysis of config → server → browser
- Config.js injects port and file-path settings into server.js

##### Architectural patterns and design principles
- Layered separation:
- Presentation (static files)
- Application/API (Express routes, business logic)
- Infrastructure (file system access, external service calls)
- Single‐process monolith—no microservices.
- Pluggable modules for external integrations (openai.js, haproxyStatus.js).
- Minimal dependency footprint, environment-driven config (dotenv).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Client/User Browser"]:::external

    %% Frontend Static Layer
    subgraph "Frontend (Static Layer)"
        direction TB
        Index["index.html"]:::frontend
        AI["aiCheck.js"]:::frontend
    end

    %% Backend/API Server
    subgraph "Backend (Node.js/Express)"
        direction TB
        Server["server.js"]:::backend
        Config["config.js"]:::backend
        OpenaiMod["openai.js"]:::backend
        HapStatus["haproxyStatus.js"]:::backend
    end

    %% Repository Assets
    subgraph "Repository Assets"
        direction TB
        Env[".env_sample"]:::repo
        Setup["setup.sh"]:::repo
        PKG["package.json"]:::repo
        PKGLock["package-lock.json"]:::repo
    end

    %% Infrastructure / External
    FS["HAProxy Config Dir"]:::storage
    HAProxy["HAProxy Process/Socket"]:::external
    OpenAIAPI["OpenAI API"]:::external

    %% Data Flows
    Browser -->|loads static files| Index
    Browser -->|loads static files| AI
    AI -->|AJAX calls| Server
    Server -->|uses settings| Config
    Server -->|read/write| FS
    Server -->|query status| HapStatus
    HapStatus -->|fetch status| HAProxy
    Server -->|invoke| OpenaiMod
    OpenaiMod -->|HTTP request| OpenAIAPI
    Server -->|sends response| AI
    AI -->|renders result| Browser

    %% Click Events
    click Index "https://github.com/mightywomble/haproxywebui/blob/main/public/index.html"
    click AI "https://github.com/mightywomble/haproxywebui/blob/main/public/aiCheck.js"
    click Server "https://github.com/mightywomble/haproxywebui/blob/main/server.js"
    click Config "https://github.com/mightywomble/haproxywebui/blob/main/config.js"
    click OpenaiMod "https://github.com/mightywomble/haproxywebui/blob/main/openai.js"
    click HapStatus "https://github.com/mightywomble/haproxywebui/blob/main/haproxyStatus.js"
    click Env "https://github.com/mightywomble/haproxywebui/blob/main/.env_sample"
    click Setup "https://github.com/mightywomble/haproxywebui/blob/main/setup.sh"
    click PKG "https://github.com/mightywomble/haproxywebui/blob/main/package.json"
    click PKGLock "https://github.com/mightywomble/haproxywebui/blob/main/package-lock.json"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#3498DB,stroke-width:1px
    classDef backend fill:#D5F5E3,stroke:#27AE60,stroke-width:1px
    classDef external fill:#FDEDEC,stroke:#E74C3C,stroke-width:1px,stroke-dasharray: 5 5
    classDef storage fill:#F4F6F6,stroke:#7F8C8D,stroke-width:1px
    classDef repo fill:#F9E79F,stroke:#D4AC0D,stroke-width:1px
```
