How hhftechnology/middleware-manager works
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