Layered Architecture Across Languages
This is the hub doc for Coding Standards — it documents how every service or client app is layered internally, once ADR-00010 has decided which language it’s built in. The concrete rulebook for any one language/framework lives in its own doc below; this page covers only what’s genuinely shared across all of them.
- Cross-Cutting Principles Across Languages
- Coding Standard: Go
- Coding Standard: Rust
- Coding Standard: Node (NestJS)
- Coding Standard: Flutter (ui-application)
- Coding Standard: React (ui-admin-application)
- Coding Standard — Deployment & Local Infrastructure
- Coding Standard — Audit Trail (Pub/Sub → document-service)
This page covers the folder-layering shape only. How logging, exception handling, tracing, metrics, and security are each enforced identically in spirit across every language — a different, equally cross-cutting concern — is documented separately in Cross-Cutting Principles Across Languages, so neither page duplicates the other.
Layered architecture — the same shape, three backend languages
Every backend service (Go, Rust) organizes by feature first, layer second — a new feature adds one file per layer under its own feature name, never a new top-level layer. Node follows the same idea through its own NestJS module structure. A feature with no gRPC surface simply has no transport/grpc/<feature>/ directory, rather than an empty placeholder.
| Layer | Owns | Go | Rust | Node (NestJS) |
|---|---|---|---|---|
domain/<feature> |
Pure business types, one file per aggregate | internal/domain/<feature>.go |
domain/<feature>.rs |
<feature>/<feature>.entity.ts |
domain/<feature>_validation |
Validation logic — always its own file, never inline in the domain type file | internal/domain/<feature>_validation.go |
domain/<feature>_validation.rs |
<feature>/<feature>.validation.ts |
repository/<feature>/ |
Every outbound I/O call — database, gRPC client, or third-party HTTP API — split into entity + mapper + interface + implementation | internal/repository/<feature>/ |
repository/<feature>/ |
<feature>/<feature>.repository.ts |
service/<feature>/ |
Business orchestration; interface + implementation | internal/service/<feature>/ |
service/<feature>/ |
<feature>/<feature>.service.ts |
transport/api/<feature>/ |
REST controller + api-model + mapper | internal/transport/api/<feature>/ |
transport/api/<feature>/ (Axum) |
<feature>/<feature>.controller.ts |
transport/grpc/<feature>/ |
gRPC server + DTO mapper | internal/transport/grpc/<feature>/, composed from @templates/go-grpc-microservice/ |
transport/grpc/<feature>/ (Tonic) |
— (no Node gRPC template in this monorepo yet) |
message_publisher/ / message_receiver/ |
Pub/Sub publish/receive, one flat file per event type | internal/message_publisher/<event>.go |
message_publisher/<event>.rs |
message/* (NestJS) |
Per-language file-naming/DI specifics, testing conventions, and language-specific gotchas live in each language’s own doc linked above, not repeated here.
Roles & responsibilities by language/framework
| Language / Framework | Where it’s used | What it’s responsible for |
|---|---|---|
| Go | 9 microservices — domain/CRUD services plus the Temporal workflow host (order-service) |
I/O-bound CRUD, aggregation, and fan-out joins; the platform’s only workflow-orchestration runtime. |
| Rust | 8 microservices — encryption-at-rest stores and gateway-facing auth verification | Memory-safe handling of secret material (PII/PCI plaintext, signing keys) and hot-path token/App-Check verification. |
| Node (NestJS) | 2 microservices + 1 Firebase Function runtime | Event/pipeline orchestration — bulk CSV verify→execute→publish, migration consume→dispatch, GCS-trigger→Pub/Sub. |
| Flutter | ui-application |
Customer-facing mobile storefront, one codebase for iOS and Android. |
| React + MUI + Zustand | ui-admin-application |
Tenant/admin management console — CRUD-heavy dashboards and wizards. |
Common coding patterns — enforced in all three backend languages
- Domain object (DTO) parameter pattern. A service method never takes multiple positional scalar parameters — a single domain object crosses every layer boundary (
transport → service,service → repository), in Go, Rust, and Node alike. - Validation always lives in its own file.
domain/<feature>_validation.*is a separate file fromdomain/<feature>.*in every template — never inline in the domain type’s own file. - Entity/mapper split by default.
repository/<feature>/splits into entity + mapper + interface + implementation; only a genuinely 1:1 shape (persisted entity fields identical to domain fields) may collapse the mapper into the entity file, and only when that template’s ownCLAUDE.mdsays so explicitly. - Typed errors, never hand-rolled.
pkg/utils/errors/(Go), theerrormodule’sAppError(Rust),core/errors.js(Node) — nevererrors.New()or an ad hoc thrownError. - Context/tracing handle through every boundary.
context.Context(Go), the tracing span/request-scope (Rust),AsyncLocalStorage-backed request context (Node) — see Cross-Cutting Principles Across Languages. - No over-engineering. No extra abstractions, error handling, or features beyond what the task requires — trust internal code and framework guarantees, validate only at system boundaries.
- Repository wraps every outbound call, including third-party APIs. A payment gateway or courier API integration is wrapped behind
repository/<provider>/exactly like a database or gRPC dependency —service/never holds a raw HTTP client. See Microservices — shipment-service and Microservices — payment-service for the two reference “External API integrations” implementations. - One repository method per provider endpoint. A third-party integration never gets one aggregate method that internally sequences several HTTP calls — orchestration/sequencing belongs in
service/, notrepository/.
Mandatory audit fields — every table and collection, no exceptions
Every MongoDB collection and every PostgreSQL table carries the same five columns, regardless of which backend language owns it:
| Column | Type | Set on |
|---|---|---|
tenant_id |
VARCHAR/TEXT |
Insert only |
created_user_id |
VARCHAR/TEXT |
Insert only |
updated_user_id |
VARCHAR/TEXT |
Insert + every update |
created_at |
TIMESTAMPTZ |
Insert only |
updated_at |
TIMESTAMPTZ |
Insert + every update |
tenant_idandcreated_user_id/updated_user_idalways come from the request’s auth context (auth.GetTenantID/auth.GetUserIDin Go,AuthClaims/HeaderAuthClaimsin Rust,req.tenantId/req.userIdin Node) — never from the request body.tenant_id,created_user_id, andcreated_atare set once, on insert, and never overwritten afterward.- Every update statement sets
updated_user_idandupdated_at— an update that touches a row without refreshing both of these is incomplete.
This is the concrete, row-level mechanism behind the platform-wide multi-tenancy rule below — it’s how TenantID actually ends up attached to a persisted record, not just passed through in transit.
Client-app feature triads
Both client apps organize each screen/feature as a fixed triad of small files, wired top-down — the shared idea, not a shared spec:
Flutter (ui-application, GetX) |
React admin (ui-admin-application, MUI + Zustand) |
|
|---|---|---|
| 1 | Binding — declares dependencies for the page lifecycle | <Feature>Types.ts — feature-scoped interfaces, no logic |
| 2 | Controller — business state, reactive streams, page logic | <Feature>Repository.ts — the only file that imports apiClient |
| 3 | View — pure declarative UI tree consuming controller state | <Feature>Service.ts — pure functions, data mapping, no React |
| 4 | Service (optional) — business logic beyond one repository call | <Feature>Controller.ts — a custom hook doing state orchestration |
| 5 | — | <Feature>Page.tsx — stateless JSX, calls the controller |
Full detail on each — the shared-controller tag gotcha, the authStore-propagation direction rule — lives in the Flutter and React docs linked above.
Tools integration by layer
| Tool | Integrates at | Mechanism |
|---|---|---|
| OpenTelemetry (tracing) | Every service/repository boundary | otel.WithSpan[T] (Go), #[tracing::instrument] (Rust), runWithRequestContext (Node) — see Cross-Cutting Principles Across Languages. |
| OpenTelemetry (metrics) | Server entrypoints, DB pools | http.server.request.duration/rpc.server.request.duration histograms, DB pool gauges — see Cross-Cutting Principles Across Languages. |
| Pub/Sub | message_publisher//message_receiver/ |
Shared envelope (tenant_id, correlation_id, traceparent) via each core lib’s pubsub module — see Coding Standard — Audit Trail for the audit-event publisher instance of this pattern. |
| gRPC | transport/grpc/<feature>/ |
@templates/go-grpc-microservice/, composed file-by-file, never merged into a combined starter kit. |
| Temporal | order-service only |
Go’s official SDK — the reason the checkout saga is hosted in Go, per ADR-00010. |
| Firebase Auth / App Check | Gateway edge (user-secure-engine) |
JWKS verification, AuthClaims header contract propagated to every downstream service — see Cross-Cutting Principles Across Languages. |
| Shared core libs | Every layer, every language | go-lang-core-lib / rust-lang-core-lib / node-lang-core-lib — never re-implement a capability the owning core lib already provides (see Coding Standard: Go, Coding Standard: Rust, Coding Standard: Node). |