Initialization and Boot Process
Source of truth:
d3chat/backend/app/main.pyd3chat/backend/app/federation/identity.pyd3chat/backend/alembic/versions/004_seed_settings.py
Startup Sequence
When backend starts, lifespan() runs this sequence:
- Runs Alembic migrations (
alembic upgrade head) in a subprocess. - Initializes federation server identity (
init_server_identity). - Ensures at least one local superadmin exists (
ensure_default_admin). - Ensures uploads directories exist (
<upload_dir>/avatarsand<upload_dir>/attachments).
Database Initialization
Migrations create and update schema, then seed runtime settings.
Seeded server_settings keys include:
app_nameapp_descriptionsession_timeout_daysmax_devices_per_userregistration_moderegistration_domain_allowlistbrand_primary_colorbrand_accent_colormessage_retention_days
All values are JSON objects using shape:
{ "value": "..." }or
{ "value": 7 }Default Superadmin Bootstrap
If no local user with role superadmin exists:
- Backend creates
adminwith passwordChange_Me_123. - This happens once per empty state.
Operational requirement: rotate this credential immediately.
Public Config Cache
GET /api/v1/config reads selected settings and caches them in Redis key public_config for 60 seconds.
When settings are updated via admin API (PUT /api/v1/admin/settings/{key}), backend invalidates this cache.
Federation Identity Bootstrap
The server publishes:
GET /.well-known/d3chat-server
Response includes:
domainsigning_key_publicapi_base_urlprotocol_version
If SIGNING_KEY_SEED is configured, signing identity is deterministic from that seed.
Runtime Middleware Initialized
- CORS from
CORS_ORIGINS - Global rate limit middleware (IP-based, per minute)
- API routers for auth/users/devices/channels/messages/keys/admin/avatars/attachments
- WebSocket router (
/ws) - Federation inbox routes (
/federation/*)