Instruction file imported from webstackdev/digest-engine (
.github/instructions/backend-python.instructions.md). Copyright stays with the author.
Backend Python Guidelines
- Preserve
projectas the scoping boundary. Do not reintroducetenantnaming. - Keep Django views and Ninja route handlers thin. Put operational logic in nearby helpers such as
core/tasks.py,core/pipeline.py,core/newsletters.py,core/plugins/, or focused modules next to the owning workflow. - For nested API resources, follow the patterns in
projects/ninja_api.pyand the owning app*_ninja_api.pymodules. - Enforce cross-project relationship validation in request schemas or endpoint-local validation instead of trusting the client.
- Preserve existing API field names in
snake_caseunless the contract is intentionally changing across backend and frontend. - Use Google-style docstrings with PEP 257 conventions for public modules, classes, functions, and non-obvious helpers.
- Keep changes small and local. Do not create generic
services.pyorutils.pyfiles unless the repo already needs that extraction. - When changing ingestion, embeddings, newsletter intake, or review behavior, keep the database, Taskiq, and Qdrant handoff coherent.
Validation
- Prefer focused checks first:
pytest core/tests/...python manage.py checkjust backend-lint
- Mock external systems such as Reddit, feed parsing, OpenRouter, email providers, and Qdrant in tests.
Good Anchors
core/models.pyprojects/ninja_api.pycore/api.pycore/tasks.pycore/pipeline.pycore/newsletters.py