diff --git a/README.md b/README.md index ae239c0..64bc5dc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,41 @@ A Python monorepo managed as a [uv workspace](https://docs.astral.sh/uv/concepts/projects/workspaces/). All members share one virtualenv and one `uv.lock`. +## What this project is + +A working template for building **several Python services and libraries in one repository** +while still testing, building and deploying each one on its own. It ships a small but +realistic microservice system so you can see every piece working together: + +- **`catalog-api`** lists products, **`orders-api`** places orders (calling the catalog over + HTTP) and publishes an `order.placed` event, and **`notifier-worker`** consumes that event + and sends a notification. +- The services share code only through libraries in `packages/`: typed **contracts** + (pydantic models for API payloads and events), a pluggable **messaging** layer (Redis, + RabbitMQ, a built-in TCP broker or in-memory, chosen with one `BROKER_URL`) and + **servicekit** (settings, logging, a FastAPI app factory with `/health`). +- The tooling around them is already wired up: strict `mypy`, `ruff`, `pytest`, pre-commit, + one slim Docker image per app, a `compose.yaml` for running everything locally, and CI + that **only tests what your change affects**. + +The example domain (products, orders, notifications) is deliberately small. The point is the +structure, which you keep, and the examples, which you replace or grow. + +## Using it for your needs + +Pick the path that matches what you want to do: + +| You want to... | Do this | +| --- | --- | +| **Try it out / learn the pattern** | Follow [Getting started](#getting-started), run the stack with `docker compose up --build`, and read [ARCHITECTURE.md](ARCHITECTURE.md) for diagrams of how the pieces fit. | +| **Start your own project from it** | Fork or copy the repo, delete the example apps you don't need (and their entries in `compose.yaml` and the root `pyproject.toml` ruff/mypy lists), then add your own services. Keep `packages/servicekit` and `packages/messaging`; they're domain-agnostic. | +| **Add a new HTTP API or worker** | Scaffold one that is fully wired in (package, Dockerfile, compose, lint/type config, tests): `python3 .claude/skills/new-service/scripts/scaffold.py inventory-api --kind http` (or `--kind worker --event ... --topic ...`). With Claude Code, just ask it to "add a new service"; the bundled `new-service` skill does the whole job. See [Adding a new service](ARCHITECTURE.md#adding-a-new-service). | +| **Add a shared library** | Create it under `packages/` and depend on it from your apps; see [Adding a member](#adding-a-member). | +| **Share data between services** | Put request/response models and events in `packages/contracts`, so producer and consumer use the same typed definition. | +| **Use a different message broker** | Switch between Redis, RabbitMQ and TCP with an env file (see below), or add a new backend (Kafka, NATS, SQS, ...) by implementing the `Broker` interface; see [ARCHITECTURE.md](ARCHITECTURE.md#adding-another-broker-kafka-nats-sqs-). | +| **Deploy services separately** | Build each app's image on its own and version/scale it independently; see [Deploying services independently](#deploying-services-independently). | +| **Keep CI fast as the repo grows** | Nothing to do: CI works out which members a change affects from the `pyproject.toml` files. See [CI](#ci). | + ![Demo: services talking over HTTP and Redis, CI testing only affected members, and scaffolding a new service](docs/demo.gif) Real commands and output, replayed by [`docs/demo/player.html`](docs/demo/player.html). Also available as an [MP4](docs/demo.mp4). Regenerate with `node docs/demo/record.mjs`.