Selected workNo. 02
ShipTrace
A deployment-tracking service, specified and threat-modelled before it was built.
- Status
- Early development · local only · not deployed
- Stack
- Python, FastAPI, PostgreSQL
- Checked
- Against the repository, 2026-11-14
ShipTrace is a small service where CI/CD pipelines report deployments, and people see the deployment history, the latest good version, deployment frequency and change failure rate. It is built as a modular monolith on FastAPI and PostgreSQL, with a written specification, architecture decision records, a threat model and an ASVS assessment that precede the code.
The problem
Teams struggle to answer simple questions: what is running in each environment, since when, and how often do changes fail? The answers are usually scattered across pipeline logs.
ShipTrace stores deployment events as an append-only log and derives status from them, so history cannot be quietly rewritten and the numbers can be explained.
Architecture
One deployable process serves HTTPS requests and talks to one PostgreSQL database; there is no queue, cache or background worker, so ingest is a single short transaction.
Code is layered api, application and domain; persistence implements ports defined by the application layer; the domain is pure and clock-free. Import contracts enforce these dependency rules in the quality gate.
Deployment events are append-only, protected by database privileges (the runtime role has column-limited INSERT and no UPDATE or DELETE) and by triggers that refuse updates, deletes and truncation. Status is derived from the events rather than stored, so there is no mutable status to race. Credentials are random opaque tokens of which only a SHA-256 digest is stored.
Fig. 1ShipTrace: one process, one database, layers enforced
Scroll the figure sideways to see all of it.
Read this figure as text
- A CI/CD pipeline posts deployment events to the API routes with a bearer token.
- Inside one FastAPI process, the routes authenticate the token (a lookup by digest in the store), then call the ingest use case.
- The use case applies pure domain rules and records through a port that the SQLAlchemy store implements.
- The store inserts into PostgreSQL, where triggers and column grants make the event tables append-only.
- Migrations are a separate step that connects as a different database role.
One request, step by step
One ingest request followed through the layers. Authentication and scope come before the body is even read, so an unauthenticated caller learns nothing about the payload.
Fig. 2ShipTrace: recording one deployment event
Scroll the figure sideways to see all of it.
Read this figure as text
- The pipeline posts an event to /api/v1/deployment-events with a bearer token.
- The API looks up the active credential by the SHA-256 digest of the token and checks that its scope allows ingest. Only then is the body parsed.
- The ingest use case validates the fields and checks that the service and environment match the credential's binding.
- The store reads the deployment, applies the pure domain rule and inserts the event in one transaction. It commits only an accepted event.
- The API answers 201 for a new event, 200 for a replay, or a problem document that echoes nothing from the request.
Engineering decisions
Append-only events
Two independent layers, privileges and triggers, with the residual risks that remain (a table owner can disable a trigger) written down, not hidden.
ADR 0003 (accepted)
Derived status and what counts as a failed change
Status is computed from the event log by one domain rule that a SQL predicate must agree with; the failed-change definition drives the change-failure metric.
ADR 0004 (accepted)
API credentials and the credential write model
Opaque tokens, digest-only storage, scopes, and a write model in which the application role can issue credentials but not choose identifiers or timestamps.
ADR 0005, ADR 0012 (accepted)
Schema compatibility and readiness
Migrations run as a separate step with expand/contract changes; readiness reports whether the schema is compatible with the running version.
ADR 0011 (accepted)
Trade-offs
Append-only has residual risk
Privileges and triggers are two independent layers, but a table owner can still disable a trigger. The decision record lists that risk instead of hiding it.
ADR 0003
Status is derived, so reads do more
There is no mutable status column to race or to corrupt, but every read computes status from the event history.
ADR 0004
No queue means no buffer
Ingest is one short transaction. When the bounded database pool is exhausted the service answers 503 with Retry-After instead of queueing work.
ADR 0001
Migrations only go forward
Schema changes run as a separate expand and contract step. Rolling back past a contract migration is deliberately not supported.
ADR 0011
Implementation
- Runtime
- Python 3.14, FastAPI and Uvicorn, SQLAlchemy and Alembic, PostgreSQL 18
- Quality gates
- uv with a locked dependency set, Ruff (format and lint), mypy (strict), import-linter, pytest with coverage, gitleaks configuration
- Local environment
- Docker Compose (PostgreSQL pinned by digest), Bash verification and smoke scripts
Testing and verification
| Check | Result |
|---|---|
| Tests | 2,075 pass against real PostgreSQL |
| Branch coverage | 98.3% (gate threshold 90%) |
| Static gates | Ruff format and lint, strict mypy, import contracts pass |
| Packaging | built wheel ships the migrations |
| Smoke test | real-process run against Compose PostgreSQL: migrations, HTTP, graceful shutdown |
Results from running the repository's full verification script in November 2026. The repository keeps a numbered verification log of what each phase checked and what it found.
Security and reliability
- Bounded database pool with load shedding: an exhausted pool returns 503 with Retry-After; statement, lock and idle-in-transaction timeouts are set on every connection.
- Three database roles: admin, migrator (owns the schema, used only by migrations) and a least-privilege application role; roles are created by a bootstrap step outside Alembic.
- Authorization is deny-by-default in an application-layer check, not only in routing. A threat model and an ASVS assessment are maintained alongside the code, and security reviews of each phase gate are recorded.
- Planned, not yet built: dashboard accounts with server-side sessions, rate limiting, trusted-proxy handling, JSON logs and OpenTelemetry export.
Operations
- Runs locally against a Compose PostgreSQL; /healthz never touches dependencies and /readyz reports schema compatibility with a one-second cache.
- Migrations are a one-shot step before rollout, never at application start. Rollback past a contract migration is deliberately not supported.
- No cloud environment exists: the cloud target is a plan that requires explicit approval before anything is provisioned.
Known limitations
- Early development: the HTTP read routes and dashboard are not finished, and there is no container image, CI/CD pipeline, supply-chain evidence or recovery drill yet. They are planned phases, not implied features.
- No performance or capacity measurements have been taken, and nothing is deployed, so there is no operational history.
- Several decision records (modular monolith, rate limiting, observability, supply chain) are still proposals awaiting acceptance.
Sources
Editable diagram sources: diagrams/shiptrace.architecture.json and diagrams/shiptrace.sequence.json in the portfolio repository.