Skip to content

Layers ​

This is the implementation layer model reviewed at commit eec3592912d9c0156574495bb090caf3fd78c794 on 2026-11-07. A layer is a runtime responsibility, not a directory. The boundaries below explain what owns state, which channel it uses, where configuration enters, and how a unit starts and stops.

Layer map ​

#LayerResponsibilityRepresentative implementation
1Web consoleAuthenticate the operator, keep scope and token in the browser, render pages and emit REST/SSE calls.web/src/app.tsx:113; web/src/services/core/http.ts:40
2Server HTTP APIValidate identity and scope, route REST requests to application services, and own the HTTP process lifecycle.cmd/server/root.go:402; internal/handler/routes.go:89
3Server application servicesExecute authorization, approvals, audit, contracts, pages, registry operations and dispatch use cases.internal/svc/service_context.go:221; internal/platform/functioninvoke/govern.go:63
4Storage and coordinationOwn durable records, cache, analytics storage, owner election and file-backed task routing.internal/svc/migrations.go:186; internal/cache/helper.go:15; internal/cluster/owner_store.go:8
5Agent runtimesDial the Server, keep registration and heartbeat alive, execute capture, probes, host operations and managed processes.internal/app/agent/app.go:184; agents/capture/runner/runner.go:201; agents/devops/session/broker.go:92
6Session transportFrame and multiplex outbound agent sessions and define request IDs for control, invocation, task and operations messages.core/transport/tcp/framing.go:25; pkg/protocol/message.go:51
7Provider sessionsTerminate SDK provider connections locally, route to healthy instances, invoke handlers and adapt plugin protocols.internal/agent/local_handler.go:91; agents/sidecar/funcplugin/protocol/funcplugin.proto:24
8Page/dashboard DSLModel drafts, published pages, menus and selector bindings, then execute only the bindings frozen at publish time.internal/dashboard/spec/types.go:537; internal/api/console/service.go:313

Glossary ​

TermEnglishDefinitionEvidence
Operator scopeOperator scopeThe current game/environment selection used by web requests.web/src/services/core/scope.ts:56
Provider tokenProvider tokenThe browser-held authentication token used after sign-in.web/src/app.tsx:113
Scoped routeScoped routeA REST route group whose game database is selected by GameDBMiddleware.internal/handler/routes.go:150
HTTP lifecycleHTTP lifecycleThe SIGINT/SIGTERM-driven REST server start, drain, background-stop and pool-close sequence.cmd/server/root.go:417; cmd/server/root.go:440
Service contextService contextThe Server's composition root for databases, cache, registries, approvals, audit and background jobs.internal/svc/service_context.go:221
Execution governanceExecution governanceThe shared disable, assignment, subject, ACL, policy, input and approval chain used by HTTP, tasks and schedules.internal/platform/functioninvoke/govern.go:63
Function contractFunction contractThe durable metadata for invocation, schema, risk, permission and approval.internal/model/function_contract.go:15
Task runTask runThe persisted state machine for an asynchronous function run.internal/platform/dispatch/dispatcher.go:54
DispatchDispatchThe server-side selection of an agent session and creation of a durable run before an agent request.internal/platform/dispatch/dispatcher.go:336; internal/platform/dispatch/dispatcher.go:775
Relational model storeRelational model storeThe MySQL/PostgreSQL/SQLite model layer defined by GORM models and migrations.internal/svc/migrations.go:186; internal/model/task.go:8
Cache storeCache storeThe Redis or in-process cache selected from configuration.internal/cache/helper.go:15; internal/cache/helper.go:41
Analytics sinkAnalytics sinkThe ClickHouse batch sink behind the analytics worker.internal/analytics/worker/worker.go:394; internal/analytics/worker/worker.go:435
Cluster ownerCluster ownerThe shared-database or Redis resolver that assigns scope ownership to one server instance.internal/cluster/owner_store.go:8; internal/cluster/owner_redis.go:27
File task routingFile task routingThe JSON-file or in-memory adapter that maps task IDs to agents.internal/platform/dispatch/task_routing_store.go:28; internal/platform/dispatch/task_routing_store.go:162
Agent runtimeAgent runtimeThe outbound process containing registration, heartbeat, local services and role-specific runners.internal/app/agent/app.go:138; internal/app/agent/app.go:184
Agent sessionAgent sessionThe agent-initiated Server TCP session carrying control and execution traffic.internal/app/agent/app.go:190; internal/server/control_handler.go:128
Capture gateCapture gateThe capture-runtime policy for sources, filters and durable delivery.agents/capture/runner/runner.go:201; agents/capture/runner/runner.go:272
DevOps admissionDevOps admissionThe audit-and-admit check that must pass before a host session opens.agents/devops/session/broker.go:92; agents/devops/session/broker.go:126
Wire frameWire frameThe 4-byte big-endian length-prefix framing shared by transport peers.core/transport/tcp/framing.go:25
Message IDMessage IDThe 24-bit wire operation identifier for registration, invocation, task and operations families.pkg/protocol/message.go:51; pkg/protocol/message.go:71
Provider managerProvider managerThe sidecar-side registry and health window for SDK provider sessions.internal/agent/local_handler.go:52; internal/agent/local_handler.go:34
Provider invocationProvider invocationThe local request that selects a healthy provider and invokes its registered handler.internal/agent/local_handler.go:290; internal/agent/tcp_local_listener.go:28
Function pluginFunction pluginThe sidecar plugin contract for describing and invoking plugin functions.agents/sidecar/funcplugin/protocol/funcplugin.proto:24; agents/sidecar/funcplugin/protocol/funcplugin.proto:62
Probe pluginProbe pluginThe synthetics go-plugin contract for describing and running probes.agents/synthetics/pluginhost/protocol/probeplugin.proto:18; agents/synthetics/pluginhost/protocol/probeplugin.proto:30
PageSpecPageSpecThe typed draft page model, including layout, localized text and bindings.internal/dashboard/spec/types.go:537; internal/dashboard/spec/types.go:18
Published pagePublished pageThe immutable snapshot that freezes scope, version, bindings and contract digests.internal/dashboard/spec/types.go:797; internal/dashboard/spec/types.go:823
Console menuConsole menuThe runtime navigation model generated from published pages and menu records.internal/dashboard/spec/types.go:850; internal/api/console/service.go:62
Binding executionBinding executionThe published-snapshot execution path that maps inputs, invokes functions and wraps only the approved response shape.internal/api/console/service.go:313; internal/api/console/service.go:413

