Skip to content

Commit 16afb4d

Browse files
febus982claude
andcommitted
Add CLAUDE.md for Claude Code guidance
Provides essential commands, architecture overview, and development patterns to help Claude Code instances work effectively in this repo. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 64e384a commit 16afb4d

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

CLAUDE.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build and Development Commands
6+
7+
**Package Management (uv):**
8+
- `make dev-dependencies` - Install all dependencies including dev
9+
- `make install-dependencies` - Install production dependencies only
10+
- `make update-dependencies` - Update and sync dependencies
11+
12+
**Running Applications:**
13+
- `make dev-http` - Run HTTP application with hot reload (Docker)
14+
- `make dev-socketio` - Run Socket.io application with hot reload (Docker)
15+
- `docker compose up dramatiq-worker` - Run Dramatiq worker
16+
17+
**Testing:**
18+
- `make test` - Run full test suite with coverage (parallel execution)
19+
- `uv run pytest tests/path/to/test_file.py` - Run a single test file
20+
- `uv run pytest tests/path/to/test_file.py::test_function` - Run a specific test
21+
- `uv run pytest -k "pattern"` - Run tests matching pattern
22+
23+
**Code Quality:**
24+
- `make check` - Run all checks (lint, format, typing, test)
25+
- `make fix` - Auto-fix linting and formatting issues
26+
- `make typing` - Run mypy type checking
27+
- `make lint` - Run ruff linter
28+
- `make format` - Check code formatting
29+
30+
**Database:**
31+
- `make migrate` - Run database migrations
32+
- `make autogenerate-migration` - Generate new migration file
33+
34+
**Documentation:**
35+
- `make docs` - Serve documentation locally
36+
37+
## Architecture Overview
38+
39+
This is a Clean Architecture Python application with multiple entry points (HTTP/FastAPI, WebSocket/Socket.io, async tasks/Dramatiq).
40+
41+
### Layer Structure (`src/`)
42+
43+
```
44+
domains/ → Business logic (services, models, DTOs, events)
45+
gateways/ → External system interfaces (event gateways)
46+
http_app/ → FastAPI application and routes
47+
socketio_app/ → Socket.io application and namespaces
48+
dramatiq_worker/ → Async task worker
49+
common/ → Shared infrastructure (config, DI, storage, telemetry)
50+
migrations/ → Alembic database migrations
51+
```
52+
53+
### Dependency Injection Pattern
54+
55+
Uses `dependency-injector` library. Interface mappings are defined in `src/common/di_container.py`:
56+
57+
```python
58+
# Container maps interfaces to implementations
59+
BookRepositoryInterface: Factory[BookRepositoryInterface] = Factory(
60+
SQLAlchemyAsyncRepository,
61+
bind=SQLAlchemyBindManager.provided.get_bind.call(),
62+
model_class=BookModel,
63+
)
64+
```
65+
66+
Services use `@inject` decorator with `Provide[]`:
67+
68+
```python
69+
@inject
70+
def __init__(
71+
self,
72+
book_repository: BookRepositoryInterface = Provide[BookRepositoryInterface.__name__],
73+
)
74+
```
75+
76+
### Application Bootstrap
77+
78+
All applications share common initialization via `application_init()` in `src/common/bootstrap.py`:
79+
- Configures DI container
80+
- Initializes logging (structlog)
81+
- Sets up SQLAlchemy storage
82+
- Configures Dramatiq
83+
- Instruments OpenTelemetry
84+
85+
### Domain Structure (example: `domains/books/`)
86+
87+
- `_models.py` - SQLAlchemy models (imperative mapping)
88+
- `_service.py` - Business logic services
89+
- `_gateway_interfaces.py` - Repository/gateway protocols
90+
- `_tasks.py` - Dramatiq async tasks
91+
- `dto.py` - Pydantic DTOs for API layer
92+
- `events.py` - CloudEvents definitions
93+
- `interfaces.py` - Public domain interfaces
94+
95+
### Testing
96+
97+
Tests mirror source structure in `src/tests/`. Key patterns:
98+
- Integration tests use `TestClient` with in-memory SQLite
99+
- Unit tests mock dependencies via `AsyncMock`/`MagicMock`
100+
- 100% coverage required (`fail_under = 100` in pyproject.toml)
101+
- Storage tests in `tests/storage/` use isolated database fixtures
102+
103+
### Configuration
104+
105+
Environment-based configuration via Pydantic Settings in `src/common/config.py`. Nested configs use `__` delimiter (e.g., `DRAMATIQ__BROKER_URL`).

0 commit comments

Comments
 (0)