Skip to Content

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 --> Auth

Backend (Discord-MultiBot)

The Node process runs the Discord client and an Express server on the same host (Docker Compose).

API routes

MethodPathPurpose
GET/api/metricsCommand counts, avg response time, errors (7 days)
GET/api/logsLatest log rows; optional command query
GET/healthLiveness / ops checks

Authentication (verifyAuth middleware):

  1. Authorization: Bearer plus an Appwrite user JWT — The API validates the session, loads the user, and attaches roles for optional requireRole checks.
  2. 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 discordbot for 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:

  1. Read appwrite-session from the request.
  2. Exchange session for a short-lived JWT on the server.
  3. Forward the request to API_PROXY_TARGET (production: https://multibot-api.mohamedlakssirt.tech) with Authorization: Bearer.
  4. 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).

RoleTypical access
ownerFull access; member management
adminOrg branding + member management
analystAnalytics read; profile edit
viewerRead-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.example on GitHub
  • Dashboard demo at analytics.mohamedlakssirt.tech requires login

Back to overview

On this page