Layer details ​

1. Web console ​

The browser layer owns sign-in, the operator-selected gameId + env, and REST/SSE access. It does not open Agent sessions. The UI runtime reads a token from browser storage (web/src/app.tsx:113) and the HTTP service injects scope headers (web/src/services/core/scope.ts:64; web/src/services/core/http.ts:40). Configuration comes from Umi environment/config builds; process routes are declared in web/config/routes.ts. State is browser-local and transient.

2. Server HTTP API ​

runServer loads YAML and CLI overrides, validates cluster TLS, builds the service context, registers routes, starts the scheduler and REST/TCP processes, then performs an ordered shutdown (cmd/server/root.go:124; cmd/server/root.go:202; cmd/server/root.go:440). RegisterHandlers is the route table (internal/handler/routes.go:89), while scoped groups attach GameDBMiddleware (internal/handler/routes.go:150). REST requests call application services synchronously; SSE uses the long-write HTTP server (cmd/server/root.go:409). Its schema is internal/config/config.go:13, with seed examples under configs/.

3. Server application services ​

NewServiceContext composes relational models, cache, registry, approvals, audit, scheduler and role-specific services (internal/svc/service_context.go:221; approvals at internal/svc/service_context.go:366; audit at internal/svc/service_context.go:374). The unified invocation path runs functioninvoke.Invoke (internal/platform/functioninvoke/invoke.go:26), whose Govern chain is shared by HTTP, task start, page bindings and schedules (internal/platform/functioninvoke/govern.go:63). Domain state is relational except for short-lived execution queues and cache. Configuration is layered at boot (cmd/server/root.go:205) and backed by internal/platform/settings/layered.go:187.

4. Storage and coordination ​

This layer separates authoritative relational state, optional cache, analytics, coordination and file adapters. GORM migrations define relational schemas (internal/svc/migrations.go:186). Cache selection is configuration-driven (internal/cache/helper.go:15). ClickHouse writes are batched by the analytics worker (internal/analytics/worker/worker.go:435); its process reads environment inputs at internal/analytics/worker/worker.go:106 and ingest validation is in cmd/ingest/cmd/root.go:152. Owner state can use the shared relational database or Redis (internal/cluster/owner_store.go:8; internal/cluster/owner_redis.go:27). Task routing can use a JSON file or memory (internal/platform/dispatch/task_routing_store.go:34; internal/platform/dispatch/task_routing_store.go:162).

5. Agent runtimes ​

The sidecar runtime creates the Server connection and starts the local provider listener (internal/app/agent/app.go:184; internal/app/agent/app.go:190). Capture builds gates, applies them, reads sources, consumes durable records and records hits (agents/capture/runner/runner.go:201; agents/capture/runner/runner.go:423; agents/capture/runner/runner.go:565). Synthetics uses its own runner and plugin host; DevOps requires audit admission before opening a host session (agents/devops/session/broker.go:126; session limits are enforced at agents/devops/session/hub.go:98). YAML examples live in configs/agent.yaml, configs/capture-agent.example.yaml, configs/synthetics-agent.example.yaml and configs/devops-agent.example.yaml.

