Python microservice: PDF invoice → structured JSON extraction. Pipeline: PDF → PyMuPDF (text) → Anthropic Claude (structured output) → JSON.
- Framework: FastAPI
- PDF parsing: PyMuPDF
- LLM: Anthropic Claude via
anthropicSDK (Structured Output withoutput_config) - Config: pydantic-settings
- Package manager: uv
- Python: 3.11.7
make install— install dependenciesmake dev— run dev server with hot reloadmake test— run testsmake lint— ruff checkmake format— ruff formatmake typecheck— mypy
src/app/main.py— FastAPI app creation & exception handlerssrc/app/config.py— Settings via pydantic-settingssrc/app/dependencies.py— Auth dependency (bearer token)src/app/routes/— API route handlerssrc/app/schemas/— Pydantic request/response modelssrc/app/services/— Business logic (PDFParser, LLMExtractor)src/app/prompts/— Prompt templatestests/— Unit and integration tests
- Follow SOLID principles — single responsibility per class/module
- DRY — extract shared logic, don't repeat yourself
- TDD — write tests first when implementing new features
- Type hints on all function signatures
- Use
rufffor linting and formatting - Keep functions small and focused
- Prefer dependency injection over global state
- Error handling: raise HTTPException with appropriate status codes at the route level, let services raise domain-specific exceptions
- Import order: stdlib → third-party → local (enforced by ruff)
- Use
async deffor route handlers - Services are synchronous classes (PDF parsing and LLM calls are blocking)
- Settings loaded once via
get_settings()with@lru_cache - Auth via FastAPI
Depends(verify_token)on protected endpoints