Skip to content

Commit 1a29a79

Browse files
committed
add CLAUDE.md
1 parent 3cb5723 commit 1a29a79

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
```bash
8+
just install # Install all deps (uv lock --upgrade + uv sync --all-extras)
9+
just lint # Format and lint with fixes (ruff format, ruff check --fix, mypy)
10+
just lint-ci # Lint check without fixes
11+
just test # Run full test suite with coverage
12+
just test tests/path/to/test_file.py # Run single test file
13+
just test -k test_name # Run tests matching a name
14+
```
15+
16+
## Architecture
17+
18+
Microbootstrap auto-wires production instrumentation (observability, logging, tracing, etc.) into Python web/messaging frameworks via a settings-driven plugin system.
19+
20+
### Core concepts
21+
22+
**Instruments** (`microbootstrap/instruments/`) — Independent plugins for each tool (Sentry, OpenTelemetry, Prometheus, structlog, Pyroscope, Swagger, CORS, health checks). Each instrument has:
23+
- A config class extending `BaseInstrumentConfig` (Pydantic model)
24+
- `is_ready()` — gating check before activation
25+
- `bootstrap_before()` → returns `dict` merged into app constructor kwargs
26+
- `bootstrap()` — side-effectful initialization
27+
- `bootstrap_after(app)` — post-construction setup (middleware, routes)
28+
29+
**Bootstrappers** (`microbootstrap/bootstrappers/`) — Framework-specific orchestrators for Litestar, FastAPI, FastStream, and a framework-agnostic `InstrumentsSetupper`. They:
30+
1. Accept a settings object and extract per-instrument configs
31+
2. Build the framework app by merging all `bootstrap_before()` dicts with user-supplied config
32+
3. Call `bootstrap_after(app)` on each instrument
33+
4. Register instruments via the `@Bootstrapper.use_instrument()` class decorator
34+
35+
**Settings** (`microbootstrap/settings.py`) — Pydantic Settings classes combining `BaseServiceSettings` with per-instrument config mixins. Each framework (`LitestarSettings`, `FastApiSettings`, `FastStreamSettings`) inherits all relevant config mixins. Reads from env vars, with optional `ENVIRONMENT_PREFIX` namespacing.
36+
37+
**Config merging** (`microbootstrap/helpers.py`) — When merging instrument dicts with user-supplied framework config: scalars are overridden, containers (dict/list/set/tuple) are deep-merged/extended.
38+
39+
### Adding a new instrument
40+
41+
1. Create config class extending `BaseInstrumentConfig` in `instruments/`
42+
2. Create instrument class extending `Instrument[YourConfig]` — implement `is_ready`, `bootstrap`, `bootstrap_before`, `bootstrap_after`
43+
3. Create framework-specific subclasses extending both the base instrument and `LitestarInstrument`/`FastApiInstrument`/etc.
44+
4. Register each with `@LitestarBootstrapper.use_instrument()` (and other frameworks as needed)
45+
5. Add config mixin to the relevant Settings classes
46+
47+
### Key constraints
48+
49+
- Strict mypy — all code must type-check cleanly
50+
- Python 3.10–3.14 support required; avoid 3.11+ syntax
51+
- All instrument extras are optional deps; use `TYPE_CHECKING` guards where needed

0 commit comments

Comments
 (0)