API services and request lifecycle
The Go backend is the service boundary for Arcane's Docker management product. It starts one application with shared state, domain services, background work, observability, and network listeners. Client requests enter through a common boundary and reach the domain service that owns the requested action. For transport rules, live connections, and webhook details, see API transport, realtime connections, and webhooks.
Backend application
The backend application turns process startup into one managed service. Bootstrap loads runtime state, builds the service graph, restores work that must be safe before traffic arrives, starts the API and background work, and coordinates shutdown.
The startup path follows this broad sequence:
- Load runtime configuration and process identity.
- Open the database and apply migrations.
- Load the persisted instance identity and prepare telemetry export.
- Build shared resources, domain services, route modules, and jobs.
- Prepare Docker access, identity state, local environment state, and mode-specific state.
- Recover interrupted project and operational work.
- Build the API router and start the network listener.
- Start scheduled work and any configured edge connection.
- On shutdown, cancel application work, drain listeners and accepted actions, stop jobs, flush telemetry, and close storage.
The following diagram shows how startup connects the process entry point to requests and work that continues after a request.
flowchart TD
Command[Arcane command] --> Bootstrap[Application bootstrap]
Bootstrap --> State[Configuration and database]
Bootstrap --> Telemetry[Telemetry providers]
Bootstrap --> Graph[Shared resources and domain services]
Graph --> Router[API router]
Router --> Listener[HTTP and WebSocket listener]
Listener --> Requests[Client requests]
Graph --> Jobs[Scheduled and durable work]
Bootstrap --> Edge[Optional edge connection]
References: backend/…/main.go• L1-13 backend/…/root.go• L19-47 backend/…/bootstrap.go• L46-166 backend/…/bootstrap.go• L193-323 backend/…/service.go• L42-123
Dependency graph
The dependency graph supplies shared resources first, then composes domain modules around them. A domain module is the wiring unit for one product area. It connects the service, its collaborators, its route registration, and any child domains so the same business capability can serve requests and background work.
The graph also supplies the managed work runtime. Accepted work uses this runtime for coordination, admission, and workflow monitoring. Domain services register workflows during composition so request-triggered and scheduled work use the same execution model.
The graph centers on these foundations:
| Foundation | Role in the service graph |
|---|---|
| Configuration | Defines runtime mode, network settings, storage, and security choices. |
| Database | Stores durable application state and supports startup migration. |
| Actor and workflow runtime | Runs accepted background work, controls admission, and monitors durable workflows within the application lifetime. |
| Docker client | Connects domain services to Docker state and actions. |
| Environment service | Selects local or remote execution and keeps environment state aligned. |
| Identity and role services | Resolve callers and the permissions used by request handling. |
| Runtime settings | Combine database values with environment overrides and publish safe changes to dependent services. |
| Domain modules | Join a product service, its collaborators, and its API surface. |
The graph is connected across domains. Container work can use project, image, settings, activity, and event services. A Compose-managed container can pass redeploy work to the project service so the project definition stays authoritative. The system service groups system actions with pruning, upgrades, and backups. The backup engine provides shared admission, per-repository serialization, and durable run handling for backup domains. The updater coordinates image state, projects, Docker, activity, events, and notifications.
These links matter because a request can change more than one system. A container action can change Docker state and create an event. An image update can change a workload and its activity record. A backup can outlive the request and must remain visible to recovery and scheduling.
References: backend/…/di.go• L54-159 backend/…/di.go• L162-186 backend/…/providers.go• L102-168 backend/…/providers.go• L300-382 backend/…/providers.go• L504-534 backend/…/service.go• L188-254 backend/…/service.go• L432-571 backend/…/service.go• L51-92 backend/…/service.go• L551-656 backend/…/service.go• L50-99 backend/…/module.go• L15-47 backend/…/service.go• L61-148 backend/…/service.go• L128-185 backend/…/service.go• L707-809 backend/…/service.go• L65-188
HTTP service
The HTTP service is the shared network boundary for the browser API, live connections, manager-side edge traffic, and browser telemetry. The listener owns socket, TLS, protocol selection, and graceful shutdown. The router owns middleware and request behavior.
Traffic is split by protocol and path. Normal requests use the API router. Manager-side tunnel traffic uses the tunnel service on the same listener. Long-lived request contexts are canceled before shutdown waits for the listener to drain. This lets streams and tunnel sessions release their producers instead of blocking process exit.
| Service path | Purpose |
|---|---|
| HTTP API | Serves typed REST operations and public trigger routes. |
| JSON stream | Carries live environment, dashboard, activity, and event updates. |
| WebSocket API | Supports interactive sessions and live resource data. |
| Edge tunnel | Carries manager-to-agent control and data traffic. |
| Static frontend | Serves the bundled web application when included in the build. |
| Browser telemetry relay | Checks browser OTLP/JSON signals and forwards allowed traces, metrics, or logs to the configured collector. |
References: backend/…/server_bootstrap.go• L31-118 backend/…/server_bootstrap.go• L147-217 backend/…/router_bootstrap.go• L294-344 backend/…/service.go• L54-83 backend/…/service.go• L121-160
API composition
The API composition layer creates the shared API group and attaches common controls before domain modules add their routes. Each module contributes operations for its product area. Child modules add focused surfaces without creating a separate request boundary. Echo remains the host for middleware, WebSocket handlers, streams, the frontend, and routes with special transport rules.
The typed API applies one request and response contract. Shared serialization and input normalization run before typed validation. This keeps client errors consistent while allowing domain handlers to focus on business actions.
The composed surface covers identity and access, environments, Compose projects, containers, images, volumes, networks, Swarm resources, builds, backups, jobs, system operations, activity, notifications, customization, GitOps, vulnerabilities, webhooks, and federated access. The domain service owns the action and its downstream effects. The child page API transport, realtime connections, and webhooks describes the transport and route contract in detail.
References: backend/…/api.go• L268-330 backend/…/api.go• L363-453 backend/…/router_bootstrap.go• L223-319 backend/…/module.go• L31-47 backend/…/module.go• L49-273
Request policy
Shared request policy decides whether a request can enter a domain service. The router applies recovery, logging, cross-origin rules, cross-site request forgery protection, and targeted rate limits. The API layer resolves browser sessions, bearer tokens, API keys, environment credentials, and agent credentials into a caller and permission set.
The authentication service supports local credentials and OIDC identity. It can require passkey multi-factor authentication before it creates a session. It then issues session-backed access and refresh credentials, while request verification checks both the signed credential and its active session. Role changes, account changes, and session revocation invalidate cached verification so access changes take effect promptly.
Environment-scoped requests add a second choice. The environment layer checks the target environment and caller access. It then runs the action locally or forwards it to a remote environment. Clients keep one API shape while the backend selects the execution site.
Public authentication and trigger flows use the same boundary with different credentials. A webhook uses its URL token. An agent event uses environment credentials. A browser login establishes identity rather than using an existing session.
References: backend/…/router_bootstrap.go• L87-167 backend/…/router_bootstrap.go• L215-290 backend/…/service.go• L200-345 backend/…/service.go• L657-790 backend/…/huma_middleware.go• L186-232 backend/…/environment_middleware.go• L127-190 backend/…/module.go• L79-181 backend/…/service.go• L521-578
Domain request flow
The request lifecycle carries a client action from transport policy to a domain service and then to its effects. The handler translates the request into a domain call. The service coordinates storage, Docker, remote environments, activity, notifications, and event records as needed before the response returns.
The following diagram shows the normal relationship between request policy, domain coordination, and downstream systems.
sequenceDiagram
participant Client
participant Router as API router
participant Policy as Identity and environment policy
participant Handler as Domain handler
participant Service as Domain service
participant Systems as Database, Docker, or remote environment
participant Records as Activity, event, and notification services
Client->>Router: Request
Router->>Policy: Resolve caller and target access
Policy-->>Router: Allow or reject
Router->>Handler: Dispatch operation
Handler->>Service: Apply domain action
Service->>Systems: Read or change managed state
Service->>Records: Record progress and outcome
Service-->>Handler: Domain result
Handler-->>Client: Response
Long-running work uses activity and durable run records as its view of progress. The HTTP response can return while a scheduler or actor completes the action. The activity and event records preserve the result for the client and for recovery.
References: backend/…/api.go• L268-325 backend/…/stream.go• L53-119 backend/…/huma_middleware.go• L198-232 backend/…/environment_middleware.go• L208-275 backend/…/handler.go• L69-99 backend/…/handler.go• L144-221 backend/…/service.go• L917-1114 backend/…/service.go• L217-321
Client stream
The client stream is a multiplexed JSON-lines service for live state that does not fit repeated REST calls. A client selects the channels it needs. The stream starts only producers that the caller may read and sends heartbeats while the connection remains open.
The channels are:
environmentsfor environment state.dashboardfor dashboard action items.activitiesfor operation progress.eventsfor the event log.
Local and remote producers can feed the same channel. Each producer keeps ownership of its data while the stream wraps results in one event shape. A caller without access to a channel receives no data from that channel but can still receive heartbeats.
References: backend/…/stream.go• L39-80 backend/…/stream.go• L101-228
Domain coordination
Domain services make the API useful because they turn resource requests into changes across Arcane state and Docker state. The most important relationships are shared rather than endpoint-specific.
| Domain capability | Coordination role |
|---|---|
| Projects | Keep Compose definitions, workspace state, deployment actions, and project-linked updates together. |
| Containers | Apply lifecycle actions, preserve rollback paths during recreation, and use project services for known Compose workloads. |
| Image updates | Compare local and registry image state, record update activity, and coordinate pulls, project updates, events, and notifications. |
| System operations | Group container actions with pruning, self-upgrade, and backup services. |
| Backups | Serialize repository work, admit durable runs, record progress, and reconcile accepted work after interruption. |
| Updater | Run image updates at container, project, or batch scope while sharing activity, recovery, event, and notification state. |
This composition keeps product rules in the owning domain. For example, a known Compose container does not silently use a standalone Docker recreation if the project update fails. A backup request is not treated as complete until its durable run state and snapshot outcome are known.
References: backend/…/module.go• L31-47 backend/…/service.go• L551-656 backend/…/service.go• L658-735 backend/…/service.go• L243-363 backend/…/service.go• L61-148 backend/…/service.go• L228-302 backend/…/service.go• L180-250 backend/…/service.go• L707-809 backend/…/service.go• L917-1241 backend/…/service.go• L217-381
WebSocket service
The WebSocket service provides live data and interactive control when one response cannot express the client need. It serves environment-scoped logs, container statistics, system statistics, terminals, and diagnostics. Each connection passes shared identity and environment policy before upgrade.
The backend treats a live connection as managed application work. It tracks connection state, detects dead peers, and closes the connection when its producer or client ends. Shared producers let several clients follow one resource without starting a separate source for each client. The child page API transport, realtime connections, and webhooks describes connection contracts.
References: backend/…/handler.go• L37-169 backend/…/exec.go• L34-104 backend/…/system_stats.go• L39-181 backend/…/ws_proxy.go• L25-88 backend/…/proxy.go• L14-99
Background coordination
The backend coordinates work that must continue beyond one request through the actor and workflow runtime and the job scheduler. Dependency composition registers domain workflows before the application starts. Bootstrap then registers recurring jobs and per-entity jobs. Domain services own the work while the runtime and bootstrap own admission, registration, and application lifetime.
The scheduler supports updates, health checks, backups, GitOps sync, cleanup, pruning, notifications, vulnerability scans, and system upgrades. Some jobs are dynamic. Environments and backup policies can add or remove jobs as state changes. Settings can change job timing and selected behavior, including behavior sent to remote environments.
Accepted work has a durable outcome. Activity records show progress to clients. Event records show state changes. Durable run state lets selected work recover after interruption. Backup acceptance persists the run intent before dispatch. Startup reconciliation can resolve uncertain submissions and repair dispatches that ended in a terminal state before the work ran. Shutdown therefore drains or rejects new work before the application closes its shared resources.
References: backend/…/providers.go• L102-168 backend/…/providers.go• L300-382 backend/…/jobs_bootstrap.go• L29-73 backend/…/jobs_bootstrap.go• L113-204 backend/…/jobs_bootstrap.go• L219-350 backend/…/service.go• L917-1241 backend/…/service.go• L132-148 backend/…/service.go• L505-517
Edge service modes
Arcane can run as a manager or an agent. A manager accepts agent sessions and maps them to stored environments. An edge agent can open an outbound session to the manager. A direct agent can serve its local API without an outbound session.
Managed edge sessions can use gRPC, WebSocket, or poll control. Automatic mode prefers gRPC and can fall back to WebSocket. Poll control starts or stops an on-demand data session. Reconnect backoff and optional edge mTLS protect the session from repeated failure and unauthorized tunnel access.
The tunnel carries more than connectivity. Agent status updates environment state and events. The manager remains the API control surface while execution stays near the managed Docker host.
References: backend/…/bootstrap.go• L370-392 backend/…/client.go• L78-161 backend/…/client.go• L205-290 backend/…/client_transport_grpc.go• L25-98 backend/…/client_transport_poll.go• L26-111 backend/…/transport.go• L9-81 backend/…/tls.go• L65-112
Webhook-triggered work
A webhook is a stored external trigger for a known domain action. The public trigger route uses the URL token as its caller credential. The service validates the token and enabled state, accepts the trigger, and starts the action in the background. The caller receives a fast acknowledgement while the event log records the later result.
Webhook actions can target a container, Compose project, environment-wide updater, or GitOps sync. A remote target uses the environment proxy. A local target calls the owning domain service. This keeps webhook work subject to the same domain rules as client requests.
The application lifecycle protects accepted work. Webhook token state loads before the server accepts requests. Shutdown waits for accepted actions until its deadline. The child page API transport, realtime connections, and webhooks describes the public trigger and transport contract.
References: backend/…/service.go• L67-101 backend/…/service.go• L142-170 backend/…/service.go• L521-606 backend/…/service.go• L653-831 backend/…/webhooks_trigger.go• L14-42
Change checklist
When these files or sections are changed, remember to consider these:
- A new domain or child module must enter both dependency composition and API registration. If it serves jobs, align its provider and lifecycle access too.
- A new environment-scoped action must preserve the local and remote execution contract, including permission checks before forwarding.
- A new live route or stream channel must update its access map, producer rules, and remote proxy contract together.
- A request that can outlive its HTTP response must define its activity, durable outcome, recovery path, and shutdown behavior.
- A Compose-managed container action must keep project lookup, service selection, and standalone fallback as one explicit contract. A failed project action must not fall back silently.
- A backup or updater change must preserve admission, repository serialization, progress records, event outcomes, and restart reconciliation across both HTTP and scheduled entry points.
- A backup policy change must keep validation, stored policy rows, and scheduled job registration in step.
- A webhook action change must update target validation, local and remote dispatch, event reporting, and action draining together.
- A shared-listener change must preserve HTTP, WebSocket, and manager tunnel routing on the selected protocol and port.
- A settings change must preserve the database snapshot, environment override rules, change notifications, and the dependent job or remote-environment behavior.
- An authentication change must keep local and OIDC login, MFA completion, session state, token verification, and permission-cache invalidation aligned.
- A telemetry change must keep the persisted instance identity, signal endpoint selection, frontend resource identity check, payload limit, and exporter shutdown behavior aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A domain service is composed without its route module or provider | Startup can fail or a documented operation can have no working service | Add dependency wiring and route registration as one change. |
| A remote operation skips environment permission checks | A caller can reach an agent without manager-granted access | Resolve identity and permissions before forwarding. |
| A Compose-managed container redeploy falls back after a project action fails | Standalone Docker recreation can overwrite or hide partial Compose state | Surface the project error and stop the fallback path. |
| Accepted backup or webhook work is not drained at shutdown | The caller receives acceptance but the action can be dropped | Persist or track accepted work and drain it before teardown. |
| Backup operations for one repository run at the same time | Snapshot, restore, or prune actions can observe conflicting repository state | Keep repository operations behind the shared repository lock. |
| A backup dispatch fails after its durable intent is saved | A valid run can remain queued without execution | Reconcile unresolved submissions and repair terminal dispatch jobs. |
| A durable run loses its state or recovery data | The scheduler cannot resume or explain interrupted work | Persist intent and progress before destructive work and reconcile on startup. |
| A remote backup repository cannot be verified before a destructive action | A caller can delete local state while the remote copy is unavailable | Bound repository checks and return transport or credential errors instead of forgetting blindly. |
| A live route lacks the matching permission or proxy mapping | Local and remote live access can disagree | Keep route registration, access policy, and proxy mapping synchronized. |
| The shared listener cannot bind or complete TLS setup | HTTP, live connections, and tunnel traffic do not start | Validate listener and TLS settings before opening the socket. |
| A browser telemetry payload is not a permitted OTLP signal or exceeds the size limit | The relay rejects the signal and the collector receives no data | Keep signal shape, service.name, and the 512 KiB limit consistent with the frontend exporter. |
| Telemetry starts without a stable instance identity or is not flushed on stop | Collector data cannot identify the installation or recent signals can be lost | Open the database before telemetry setup and shut down providers within the application stop window. |
Key files
| File | Why to read it |
|---|---|
| backend/…/main.go | Shows the process entry point. |
| backend/…/root.go | Shows signal-aware command execution and the handoff to bootstrap. |
| backend/…/bootstrap.go | Shows application startup, telemetry setup, recovery, edge startup, and shutdown. |
| backend/…/server_bootstrap.go | Shows the shared HTTP, WebSocket, TLS, and tunnel listener. |
| backend/…/router_bootstrap.go | Shows middleware order, environment routing, public routes, and live route setup. |
| backend/…/api.go | Shows typed API setup and shared API policy. |
| backend/…/di.go | Shows high-level service and job providers. |
| backend/…/providers.go | Shows how shared services, workflows, and domain collaborators are connected. |
| backend/…/service.go | Shows the browser telemetry relay and its collector boundary. |
| backend/…/service.go | Shows identity setup, session-backed credentials, OIDC, MFA, and token verification. |
| backend/…/service.go | Shows the runtime settings snapshot, environment overrides, and change effects. |
| backend/…/module.go | Shows how a domain service becomes a secured API surface. |
| backend/…/service.go | Shows Docker actions and the Compose-aware container boundary. |
| backend/…/service.go | Shows image update checks and their activity and event effects. |
| backend/…/service.go | Shows system operations and child service composition. |
| backend/…/service.go | Shows repository serialization, shared backup admission, durable runs, remote checks, and shutdown behavior. |
| backend/…/service.go | Shows scoped and batch update coordination. |
| backend/…/service.go | Shows token acceptance, local or remote dispatch, and action draining. |
| backend/…/jobs_bootstrap.go | Shows scheduler registration and dynamic background work. |
| backend/…/stream.go | Shows the multiplexed client stream. |
| backend/…/handler.go | Shows the live connection boundary. |
| backend/…/client.go | Shows agent reconnect behavior and transport selection. |
| backend/…/webhooks_trigger.go | Shows the public webhook acceptance boundary. |