Project skeleton with a live probe (#74) #193

Closed
bobby wants to merge 1 commits from 74-project-skeleton into main
pull from: 74-project-skeleton
Owner

Closes #74

Summary

hapi serve                        # one process, one event loop (ADR-0009)
  uvicorn :8000  create_api_app()     public API, the only port the Gateway routes
  uvicorn :8081  create_probe_app()   GET /livez -> 200 {"status":"ok"}, unauthenticated
  SIGINT/SIGTERM -> stop both listeners
src/hapi/
├── app.py, cli.py        # composition root (top layer)
├── finance/ fitness/ maintenance/ smart_home/
│   └── service.py        # the only module other domains may import
└── platform/             # bottom layer: health.py (probes), server.py (two listeners, one loop)
bots/                     # forbidden from importing hapi.*

import-linter contracts, each checked by breaking it on purpose (and checking the allowed imports still pass):

platform  -> finance.service   BROKEN (layers)
finance   -> app               BROKEN (layers)
fitness   -> finance.models    BROKEN (protected)
fitness   -> finance.service   kept
bots      -> hapi.*            BROKEN (forbidden)

uv is the only tool needed outside the project venv. just, pre-commit, Ruff, pyright and import-linter are dev dependencies, so the commands are uv run just lint|test|dev.

Evidence

  • Before: no app, no tooling.
    After:
$ uv run just test
tests/test_probes.py   livez returns constant ok on the probe listener      PASSED
                       livez is not served on the public api (404)           PASSED
tests/test_serve.py    probes answer on the probe port only (real sockets)   PASSED
                       sigterm stops both listeners cleanly (exit 0)         PASSED

$ uv run pre-commit run --all-files
ruff check / ruff format / pyright / import-linter / gitleaks   Passed

The 404 test fails if the probe router is mounted on the API app.

Merge Danger

Door: two-way

It's greenfield, so nothing depends on it yet. The layout and contract shapes are what later tickets will build on.

Blast Radius: none

Notes for later tickets:

  • --host defaults to 127.0.0.1. The image needs 0.0.0.0, or this becomes a setting in #75.
  • The OpenAPI docs are still on. Turning them off in prod needs the config from #75.
  • #77 (/readyz + drain) should build on the shared shutdown in platform/server.py.
  • The test_serve.py tests run hapi serve as a subprocess, not in-process as spec Seam 2 says, because real ports and signals are the behaviour under test.

🤖 Generated with Claude Code

Closes #74 ## Summary ```text hapi serve # one process, one event loop (ADR-0009) uvicorn :8000 create_api_app() public API, the only port the Gateway routes uvicorn :8081 create_probe_app() GET /livez -> 200 {"status":"ok"}, unauthenticated SIGINT/SIGTERM -> stop both listeners ``` ```text src/hapi/ ├── app.py, cli.py # composition root (top layer) ├── finance/ fitness/ maintenance/ smart_home/ │ └── service.py # the only module other domains may import └── platform/ # bottom layer: health.py (probes), server.py (two listeners, one loop) bots/ # forbidden from importing hapi.* ``` import-linter contracts, each checked by breaking it on purpose (and checking the allowed imports still pass): ```text platform -> finance.service BROKEN (layers) finance -> app BROKEN (layers) fitness -> finance.models BROKEN (protected) fitness -> finance.service kept bots -> hapi.* BROKEN (forbidden) ``` `uv` is the only tool needed outside the project venv. `just`, `pre-commit`, Ruff, pyright and import-linter are dev dependencies, so the commands are `uv run just lint|test|dev`. ## Evidence - **Before:** no app, no tooling. **After:** ```text $ uv run just test tests/test_probes.py livez returns constant ok on the probe listener PASSED livez is not served on the public api (404) PASSED tests/test_serve.py probes answer on the probe port only (real sockets) PASSED sigterm stops both listeners cleanly (exit 0) PASSED $ uv run pre-commit run --all-files ruff check / ruff format / pyright / import-linter / gitleaks Passed ``` The 404 test fails if the probe router is mounted on the API app. ## Merge Danger **Door:** two-way It's greenfield, so nothing depends on it yet. The layout and contract shapes are what later tickets will build on. **Blast Radius:** none Notes for later tickets: - `--host` defaults to `127.0.0.1`. The image needs `0.0.0.0`, or this becomes a setting in #75. - The OpenAPI docs are still on. Turning them off in prod needs the config from #75. - #77 (`/readyz` + drain) should build on the shared shutdown in `platform/server.py`. - The `test_serve.py` tests run `hapi serve` as a subprocess, not in-process as spec Seam 2 says, because real ports and signals are the behaviour under test. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
bobby added 1 commit 2026-11-27 16:56:16 -05:00
uv project on Python 3.14 with Ruff (incl. DTZ), pyright strict, and
import-linter contracts: composition root above domains above platform,
each domain reachable from others only through its `service` module, and
`bots/` forbidden from importing `hapi`. `just dev/test/lint` recipes and
pre-commit running the same checks plus gitleaks. `just` and `pre-commit`
are dev dependencies, so uv is the only tool needed outside the venv.

`hapi serve` runs the public API (:8000) and the internal probe listener
(:8081) as two uvicorn servers in one event loop (ADR-0009); `/livez` is
constant and served only on :8081.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Superseded by a stack of four smaller PRs, to merge in order: #194 → #195 → #196 → #197. The combined tree matches this one, plus .gitattributes marking uv.lock as generated.

Superseded by a stack of four smaller PRs, to merge in order: #194 → #195 → #196 → #197. The combined tree matches this one, plus `.gitattributes` marking `uv.lock` as generated.
bobby closed this pull request 2026-11-27 17:01:51 -05:00

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.