Server Overview

The Enclavr backend is a Go server providing REST API, WebSocket, and WebRTC signaling.

Project Structure

server/
├── cmd/
│   └── server/           # Main entry point
├── internal/
│   ├── handlers/        # HTTP handlers
│   ├── services/        # Business logic
│   ├── models/          # Database models
│   ├── database/        # Database connections
│   ├── websocket/       # WebSocket hub
│   ├── voice/           # WebRTC signaling
│   ├── auth/            # Authentication
│   ├── config/          # Configuration
│   ├── middleware/      # HTTP middleware
│   ├── metrics/         # Prometheus metrics
│   └── grpc/            # gRPC support
└── pkg/
    └── logger/          # Logging utilities

Key Features

Running the Server

cd server
go run ./cmd/server

The server runs on http://localhost:8080

Server Startup

Graceful Shutdown

The server handles SIGINT and SIGTERM signals for graceful shutdown with connection draining. Active connections are allowed to complete before the server exits.

Admin Bootstrapping

On first startup, the server can create an admin account. This is controlled by:

VariableDescriptionDefault
FIRST_USER_IS_ADMINFirst registered user becomes admintrue
ADMIN_USERNAMEConfigured admin usernameadmin
ADMIN_PASSWORDConfigured admin password-
ADMIN_EMAILConfigured admin emailadmin@enclavr.local

WebSocket Hub Initialization

The WebSocket hub is initialized at startup. It supports both in-memory and Redis-backed operation for horizontal scaling.

Login Attempt Tracker

The login attempt tracker is initialized with 5 max attempts and a 15-minute lockout window per account.

Debug and Metrics Endpoints

EndpointDescription
/debug/pprof/pprof debug endpoints (heap, goroutine, block, mutex)
/metricsPrometheus metrics endpoint