Architecture
Guides, route-group overviews, and live schema entry points for the Plexichat backend.
Docker architecture
System design, networks, and data flows for the Plexichat Docker deployment.
System overview
EXTERNAL
|
| HTTPS (443, 80 redirects to 443)
v
+-------------------+
| Client (Nginx) |
| Reverse proxy |
+-------------------+
|
| Docker default bridge network (plexichat_default)
v
+-------------------+
| Backend (FastAPI) | <--+
| REST + WebSocket | |
+-------------------+ |
| |
+------> +-----------+ <-- PostgreSQL database
| | PostgreSQL|
| | 18-alpine |
+------> +-----------+
|
+------> +--------+
| Valkey |
|9.1.1 |
|alpine |
+--------+
|
+------> +---------+
| RustFS |
| 1.0.0 |
+---------+
docker-compose.yml defines a single default bridge network (plexichat_default).
All services resolve each other by service name. No custom networks are defined.
Containers
1. Database (PostgreSQL)
Stores all application data.
- Image:
postgres:18-alpine - Data: User accounts, messages, servers, and media metadata.
- Volume:
postgres_data(persistent) mounted at/var/lib/postgresql. PostgreSQL 18 keeps the cluster in/var/lib/postgresql/<major>/dockerand refuses to start when/var/lib/postgresql/datais itself a mount (docker-library/postgres#1259), so the parent directory is the mount point. - Environment:
POSTGRES_DB,POSTGRES_USER,POSTGRES_PASSWORD(required). Compose fails fast ifPOSTGRES_PASSWORDis unset. - Network: Default bridge network. Backend connects at
db:5432. - Connection pooling: 5 to 20 connections for development (the
.env.exampledefaults), 20 to 100+ for production. See Connection pooling. - Health check:
pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}every 10 seconds, timeout 5 seconds, 10 retries.
2. Valkey (cache and session store)
High-speed caching, session storage, and cross-worker event dispatch.
- Image:
valkey/valkey:9.1.1-alpine - Data: Sessions, presence status, pending events, and rate-limit counters. Volume
valkey_dataat/datawith--appendonly yes. Keys expire by TTL. - Authentication: Started with
--requirepass ${VALKEY_PASSWORD}. Compose fails fast ifVALKEY_PASSWORDis unset. Health check authenticates withREDISCLI_AUTH. - Network: Default bridge network. Backend connects at
valkey:6379with a 50-connection pool by default (VALKEY_CONNECTION_POOL). - Pub/Sub: Channel
plexichat:events:cross_workerforwards WebSocket events between backend replicas. - Health check:
REDISCLI_AUTH="..." redis-cli ping | grep PONGevery 10 seconds, timeout 5 seconds, 10 retries.
3. RustFS (S3-compatible object storage)
Stores media files.
- Image:
rustfs/rustfs:1.0.0 - Services: S3 API on port 9000 and web console on port 9001.
- Data: Uploaded files and thumbnails. Volume
rustfs_dataat/data. - Configuration:
RUSTFS_ADDRESS(default0.0.0.0:9000),RUSTFS_CONSOLE_ADDRESS(0.0.0.0:9001),RUSTFS_ACCESS_KEY/RUSTFS_SECRET_KEY(mapped fromS3_ACCESS_KEY/S3_SECRET_KEY, both required),RUSTFS_VOLUMES(/data/rustfs), andRUSTFS_CORS_ALLOWED_ORIGINS(empty by default, keep private). - Network: Default bridge network. Backend connects at
rustfs:9000. Ports 9000 and 9001 are exposed internally, not published to the host. - File ownership: RustFS runs as UID/GID
10001:10001. Therustfs-permsinit container (alpine:3.24) runschown -R 10001:10001 /databefore RustFS starts. - Health check:
curl -f http://127.0.0.1:9000/health && curl -f http://127.0.0.1:9001/rustfs/console/healthevery 15 seconds, timeout 10 seconds, 10 retries, start period 40 seconds.
4. RustFS-Init (one-time setup)
Creates the S3 bucket.
- Image:
rustfs/rc:v0.1.30 - Behavior: Waits for RustFS to be healthy, runs
rc alias setandrc mb local/${S3_BUCKET}, then exits. Usesrestart: "no". - Dependency:
rustfswithcondition: service_healthy. - Bucket:
${S3_BUCKET}(defaultplexichat-media).
5. Cert-Init (one-time setup)
Generates TLS certificates for development.
- Image:
alpine:3.24 - Behavior: Installs
openssland creates self-signed/certs/fullchain.pemand/certs/privkey.pemif they do not exist. Exits after completion. Usesrestart: "no". - Volume:
certsmounted at/certsinside this container and at/etc/nginx/certsinside the client container. - Dependency: None. The client waits for this container with
condition: service_completed_successfullyto avoid a race on first boot.
6. ClamAV (malware scanner)
Scans uploaded files for malware.
- Image:
clamav/clamav:1.5.4 - Services:
clamdon TCP 3310 andfreshclamfor signature updates. Limits:StreamMaxLength,MaxScanSize, andMaxFileSizeare 600 MB,MaxScanTimeis 300,000 ms. - Volume:
clamav_dbat/var/lib/clamav(persists signatures). - Sidecar:
clamav-unofficial-sigs(ghcr.io/extremeshok/clamav-unofficial-sigs:8.0.0, modeupdater, every 2 hours) sharesclamav_db. - Network: Default bridge network. Backend connects at
clamav:3310(SCANNER_HOST/SCANNER_PORT). - Health check:
echo PING | nc -w 2 localhost 3310 | grep PONGevery 30 seconds, timeout 10 seconds, 5 retries, start period 120 seconds. - Dependencies: None.
7. Backend (FastAPI server)
Core application logic.
- Image:
${CI_REGISTRY_IMAGE:-gitlab.plexichat.com/plexichat/plexichat}/backend:${BACKEND_VERSION:?BACKEND_VERSION must be set to a pinned release tag/digest}built fromplexichat/Dockerfile(python:3.14.8-slim-trixie, non-root userplexichatUID 10001). - Services: REST API at
/api/v1/*, WebSocket gateway at/gateway, liveness probe atGET /api/v1/ready, deep health atGET /api/v1/healthandGET /health, documentation at/docsand/redoc, admin UI at/admin. - Environment:
PLEXICHAT_CONFIG=/app/config/docker-config.yaml,PLEXICHAT_PUBLIC_SERVER_URL,NO_STRICT_CONFIG=false,SCANNER_ENABLED=true,SCANNER_HOST=clamav,SCANNER_PORT=3310,SEARCH_BACKEND=sqlite_fts5(default). - Volumes:
./config:/app/config(writable: the server persists env overrides and the generatedmedia.signing_keythere on every start) andplexichat_home:/home/plexichat/.plexichat. - Network: Default bridge network.
- Database at
db:5432 - Valkey at
valkey:6379 - RustFS at
rustfs:9000 - ClamAV at
clamav:3310
- Database at
- Dependencies:
db(service_healthy),valkey(service_healthy),rustfs-init(service_completed_successfully),clamav(service_healthy). - Ports (single-replica mode):
8000:8000(TCP) and30000-30100:30000-30100/udpfor WebRTC. When you scale withdocker compose up --scale backend=N, remove bothportsmappings and rely on the client Nginx proxy, which load-balances tobackend:8000withip_hashsticky sessions. - Health check:
curl -sf http://localhost:8000/api/v1/readyevery 15 seconds, timeout 5 seconds, 3 retries, start period 10 seconds. This is a pure liveness probe that returns{"status": "ready"}as soon as the HTTP server is bound. The same probe is defined in the DockerfileHEALTHCHECK. UseGET /healthorGET /api/v1/healthfor the deeper check that includes EventManager metrics and cross-worker listener status.
8. Client (Nginx)
Frontend and reverse proxy.
- Image:
${CI_REGISTRY_IMAGE:-gitlab.plexichat.com/plexichat/plexichat-client}/nginx:${CLIENT_VERSION:?CLIENT_VERSION must be set to a pinned release tag/digest}built fromplexichat-client/Dockerfile(nginx:stable-alpinewithcurl, Vite build staged fromnode:20-alpine). - Services: Serves the Vite-built static app, reverse-proxies
/api/,/docs,/openapi.json,/redoc,/admin, and/gatewayto the backend upstream (backend:8000withip_hash), terminates TLS, and redirects HTTP to HTTPS. - Upstream behavior:
client_max_body_size 10mmatches the backend body limit so uploads are not rejected at the proxy. - Dependencies:
backend(service_started) andcert-init(service_completed_successfully). - Volumes:
certs:/etc/nginx/certsand./docker/runtime/client-config.js:/usr/share/nginx/html/config.js:ro. - Ports:
80:80and443:443. - Health check: No Docker health check is defined for this service. Verify it with
curl http://localhost/orcurl -k https://localhost/. - Network: Default bridge network. Reaches the backend as
http://backend:8000.
9. Backup (Restic)
Automated encrypted and deduplicated backups.
- Image:
${CI_REGISTRY_IMAGE:-gitlab.plexichat.com/plexichat/plexichat}/backup:${BACKEND_VERSION:?BACKEND_VERSION must be set to a pinned release tag/digest}built fromplexichat/docker/backup/Dockerfile(alpine:3.24withpostgresql-client,restic,supercronic 0.2.33,bash,tzdata,curl,gzip). - Schedule: Supercronic runs
BACKUP_SCHEDULE(default0 2 * * *, 2 AM) and applies retention (BACKUP_KEEP_DAILY=7,BACKUP_KEEP_WEEKLY=4,BACKUP_KEEP_MONTHLY=6,BACKUP_KEEP_YEARLY=0). - Repository:
backup_repoat/repoplus optionalBACKUP_SECONDARY_REPOfor off-site replication. RequiresBACKUP_RESTIC_PASSWORD(compose fails fast if unset). - Source volumes (read-only):
postgres_data:/var/lib/postgresql/data,plexichat_home:/plexichat-home,rustfs_data:/rustfs-data. - Dependencies:
db(service_healthy). - Health check:
/scripts/healthcheck.shevery 5 minutes, timeout 10 seconds, 3 retries, start period 2 minutes. The script verifies supercronic is running and a recent successful backup exists. - CLI:
docker exec backup /scripts/backup.sh list docker exec backup /scripts/backup.sh restore-db docker exec backup /scripts/backup.sh restore <snapshot>
10. Optional profile-gated services
These services start only with --profile.
- Shieldstral (AI moderation): Profile
ai. Imageghcr.io/ggml-org/llama.cpp:server-b10614, model at/models/shieldstral/Shieldstral-1.0-3B-Q4_K_M.gguf(configurable viaSHIELDSTRAL_MODEL,SHIELDSTRAL_MMPROJ,SHIELDSTRAL_CONTEXT,SHIELDSTRAL_GPU_LAYERS). Health checkcurl -sf http://localhost:8080/health. - Meilisearch: Profiles
searchandsearch-meilisearch. Imagegetmeili/meilisearch:v1.12atmeilisearch:7700(MEILI_MASTER_KEYfromMEILISEARCH_API_KEY). Health checkwget/curlon/health. - Elasticsearch: Profile
search-elastic. Imagedocker.elastic.co/elasticsearch/elasticsearch:8.15.0atelasticsearch:9200(ES_JAVA_OPTS, single-node, security disabled). Health checkcurl -sf http://localhost:9200/_cluster/health.
Networks
docker-compose.yml defines a single default bridge network. All services communicate by service name:
- Backend reaches the database at
db:5432 - Backend reaches Valkey at
valkey:6379 - Backend reaches RustFS at
rustfs:9000 - Backend reaches ClamAV at
clamav:3310 - Client reaches the backend at
backend:8000
Only client (80, 443) and, in single-replica mode, backend (8000/TCP and 30000-30100/UDP) publish host ports. rustfs ports 9000 and 9001 are exposed internally, not published. When you scale the backend, remove the backend ports section and rely on the client proxy.
Volumes
| Volume | Used by | Purpose | Persistent |
|---|---|---|---|
postgres_data |
PostgreSQL, Backup (ro) | Database files | Yes |
valkey_data |
Valkey | Cache dump and AOF | Yes |
rustfs_data |
RustFS, Backup (ro), rustfs-perms | Media objects | Yes |
plexichat_home |
Backend, Backup (ro) | Application state at /home/plexichat/.plexichat |
Yes |
certs |
Cert-Init, Client | TLS certificates | Yes |
backup_repo |
Backup | Restic repository at /repo |
Yes |
clamav_db |
ClamAV, clamav-unofficial-sigs | ClamAV signatures | Yes |
meilisearch_data |
Meilisearch (profile) | Search index | Yes |
elasticsearch_data |
Elasticsearch (profile) | Search index | Yes |
Data loss risk: docker compose down -v deletes all volumes, including the Restic repository. The repository is for fast local recovery. Configure BACKUP_SECONDARY_REPO for off-site protection.
Data flows
1. REST API request
Browser --HTTPS (443)--> Nginx --HTTP (backend:8000)--> Backend --SQL--> PostgreSQL
|
v
Backend (JSON) --> Nginx --> Browser
2. WebSocket connection
Browser --wss (443)--> Nginx --ws (backend:8000)--> Backend --store--> Valkey (session)
--pub/sub--> Valkey --> Other backends --> Clients
When the backend is scaled, Valkey pub/sub on plexichat:events:cross_worker ensures every replica receives each event.
3. Media upload
Browser --POST /api/v1/media/upload--> Nginx --> Backend
|
+--> ClamAV (scan at clamav:3310)
+--> Validate, encrypt, store in RustFS (rustfs:9000)
+--> Save metadata in PostgreSQL
v
Backend returns /api/v1/media/attachments/... URL
4. Message flow
User A --WebSocket--> Backend --validate--> encrypt (AES-GCM) --> store in PostgreSQL
|
+--> publish to Valkey pub/sub --> User B, User C via WebSocket
Startup sequence
- The deploy script generates
.env,config/docker-config.yaml, anddocker/runtime/client-config.js. - Docker Compose parses the configuration.
db,valkey,rustfs,clamav, andrustfs-permsstart in parallel.rustfs-permsfixes volume ownership and exits.rustfs-initwaits forrustfsto be healthy, creates the bucket, and exits.cert-initgenerates certificates if missing and exits.- The backend waits for
dbandvalkeyto be healthy,rustfs-initto complete, andclamavto be healthy, then starts. - The client waits for
cert-initto complete and the backend to start, then starts. backupwaits fordbto be healthy, then starts supercronic.
Typical startup time is 20 to 40 seconds from docker compose up.
Resource usage
Memory
- Backend: 500 MB to 2 GB depending on users and
BACKEND_REPLICAS - Database: 200 MB to 1 GB
- Valkey: 100 MB to 500 MB
- RustFS: ~100 MB
- ClamAV: ~1 to 2 GB after signatures load
- Client (Nginx): ~20 MB
- Meilisearch (if enabled): ~150 to 512 MB
- Elasticsearch (if enabled): ~1 to 2 GB
Typical total without search is 1 to 4 GB.
CPU
- Idle: Less than 5% per core
- Active: 10% to 50% per core depending on load
Disk
- Database grows with messages and activity
- RustFS grows with uploaded files
- Typical total: 10 GB to 100 GB or more
Security model
Network isolation
External clients reach only published ports (80, 443, and optionally 8000 and 30000-30100/UDP in single-replica mode). Database, Valkey, RustFS, ClamAV, backup, and search services are reachable only inside the Docker network.
Authentication
- Frontend to backend: JWT in header or cookie
- Backend to PostgreSQL:
POSTGRES_USERandPOSTGRES_PASSWORDfrom.env - Backend to Valkey:
VALKEY_PASSWORDfrom.env - Backend to RustFS:
S3_ACCESS_KEYandS3_SECRET_KEYfrom.env - Backend to Meilisearch:
MEILISEARCH_API_KEYif configured
Encryption
- External traffic uses TLS/HTTPS (certificates in the
certsvolume) - Messages are encrypted at rest in the database (AES-GCM)
- Passwords are hashed with Argon2
Monitoring points
- Liveness:
GET /api/v1/readyreturns{"status": "ready"}. Used by the Docker health check for both the Dockerfile anddocker-compose.yml. - Deep health:
GET /api/v1/healthandGET /healthreturnstatus,version,events_metrics,is_queue_recreate_pending, andcross_worker_listener. - Database:
pg_isready - Valkey:
redis-cli pingwithREDISCLI_AUTH - RustFS:
GET /healthandGET /rustfs/console/health - ClamAV:
PINGover TCP 3310 - Backup:
/scripts/healthcheck.sh
Next steps
- Production setup for hardening
- Development workflow for local iteration
- Troubleshooting for common issues