Project Workshop — Dockerized FastAPI Stack
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Docker · Docker Compose · nginx · Alpine
Expected effort: 10–16 focused hours · Minimum meaningful tests: 12What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | FROM/RUN/COPY/ADD/WORKDIR/ENV/ARG/EXPOSE/CMD/ENTRYPOINT produces the specified behavior inside Dockerfile & multi-stage builds | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | COPY vs ADD, CMD vs ENTRYPOINT (exec vs shell form) produces the specified behavior inside Dockerfile & multi-stage builds | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | .dockerignore and layer caching (requirements.txt first) produces the specified behavior inside Dockerfile & multi-stage builds | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | multi-stage: FROM...AS builder + COPY --from=builder produces the specified behavior inside Dockerfile & multi-stage builds | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.5 | 800MB→50MB with distroless/Alpine base images produces the specified behavior inside Dockerfile & multi-stage builds | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | services/networks/volumes configuration produces the specified behavior inside Docker Compose | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | depends_on with condition: service_healthy + healthcheck produces the specified behavior inside Docker Compose | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | env_file and named vs bind mount vs tmpfs volumes produces the specified behavior inside Docker Compose | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | profiles for optional services produces the specified behavior inside Docker Compose | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.5 | docker-compose.override.yml for dev overrides produces the specified behavior inside Docker Compose | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | bridge/host/none/overlay/macvlan network types produces the specified behavior inside Networking, storage & sizing | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | embedded DNS and service discovery produces the specified behavior inside Networking, storage & sizing | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | named/bind/tmpfs volume lifecycle produces the specified behavior inside Networking, storage & sizing | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | Python wheel builder and distroless runtime produces the specified behavior inside Networking, storage & sizing | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.5 | image history and size budget below 150MB produces the specified behavior inside Networking, storage & sizing | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1delivery/2├── app/3├── Dockerfile4├── compose.yaml5├── .github/workflows/6├── deploy/{base,overlays,helm}/7├── cloud/{sam,terraform}/8├── observability/{prometheus,grafana,otel,alerts}/9├── tests/{smoke,policy,load}/10└── runbooks/Build plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Dockerfile & multi-stage builds | FROM/RUN/COPY/ADD/WORKDIR/ENV/ARG/EXPOSE/CMD/ENTRYPOINT; COPY vs ADD, CMD vs ENTRYPOINT (exec vs shell form); .dockerignore and layer caching (requirements.txt first) | Demonstration plus focused tests |
| 2 | Docker Compose | services/networks/volumes configuration; depends_on with condition: service_healthy + healthcheck; env_file and named vs bind mount vs tmpfs volumes | Demonstration plus focused tests |
| 3 | Networking, storage & sizing | bridge/host/none/overlay/macvlan network types; embedded DNS and service discovery; named/bind/tmpfs volume lifecycle | Demonstration plus focused tests |
| 4 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1FROM python:3.12-slim AS builder2ENV VIRTUAL_ENV=/opt/venv3RUN python -m venv $VIRTUAL_ENV4COPY requirements.txt .5RUN $VIRTUAL_ENV/bin/pip install --no-cache-dir -r requirements.txt6
7FROM python:3.12-slim AS runtime8ENV PATH=/opt/venv/bin:$PATH PYTHONUNBUFFERED=19RUN addgroup --system app && adduser --system --ingroup app app10WORKDIR /app11COPY --from=builder /opt/venv /opt/venv12COPY --chown=app:app app ./app13USER app14EXPOSE 800015CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]Expected result
1The runtime image contains the virtual environment and application but no compiler or root process.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | FROM python:3.12-slim AS builder | Adds a relational selection, combination, ordering, bound, or returned-value rule to the statement. |
| 2 | ENV VIRTUAL_ENV=/opt/venv | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 3 | RUN python -m venv $VIRTUAL_ENV | Implements the next dockerfile statement in the example's data flow. |
| 4 | COPY requirements.txt . | Begins a declarative database or protocol operation; subsequent lines refine its contract. |
| 5 | RUN $VIRTUAL_ENV/bin/pip install --no-cache-dir -r requirements.txt | Implements the next dockerfile statement in the example's data flow. |
| 7 | FROM python:3.12-slim AS runtime | Adds a relational selection, combination, ordering, bound, or returned-value rule to the statement. |
| 8 | ENV PATH=/opt/venv/bin:$PATH PYTHONUNBUFFERED=1 | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 9 | RUN addgroup --system app && adduser --system --ingroup app app | Implements the next dockerfile statement in the example's data flow. |
| 10 | WORKDIR /app | Implements the next dockerfile statement in the example's data flow. |
| 11 | COPY --from=builder /opt/venv /opt/venv | Begins a declarative database or protocol operation; subsequent lines refine its contract. |
| 12 | COPY --chown=app:app app ./app | Begins a declarative database or protocol operation; subsequent lines refine its contract. |
| 13 | USER app | Implements the next dockerfile statement in the example's data flow. |
| 14 | EXPOSE 8000 | Implements the next dockerfile statement in the example's data flow. |
| 15 | CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] | Implements the next dockerfile statement in the example's data flow. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Dockerfile & multi-stage builds | Alpine is not automatically smaller after native build dependencies and may introduce musl compatibility issues. | Copy dependency manifests before source, pin bases by digest where required, and run as non-root. |
| Docker Compose | depends_on is not a distributed readiness protocol. | Keep production-like topology but separate development overrides and secrets. |
| Networking, storage & sizing | Deleting a secret or large file in a later RUN does not remove it from the earlier layer and can leave both size and exposure intact. | Use .dockerignore, multi-stage builds, no-cache package installs, wheel/runtime separation, and docker history or layer-analysis tools to enforce the measured budget. |
Engineering checklist for this stack
- To do: run with least privilege and immutable artifacts
- To do: declare resource bounds and health behavior
- To do: separate secrets from versioned configuration
- To do: prove rollback and restore
- To do: correlate deployment version with metrics, logs, and traces
Test strategy
Implement at least 12 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 4 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1set -euo pipefail2docker build --check .3trivy image --exit-code 1 "$IMAGE_DIGEST"4helm lint ./deploy/helm5helm template test ./deploy/helm | kubeconform -strict6pytest -q tests/smoke7locust --headless --users 100 --spawn-rate 10 --run-time 2mFailure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?