A reference architecture for self-hosted product platforms. It is a monorepo where every reusable decision is already made. Each decision is recorded in an ADR, and a machine enforces it.
Fork it, generate from it, or read the ADRs and ignore the code. All three are valid uses.
The stance, in three lines:
- The menu is omakase. The stack is decided in advance. You start at
build features, not atpick tools. - A paved road, with exits. You can deviate, and the deviation is documented. It must be on purpose.
- Machines enforce it. Rules are admission policies, type checks, and drift checks. Review is the fallback, not the mechanism.
This template ships one profile and documents three neighbours.
| Profile | You are here if | Style | Data | Deployables | Platform floor | What platform work looks like |
|---|---|---|---|---|---|---|
modular-monolith |
No decomposition force applies. See the next section | Modular monolith | one database | 1 | whatever the provider runs for you | nobody's job. The provider operates it |
service-based |
Teams block each other on deploys, and a shared database is still acceptable | Service-based | services share a database | usually 3 to 8 | a few components, on managed foundations | part of a backend role |
microservices |
Services must change their data without coordination, so each service owns its data | Microservices | each service owns its data | often 15 or more | large, but still on managed foundations | a standing responsibility that a named person owns |
sovereign, this repo |
Self-hosting is binding, not preferred | Microservices | each service owns its data | often 15 or more | everything, and it is fixed for any service count | a primary responsibility, and it never rests on one person |
ADR-0000 sets the positions. docs/operational-surface.md is the component inventory of this repo, and it is the only place where components are counted.
These are not maturity levels. For most systems, a modular monolith is a correct final state. Higher rows are more expensive answers to pressures that you may not have. Richards and Ford treat architecture styles as risk profiles rated against characteristics, not as a ladder.
This repo implements sovereign. The other three rows are positions, not presets to generate. A project at one of them does better with a smaller template. For modular-monolith, that is nextjs-mvp-template, with the same conventions at that scale.
The service count is an outcome, not a target. Each force alone justifies a boundary. If no force applies, build a modular monolith.
| # | Force | Test |
|---|---|---|
| 1 | Independent deploy cadence | Two parts must ship without a coordinated release |
| 2 | Number of teams | Teams block each other. This is Conway's law: it counts teams, not headcount and not features |
| 3 | Failure isolation | The failure of one part must not take another part down, as a stated requirement |
| 4 | Resource heterogeneity | Truly different scaling profiles: CPU, IO, or memory |
| 5 | Technology heterogeneity | A part must run on another runtime, such as ML in Python or chain code in Rust |
| 6 | Compliance boundary | Data residency or audit scope is cheaper to enforce by structure than by policy |
The product category, such as fintech, B2B SaaS, or marketplace, decides almost nothing. Two products in one category often sit at opposite ends of every axis. These three axes decide almost everything:
| Axis | Question | Range | This repo |
|---|---|---|---|
| A: Decomposition pressure | Must parts ship, scale, or fail independently | from monolith to many services | high |
| B: Operational sovereignty | Who is permitted to run it | from managed, through hybrid, to self-hosted | maximum |
| C: Correctness stakes | What a wrong answer costs | from cosmetic, through transactional, to regulated | high |
Axis B is the choice that makes this repo different. Most reference architectures at this position on A and C assume managed services underneath. This one does not. That single decision creates more of the machinery here than A and C together.
Need decides what you build. Capacity decides what you can run. The gap is your risk.
Team size is a budget, not a design driver. It tells you only whether you can operate what you have.
What sovereign costs to run:
- An always-on platform floor of about two dozen components: gateway, GitOps, identity, authz, workflow, data, storage, observability, registry, forge, and outbound mail.
docs/operational-surface.mdis the inventory. - Platform work as a primary responsibility, not a rotation. A rotation optimises for the incident in front of it. The real cost of this floor is the upgrades and drills that nothing forces you to do this week. This is the most common way a self-hosted platform decays.
- No Core component whose only competent operator is one person. The floor stays operable through a departure and an absence at the same time.
This repo states no headcount, and you should not infer one. The answer depends on your coverage hours, your operational skill, and your tolerance for detection latency. docs/operational-surface.md has the recurring obligation and the failure-response requirement of every component. Sum that against your own facts, and you get your number, not ours.
If the number is higher than what you have, read docs/adoption-path.md. It is the ranked list of what to give up, and in what order.
Building it with an LLM changes the authoring cost and nothing else. Generating a service, a chart, or a migration is now cheap. This moves the bottleneck, and it does not remove it:
- The operational surface does not change.
- Coherent review gets harder as the volume of generated change grows. A reviewer must know that a generated change agrees with the twenty decisions it touches.
The ADRs, the Rules sections, and the requirements of each service exist partly for this reason. They are the constraint that an agent must follow when nobody has time to work out the reasons again.
Fewer services make the platform relatively heavier. The floor is fixed. So with a few services, the ratio of application work to platform work is about 1:1, and the case for austerity is stronger.
Not everything here ships at once. Capabilities are deferred behind a hard trigger: an observable condition, never when we grow. A deferral without a trigger is temporary, and ADR-0000 forbids that.
A deferral is safe only when a seam exists. A seam is a pre-built slot where the capability fits in without restructuring:
- Full: the seam exists. Adoption is additive. Deferral costs nothing but the wait.
- Partial: no full seam exists. Adoption is structural. This is a bet, not a deferral. Adopt earlier, or accept a rewrite later.
| Capability | Trigger | Seam | Tier |
|---|---|---|---|
| Ory Hydra, the OAuth2 server | A public API or an external machine client exists | Full: behind a flag. The internal request shape does not change | Opt-in |
| Mimir, for metrics at scale | Prometheus needs multi-tenancy, HA, or long retention | Full: the same query API. Dashboards and alerts move unchanged | Scale |
| Tail sampling | Trace volume makes head sampling lose data | Full: services only emit to localhost:4317 |
Scale |
| Loki and Tempo microservices mode | The ingest volume of a single backend needs it | Full: the same storage and the same API | Scale |
| Rust or Python service | A measured shortfall of Go, or a need for an ecosystem native to that runtime | Full: contracts are HTTP with OpenAPI, not shared code | Opt-in |
| Storybook | A second frontend app, or a design-system maintainer | Partial | Opt-in |
| Service mesh | A measured need that Cilium with WireGuard cannot meet | Partial: mTLS is covered, and policy for each request is not | Scale |
| Escalation and paging | An on-call rota exists | Partial: no credible self-hosted escalation layer exists. Alertmanager does the routing, and a hosted service does the paging, per 0502 | Opt-in |
A deferral on purpose, with the trigger written down, is the last responsible moment applied to architecture. It is not the same as an open decision.
- No decomposition force applies. Use
modular-monolith. This is the common case. - Platform work would be a rotation, not someone's primary job. The floor is heavier than its component count suggests. Read
docs/adoption-path.mdbefore you adopt. Move down axis B on purpose. Do not find the gap during an incident. - Managed services are acceptable to you. Much of this repo solves a problem that you do not have.
- Correctness stakes are low. The typing, contract, and policy discipline here is priced for systems that handle money. For you, it will feel like friction.
Axis B is an axis, not a test of virtue. A smaller team should sit lower on it, on purpose. That is a better answer than to adopt the self-hosted floor and hope.
Axis B is also the axis that this template is least coupled to. A move down it swaps operators, not architecture. A managed swap does not change:
- the ADRs
- the OpenAPI contracts and codegen
- the service template
- the Helm and GitOps trees
- policy-as-admission
- the repo layout
- the release flow
- the local dev loop
docs/adoption-path.md is the canonical ranked order of swaps. It has three bands:
- deferrals, which cost only the wait
- managed swaps, which cost sovereignty
- capability concessions, which are bets
Each row has a restore trigger and a cost to reverse. The document also marks the line past which a project runs a different platform.
A hybrid position is legitimate and common. Self-host the orchestrator and the stateless platform. Use managed Postgres, object storage, email, and paging. This removes most of the pager load. It keeps the parts that were usually the reason for self-hosting.
Ten principles decide every entry in the stack table below. A principle must pass one test to be on this list:
A principle earns its place only if it has rejected something we wanted.
A principle that cannot name a casualty is a statement of virtue, not a criterion.
Each principle is anchored to an external standard. Where no standard applies, it is marked local. A borrowed criterion survives a new debate, and a house rule gets argued again every year. ADR-0000 has the full reasons.
Selection: how a tool gets in:
| # | Principle | Anchored to | It rejected |
|---|---|---|---|
| 1 | Configuration lives in the repository, not in the component | OpenGitOps principles 1 and 2, extended one level out | SigNoz, OpenObserve, Coroot, Zitadel |
| 2 | The always-on floor is the budget, measured in concerns | Team Topologies, with cognitive load as the unit, applied to operators and not to users | GitLab CE, Coroot, a second CI system |
| 3 | Operational sovereignty: run it yourself | axis B, above | every managed service |
| 4 | Spend novelty by exit cost, not by taste | Innovation tokens | Garage, Encore |
| 5 | One primitive per concern, with no parallel mechanisms for one problem | local. It follows from principle 2 | Woodpecker, Tekton, Argo Workflows |
| 6 | Two languages, and no ambient runtime | 12-Factor II: never relies on implicit existence of system-wide packages. The two-language cap itself is local | Semgrep and sqlfluff, which both need Python |
| 7 | No adoption without a recorded comparison | local. It is principle 4 applied to the record, and 0002 sets the depth | the process gate for all of the above |
Construction: how the system is built once a tool is in:
| # | Principle | Anchored to | It rejected |
|---|---|---|---|
| 8 | Local-prod parity at the manifest and API layer | 12-Factor X: resists the urge to use different backing services between development and production | Docker Compose, which is a second definition of the system |
| 9 | Generated code is committed and drift-checked in CI | local. It is principle 1 applied to generated artifacts | codegen at runtime or at deploy |
| 10 | Service boundaries are HTTP with OpenAPI. Never shared code, and never a shared database | Fowler, IntegrationDatabase: integration databases should be avoided | shared libraries and shared schemas as coupling |
Read principle 4 twice, because people often misread it as conservatism. Be adventurous where abandonment costs days: CI, query layers, registries, and policy engines. Be conservative where it costs months and customer data: storage, databases, and the message bus. Talos, Kyverno, and zot all sit on the cheap-exit side of that line. SeaweedFS and CNPG sit on the expensive side, and they were chosen with that in mind.
Every row is a decision recorded in an ADR, with a comparison against the alternatives and the trigger that would open it again. A tool with no recorded comparison is an assumption, not a decision.
Every tool here also has a row in docs/tool-register.md. The row has its exit-cost tier, licence, governing body, and the alternatives it was recorded against.
| Concern | Current decision | ADR |
|---|---|---|
| Backend language | Go | 0110 |
| Frontend | Next.js and TypeScript on Node.js, one app with route groups | 0110, 0400 |
| Design system | shadcn/ui, vendored as source, on Tailwind, with the brand in one token file |
0400, 0701 |
| Toolchain | Nix with flakes, through the tabkit module | 0100 |
| Custom rules and generators | tabkit, configured in .config/tabkit.toml |
0104 |
| Task runner | just |
0103, 0111 |
| Machines | Talos Linux, configured by machine config | 0200 |
| Cloud resources | OpenTofu, for each project. Skipped where the infrastructure is provided | 0200 |
| Cluster | upstream Kubernetes on etcd in every tier, on kind for both local tiers | 0200, 0600 |
| Deploy | Argo CD, the only mechanism. One shared Helm chart, with values for each environment | 0201 |
| Network and policy | Cilium with Hubble, WireGuard, default-deny | 0206 |
| Policy enforcement | Kyverno at admission, PSA restricted, CiliumNetworkPolicy, CI lints |
0203 |
| Resource governance | LimitRange, ResourceQuota, PriorityClass, PDB | 0204 |
| Edge | Traefik, Ory Oathkeeper, and cert-manager | 0305 |
| Identity and authz | Ory Kratos and OpenFGA. Hydra when a public API exists | 0304 |
| Trust tiers | product apex, and *.ops.<host> for operator tooling |
0306 |
| Secrets | SOPS and age, decrypted in the cluster by an operator | 0202 |
| Database | PostgreSQL on CNPG. sqlc, dbmate, sqruff | 0300 |
| Object storage | SeaweedFS everywhere. In prod it runs outside the cluster with Object Lock | 0207, 0205 |
| Workflows | self-hosted Temporal, versioned workers | 0302 |
| API contract | hand-written OpenAPI 3.1. ogen, openapi-typescript, vacuum, oasdiff | 0303 |
| API mocking | Prism, vendored, from the committed projection | 0600 |
| Observability | OpenTelemetry into Grafana, Loki, Tempo, Prometheus, Pyroscope | 0500 |
| Operator UIs | Grafana funnel, Hubble UI, Headlamp | 0501 |
| Alerting | Prometheus rules and Alertmanager. Escalation goes to a hosted service | 0502 |
| Error tracking | OTel exceptions with a computed error.fingerprint. No separate product |
0503 |
| Source control and CI | Forgejo and Forgejo Actions, entered through just ci:*. A provider-hosted forge is the bootstrap path |
0116 |
| Supply chain | cosign with a key pair held in SOPS, syft SBOM, SLSA provenance, Trivy as a merge gate | 0113 |
| Registry | zot, one instance for each environment, backed by object storage | 0114 |
| Testing | Playwright, k6, go test, Vitest |
0601 |
| Internal admin | Lowdefy over the service APIs. pgweb, read-only | 0401 |
| Analytics | Faro events into a first-party service | 0700 |
| Dependency updates | Renovate, grouped, with digest pinning | 0117 |
| Making and updating a project | nix flake new -t and just init. A coding agent applies a later release with template/UPDATE.md |
0117 |
# A new project
nix flake new -t github:tabmadi/sovereign-platform-template my-platform
cd my-platform && git init && git add -A
nix develop # the pinned toolchain from flake.lock, and the git hooks
just init # seven questions: names, forge, and provisioning
just bootstrap # dependencies, .env, and the SOPS keys
just secrets-age # your age key, per ADR-0202
# Local cluster: the same charts as production, on two tiers
just cluster-up # the floor: edge, identity, Postgres, mocks
just cluster-up full # the whole platform, driven by Argo CD, with observability
# Inner loop on one service: a native process, no image build
cd services/catalog
just serverThe full walkthrough is docs/dev-loop.md.
With Nix, run the first block above, then follow these steps:
nix flake new prints a command that writes the exact template commit into .template-version. Run that command first.
-
Run
just init. It asks seven questions, renames the project, applies the setup modes, and removes theA new copyline ofAGENTS.md. -
Run
just bootstrap, thenjust genandjust check, and commit. -
Rewrite this README for the project.
-
Update the contacts in
.github/SECURITY.mdand the copyright line inLICENSE. -
On GitHub, set the squash merge message to the pull request title, with no body, and turn off the other merge styles:
gh api -X PATCH repos/OWNER/REPO -f squash_merge_commit_title=PR_TITLE -f squash_merge_commit_message=BLANK -F allow_merge_commit=false -F allow_rebase_merge=false
On Forgejo,
just initwrites.forgejo/default_merge_message/SQUASH_TEMPLATE.md, which sets the message. -
Run Renovate from its workflow, per ADR-0117, and keep
.template-versionfor the next update.
The button copies every file, the template/ folder included. Its first commit, Initial commit, is not a Conventional Commit, and it can start workflows while the copy still has the old names.
-
Clone the new repository, and run
nix developin it. -
Record the template commit of this copy, then run
just init:created=$(TZ=UTC git log --max-parents=0 --format=%ad --date=format-local:%Y-%m-%dT%H:%M:%SZ HEAD) gh api -X GET repos/tabmadi/sovereign-platform-template/commits -f sha=master -f until="$created" -f per_page=1 --jq '.[0].sha' >.template-version just init
-
Replace the first commit of GitHub. This is safe before anyone else clones the repository:
git add -A git commit --amend -m "chore: start from <template> <release>" git push --force-with-lease -
Follow the steps above from step 2.
services/<name>/ Go service: OpenAPI contract, server, worker, sqlc, migrations
apps/frontend/ one Next.js app, with the route groups landing, panel, analytics, and devportal
apps/admin/ Lowdefy YAML for internal admin
libs/go/<name>/ shared Go packages: observability, middleware, errors
libs/{go,ts}/sdks/ generated OpenAPI clients, committed and drift-checked in CI
infra/helm/ the shared service chart, and the platform component charts
infra/gitops/ Argo CD Applications and the values for each environment
infra/talos/ machine configs
infra/opentofu/ provisioning, where the project owns its infrastructure
docs/adr/ the decisions, and the reasons for them
These conventions are not negotiable for each service. 0111, 0300, and 0303 depend on them. A deviation needs a new ADR.
A small example that uses every mechanism once. It is not a realistic product.
| Service | Demonstrates |
|---|---|
orgs |
Kratos identity, B2B multi-tenancy, and OpenFGA ReBAC |
catalog |
Plain CRUD: contract, handler, sqlc, migrations, observability |
orders |
A Temporal checkout saga that calls catalog and payment over HTTP |
payment |
A child workflow with idempotency and compensation |
Build real services from services/_template/.
- ADRs: every load-bearing decision, with a comparison against the alternatives and the trigger that would open it again. Start at ADR-0000.
docs/adr/README.mdhas the block map and the full index. - ADR-0001: the rules for these documents. It covers density, banned constructs, section order, and the same rules for code comments.
- Rules sections: each ADR ends with flat, greppable normative statements. They are written so that humans and LLMs apply them the same way.
- Requirements: what each service must do, in
services/<name>/requirements.md, and what each journey across services must do, indocs/requirements/. Every requirement has an ID that a test cites, and CI checks the trace, per ADR-0602. - Fitness functions: machines enforce rules wherever possible, through admission control, type checking, drift-checked codegen, and static analysis for architectural invariants. A rule that a machine enforces names its mechanism, per ADR-0001.
This template borrows its framing:
- Richards and Ford, Fundamentals of Software Architecture: architecture styles rated against characteristics as risk profiles. This is the source of the profile table above, and of the term service-based architecture.
- Team Topologies: cognitive load as the sizing unit. Here it applies to the people who run the platform, not to the people who build on it.
- DORA and Accelerate: capability models instead of maturity ladders.
- Ford, Parsons, and Kua, Building Evolutionary Architectures: fitness functions.
- Poppendieck, Lean Software Development: the last responsible moment.
- Feathers, Working Effectively with Legacy Code: seams.
- Fowler, MonolithFirst and MicroservicePremium: the prerequisite bar for decomposition.
- 12-Factor, Choose Boring Technology, and the CNCF Platforms White Paper.
This repo is closest to the genre of the internal engineering handbook. Examples:
- the paved road of Netflix
- the account by Monzo of running a bank on a large set of services
- the writing by Shopify on decomposition
The term paved road at the top of this file comes from Netflix.
They are better than this repo at the one thing a template cannot fake: operational narrative. Each one is written by a team about a platform it has run at scale for years. So real events back the reasons: outages that happened, migrations that went badly, and decisions that were reversed. That evidence is the most valuable part of the genre, and none of it is here.
This repo offers the falsifiable half instead. Every decision states what it was compared against, what would open it again, and how it is enforced. docs/reference/ combines the decisions into the numbers they add up to, and this includes the unflattering numbers. Read the handbooks for what happens when a platform meets reality. Read this repo for the record of what was chosen and why. You can argue with it before you own the consequences.
- It is a template, not a product. Fork it and own your copy. There is no support channel and no compatibility promise.
- A project takes a later release through a coding agent that follows
template/UPDATE.md, andjust cidecides. - Disagreement is expected. The ADRs record the reasons so that you can overturn a decision on purpose, not by accident. If a comparison table is wrong, that is the most useful issue you can open.
Apache License 2.0. See LICENSE.