Architecture

Enclavr uses a modular architecture with separate repositories for frontend, server, and infrastructure.

System Overview

┌─────────────────────────────────────────────────────────────────┐
│                        Browser                                   │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────────┐ │
│  │  WebRTC       │  │  WebSocket   │  │  REST API            │ │
│  │  (Voice)      │  │  (Chat/DM)   │  │  (HTTP)              │ │
│  └──────┬───────┘  └──────┬───────┘  └──────────┬───────────┘ │
└─────────┼──────────────────┼────────────────────┼─────────────┘
          │                  │                    │
          ▼                  ▼                    ▼
┌─────────────────────────────────────────────────────────────────┐
│                       Coturn (TURN Server)                      │
│                     Ports: 3478, 49152-49172                     │
└─────────────────────────────────────────────────────────────────┘
          │
          ▼
┌─────────────────────────────────────────────────────────────────┐
│                        Frontend                                 │
│                    Next.js 16 (Port 3000)                       │
└─────────────────────────────┬───────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                         Server                                   │
│                 Go 1.25 (Port 8080)                             │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────────┐  │
│  │  REST API    │  │  WebSocket   │  │  gRPC (TLS)          │  │
│  │  230+ routes │  │  Hub + DM    │  │  4 services          │  │
│  └──────────────┘  └──────┬───────┘  └──────────────────────┘  │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────────┐  │
│  │  WebRTC      │  │  WebAuthn    │  │  OAuth/OIDC          │  │
│  │  Signaling   │  │  FIDO2       │  │  Providers           │  │
│  └──────────────┘  └──────────────┘  └──────────────────────┘  │
└────────────────────────────┼───────────────────────────────────┘
                             │
              ┌──────────────┼──────────────┐
              ▼              ▼              ▼
     ┌────────────┐  ┌────────────┐  ┌────────────┐
     │ PostgreSQL │  │   Redis    │  │   STUN     │
     │  :5432     │  │   :6379    │  │ Google     │
     └────────────┘  └────────────┘  └────────────┘

Project Structure

Enclavr uses git submodules:

RepositoryDescription
enclavr/enclavrRoot monorepo
enclavr/frontendNext.js frontend
enclavr/serverGo backend
enclavr/infraDocker deployment

Data Flow

Authentication Flow

  1. User submits credentials to Frontend
  2. Frontend calls Server /api/auth/login
  3. Server validates and returns JWT + refresh token
  4. Frontend stores tokens and includes JWT in subsequent requests

Chat Flow

  1. User sends message via Frontend
  2. Frontend sends to Server via REST API
  3. Server stores in PostgreSQL
  4. Server broadcasts to room via WebSocket
  5. Other users receive real-time update

Voice Flow

  1. User joins voice channel
  2. Frontend connects to Server WebSocket (/api/voice/ws)
  3. Server performs ICE handshake with STUN/TURN
  4. Peers connect directly via WebRTC
  5. Audio streams peer-to-peer

Communication Channels

ChannelProtocolPortPurpose
REST APIHTTP/HTTPS8080CRUD operations, auth, admin
WebSocketWS/WSS8080Real-time chat, DM, presence, voice signaling
gRPCHTTP/2 + TLS8081Service-to-service communication (Auth, Room, Message, User)
WebRTCDTLS/SRTPP2PVoice/video media streams
WebAuthnHTTP8080Passkey/FIDO2 authentication ceremonies

gRPC Services

The server exposes a gRPC interface defined in api/enclavr.proto with 4 services:

ServiceMethods
AuthServiceRegister, Login, RefreshToken, GetMe
RoomServiceGetRooms, CreateRoom, GetRoom, JoinRoom, LeaveRoom
MessageServiceGetMessages, SendMessage, UpdateMessage, DeleteMessage, SearchMessages
UserServiceSearchUsers, GetProfile

Scaling