Local infrastructure
Docker Compose services for local development: MongoDB (+ Mongo Express), Redis, and an OpenTelemetry Collector with Grafana.
Usage
cd LOCAL_INFRA
cp .env.example .env # optional — defaults already work
docker compose up -dOr, from the repo root: pnpm infra:up / pnpm infra:down.
Every port below is published on 127.0.0.1 only, so nothing here is reachable from the network.
- MongoDB:
mongodb://localhost:${MONGO_PORT:-27017}(root credentials from.env) - Mongo Express: http://localhost:${MONGO_EXPRESS_PORT:-8081} (basic-auth credentials from
.env) - Redis:
redis://localhost:${REDIS_PORT:-6379}(default-user password from.env) - RedisInsight: http://localhost:${REDIS_INSIGHT_PORT:-8082} (no login — the
redisconnection is preconfigured on start) - OpenTelemetry Collector: OTLP at
http://localhost:${OTEL_COLLECTOR_HTTP_PORT:-4318}(HTTP) andlocalhost:${OTEL_COLLECTOR_GRPC_PORT:-4317}(gRPC) - Grafana: http://localhost:${GRAFANA_PORT:-9300} (
admin/admin), with Tempo (traces), Loki (logs) and Prometheus (metrics)
Data lives in ./mongo-data, ./redis-data, and ./redisinsight-data, plain local directories
(not named Docker volumes) — inspect or wipe them directly. Grafana's data is the exception: the named volume
lgtm-data, because Loki fails to ingest on a macOS bind mount (docker volume rm gentlemans-stack_lgtm-data wipes it).
RedisInsight (redis/redisinsight) is free to use
but source-available under Redis's own license (SSPL), not OSI-approved open source — fine for
local dev tooling, worth knowing if that distinction matters to you.
Replica set
MongoDB runs as a single-node replica set named rs0, because transactions need one (Better Auth's adapter
uses them). The mongodb service's entrypoint writes a fresh keyfile to /data/keyfile and starts mongod --replSet rs0 --keyFile /data/keyfile; its healthcheck runs rs.initiate the first time (member localhost:27017)
and passes once the node is primary.
Existing ./mongo-data is kept. After pulling this change, run pnpm infra:up to recreate the container. The
connection URIs are unchanged: host clients connect to localhost:27017 without directConnection.
The shared database (MongoDB)
Services never use the Mongo root user. Every service shares one database, gentlemans-stack, and one scoped
application user (gentlemans_stack), provisioned by mongo/init/10-gentlemans-stack.js.
Each domain owns its own collections inside it, so a new service needs no new database or user: point its Mongo URI at
mongodb://gentlemans_stack:gentlemans_stack_local_dev@localhost:27017/gentlemans-stack. The rest of this section is for
when you really need a separate database — Mongo's
docker-entrypoint-initdb.d mechanism runs every .js/.sh
file there, in filename order, but only the first time a container starts against an empty
./mongo-data.
To add one, drop a new file next to mongo/init/10-gentlemans-stack.js,
e.g. mongo/init/20-my-service.js:
db = db.getSiblingDB("my-service");
db.createUser({
pwd: "my_service_local_dev",
roles: [{ db: "my-service", role: "readWrite" }],
user: "my_service",
});Then point the service's Mongo URI at it:
MY_SERVICE_MONGO_URI=mongodb://my_service:my_service_local_dev@localhost:27017/my-serviceThese are local-dev-only credentials committed for convenience — never reuse them outside this compose stack.
Dropping a new file into mongo/init/ does nothing on its own once ./mongo-data already has
data in it — Mongo only runs that directory the first time it initializes an empty data
directory, restarting the container included. Two ways to actually apply a new file:
-
Wipe and reinitialize (loses every database in the instance, not just the new one):
docker compose down rm -rf mongo-data/* docker compose up -d -
Apply it to the running instance instead (keeps existing data — the normal case when you're just adding one more service).
mongo/init/is bind-mounted at/docker-entrypoint-initdb.d/inside the container, so the new file is already there to run directly:docker compose exec -T mongodb mongosh -u root -p root-local-dev --authenticationDatabase admin \ --quiet /docker-entrypoint-initdb.d/20-my-service.js
Adding a scoped user for a new service or app (Redis)
Redis's official image has no docker-entrypoint-initdb.d equivalent, and there's no per-database
isolation to lean on the way Mongo has separate databases — a Redis instance is one flat keyspace,
even in clustered mode. So the pattern here is: give each service its own
ACL user, scoped by
key prefix instead of by database, defined in its own file under redis/acl.d/. The container's
entrypoint concatenates every *.acl file there (plus a default user built from
REDIS_ROOT_PASSWORD) into one ACL file on every start — unlike Mongo's init scripts, this isn't a
one-time bootstrap, so adding a file just needs a restart, not a wiped volume.
To add one, drop a new file next to
redis/acl.d/10-todo-service.acl, e.g.
redis/acl.d/20-my-service.acl:
user my_service on >my_service_local_dev ~my-service:* &my-service:* +@all -@dangerousThen point the service's Redis URI at it, keeping every key it writes under that same prefix
(my-service:*) — the ACL will refuse anything outside it:
MY_SERVICE_REDIS_URI=redis://my_service:my_service_local_dev@localhost:6379Same rule as Mongo: these are local-dev-only credentials committed for convenience, never reused outside this compose stack. After adding or editing a file:
docker compose restart redisTelemetry (traces, metrics, logs)
Every service sends OTLP to the Collector (otel-collector/config.yaml), which redacts credential headers and query
strings from spans and forwards to Grafana LGTM (grafana/otel-lgtm). Services never talk to Grafana directly, so
switching backend means editing the Collector config: it has commented exporter blocks for Google Cloud and Grafana Cloud.
- Start it:
pnpm infra:up, run a service, open Grafana, Explore, pick Tempo, Loki or Prometheus. - The Services dashboard (
grafana/dashboards/services.json) is provisioned on start: request rate, p95 duration, status codes, auth failures, invitations accepted. - A log line and its trace share a
trace_id: in Loki, the line's trace id links to the trace in Tempo. - Browser telemetry:
apps/todo-uisends traces, web vitals and errors to the Collector's HTTP receiver (VITE_OTEL_COLLECTOR_URL,http://localhost:4318). That receiver is public by nature: it holds no credentials, accepts CORS only from the origins underreceivers.otlp.protocols.http.cors.allowed_origins(add your deployed UI origin there), and thetransform/redactprocessor strips query strings again on the server, so a client that skips the browser-side filter still cannot store a token. - No rate limit at the Collector:
otel/opentelemetry-collector-contrib0.166 ships onlymemory_limiter(it sheds load when memory is high, it does not limit per client). In production, put the OTLP/HTTP port behind a reverse proxy or load balancer that rate-limits per IP (for example nginxlimit_req, Cloud Armor or a Cloudflare rule) and cap the body size.