Architecture
The layers of the Nx monorepo, the platforms folder, the IAM service, observability and the generator flags that switch them on.
The repo is an Nx monorepo, layered bottom-up. AGENTS.md keeps the rules an agent must follow; this page holds the detail behind them. The reasons for each choice go in stack.md and principles.md.
Layers
The order, from the bottom up, is models/ (portable schemas), then libs/ (foundation and contract machinery) and
connectors/ (isolated infrastructure adapters), then contracts/ (public service APIs) and domains/ (Mongoose
repositories), then services/ and apps/ (composition roots).
ui-libs/design-tokens (tokens.json) feeds both the web ui-libs/design-system and every Flutter app under apps/.
Its outputs are generated and never hand-edited; adding-a-mobile-app.md lists them.
models/todo-model, contracts/todo-contracts, domains/todo-domain, services/todo-service and apps/todo-ui form
the live worked example. Point a generator at it and diff against it. Do not hand-copy a real product's code. A request through it passes the rate limit, authentication and the handler, and keeps one trace id.
Platforms
platforms/<cloud>/<pkg> holds code that only makes sense on one cloud. Today there are two packages.
platforms/gcp/auth-firebaseholds the FirebaseAuthProviders built onlibs/auth.platforms/gcp/cloud-runholds the Cloud Run deploy and cleanup scripts. They are bash, not an Nx project, and build on the coredocker:buildtarget.
A platform package may import libs/, connectors/ and models/. Only services/ and apps/ import a platform, and the
core never does. The fallow platforms zone enforces this with boundary-violation: error, checked by
fallow architecture --boundaries. Keep each vendor SDK behind its own subpath export so a service that does not use it
never loads it.
IAM service
services/iam-service is the identity service. It also serves contracts/workspace-contracts (workspaces, members and
invitations), with its data in domains/workspace-domain.
- Better Auth is mounted at
/api/auththrough themountsseam oflibs/server-setup, which also merges Better Auth's OpenAPI into/docs. - IAM owns the
user,session,accountandverificationcollections. Every service shares onegentlemans-stackMongoDB database and oneMONGO_URI, so a domain owns collections, not a database. - Local Mongo is a single-node replica set because Better Auth uses transactions.
pnpm check:iam-boundaryfails when code outsideservices/iam-servicereads Better Auth's collections.
The details are in the IAM service README.
Observability
libs/observability is the OpenTelemetry layer, covering traces, metrics and logs over OTLP to the local Collector and
Grafana in LOCAL_INFRA. Its README lists the subpaths and env vars.
- A service loads it as a second esbuild entry,
src/instrument.ts, withnode --require ./instrument.js main.js. apps/todo-uistarts/webfrom the root route.- Every API is a no-op when
OTEL_SDK_DISABLED=true, which tests set.
Generator flags
deployable-service also takes --auth=dev|iam. The default is dev, the placeholder createDevAuthProvider. With iam,
callers resolve through IAM's session endpoint with createIamSessionAuthProvider, and the generator adds
<PREFIX>_IAM_URL, _IAM_TIMEOUT_MS and _IAM_SESSION_CACHE_TTL_MS.
deployable-service and deployable-web-app take --observability=otel|none. The default is otel, which adds the
dependency, src/instrument.ts, the build entry and serve flag, the Dockerfile --require, the log drain and the span
middleware. For the app it also adds the root-route start-up and VITE_OTEL_COLLECTOR_URL.
deployable-service also takes two cloud flags. Both default to none, so the core stays cloud-free.
--platform=gcp|noneadds@gentlemans-stack/auth-firebaseas a dependency and a tsconfig reference.--deploy=cloud-run|noneneeds--platform=gcp. It writesservices/<x>/cloud-run.config.shand adeploytarget that runsplatforms/gcp/cloud-run/deploy-cloud-run.sh.
There is no generator for a platforms/<cloud>/<pkg> package yet. Hand-write it like platforms/gcp/auth-firebase.