# hhftechnology/middleware-manager architecture

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

- Interactive diagram: https://gitdiagram.com/hhftechnology/middleware-manager
- Repository: https://github.com/hhftechnology/middleware-manager

## Overview

##### Project Type and Purpose
- This is a full-stack microservice called “Middleware Manager” that provides a web UI and HTTP API for defining, assigning, and managing Traefik middlewares, routers, services, and plugins.
- It continuously syncs resources via a chosen data source (Pangolin API or Traefik API), persists configuration in an SQLite database, and writes out dynamic Traefik configuration files.

##### File Structure Analysis
- Top-level directories:
- api/handlers, api/server.go, main.go – Go HTTP API and request handlers
- services/…fetcher.go, …watcher.go, config_manager.go, config_generator.go – core business logic and background sync loops
- database/… – SQLite connection, transaction management, cleanup, migrations
- models/… – Data structures for resources, services, middlewares
- config/… – Default settings and template YAML for middleware/service definitions
- plugin/ – Static plugin list JSON
- ui/src/… – React application (components, contexts, API client)
- ui/public/index.html – Single-page app entry
- util/ – Utility functions
- Configuration & deployment:
- Dockerfile, docker-compose.yml, Makefile – container builds & orchestration
- .env.example, config/*.yaml, templates files, migrations.sql

##### README Insights
- Describes dual data source support (Pangolin vs. Traefik), dynamic config generation, template libraries, plugin hub with static config edits, SQLite persistence, and real-time synchronization loops.
- Provides Docker-Compose examples illustrating network connections among pangolin, traefik, middleware-manager, and volume mounts for /conf and /data.

a. Main Components
- Frontend UI (React SPA)
- Backend API/Microservice (Go) – composed of Handler Layer, Service Layer, Database Layer, Config Generator
- SQLite Database
- Dynamic Config Directory (mounted to Traefik file provider)
- Static Config Directory (for plugin definitions)
- External Data Source(s): Pangolin API or Traefik API
- Traefik Proxy (consumes dynamic configs)
b. Relationships and Data Flows
1. User → React UI
2. UI ↔ HTTP API (Go handlers)
3. API calls Service Layer (“fetchers” to pull resources, “watchers” to poll, config_manager to CRUD, config_generator to write YAML)
4. Service Layer ↔ SQLite (read/write resource, middleware, service records)
5. Config Generator → writes resource-overrides.yml and service templates → Dynamic Config Directory
6. Dynamic Config Directory → Traefik file provider reloads routing rules
7. Plugin Hub actions → update static config (traefik.yml) → Traefik must restart
8. Service Layer ↔ External Data Source(s) over HTTP
c. Architectural Patterns & Principles
- Layered: API Handler → Services → Persistence → External providers
- Hexagonal/Ports & Adapters: swap Pangolin vs. Traefik adapters easily
- Observer/Polling: background watcher loops detect new resources/services
- Configuration-as-code: dynamic generation of YAML for Traefik
d. Key Technologies & Frameworks
- Go (net/http, handlers, SQLite via database/sql)
- React + Context API + axios for UI
- Docker & Docker Compose for containerization
- YAML for templates and dynamic configs
- Traefik file provider & HTTP API

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend
    subgraph "Frontend"
        ReactUI["React UI"]:::frontend
    end

    %% Backend Microservice
    subgraph "Middleware Manager Service"
        direction TB
        Handlers["API Handlers"]:::backend
        Services["Service Layer\n(fetchers & watchers)"]:::service
        ConfigGen["Config Generator"]:::service
        DBLayer["Database Layer\n(SQLite)"]:::database
    end

    %% Config & Plugins
    subgraph "Configuration & Plugins"
        direction TB
        ConfigTemplates["Templates & Defaults"]:::folder
        PluginHub["Plugin Hub"]:::folder
        StaticDir["Static Config Directory\n(/conf)"]:::folder
        DynamicDir["Dynamic Config Directory\n(/data)"]:::folder
    end

    %% External
    Pangolin["Pangolin API"]:::cloud
    TraefikAPI["Traefik API"]:::cloud
    TraefikProxy["Traefik Proxy\n(File Provider)"]:::traefik

    %% Flows
    ReactUI -->|"HTTP requests"| Handlers
    Handlers -->|"invoke business logic"| Services
    Services -->|"CRUD & sync"| DBLayer
    Services -->|"poll/adapt"| Pangolin
    Services -->|"poll/adapt"| TraefikAPI
    Services -->|"generate YAML"| ConfigGen
    ConfigGen -->|"write files"| DynamicDir
    PluginHub -->|"edit static configs"| StaticDir
    DynamicDir -->|"mounted volume"| TraefikProxy
    StaticDir -->|"mounted volume"| TraefikProxy

    %% Click Events
    click ReactUI "https://github.com/hhftechnology/middleware-manager/tree/main/ui/"
    click Handlers "https://github.com/hhftechnology/middleware-manager/tree/main/api/handlers/"
    click Services "https://github.com/hhftechnology/middleware-manager/blob/main/services/config_manager.go"
    click ConfigGen "https://github.com/hhftechnology/middleware-manager/blob/main/services/config_generator.go"
    click DBLayer "https://github.com/hhftechnology/middleware-manager/blob/main/database/db.go"
    click ConfigTemplates "https://github.com/hhftechnology/middleware-manager/blob/main/config/templates.yaml"
    click PluginHub "https://github.com/hhftechnology/middleware-manager/blob/main/plugin/plugins.json"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#E8F0FE,stroke:#1F618D,color:#1F618D;
    classDef service fill:#E6F4EA,stroke:#239B56,color:#239B56;
    classDef database fill:#FEF5E7,stroke:#D35400,color:#D35400;
    classDef folder fill:#F3E5F5,stroke:#6C3483,color:#6C3483;
    classDef cloud fill:#EAFAF1,stroke:#27AE60,color:#27AE60;
    classDef traefik fill:#FEF9E7,stroke:#F1C40F,color:#B9770E;
```
