Layered Pyramid & Invariants
The Krewire codebase is governed by non-negotiable architectural invariants across all packages and workloads. They are enforced by tests, not by convention.
1. The Ecosystem Architectural Battery
The entire Krewire ecosystem flows through a unified architectural battery progression:
Go Stdlib โโโบ Krewire Libraries โโโบ Krewire UI | Krewire Auth | Krewire Krew โโโบ Krewire Cloud โโโบ Krewire Dash
(Unified Workspace)
Every stage in this progression is driven and composed through the kiw developer CLI and configured declaratively via krewire.yaml.
2. The Ecosystem Pyramid (Strict Downward Dependencies)
Seen from the whole ecosystem, every repository sits on one layer of a pyramid (source: krewire/docs/foundation/ecosystem-dag.md):
Layer 5: Unified Studio & Apex Portals Dash (virtual workspace) ยท krewire.com ยท krewire.github.io
โ
Layer 4: Platform Engines & Cloud Cloud (PaaS) โฅ Auth (IAM / SSO) โฅ Krew (AI agent)
โ
Layer 3: Universal Developer Driver & CLI krew (kiw) driven by krewire.yaml
โ
Layer 2: UI Foundation & Domain Libraries kui (.kiw components) ยท pkg/* (web, orm, sec, โฆ)
โ
Layer 1: Core Foundation & Kernel pkg/model ยท pkg/errs ยท pkg/version ยท pkg/lifecycle
โ
Layer 0: Go Standard Library & OS Primitives
- Strict downward-only: a layer may import only layers below it (
Layer N โ Layer < N). Upward imports are forbidden and caught bylayering_test.go. - Kernel isolation:
pkg/modeldepends only on the standard library andpkg/errs. - CLI encapsulation: no library or platform package may import
kiw(krew). Generated user projects depend on Krewire libraries, never on the CLI.
3. Inside the Core Repository
Zooming into github.com/krewire/krewire, the same idea is applied as a ranked ladder of packages (source: krewire/docs/foundation/architecture.md):
| Layer | Contents | May import |
|---|---|---|
| 5 | Scaffolding blueprints (templates/*) |
Layers 0โ4 |
| 4 | Developer tooling (krew) |
Layers 0โ3 |
| 3 | Domain libraries (pkg/web, pkg/sec, pkg/orm, pkg/ui, โฆ) |
Layers 0โ2 and sibling domain packages, acyclically |
| 2 | Execution & supervision (pkg/lifecycle, pkg/env, pkg/log) |
Layers 0โ1 |
| 1 | Declarative core (pkg/errs, pkg/model, pkg/version) |
Standard library (model, version may import errs) |
| 0 | Go standard library | โ |
Five invariants keep this ladder honest:
| # | Invariant | Enforced by |
|---|---|---|
| 1 | Downward-only directionality โ every import edge goes to a lower layer, or stays acyclic inside Layer 3. | TestFoundationLayering, TestUIDoesNotImportWeb in layering_test.go |
| 2 | Base floor โ pkg/errs imports only the standard library; model and version add only errs. |
pkg/errs/dependency_test.go, pkg/model/dependency_test.go |
| 3 | No upward names โ foundation packages contain no string literals naming higher packages. | TestFoundationNamesNoHigherPackage |
| 4 | Hermetic core โ pkg/model has no third-party or other Krewire imports. |
TestModel_StdlibBoundary |
| 5 | Tooling isolation โ nothing under pkg/ or templates/ imports krew. |
TestPackagesNeverImportKiw |
4. Peer Decoupling & the Bridge/Gateway Pattern
Components on the same layer are peers and stay laterally independent:
- Zero peer coupling: parallel products (
dash,cloud,auth,krew) never import each other's Go packages or private source trees. - Bridge & gateway mediation: communication between peers, or with the horizontal capabilities, goes through standard interfaces:
- API gateway / reverse proxy for HTTP and gRPC traffic with per-route authorization and rate limiting.
- Federated identity โ OpenID Connect, OAuth 2.0 bearer tokens, and public JWKS validation, with no shared database credentials.
- Event bus / SSE streams for asynchronous notifications.
- No mandatory coupling: hosted
cloudandauthare never prerequisites;dashruns self-hosted without them.
The Ecosystem DAG page lists the module edges that actually exist between the repositories today.
5. Single Source of Truth (SSOT)
A value the ecosystem must agree on is declared once, in the package that owns it:
- Banned: copying literal tables or constant lists into multiple files.
- Banned: re-deriving ordering logic that already has a canonical resolver.
- Banned: duplicating version strings in Markdown when they are declared in code.
- Required: one owner per fact; export the resolver instead of re-implementing it in consumers.
6. Pure Go (CGO_ENABLED=0)
Every library and workload binary must cross-compile to Linux, macOS (darwin/arm64), and Windows (windows/amd64) without a C toolchain. CI checks this with CGO_ENABLED=0 go build ./.... When an application needs a database driver, choose a pure-Go one โ the fullstack tutorial uses modernc.org/sqlite for exactly this reason.
Next: 11.2 Ecosystem DAG โ