6. Session transport ​

Transport peers share length-prefix framing (core/transport/tcp/framing.go:25), request multiplexing in core/transport/tcp/mux_conn.go, and a fixed message header (pkg/protocol/message.go:33). Message families are enumerated in pkg/protocol/message.go:51, with invocation/task IDs at pkg/protocol/message.go:71. Protobuf contracts live under proto/croupier/, including proto/croupier/sdk/v1/provider.proto, proto/croupier/agent/v1/register.proto, proto/croupier/agent/v1/task.proto, proto/croupier/ops/v1/ops.proto and proto/croupier/function/v1/metadata.proto. There is no separate copy-based protocol schema under configs/.

7. Provider sessions ​

SDK providers dial the sidecar; the sidecar terminates and stores local sessions, selects healthy instances and invokes handlers (internal/agent/tcp_local_listener.go:28; internal/agent/local_handler.go:290). Plugin backends use separate contracts: function plugins under agents/sidecar/funcplugin/protocol/funcplugin.proto:24 and probe plugins under agents/synthetics/pluginhost/protocol/probeplugin.proto:18. Provider descriptors and heartbeat/drain behavior are defined in proto/croupier/sdk/v1/provider.proto:11 and proto/croupier/sdk/v1/provider.proto:69. Session state is process-local unless explicitly exported through the registry.

8. Page/dashboard DSL ​

PageSpec is the typed draft, and PublishedPageSpec freezes publish facts and binding contracts (internal/dashboard/spec/types.go:537; internal/dashboard/spec/types.go:797). Draft persistence and publishing are application use cases (internal/api/page/service.go:319; internal/api/page/service.go:924). Runtime menu generation and binding execution consume only published state (internal/api/console/service.go:62; internal/api/console/service.go:313), with idempotent binding execution at internal/api/console/service.go:413. UI copy is not a separate bundle inside this DSL: LocalizedText maps locale keys to strings (internal/dashboard/spec/types.go:18); the generator consumes configs/term_dictionary.json through internal/dashboard/generator/generator.go:29.

Why these are separate layers ​

  1. Browser is a trust and session boundary. Token and scope live in the browser and are attached to HTTP (web/src/app.tsx:113; web/src/services/core/scope.ts:64), while the server independently authenticates and applies scoped database middleware (internal/handler/routes.go:150).
  2. HTTP routing is narrower than domain execution. The route layer registers endpoints and middleware (internal/handler/routes.go:89), but a single shared governance chain is deliberately reused by HTTP, tasks, schedules and pages (internal/platform/functioninvoke/govern.go:63); collapsing them would fork the approval and authorization rules.
  3. Application state and execution are not one concern. Dispatch creates the durable task run before sending to an agent (internal/platform/dispatch/dispatcher.go:775), while the service context owns cache and relational lifecycle (internal/svc/service_context.go:221). Keeping this boundary makes persistence and retries independent of route or protocol choice.
  4. Durable, cache, analytics and coordination stores have different consistency models. GORM migrations own relational schemas (internal/svc/migrations.go:186), cache is swappable (internal/cache/helper.go:15), ClickHouse is batch-oriented (internal/analytics/worker/worker.go:435), and owner leases use TTL semantics (internal/cluster/owner_redis.go:27). A single "storage layer" would hide those incompatibilities.
  5. Agents are independent failure domains. Capture gates, probe plugins and audited DevOps sessions run in separate processes and can fail without taking down REST serving (agents/capture/runner/runner.go:201; agents/synthetics/pluginhost/protocol/probeplugin.proto:18; agents/devops/session/broker.go:126).
  6. Transport is a shared mechanism, not a domain service. Agent frames and request IDs are reused across registration, invocation, task and operations traffic (core/transport/tcp/framing.go:25; pkg/protocol/message.go:51), so the Server domain does not need to encode framing in every handler.
  7. Provider connectivity is local and health-scoped. The provider listener owns the local connection and healthy-instance window (internal/agent/tcp_local_listener.go:28; internal/agent/local_handler.go:34), while plugin protocols differ by SDK and synthetics role (agents/sidecar/funcplugin/protocol/funcplugin.proto:24; agents/synthetics/pluginhost/protocol/probeplugin.proto:18).
  8. Draft pages and executable pages have different guarantees. PageSpec supports editing and validation, while PublishedPageSpec freezes version, publish facts and binding contracts (internal/dashboard/spec/types.go:537; internal/dashboard/spec/types.go:797); runtime execution refuses stale bindings against a frozen digest (internal/dashboard/spec/types.go:823).
  9. Localized copy belongs to page data, not renderer code. LocalizedText is part of the page model (internal/dashboard/spec/types.go:18) and generation can seed copy from a term dictionary (internal/dashboard/generator/generator.go:29), so a language change is data, not a renderer deployment.