|
| 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 # Update lock file and sync all extras + lint group |
| 9 | +just lint # Format and lint (eof-fixer, ruff format, ruff check --fix, ty check) |
| 10 | +just lint-ci # CI lint in check-only mode (no auto-fix) |
| 11 | +just test # Run pytest with coverage |
| 12 | +just test -- -k "test_name" # Run a single test |
| 13 | +just test-branch # Run tests with branch coverage |
| 14 | +``` |
| 15 | + |
| 16 | +All commands use `uv run` — do not invoke tools directly (e.g., use `uv run pytest`, not `pytest`). |
| 17 | + |
| 18 | +## Architecture |
| 19 | + |
| 20 | +**lite-bootstrap** bootstraps Python microservices with pre-configured observability instruments. |
| 21 | + |
| 22 | +### Core pattern |
| 23 | + |
| 24 | +``` |
| 25 | +BaseConfig (dataclass, frozen, kw_only) |
| 26 | + └── Framework configs compose multiple instrument configs via multiple inheritance |
| 27 | +
|
| 28 | +BaseInstrument (abstract) |
| 29 | + └── Instrument subclasses: lifecycle via bootstrap() / teardown() / is_ready() |
| 30 | +
|
| 31 | +BaseBootstrapper (abstract) |
| 32 | + ├── FastAPIBootstrapper |
| 33 | + ├── LitestarBootstrapper |
| 34 | + ├── FastStreamBootstrapper |
| 35 | + └── FreeBootstrapper |
| 36 | +``` |
| 37 | + |
| 38 | +### Key design decisions |
| 39 | + |
| 40 | +- **Optional dependencies**: Each instrument checks for its optional package via `import_checker.py` (`importlib.util.find_spec`). Instruments are skipped silently if the package is absent. |
| 41 | +- **Frozen dataclass configs**: All configs are `@dataclasses.dataclass(kw_only=True, frozen=True)`. `from_dict()` and `from_object()` filter unknown keys before constructing. |
| 42 | +- **Instrument registry**: `BaseBootstrapper` holds a list of instrument instances; it calls `bootstrap()` on each in order and `teardown()` in reverse during shutdown. |
| 43 | +- **Logging ↔ Sentry integration**: `logging_instrument.py` injects structlog context into Sentry events. `sentry_instrument.py` chains `before_send` callbacks via `wrap_before_send_callbacks()`. The `skip_sentry` flag in log context suppresses events. |
| 44 | +- **OTel ↔ Logging integration**: The logging instrument injects span/trace IDs from the active OpenTelemetry context into every log record. |
| 45 | + |
| 46 | +### Module layout |
| 47 | + |
| 48 | +- `lite_bootstrap/bootstrappers/` — framework-specific bootstrappers and their config classes |
| 49 | +- `lite_bootstrap/instruments/` — individual instrument implementations (one file per tool) |
| 50 | +- `lite_bootstrap/helpers/` — utility functions (`fastapi_helpers.py` serves offline Swagger UI assets) |
| 51 | +- `lite_bootstrap/import_checker.py` — detects installed optional packages |
| 52 | +- `lite_bootstrap/types.py` — shared TypeVars |
| 53 | + |
| 54 | +### Optional dependency groups |
| 55 | + |
| 56 | +Install via `pip install lite-bootstrap[<group>]` or `uv add lite-bootstrap[<group>]`: |
| 57 | + |
| 58 | +| Group | Contents | |
| 59 | +|-------|----------| |
| 60 | +| `fastapi-all` | fastapi + sentry + otl + logging + metrics | |
| 61 | +| `litestar-all` | litestar + sentry + otl + logging | |
| 62 | +| `faststream-all` | faststream + sentry + otl + logging | |
| 63 | +| `free-all` | sentry + otl + logging | |
| 64 | + |
| 65 | +## Code style |
| 66 | + |
| 67 | +- Line length: 120 characters (ruff enforced) |
| 68 | +- Ruff ALL rules enabled; notable ignores: D1 (missing docstrings), S101 (assert), TCH (type-checking imports), FBT (boolean args) |
| 69 | +- Type annotations required; checked with `ty` |
0 commit comments