|
| 1 | +This file provides guidance to AI coding agents working with this repository. |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +This repository is a reusable Python project template. It is intentionally small |
| 6 | +and generic, so changes should prefer simple, composable patterns over |
| 7 | +project-specific architecture. |
| 8 | + |
| 9 | +The current template includes: |
| 10 | + |
| 11 | +- Poetry for dependency management |
| 12 | +- Pydantic Settings for configuration |
| 13 | +- Loguru for logging |
| 14 | +- Optional Sentry initialization |
| 15 | +- Custom application exceptions |
| 16 | +- pytest, Ruff, isort, and mypy |
| 17 | +- Docker and GitHub Actions |
| 18 | + |
| 19 | +When adapting this template for a real project, preserve the clean foundation |
| 20 | +and add framework- or domain-specific code incrementally. |
| 21 | + |
| 22 | +## Common Development Commands |
| 23 | + |
| 24 | +```bash |
| 25 | +make deps # Install dependencies |
| 26 | +make format # Format code |
| 27 | +make lint # Run Ruff, isort, and mypy |
| 28 | +make test # Run tests |
| 29 | +make ci-test # Run tests with coverage |
| 30 | +make dev # Run the example entrypoint |
| 31 | +``` |
| 32 | + |
| 33 | +## Core Principles |
| 34 | + |
| 35 | +### Keep the template generic |
| 36 | + |
| 37 | +- Do not introduce business-specific naming, copy, or architecture into the |
| 38 | + template. |
| 39 | +- Prefer framework-agnostic utilities in `src/core/` unless the repository has |
| 40 | + clearly become tied to a framework. |
| 41 | +- New defaults should be broadly useful to future projects, not tailored to one |
| 42 | + app. |
| 43 | + |
| 44 | +### Favor minimal, explicit patterns |
| 45 | + |
| 46 | +- Prefer small modules with obvious responsibilities. |
| 47 | +- Avoid clever abstractions unless they clearly reduce repeated complexity. |
| 48 | +- Keep startup wiring easy to trace from `src/main.py`. |
| 49 | +- Make optional integrations truly optional by gating them with settings. |
| 50 | + |
| 51 | +### Preserve clean layering |
| 52 | + |
| 53 | +- `src/core/` is for reusable foundation code: config, logging, observability, |
| 54 | + exceptions, enums, and similar cross-cutting concerns. |
| 55 | +- `src/main.py` is the composition root for startup wiring and top-level error |
| 56 | + handling. |
| 57 | +- `tests/` should verify behavior, not implementation details. |
| 58 | + |
| 59 | +## Configuration Conventions |
| 60 | + |
| 61 | +- All configuration should live in `src/core/config.py`. |
| 62 | +- Environment variables should be documented in `.env.example`. |
| 63 | +- Copy `.env.example` to `.env` for local development; never commit secrets. |
| 64 | +- Optional services must degrade cleanly when their config is absent. |
| 65 | + |
| 66 | +Examples in this template: |
| 67 | + |
| 68 | +- Sentry is disabled when `SENTRY_DSN` is empty. |
| 69 | +- Logging configuration is environment-aware via `ENVIRONMENT`. |
| 70 | + |
| 71 | +## Logging, Observability, and Errors |
| 72 | + |
| 73 | +- Use `src/core/logging.py` for Loguru setup. |
| 74 | +- Keep observability integrations minimal in the template. Add advanced routing, |
| 75 | + filtering, or framework-specific integrations only in downstream projects. |
| 76 | +- Use custom exceptions from `src/core/exceptions/` for intentional app-level |
| 77 | + failures. |
| 78 | +- Catch custom app exceptions at the top level in `src/main.py` or the |
| 79 | + framework-specific entrypoint, log them consistently, and exit or translate |
| 80 | + them there. |
| 81 | + |
| 82 | +## Dependencies |
| 83 | + |
| 84 | +- Use Poetry for all dependency changes. |
| 85 | +- Keep runtime dependencies minimal. |
| 86 | +- Add a dependency to the template only if it is broadly useful across many new |
| 87 | + projects. |
| 88 | +- Remove stale dependencies when their integration is removed from the codebase. |
| 89 | + |
| 90 | +## Testing and Verification |
| 91 | + |
| 92 | +- Add or update focused tests for behavior changes. |
| 93 | +- Prefer test-first changes for new features and bug fixes. |
| 94 | +- After substantive edits, run: |
| 95 | + |
| 96 | +```bash |
| 97 | +make test |
| 98 | +make lint |
| 99 | +``` |
| 100 | + |
| 101 | +- If config, startup wiring, or dependency behavior changes, add tests for the |
| 102 | + new edge cases. |
| 103 | + |
| 104 | +## Code Style |
| 105 | + |
| 106 | +- Python 3.13 target. |
| 107 | +- Line length: 100. |
| 108 | +- Type hints are required for public function signatures. |
| 109 | +- Keep comments focused on why, not what. |
| 110 | +- Public modules and public classes should have useful docstrings. |
| 111 | +- Avoid commented-out code. |
| 112 | + |
| 113 | +## Template-Specific Change Guidelines |
| 114 | + |
| 115 | +- If you add a new core capability, wire it through all relevant template entry |
| 116 | + points: |
| 117 | + - dependencies in `pyproject.toml` |
| 118 | + - environment variables in `.env.example` |
| 119 | + - startup/config code in `src/core/` or `src/main.py` |
| 120 | + - tests in `tests/` |
| 121 | + - docs in `README.md` if the capability affects setup or usage |
| 122 | + |
| 123 | +- If you rename or remove a template feature, clean up: |
| 124 | + - stale tests |
| 125 | + - stale README references |
| 126 | + - stale environment variables |
| 127 | + - stale dependencies and lockfile entries |
| 128 | + |
| 129 | +## What Not to Do |
| 130 | + |
| 131 | +- Do not hardcode secrets or commit real credentials. |
| 132 | +- Do not add service-specific architecture to the template without a clear need. |
| 133 | +- Do not leave dead examples, mismatched tests, or outdated docs behind. |
| 134 | +- Do not couple the template to a framework unless that is an intentional |
| 135 | + direction change for the repository. |
| 136 | + |
| 137 | +## Keeping This File in Sync |
| 138 | + |
| 139 | +Update this file whenever the template's development workflow, architectural |
| 140 | +expectations, or core building blocks change. |
0 commit comments