Architecture
High-level flow
flowchart LR
subgraph vercel [Vercel]
UI[Next_js_dashboard]
BFF["discord_api_route"]
end
subgraph hetzner [Hetzner]
API[Express_API]
Bot[discord_js]
Mongo[(MongoDB)]
end
subgraph appwrite [Appwrite]
Auth[Auth_and_teams]
end
User --> UI
UI --> BFF
BFF -->|Bearer_JWT| API
API --> Mongo
Bot --> Mongo
UI --> Auth
API --> AuthBackend (Discord-MultiBot)
The Node process runs the Discord client and an Express server on the same host (Docker Compose).
API routes
| Method | Path | Purpose |
|---|---|---|
| GET | /api/metrics | Command counts, avg response time, errors (7 days) |
| GET | /api/logs | Latest log rows; optional command query |
| GET | /health | Liveness / ops checks |
Authentication (verifyAuth middleware):
Authorization: Bearerplus an Appwrite user JWT — The API validates the session, loads the user, and attaches roles for optionalrequireRolechecks.x-api-key— Legacy shared key for scripts and automation (not used by the browser dashboard).
CORS allows configured origins (e.g. https://analytics.mohamedlakssirt.tech, https://mohamedlakssirt.tech).
Data
- MongoDB database
discordbotfor metrics and log documents written by bot services (LogService,MetricsService). - Appwrite All-Backend project for user profiles, organizations, and events (dashboard-side).
Frontend (discord-multibot-analytics)
Appwrite Auth handles sign-up, email verification, password recovery, and sessions.
BFF proxy — app/discord-api/[...path]/route.ts:
- Read
appwrite-sessionfrom the request. - Exchange session for a short-lived JWT on the server.
- Forward the request to
API_PROXY_TARGET(production:https://multibot-api.mohamedlakssirt.tech) withAuthorization: Bearer. - Return the upstream response to the client.
The browser never receives the Hetzner API_KEY or Appwrite server API key.
Team RBAC
Organizations map to Appwrite Teams. Custom roles include admin, analyst, and viewer (Appwrite supplies owner).
| Role | Typical access |
|---|---|
| owner | Full access; member management |
| admin | Org branding + member management |
| analyst | Analytics read; profile edit |
| viewer | Read-only analytics; profile edit |
Bootstrap scripts live in the analytics repo (scripts/bootstrap-appwrite-rbac.mjs, scripts/verify-appwrite-rbac.mjs). A user-provision Appwrite function can run on user creation.
Security principles
- HTTPS only on production hostnames
- Server-side API keys on Vercel and Hetzner env — see each repo’s
.env.exampleon GitHub - Dashboard demo at analytics.mohamedlakssirt.tech requires login