Skip to content

Cloud Backend

The Cloud Backend is the central API server for the Monozu Cloud platform. It serves the Cloud SPA, handles Edge device communication, runs background jobs, and exposes internal M2M endpoints for the Management service.

ComponentTechnology
LanguageGo 1.26
HTTP frameworkFiber v3 (fasthttp)
Database clientsqlx (manual SQL, no ORM)
DatabaseAzure SQL Server (MSSQL)
AuthJWT (HS256), bcrypt, TOTP, OIDC
Loggingzerolog (structured JSON)
ObservabilityOpenTelemetry → Azure Application Insights
MigrationsFlyway (V1–V28)
Backend/
├── cmd/
│ ├── api/main.go # HTTP API (Fiber)
│ └── worker/main.go # Background schedulers + job queue consumer (ACA split)
├── internal/
│ ├── app/ # Wiring: DI, route registration
│ ├── domain/ # ~35 bounded context packages
│ ├── db/ # sqlx setup, models, RLS helpers
│ ├── middleware/ # Auth, RBAC, logging, recovery
│ ├── services/ # Shared cross-domain services
│ ├── jobs/ # Background job runners
│ ├── websocket/ # WebSocket hub and handlers
│ └── rbac/ # Permission catalog
├── db/
│ └── migration/ # Flyway SQL files (V1–V28)
└── go.mod

All API routes are registered in internal/app/register_*.go files. Each file corresponds to a domain or feature group. Routes share the /api/v1 prefix.

File patternRoutes registered
register_auth.go/api/v1/auth/*
register_assets.go/api/v1/assets/*
register_incidents.go/api/v1/incidents/*
register_security.go/api/v1/security/* (optional)
register_internal.go/internal/license/refresh

Every domain follows: handler → service → repository (sqlx)

domain/<name>/
├── handler.go # HTTP handler, input parsing, response marshalling
├── service.go # Business logic, cross-domain calls
└── repository.go # sqlx queries against Azure SQL

Handlers are thin: they parse and validate input, call the service, and write the response. Business logic lives in the service layer.

Scheduled work and async tasks use internal/jobs/:

ProcessWhenRole
cmd/apiLocal dev (no AZURE_STORAGE_ACCOUNT_JOBS)HTTP + in-process schedulers + memory queue
cmd/apiACA cloud appHTTP only; enqueues to Azure Storage Queue
cmd/workerACA worker appSchedulers + Azure queue consumer (no HTTP)

Queue transport: in-memory channel locally; Azure Storage Queue (AZURE_STORAGE_ACCOUNT_JOBS, default queue jobs) in split mode. Job payloads are JSON envelopes (type + payload).

Job typePurpose
CVE feed sync / vuln scanCatalog sync, CPE match, tenant scans
Audit log retentionDelete audit_logs past tenant retention
Tool execution / backupAsync security tools, backup collection
Notification deliveryIntegration webhook/email dispatch (ACS Email)