Architecture technique
Schema detaille
Navigateur
|
| HTTPS
v
+-----+------+ +------------------+
| Frontend | | Backend |
| React +------>| Hono API |
| (Nginx) | /api | SQLite (WAL) |
+------------+ +--------+---------+
|
HTTP POST | /caddy/reload
HTTP GET | /logs
(Bearer) |
v
+-----------+---------+
| Agent |
| Hono API |
+----+----------+-----+
| |
POST /load | | read file
v v
+----+----+ +---+--------+
| Caddy | | access.log |
| Admin | | (JSON) |
| API | +------------+
+---------+Stack technique
| Couche | Technologie |
|---|---|
| Frontend | React 19, TanStack Router, TanStack Query, Tailwind CSS |
| Backend | Hono.js, Better Auth, Drizzle ORM |
| Base de donnees | SQLite (better-sqlite3, mode WAL) |
| Agent | Hono.js (service leger sans BDD) |
| Runtime | Node.js 22+ |
| Package manager | pnpm 9.15 (monorepo workspaces) |
| Conteneurisation | Docker multi-stage, Nginx (frontend) |
Modele de donnees
users
| Colonne | Type | Description |
|---|---|---|
id | TEXT PK | Identifiant unique |
name | TEXT | Nom de l'utilisateur |
email | TEXT UNIQUE | Adresse email |
role | TEXT | admin ou user |
banned | BOOLEAN | Compte banni |
createdAt | TIMESTAMP | Date de creation |
vhosts
| Colonne | Type | Description |
|---|---|---|
id | INTEGER PK | Auto-increment |
domain | TEXT UNIQUE | Nom de domaine |
config | TEXT | Configuration Caddyfile |
enabled | BOOLEAN | Vhost actif ou non |
upstream | TEXT | URL upstream (optionnel) |
createdAt | TIMESTAMP | Date de creation |
updatedAt | TIMESTAMP | Derniere modification |
changelog
| Colonne | Type | Description |
|---|---|---|
id | INTEGER PK | Auto-increment |
userId | TEXT FK | Reference vers users.id |
action | TEXT | create, update, delete, toggle |
domain | TEXT | Domaine concerne |
diff | TEXT | JSON ancien/nouveau config |
createdAt | TIMESTAMP | Date de la modification |
Communication hub / agent
La communication se fait en HTTP avec header Authorization: Bearer <AGENT_TOKEN> :
| Operation | Methode | Endpoint | Description |
|---|---|---|---|
| Rechargement | POST | /caddy/reload | Envoie le Caddyfile complet |
| Logs | GET | /logs | Lit les logs d'acces |
| Health check | GET | /health | Sans authentification |
Generation du Caddyfile
- Recuperation des vhosts actifs (
enabled = true) - Construction du bloc global (email ACME, logs Caddy)
- Concatenation des blocs :
domaine { config } - Envoi a l'API admin Caddy (
POST /load) - En cas d'echec : rollback de la modification en base
Exemple de Caddyfile genere :
nginx
{
email admin@exemple.com
log {
output file /var/log/caddy/caddy.log
format json
}
}
app.exemple.com {
reverse_proxy http://backend:8080
log {
output file /var/log/caddy/access.log {
roll_size 100mb
roll_keep 5
}
format json
}
}