System architecture
One Go process hosts multiple logical APIM services and exposes separate public surfaces:
Microsoft SDK / ARM client API consumer / portal user | | management.azure.localhost *.azure-api.localhost | | Management API Gateway ingress | | Resource store ---- compile ----> immutable runtime snapshot | | Portal content policy pipeline | | Emulator control backend transport | protected backend APIsProcess boundaries
Section titled “Process boundaries”The default distribution is a single binary. Optional integrations run out of process only when their native runtime or security boundary justifies it:
- a future exact .NET expression worker is optional and never required by default
- external telemetry collectors remain external
- self-hosted gateway nodes may run as separate instances of the same Go binary
- portal assets are built ahead of time and embedded with
go:embed
Planned Go packages
Section titled “Planned Go packages”cmd/azure-apim-emulator process entry pointpkg/emulator embeddable test APIinternal/config flags, environment, validationinternal/clock real and controllable clocksinternal/arm ARM routing, auth, errors, paging, LROsinternal/model canonical resource and API document modelsinternal/store SQLite repositories and migrationsinternal/compiler resource graph to runtime snapshotinternal/gateway ingress, route selection, pipeline, transportinternal/policy XML model, inheritance, compilation, policiesinternal/expression lexer, parser, binder, evaluator, APIM type modelinternal/protocol REST, SOAP, GraphQL, WebSocket, gRPC, SSE, MCPinternal/portal portal data, content, revisions, publishing, authinternal/workspace isolation, references, gateways, governanceinternal/identity ARM auth, JWT, subscriptions, users, managed identityinternal/network hostnames, TLS, reachability, private simulationinternal/telemetry traces, logs, metrics, analytics, exportersinternal/operator /_emulator controls and diagnostic portal APIinternal/parity fixture normalization and comparison helpersportal/ embedded operator portaldeveloper-portal/ APIM-compatible developer portal assets and adapterse2e/ official SDK and product workflow suitesPackage ownership follows behavior, not REST file layout. Generated schema
types may live under internal/arm/spec, but generated code never owns runtime
semantics.
Runtime snapshots
Section titled “Runtime snapshots”Management writes use SQLite transactions. A successful write triggers a configuration compile:
- Read the affected service/workspace resource graph.
- Validate references and tier applicability.
- Expand policy scope and
<base />inheritance. - Compile routes, policies, expressions, backends, certificates, and limits.
- If compilation fails, keep the prior active snapshot and return the matching management error.
- Atomically publish an immutable snapshot with a monotonically increasing revision.
- Existing requests finish on their captured snapshot; new requests use the new one.
This isolates management concurrency from the hot request path and prevents partially applied policy state.
Storage
Section titled “Storage”Use modernc.org/sqlite to keep the binary CGO-free. Separate tables hold:
- ARM resource envelopes and version-specific projections
- canonical APIs, operations, schemas, products, users, groups, and subscriptions
- original API definitions and policy XML
- named values, backends, certificates, identity and authorization configuration
- portal draft content, media metadata, revisions, and published snapshots
- workspace ownership and gateway associations
- LRO records, deployment state, and ETags
- rate, quota, cache, session, trace, analytics, and fault-injection state
Secrets are encrypted-at-rest only as a local safety feature, never presented as an HSM or Azure security boundary. Tests can select an in-memory store.
Determinism
Section titled “Determinism”A shared clock drives LRO progression, subscription expiry, token validation, cache expiry, retry windows, rate and quota periods, certificate lifetime, portal reports, and telemetry timestamps. The operator API can freeze, advance, or reset it. Stable seeded IDs and keys make CI output reproducible.
Configuration surfaces
Section titled “Configuration surfaces”- environment variables and flags for process concerns
- ARM resources for Azure-compatible service configuration
/_emulatorfor test-only clock, faults, snapshots, reset, inspection, and parity capture- no emulator-only fields are inserted into Azure resource representations
Distribution targets
Section titled “Distribution targets”- native Linux, macOS, and Windows binaries for amd64 and arm64
- distroless container image
- Homebrew, winget, and
go install - Docker Compose with companion emulators and representative backends
- embeddable Go package that allocates ports and cleans up with
testing.T