How margo/sandbox works
1. Repository purpose
- This is a Margo “code-first sandbox” for experimenting with fleet-management workflows, package formats, and device-side behavior.
- It is not a single deployable product; it is a set of cooperating components, libraries, deployment assets, and proof-of-concept implementations.
2. Main architectural boundary: three code zones
- shared-lib contains reusable building blocks with no Margo-specific deployment role.
- standard contains code mapped to the Margo specification snapshot.
- non-standard contains enabling functionality that the sandbox needs, but that is not part of the Margo spec itself.
3. Standard/spec-aligned layer
- standard/generatedCode/wfm/sbi and non-standard/generatedCode/wfm/nbi are generated Go clients/models for the spec-defined service interfaces.
- standard/pkg/parser.go suggests spec-to-code translation and parsing of the snapshot spec in standard/snapshot.spec.yaml.
- This layer is the “contract boundary” for Margo API compatibility and traceability.
4. Non-standard package management layer
- non-standard/pkg/packageManager is a dedicated subsystem for handling application packages as either directory-based packages or OCI-backed packages.
- It includes validation, error handling, and package type abstractions, so package ingestion and retrieval are isolated from workload deployment logic.
- non-standard/pkg/models defines package/application state objects used by that management flow.
5. Shared library layer
- shared-lib centralizes cross-cutting capabilities used by sandbox components:
- archive extraction and packaging
- caching of bundles and deployments
- crypto/digest/signing/TLS/verifier support
- HTTP helpers and auth token handling
- git cloning/branch/pull operations
- OCI client/image/repository utilities
- workload execution helpers for Compose and Helm
- Architecturally, this is the foundation layer beneath both control-plane and device-side code.
6. Device-agent proof of concept
- poc/device/agent is a standalone device-side agent implementation with its own main.go, configuration, and local persistence.
- Subcomponents include:
- onboarding.go for initial registration/joining
- stateSync.go for syncing device/workload state
- monitor.go and status.go for health/telemetry/status handling
- deployment.go plus device/capabilities.go for interpreting what the device can run
- database/database.go backed by a local JSON database under data/
- This agent is the sandbox’s “managed device” endpoint for workload lifecycle interactions.
7. Lifecycle/data flow on the device side
- The agent receives configuration, establishes secure connectivity, and persists local state.
- It consumes package metadata/capability information, determines whether a workload is deployable, and then coordinates deployment/update/monitoring.
- State changes are stored locally and synchronized outward, rather than keeping all truth only in memory.
8. Workload execution backends
- The sandbox supports two practical workload formats:
- Helm via shared-lib/workloads/helm.go
- Docker Compose via shared-lib/workloads/compose.go and the Docker client wrapper
- This means the runtime boundary is not “one runtime only”; the repo abstracts multiple workload substrates behind shared helpers.
9. Registry and artifact flow
- Harbor is the primary registry/repository backend described in the README and supported by scripts/harbor.
- Application packages, container images, and Helm artifacts are expected to be stored and retrieved from OCI-compatible repositories.
- The package manager and OCI helpers form the bridge between package metadata and pullable deployable artifacts.
10. Sandbox deployment targets
- helmchart/ provides Kubernetes/K3s deployment packaging for sandbox components.
- docker-compose/ provides a compose-based deployment path for local or simpler environments.
- These are environment-specific delivery layers, not core business logic.
11. Operational and bootstrap tooling
- scripts/ contains environment setup and orchestration helpers for installing/configuring core dependencies such as Docker, Go, Helm, k3s, Redis, Harbor, ORAS, and observability tools.
- scripts/easy-cli and scripts/wfm-cli.sh indicate command-line workflows for managing packages, instances, and environment configuration.
- justfile likely provides a unified developer entrypoint for common tasks.
12. Observability and telemetry
- The sandbox is designed to emit telemetry from the device/client side to external backends.
- The README identifies OpenTelemetry Collector, Promtail, Prometheus, Grafana, Loki, and Jaeger as the monitoring stack.
- In architecture terms, telemetry is a side-channel from the device agent/workload client into centralized observability services, not part of the package deployment path.
13. Security and transport
- The repo emphasizes HTTP/1.1 over TLS with server-side TLS rather than mTLS as the default secure transport model.
- shared-lib/crypto and shared-lib/http/auth provide the TLS, digest, signer, verifier, and token-related building blocks used across components.
- Client and server identity are treated as certificate-backed concerns, especially around onboarding and package/API interactions.
14. Test and sample artifacts
- poc/tests/artefacts contains sample application packages for Helm and Compose scenarios.
- These artifacts serve as integration inputs for validating package ingestion, repository flows, and deployment behavior across the sandbox.
15. Overall system picture
- The repository is centered on a control/data path where application packages are stored in a registry, discovered through Margo-aligned APIs, and deployed by a device-side agent using Helm or Compose.
- Supporting layers provide spec alignment, OCI/package management, secure transport, local state persistence, observability, and environment bootstrap tooling.
Main entry points: packageManager.go Package manager · main.go Agent main · wfm-cli.sh Bootstrap scripts · deployment.go Deployment
Components 24
shared-lib
Reusable foundation utilities shared across sandbox components.
- Archive · Archive extraction and packaging helpers.
shared-lib/archive/archiver.go - Cache · Bundle and deployment cache primitives.
shared-lib/cache/cache.go - Crypto · Digest, signer, TLS, and verifier support.
shared-lib/crypto/tls.go - HTTP auth · HTTP request and token/auth helpers.
shared-lib/http/auth/token.go - OCI utils · OCI client, image, and repository utilities for artifact flow.
shared-lib/oci/client.go - Git ops · Clone, branch, pull, and auth helpers for repository access.
shared-lib/git/client.go - Workloads · Helm and Docker Compose execution helpers plus Docker client wrapper.
shared-lib/workloads/helm.go
standard
Margo spec-aligned contract and generated API layer.
- Spec snapshot · Canonical Margo workflow-management snapshot used for code generation and traceability.
standard/snapshot.spec.yaml - Parser · Translates or interprets the spec snapshot into code-facing structure.
standard/pkg/parser.go - SBI client · Generated client/models for the spec-defined southbound interface.
standard/generatedCode/wfm/sbi/client.go
non-standard
Sandbox-enabling functionality outside the core Margo specification.
- NBI client · Generated client/models for the non-standard northbound interface.
non-standard/generatedCode/wfm/nbi/client.go - Package manager · Coordinates directory-based and OCI-backed package handling.
non-standard/pkg/packageManager/packageManager.go - Package types · Package abstractions, validation, and error/domain types for ingestion and retrieval.
non-standard/pkg/packageManager/types.go - Pkg models · Application and package state objects used by the management flow.
non-standard/pkg/models/applicationPackage.go
device agent
Standalone proof-of-concept managed-device runtime.
- Agent main · Standalone device-side agent entrypoint and local runtime configuration.
poc/device/agent/main.go - Onboarding · Initial registration and secure joining behavior.
poc/device/agent/onboarding.go - State sync · Synchronizes device and workload state outward and into local persistence.
poc/device/agent/stateSync.go - Deployment · Interprets capabilities and coordinates workload deployment/update decisions.
poc/device/agent/deployment.go - Local DB · Local JSON-backed persistence for agent state.
poc/device/agent/database/database.go - Capabilities · Device capability interpretation for deployability decisions.
poc/device/agent/device/capabilities.go
delivery
Environment-specific deployment packaging and sample artifacts.
- Helm chart · Kubernetes/K3s packaging for sandbox components.
helmchart/Chart.yaml - Compose stack · Compose-based delivery path for local or simpler environments.
docker-compose/docker-compose.yaml - Sample artefacts · Helm and Compose package samples used to validate ingestion and deployment behavior.
poc/tests/artefacts/custom-otel-helm-app/margo-package/margo.yaml
scripts
Bootstrap, environment setup, and operational tooling.
- Bootstrap scripts · Environment setup and orchestration helpers for Docker, Go, Helm, k3s, Harbor, ORAS, Redis, and observability.
scripts/wfm-cli.sh
Connections 27
- Spec snapshot → Parser: parsed by · The spec snapshot is the input to code translation and generation.
- Parser → SBI client: generates · Spec-aligned southbound client/models are produced from the snapshot.
- Parser → NBI client: generates · Non-standard API client/models are generated alongside the spec-aligned layer.
- Package manager → Package types: uses · Package manager relies on package abstractions, validation, and error types.
- Package manager → Pkg models: updates · Package handling produces and consumes application/package state objects.
- Package manager → OCI utils: pulls via · OCI-backed package handling bridges metadata to registry artifacts.
- Package manager → Archive: extracts via · Directory-based packages rely on archive extraction and packaging helpers.
- Package manager → Crypto: verifies via · Package and transport flows use digest/signing/TLS primitives.
- Package manager → HTTP auth: auth via · Package/API interaction uses HTTP token helpers.
- Package manager → Cache: caches · Package and deployment artifacts can be cached across operations.
- Git ops → Package manager: feeds · Git-backed sources can supply package material into the package flow.
- Workloads → Helm chart: deploys · Helm helpers execute chart-based workloads.
- Workloads → Compose stack: deploys · Compose helpers execute compose-based workloads.
- Agent main → Onboarding: starts · Agent bootstraps with onboarding and initial registration.
- Agent main → State sync: runs · Agent continuously syncs state with its control environment.
- Agent main → Deployment: coordinates · Agent delegates lifecycle decisions to deployment logic.
- Agent main → Local DB: persists · Agent stores local state in JSON-backed persistence.
- Deployment → Capabilities: evaluates · Deployability decisions depend on device capability interpretation.
- Deployment → Workloads: invokes · Deployment flows use shared workload adapters.
- Deployment → Package manager: consumes · Deployment uses package metadata and retrieval logic.
- State sync → Local DB: reads/writes · State synchronization is backed by local persistence.
- Onboarding → Crypto: secures · Onboarding depends on TLS and identity primitives.
- Sample artefacts → Package manager: validates · Sample artefacts exercise package ingestion and retrieval behavior.
- Bootstrap scripts → Agent main: boots · Scripts provide startup and environment wiring for the agent.
- Bootstrap scripts → Helm chart: installs · Bootstrap tooling supports Helm/K3s deployment paths.
- Bootstrap scripts → Compose stack: orchestrates · Bootstrap tooling supports compose-based local environments.
- Bootstrap scripts → OCI utils: prepares · Operational scripts install and configure OCI/registry dependencies.