28 KiB
Local deployment and Compose
This guide describes the checked-in configuration. Compose provides a local technical stack; it does not establish a production deployment.
Core application
Install Docker Engine and the Docker Compose plugin. At the repository root, copy .env.example to .env, replace every placeholder password, and keep the file local. Then run:
make -C deploy config
make -C deploy up
deploy/docker/docker-compose.yml starts PostgreSQL, Redis, SeaweedFS, Kafka, the Go backend, and the frontend container. Nginx in the frontend container serves static assets and proxies /api to Go. PostgreSQL, Redis, SeaweedFS, Kafka, Go, and Nginx communicate on the Compose network.
Before it opens its listeners, the backend applies the database migrations embedded in its binary; a migration error stops the container. Compose does not pass DATABASE_MIGRATE_ON_START, so the deployed backend always migrates at startup, and the PostgreSQL role in DATABASE_URL needs DDL rights on the application schema. That flag is a local development option; a separate least-privilege migration role is future work. Right after the migrations, and only when they run, the backend seeds the demo product policy: when the product policy family has no version, it publishes version 1 and logs demo product policy published; otherwise it logs that the seed was skipped and changes nothing. With DATABASE_MIGRATE_ON_START=false the seed is skipped too. A database error during the seed stops the container like a migration error. See DEVELOPMENT.md and ARCHITECTURE.md.
The backend build context is backend/, so Docker applies backend/.dockerignore. Local tools, caches, environment files, and build outputs are excluded from that context.
The current postgres:alpine volume mounts at /var/lib/postgresql; the image stores data in a subdirectory for its major version. When the tag advances to a new major version, migrate an existing database with pg_upgrade or backup/restore. Updating the image alone does not convert the data.
Open http://127.0.0.1:8080. The host port binds to loopback. Nginx handles /healthz, proxies /api/ to Go, and uses the SPA fallback for other paths. The public API health route is /api/v1/healthz through Nginx /api/. On the internal port 8080, Go also serves /healthz for the process and /readyz, which checks PostgreSQL with SELECT 1, Redis with PING, and the SeaweedFS bucket with HeadBucket; any dependency being unavailable produces 503. The internal backend port 9090 serves /metrics.
This Nginx configuration has no production TLS. The current bind does not expose the app directly to the public network. Remote access needs a selected TLS reverse proxy, firewall rules, and environment-specific configuration.
Useful commands:
make -C deploy config
make -C deploy up
make -C deploy logs
make -C deploy down
make -C deploy smoke
Redis uses redis:alpine, the REDIS_PASSWORD value from .env, and the internal redis:6379 address; it publishes no host port. Data is limited to 128 MB with allkeys-lru eviction, and the container memory limit is 256 MB. RDB and AOF are disabled with no persistent volume: restarting Redis clears the cache. Do not keep the only copy of a record there. The backend and Redis exporter both require its password.
Backend settings are REDIS_ADDR, REDIS_PASSWORD, REDIS_DB, and REDIS_TIMEOUT. Compose supplies redis:6379; a directly launched Go process defaults to localhost:6379, DB 0, and a 1s timeout. Provide a separately reachable Redis address for direct execution because the current Compose does not publish Redis outside its network.
SeaweedFS uses chrislusf/seaweedfs:latest with weed mini: master, volume, filer, and S3 API share one container. The named seaweedfs_data volume mounts at /data and preserves object content and metadata. S3 is reachable only inside the network at http://seaweedfs:8333, with no published host port. WebDAV, Admin UI, IAM API, Iceberg, and Lance are disabled. Nginx continues to serve the frontend and /api; there is no direct object route.
Set SEAWEEDFS_ACCESS_KEY and SEAWEEDFS_SECRET_KEY in .env, replacing the example values. Compose passes them to the server as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, and passes SEAWEEDFS_BUCKET as S3_BUCKET to initialize the bucket at startup. This is one administrative credential pair for the local stack, not production service-level access separation. Never provide it to browser clients.
Backend settings are SEAWEEDFS_ENDPOINT, SEAWEEDFS_ACCESS_KEY, SEAWEEDFS_SECRET_KEY, SEAWEEDFS_BUCKET, SEAWEEDFS_REGION, and SEAWEEDFS_TIMEOUT. Compose supplies endpoint http://seaweedfs:8333; a directly launched Go process defaults to http://localhost:8333, bucket lincodex, region us-east-1, and timeout 10s. Credentials are required. Direct execution needs a separately reachable private endpoint. Readiness checks the bucket; the backend does not create it.
Ordinary down preserves the SeaweedFS volume. Losing the volume loses both objects and metadata; prepare a verified backup before changing the image or deleting the volume. This is one node without HA, cross-node replication, or configured off-host backups.
Kafka uses the official apache/kafka:latest image as one KRaft node that combines the broker and controller roles; there is no ZooKeeper. Clients use the PLAINTEXT listener at kafka:9092, which is reachable only inside the Compose network and publishes no host port. The controller listener binds to 127.0.0.1:9093 inside the container, so other containers cannot reach it. The client listener has no TLS, authentication, or ACLs: any container attached to the Compose network, including monitoring services that join it, can produce and consume. Keep the network private and do not publish the port.
The named kafka_data volume mounts at /var/lib/kafka/data and stores topic logs, consumer offsets, and KRaft metadata, so events survive container restarts and an ordinary down. KAFKA_HEAP_OPTS bounds the JVM heap to -Xms256m -Xmx512m, and the container memory limit is 1 GB. The image's default JMX agent is disabled, so no JMX port is open. Topic data is kept for 7 days or up to 1 GiB per partition, whichever limit is reached first, in 128 MiB segments. Replication factors and the minimum in-sync replica count are 1 because there is one node. This node provides no HA or replication; losing the volume loses all events and consumer offsets.
KAFKA_CLUSTER_ID in .env is required. It identifies the KRaft cluster that formatted the volume. It is not a credential and grants no access, so .env.example contains a sample value. Generate your own value once before the first start:
docker run --rm apache/kafka:latest /opt/kafka/bin/kafka-storage.sh random-uuid
Changing the value after the volume is formatted stops Kafka from starting with that volume.
Automatic topic creation is disabled: writing to a missing topic fails instead of creating it. The backend creates its events topic itself (see Outbox relay); create any other topic explicitly. Kafka CLI tools inherit the broker's KAFKA_HEAP_OPTS, so give them a small heap when running them in the container. For example, a manual technical check with the default app project:
docker compose --env-file .env -p app -f deploy/docker/docker-compose.yml \
exec -e KAFKA_HEAP_OPTS=-Xmx128m kafka /opt/kafka/bin/kafka-topics.sh \
--bootstrap-server localhost:9092 --create --topic lincodex.technical.probe \
--partitions 1 --replication-factor 1
The Compose health check runs kafka-broker-api-versions.sh against localhost:9092, so Kafka is healthy only after the broker answers API requests. make -C deploy smoke waits for that health check together with the other core services; it does not check the relay or read events.
The backend receives KAFKA_BROKERS, a comma-separated list of host:port bootstrap addresses. Compose supplies kafka:9092; a directly launched Go process defaults to localhost:9092. An explicitly empty value, an empty list entry, a missing or zero port, or a URL scheme fails configuration. The outbox relay connects to these brokers in the background: the backend does not wait for Kafka at startup, and /readyz does not check Kafka. The advertised address kafka:9092 resolves only inside the Compose network, so direct execution needs a separately reachable broker. Redis stays a cache and is not used as a queue.
PASSWORD_HASH_CONCURRENCY sets the Argon2id memory budget in derivations of 64 MiB and four lanes each (from 1 to 4). Compose passes the value from .env, default 1, because the backend container has 1 CPU and 768 MB: a second derivation would only add 64 MiB while sharing the CPU. A directly launched backend without the variable uses the smaller of 2 and GOMAXPROCS. Further registrations and logins wait for memory until their request context ends. Compose also sets GOMEMLIMIT=600MiB, about 78% of the container limit, so the Go collector reclaims finished derivations before the container runs out of memory; change it together with the memory limit. The value is read and validated at startup; registration and login will use it once they are implemented. See ARCHITECTURE.md.
down stops containers and keeps named volumes. Do not delete database or file volumes during an ordinary stop.
Outbox relay
The backend runs the outbox relay in its own process next to the HTTP servers. The relay publishes committed outbox events to Kafka; its design is in ARCHITECTURE.md. Compose passes none of the settings below, so the stack uses the defaults; to change one, add it to the backend environment in deploy/docker/docker-compose.yml. A directly launched backend reads them from its environment. An invalid value stops startup.
| Variable | Default | Meaning |
|---|---|---|
RELAY_ENABLED |
true |
true or false. With false, or without DATABASE_URL, the relay does not run and events stay in the outbox. |
RELAY_BATCH_SIZE |
100 |
Events one pass locks and publishes, from 1 to 1000. |
RELAY_POLL_INTERVAL |
1s |
Wait after a pass that found no pending event, from 10ms to 5m. |
RELAY_PRODUCE_TIMEOUT |
10s |
Longest wait for the broker acknowledgements of one pass and for topic creation, from 1s to 2m. The pass keeps its transaction open for that long at most. |
RELAY_STATEMENT_TIMEOUT |
5s |
Server-side statement_timeout of each SQL statement of a pass, from 100ms to 1m. The pass transaction also gets idle_in_transaction_session_timeout of RELAY_PRODUCE_TIMEOUT plus this value, so PostgreSQL ends the transaction of a frozen or disconnected backend and releases its locks. |
RELAY_BACKOFF_INITIAL |
500ms |
Wait after the first failed pass; it doubles with each consecutive failure. |
RELAY_BACKOFF_MAX |
30s |
Longest wait between retries, from RELAY_BACKOFF_INITIAL to 10m. |
KAFKA_EVENTS_TOPIC |
lincodex.domain.events |
Topic for all domain events: up to 249 letters, digits, dots, underscores, or hyphens. |
KAFKA_EVENTS_TOPIC_PARTITIONS |
3 |
Partitions of a topic the relay creates, from 1 to 1000. |
KAFKA_EVENTS_TOPIC_REPLICATION_FACTOR |
-1 |
Replication factor of a topic the relay creates: -1 takes the broker's default.replication.factor, otherwise from 1 to the broker count. |
KAFKA_EVENTS_TOPIC_MIN_INSYNC_REPLICAS |
unset | min.insync.replicas of a topic the relay creates, at least 1 and not above an explicit replication factor. Unset leaves the broker default. |
KAFKA_PROVISION_TOPICS |
true |
With false the relay never creates the topic, and every publish fails until the topic exists. |
SHUTDOWN_TIMEOUT also bounds the relay: a pass in progress at shutdown has that long to finish, otherwise it rolls back and its events stay pending. Compose gives the backend stop_grace_period: 20s, more than the default 10s SHUTDOWN_TIMEOUT, so Docker does not kill the process while a pass commits; raise it together with SHUTDOWN_TIMEOUT.
The single-node stand creates the topic with the broker defaults of the Compose Kafka: replication factor 1 and min.insync.replicas 1. That is acceptable only for this stand: one broker cannot replicate, and losing its volume loses the events. A production cluster needs at least three brokers, a replication factor of at least 3, and min.insync.replicas 2, either as broker defaults or through KAFKA_EVENTS_TOPIC_REPLICATION_FACTOR=3 and KAFKA_EVENTS_TOPIC_MIN_INSYNC_REPLICAS=2. The producer always uses acks from all in-sync replicas, so with these values an acknowledged event survives the loss of one broker, and writes stop rather than land on a single replica when two of three brokers are down.
The relay creates a missing topic and never changes an existing one; when the existing topic has another partition count or replication factor than configured, the relay logs one warning. Adding partitions to the topic later moves aggregate keys to other partitions, so per-aggregate order is not guaranteed across that change.
When Kafka is unavailable, the backend still starts and serves the API. The relay logs warnings such as outbox relay could not prepare the event bus or outbox relay pass failed with the retry delay and keeps retrying; events stay in outbox_events until Kafka answers. In Compose the backend does not wait for the Kafka health check, so these warnings are expected during the first seconds after make -C deploy up. Relay logs carry the outbox_relay component and contain event IDs, counts, and broker errors, never payloads.
The internal /metrics endpoint shows the backlog: lincodex_outbox_relay_pending_events and lincodex_outbox_relay_oldest_pending_age_seconds are refreshed at most every 15 seconds, and lincodex_outbox_relay_events_total counts the published and failed outcomes. A growing age with a flat published count means the relay is stuck; the relay warnings name the event IDs, and ARCHITECTURE.md describes the causes. Every backend instance reports the same backlog, so aggregate it with max. Published rows stay in outbox_events; their retention is not implemented yet.
The backend sends mail through the MailSender port. EMAIL_PROVIDER selects exactly one transport: resend (the Resend HTTP API, the primary provider for the working stand), smtp (a separate SMTP relay), or disabled. It has no default, and there is no fallback: when the selected transport cannot start, the backend stops instead of switching to another one. Settings of transports that are not selected are not read.
Current state: this build contains the disabled and resend transports. With smtp, the backend validates the SMTP settings and then exits with EMAIL_PROVIDER=smtp: mail transport is not available in this build; under Compose, restart: unless-stopped restarts the container repeatedly. SMTP is outside the MVP. .env.example and make -C deploy smoke use disabled, so local runs need no key; the working stand sets EMAIL_PROVIDER=resend and RESEND_API_KEY explicitly. No flow sends mail yet: the delivery layer that calls the transport is planned.
resend sends each message with one request to https://api.resend.com/emails. Building the transport makes no network call, so startup checks neither the key nor the sender domain; a wrong key or an unverified domain in EMAIL_FROM shows up as a rejected send. One attempt is limited by EMAIL_TIMEOUT. The transport follows no redirects, never retries, and logs nothing; retries, backoff, rate-limit pacing, waiting for a daily or monthly quota reset, and outcome records belong to the planned delivery layer. Each request carries the message's idempotency key, and Resend deduplicates the same key and body for 24 hours; after that window a retry may send the mail twice. A success means that Resend accepted the request and returned a message ID, not that the mail was delivered or read. A timeout, a lost answer after the request was sent, or a Resend 500 error is unknown (delivery_uncertain), not a failure. The backend process follows the standard HTTPS_PROXY and NO_PROXY variables, but the Compose backend service does not pass them, so under Compose the request goes directly to Resend; a stand that needs an egress proxy must add them to the backend environment. The full mapping of answers is in ARCHITECTURE.md.
disabled sends nothing. Every send returns ErrMailChannelUnavailable without a provider message ID and is never reported as accepted or delivered. It does not confirm an email address, mark an account verified, or skip an account check. The startup log contains mail transport selected with email_provider and, for disabled, a mail delivery is disabled warning.
| Variable | Default | Validation |
|---|---|---|
EMAIL_PROVIDER |
none, required | resend, smtp, or disabled, case-insensitive |
EMAIL_FROM |
none, required | One mailbox: no-reply@example.com or Lincodex <no-reply@example.com>. Printable ASCII only. The address follows the account address rules: unquoted local part and a DNS domain with at least two labels, no IP literal. |
EMAIL_TIMEOUT |
10s |
Go duration from 1s to 1m; limits one transport attempt |
APP_PUBLIC_URL |
none, required | Public origin for links in mail: https://host[:port], or http only for localhost, 127.0.0.1, or [::1]. No credentials, path, query, or fragment; one trailing / is dropped. |
RESEND_API_KEY |
empty | Read only for resend, where it is required. Printable ASCII without whitespace. The re_ prefix shown in Resend examples is not enforced. |
SMTP_HOST |
empty | Read only for smtp, where it is required. Hostname or IP address without a port. |
SMTP_PORT |
empty | Required for smtp. Integer from 1 to 65535. |
SMTP_USERNAME, SMTP_PASSWORD |
empty | Required for smtp; an anonymous relay is not supported. |
SMTP_TLS_MODE |
empty | Required for smtp. starttls (upgrade with STARTTLS, usually port 587) or tls (TLS from the start, usually port 465). Plaintext SMTP is not supported. |
Compose passes these variables from the root .env. EMAIL_PROVIDER, EMAIL_FROM, and APP_PUBLIC_URL are required, so Compose refuses to render the project without them; copy the mail block from .env.example into an existing .env. Keep RESEND_API_KEY and SMTP_PASSWORD in the server environment or a deployment secret store and never commit them. Configuration errors name the setting but never print its value, and the startup log names only the selected provider.
Mail templates
Implemented: the renderer in backend/internal/usecase/notification/mailtemplate/ with templates for email verification, password reset, and a short notification. Nothing calls it yet: registration, verification, password reset, and mail delivery are planned, so the current build renders and sends no message.
- Templates are embedded in the binary with
go:embedand parsed once when the renderer is created; a broken template fails its creation. Each version has three files:<kind>.v<N>.subject.tmpl,<kind>.v<N>.txt.tmpl, and<kind>.v<N>.html.tmpl. The HTML part useshtml/template, the plain-text part and the subject usetext/template. Every transport sends the same rendering; templates hold no provider settings, keys, or sender address. - Links start with
APP_PUBLIC_URL, which the renderer checks again with the same rules. Verification:<APP_PUBLIC_URL>/verify-email#token=<token>; password reset:<APP_PUBLIC_URL>/reset-password#token=<token>(the page and the API for the reset are planned). The token is only in the URL fragment, never in the query. A notification link is a path inside the application, such as/candidate/invitations; an absolute URL,//host, a scheme such asjavascript:, a query, a fragment, a percent sign, and.or..segments are rejected. - Messages contain no name, email address, or other contact. Caller text in a notification is escaped in the HTML part; control and bidirectional characters are removed from the plain-text part, and the subject becomes one line, so CR and LF cannot add header lines. The notification subject is limited to 100 characters and the body to 2000.
- Copy is in Russian. A released version is immutable: changing copy adds the next version, for example
verification.v2, and switches the current version in code. Versions share no files, so one version cannot change the body of another. Each rendering carries its version and a SHA-256 content hash over the version, subject, and both parts; the same version and data always give the same body. The planned delivery layer is expected to store the rendered body with the hash and resend the stored body on retry instead of rendering again; keep the files of an old version while stored deliveries name it. - The renderer does not log. A rendering and notification data print only the kind, version, and content hash in
fmtandslogoutput; tokens, links, and bodies are never printed. - Golden files in
testdata/make every copy change visible in review. After an intended change, rungo test ./internal/usecase/notification/mailtemplate -updatefrombackend/and review the diff.
Separate ML Compose project
ML uses a separate Compose file and project; it does not require or start Redis or SeaweedFS in the current scaffold. Its default host bind is 127.0.0.1:8000. Set ML_BIND_ADDRESS only after choosing a private address and preparing firewall rules. Prometheus does not scrape remote ML while ML_METRICS_TARGET is empty.
The ML image uses python:alpine and upgrades system packages during the build. Dependencies are installed with uv only in the build stage; the final runtime contains the prepared virtual environment without pip or ensurepip. Current dependencies support musl. Check Alpine compatibility before adding inference or GPU libraries; glibc-dependent libraries will require a different validated runtime.
make -C deploy ml-config
make -C deploy ml-up
make -C deploy ml-logs
make -C deploy ml-down
GET /healthz checks the process. GET /readyz checks inference readiness and returns 503 while a model is unavailable. The current scaffold has no working model. Readiness does not measure model quality or inference behavior.
Separate monitoring Compose project
Start the core project first. Monitoring joins its Docker network. Monitoring starts separately and is not required to run the app:
make -C deploy monitoring-config
make -C deploy monitoring-up
make -C deploy monitoring-logs
make -C deploy monitoring-down
Grafana is available at http://127.0.0.1:3000. Credentials come from GRAFANA_ADMIN_USER and GRAFANA_ADMIN_PASSWORD in .env. Prometheus, Loki, exporters, and backend metrics publish no host ports.
Prometheus retains metrics for 14 days with a 4 GB size limit. Loki retains logs for 7 days. Alloy discovery filters by Compose project and collects logs only from backend, frontend, postgres, redis, and seaweedfs. Kafka logs and metrics are not collected yet; read the logs with make -C deploy logs. Loki labels are limited to service and environment; do not add user IDs, addresses, resume text, request bodies, or full URLs.
Frontend telemetry is not connected in the React app yet. Nginx and Alloy provide a restricted /telemetry receiver and Faro configuration, but the UI SDK and end-to-end event check are absent.
Alloy uses docker-socket-proxy for container discovery. The proxy enables only the needed Docker API sections for containers, events, ping, and version; POST is disabled. Set the socket path with DOCKER_SOCKET_PATH. Rootless Docker may use a path such as /run/user//docker.sock; use the path on your own host instead of copying another developer's local path. The proxy restricts API sections, but access to the Docker socket remains privileged and its exact configuration needs review.
PostgreSQL creates a separate exporter role only while initializing an empty volume and when POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD are set. Set both before the first make -C deploy up. Changing them after the volume exists does not rerun the init script.
For remote ML scraping, set ML_METRICS_TARGET to hostname:port or IPv4:port and verify private routing and firewall rules. The standalone ML host does not yet have a separate Alloy config for forwarding its container logs to Loki.
Services and images
Container images use moving latest or alpine tags where the upstream publishes them. Check the current Compose references when updating the stack. These tags can move; resolve and record actual image digests and an SBOM for a release. Application dependency lockfiles remain checked in separately.
| Component | Current image source | Principal upstream license |
|---|---|---|
| PostgreSQL | Docker Official Image, docker-library/postgres | PostgreSQL License for the server; packaging repository is MIT |
| SeaweedFS | chrislusf/seaweedfs | Apache-2.0 |
| Apache Kafka | apache/kafka, the Apache Kafka project's image | Apache-2.0 |
| Prometheus | prom/prometheus | Apache-2.0 |
| Loki | grafana/loki | AGPL-3.0-only by default; see LICENSING.md exceptions |
| Grafana Alloy | grafana/alloy | Apache-2.0 by default |
| Grafana | grafana/grafana | AGPL-3.0-only by default |
| Node exporter | prometheus/node_exporter | Apache-2.0 |
| PostgreSQL exporter | prometheus-community/postgres_exporter | Apache-2.0 |
| Docker socket proxy | Tecnativa/docker-socket-proxy | Apache-2.0 |
| BusyBox | busybox | GPL-2.0-only |
Upstream references: PostgreSQL image, Prometheus, Loki license details, Alloy license details, Grafana license details, node_exporter, postgres_exporter, socket proxy, BusyBox license.
These entries name the principal upstream project's license; they are not a complete inventory of every file in an image. Base OS packages and bundled dependencies may have separate terms. Before redistribution, inspect the exact image tag or digest, its notices, and an SBOM. This repository has no project-wide license.
The backend builds with Go 1.26.8; its runtime image is selected in backend/Dockerfile. Frontend and ML base images are selected in their Dockerfiles. Upstream sources include Docker Official Images, Distroless, and NGINX unprivileged images; inspect exact tags and layers before distribution.
Observability configuration
Prometheus scrapes backend /metrics on port 9090, PostgreSQL exporter, Redis exporter on port 9121, SeaweedFS on port 9327, node exporter, itself, and the optional ML target. Loki uses a single-binary filesystem store with 168-hour retention. Grafana provisions Prometheus and Loki datasources from observability/grafana/provisioning/.
The five checked-in dashboard JSON files are maintained as project dashboards: Go runtime, PostgreSQL, Redis, SeaweedFS, and Linux system. The Redis dashboard covers availability, memory, cache hits/misses, evictions/expired keys, and client connections. The exporter collects aggregate metrics without scanning keys. The SeaweedFS dashboard covers availability, S3 request rate and duration, errors, disk, and memory; Prometheus retains only selected aggregate metrics without object paths. They were not copied from Grafana dashboard IDs. No external dashboard provenance or license is claimed for them.
The local monitoring stack is a single-node development/demo setup and provides no HA. Compose validation does not establish production retention, off-host backups, public access control, alert delivery, or core application behavior.
Workflow files exist in .github/workflows/. Their presence does not mean they have run on GitHub. See the testing guide for the difference between configuration validation, an infrastructure smoke, and product-flow tests.