Repository navigation
[M0.5] Configurable dev stack ports - #26
Merged
Merged
Conversation
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 3, 2026
## Task [M2.1a] API skeleton (first half of M2.1, split recorded in `docs/PLAN.md`). Refs #20 ## What changed **Domain (`packages/domain`)** - `Secret<T>`: wraps credentials and renders `[REDACTED]` through `String()`, template literals, `JSON.stringify`, `util.inspect`; the value is reachable only via `expose()`. Constant-time `equals`. TypeScript counterpart of Go `lib/secret` (CLAUDE.md rule 8). - `DomainError` base (kind + stable `code` + optional details) with `InvalidInputError`, `NotFoundError`, `ConflictError`. Pure, no framework imports. **Control plane (`apps/api`), NestJS 12** - `platform/config`: zod schema for the environment (`DATABASE_URL` becomes a `Secret`, ports and URLs validated, every problem reported at once without echoing values), `AppConfig` typed accessor, `.env` read in development only. - `platform/logging`: pino JSON request logs through nestjs-pino. One line per request with request id (honours a safe `x-request-id`), method, URL, status, duration. `authorization`, `cookie`, `set-cookie`, `x-api-key`, join-token headers and token query parameters are redacted; bodies are never logged; health probes are not logged. - `platform/http`: global `ProblemDetailsFilter` producing RFC 9457 `application/problem+json` with `type` = `https://shipkeep.dev/problems/<code>`, `code`, `instance`, `requestId`, field `errors` for validation. Domain error kinds map to 400/401/403/404/409/412; unknown errors become an opaque 500 (internal messages never leak). Validation pipe: whitelist, forbid unknown properties, transform. - `platform/prisma`: Prisma 7 with the `pg` driver adapter; the connection string is exposed only into the driver. `ping()` for readiness. Schema and `prisma.config.ts` in place; the first models arrive with M2.1b. The generated client is not committed; `pnpm install` regenerates it. - `platform/health`: `GET /api/v1/health` (liveness) and `GET /api/v1/ready` (database probe, 503 problem when down). - `platform/openapi`: OpenAPI 3.1 document at `/api/v1/openapi.json`, bearer and session-cookie security schemes, UI at `/api/v1/docs` when `OPENAPI_UI` is on (default outside production). `helmet` on every response. - `bootstrap.ts` builds the app once for `main.ts`, the OpenAPI generator and the tests. **Contract and client** - `apps/api/openapi.json` generated by `pnpm gen:openapi` (document-only run of the built API, no port, no database). `packages/api-client` exposes `createShipkeepClient()` over openapi-fetch with types generated by openapi-typescript (`pnpm gen:api-client`), plus `isProblemDetails()`. `pnpm gen` runs the whole chain; CI fails on drift. **Tooling** - NestJS 12 is ESM-only, which Jest (CJS) cannot load: the API now tests with vitest like every other project (swc plugin for decorator metadata). Jest is removed from the workspace. `pnpm test:integration` runs `api:test:integration` (vitest, Testcontainers PostgreSQL or `DATABASE_URL`). - `@nx/nest` removed (generator only, pinned to Nest <12). ## Why Every control plane module (identity, fleet, audit...) needs configuration, logging, error mapping, the database client and the OpenAPI contract in place first. SPEC section 8 fixes the base path, the problem-details format and the OpenAPI location. ## How it was tested - `pnpm nx run-many -t lint typecheck test build`: all 7 projects green. Unit tests: 13 domain, 15 api (config schema, filter mapping, HTTP pipeline with security headers, 404 problem, readiness 503, OpenAPI document and UI), 3 api-client, 86 config-schema, 3 proto-ts. - `pnpm test:integration`: the API starts against a real PostgreSQL 17 started by Testcontainers and `GET /api/v1/ready` returns `{"status":"ok","checks":{"database":"ok"}}`. - `pnpm gen` twice: no drift. `prettier --check`: clean. - Local `pnpm dev:infra` stack verified earlier today (PR #26). ## Security considerations - Secrets: `DATABASE_URL` is a `Secret`; the only `expose()` is the Prisma adapter constructor. Request logs redact credential headers and never include bodies. Internal errors are not echoed to clients. - `helmet` defaults; `x-powered-by` removed. - Validation rejects unknown properties (`forbidNonWhitelisted`). - No authentication yet (M2.2); the only routes are health, readiness and the OpenAPI document. The `security-review` label is set because this PR defines the error, logging and configuration foundations every later module inherits. ## Checklist - [x] Acceptance criteria from `docs/PLAN.md` are met and M2.1a is ticked - [x] Lint, TS tests, Go tests and `buf lint` pass - [x] Tests added, including redaction and unknown-property tests - [x] No new shell invocation in product code (`tools/gen/openapi.mjs` runs the built API with fixed arguments and carries a justified `nosemgrep`) - [x] Audit events: not applicable yet (no state changes; M2.1b adds the audit writer) - [x] CLAUDE.md and README updated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
[M0.5] Local dev environment, follow-up. Refs #5
What changed
deploy/dev/compose.yml: host ports readSHIPKEEP_DEV_POSTGRES_PORT,SHIPKEEP_DEV_VICTORIALOGS_PORT,SHIPKEEP_DEV_VICTORIAMETRICS_PORTandSHIPKEEP_DEV_REGISTRY_PORTwith the previous values as defaults. Still bound to 127.0.0.1.pnpm dev:infra*run Compose with--project-directory .so the root.env(gitignored) is read when present..env.exampledocuments the four variables; README explains the override.Why
First real run of the stack on a developer machine: PostgreSQL 5432 was already taken by another local database. The M0.5 PR could not be exercised with Docker at the time; this run closes that gap.
How it was tested
pnpm dev:infrawithSHIPKEEP_DEV_POSTGRES_PORT=5433in.env: all four containers healthy (--waitreturned),pg_isreadyaccepting connections, VictoriaLogs and VictoriaMetrics/healthOK, registry/v2/HTTP 200..envthe defaults are unchanged.Security considerations
None. Ports stay loopback-only;
.envremains ignored by git.Checklist
docs/PLAN.mdare met (stack now verified with Docker).env.exampleupdated