Infrastructure Overview

Enclavr uses Docker Compose for deployment with 19 services across 3 isolated networks.

Architecture

The stack is organized into three Docker networks:

NetworkPurposeServices
frontendPublic-facing trafficFrontend, Server, Coturn, Caddy
backendInternal service communicationServer, PostgreSQL, Redis, postgres-exporter, redis-exporter, postgres-backup
monitoringMetrics and observabilityPrometheus, Grafana, Node Exporter, PostgreSQL Exporter, Redis Exporter, Loki, Alloy, Docker Socket Proxy, Coturn

Services (19 total)

#ServiceImagePurposeProfile
1FrontendBuilt from DockerfileNext.js web application (served via Nginx)core
2ServerBuilt from DockerfileGo backend APIcore
3PostgreSQLpostgres:18.3-alpinePrimary databasecore
4Redisredis:8-alpinePub/Sub and cachingcore
5Coturncoturn/coturn:4.9.0-alpineTURN server for WebRTC NAT traversalvoice
6Prometheusprom/prometheus:v3.10.0-alpineMetrics collectionmonitoring
7Grafanagrafana/grafana:11.2.0Metrics dashboardsmonitoring
8Node Exporterprom/node-exporter:v1.8.0-alpineSystem metricsmonitoring
9PostgreSQL Exporterprometheuscommunity/postgres-exporter:v0.15.0-alpineDatabase metrics (custom queries)backend, monitoring
10Redis Exporteroliver006/redis_exporter:v1.61.0-alpineCache metricsmonitoring
11Lokigrafana/loki:3.6.8Log aggregationmonitoring
12Alloygrafana/alloy:v1.7.4Log collection agent (replaces Promtail)monitoring
13Alertmanagerprom/alertmanager:v0.28.1Alert routing and notificationmonitoring
14Docker Socket Proxytecnativa/docker-socket-proxy:0.1.2Secure Docker API access for Alloymonitoring
15MinIOminio/minio:RELEASE.2025-03-12T18-04-18ZS3-compatible object storagestorage
16MinIO Clientminio/mc:RELEASE.2025-03-12T17-31-15ZMinIO bucket initializationstorage
17Postgres BackupCustom DockerfileAutomated database backupsbackup
18Caddycaddy:2-alpineReverse proxy with automatic HTTPStls
19Watchtowercontainrrr/watchtower:latestAutomatic container updatesmaintenance

Docker Compose Profiles

Services are organized into profiles for flexible deployment:

ProfileServicesUsage
core (default)PostgreSQL, Redis, Server, Frontendmake up
monitoringPrometheus, Grafana, Loki, Alloy, Alertmanager, Node Exporter, PostgreSQL Exporter, Redis Exporter, Docker Socket Proxymake monitoring
voiceCoturnmake voice
storageMinIO, MinIO Clientmake storage
backupPostgres Backupmake backup
tlsCaddymake tls
maintenanceWatchtowerdocker compose --profile maintenance up -d
fullAll services (voice + monitoring + backup)make full
prodAll services + TLSmake prod

Security

Quick Start

cd infra
cp .env.example .env
docker compose up -d

After startup, access the application at http://localhost:3000.

PostgreSQL Initialization (init-db.sql)

The init-db.sql script runs on first database creation. It configures extensions, performance tuning, and monitoring.

Extensions

ExtensionPurpose
uuid-osspUUID generation
pg_trgmTrigram similarity for text search
pg_stat_statementsQuery performance tracking

pg_stat_statements Configuration

SettingValue
shared_preload_librariespg_stat_statements
pg_stat_statements.trackall
pg_stat_statements.max5000
pg_stat_statements.track_utilityon

Performance Tuning

SettingValue
shared_buffers128MB
effective_cache_size256MB
work_mem4MB
maintenance_work_mem64MB
wal_buffers16MB
checkpoint_completion_target0.9
max_wal_size1GB
min_wal_size256MB
max_connections100
random_page_cost1.1
effective_io_concurrency200

Logging

SettingValue
log_min_duration_statement1000ms (log queries > 1s)
log_checkpointson
log_connectionson
log_disconnectionson
log_lock_waitson
log_temp_files0 (log all temp file usage)

Autovacuum

SettingValue
autovacuum_vacuum_scale_factor0.05
autovacuum_analyze_scale_factor0.02
autovacuum_max_workers2

Redis Configuration (redis.conf)

The redis.conf file configures Redis 8 for optimal pub/sub and caching performance.

Memory

SettingValue
maxmemory200mb
maxmemory-policyallkeys-lru
maxmemory-samples10

Persistence (AOF)

SettingValue
appendonlyyes
appendfsynceverysec
auto-aof-rewrite-percentage100
auto-aof-rewrite-min-size64mb

Persistence (RDB)

RuleDescription
save 60 1Save if 1+ keys changed in 60s
save 300 100Save if 100+ keys changed in 300s
save 600 1000Save if 1000+ keys changed in 600s

Additional: stop-writes-on-bgsave-error: yes, rdbcompression: yes, rdbchecksum: yes

Performance

SettingValue
tcp-backlog511
timeout300 (client idle timeout in seconds)
tcp-keepalive60
lazyfree-lazy-evictionyes
lazyfree-lazy-expireyes
lazyfree-lazy-server-delyes
lazyfree-lazy-user-delyes
hz10
dynamic-hzyes

Security

SettingValue
protected-modeyes
rename-command FLUSHALL"" (disabled)
rename-command FLUSHDB"" (disabled)
rename-command DEBUG"" (disabled)
maxclients1000

Ports

ServicePortExposed
Frontend3000Yes
Server8080Yes
PostgreSQL5432No (internal)
Redis6379No (internal)
Coturn3478, 5349, 49152-49172Yes
Prometheus9090No (internal)
Grafana3030No (internal)

Volumes

VolumeServicePurposeBackup
postgres_dataPostgreSQLDatabase filesYes
redis_dataRedisAOF/RDB persistenceNo
minio_dataMinIOObject storage dataYes
grafana_dataGrafanaDashboards and configYes
prometheus_dataPrometheusMetrics time-seriesNo
server_uploadsServerUser-uploaded filesYes
loki_dataLokiLog storageNo
alertmanager_dataAlertmanagerAlert silences and historyNo
backup_dataPostgres BackupCompressed database backupsYes
caddy_dataCaddyTLS certificatesNo
caddy_configCaddyCaddy config cacheNo