| applyTo |
|---|
**/*.py |
- If required context is missing (caller expectations, types, invariants, IO behavior), stop and ask for what’s missing rather than inventing it.
- Never invent modules, functions, env vars, CLI commands, or APIs that are not already present in the repo. If something is referenced but not found, say so.
- Change only what the task requires. No drive-by refactors.
- Do not rename identifiers, reorder code, or reformat unrelated sections.
- Prefer the smallest diff that preserves readability and keeps
ruff+tyhappy.
- Formatting: use ruff format (line length 88, target
py314). - Linting: fix issues rather than suppressing; use
# noqa: <CODES>only when justified. - Re-exports: use
from .module import X as Xinstead of suppressingF401or adding__all__just to appease lint. - Imports: prefer absolute imports from the package root; sibling imports (
.) are acceptable. - Exceptions (TRY003): avoid long formatted strings in
raise; prefer a custom exception class. - Typing: keep code ty-clean; avoid
Any/cast()unless bridging an external/untyped boundary.
- Follow PEP 8/PEP 257 as enforced by ruff.
- Keep formatting consistent with the existing file; don’t beautify unrelated code.
- Minimize comments; add them only when intent/invariants are not obvious.
- Python
>=3.14(modern syntax only when needed). - Dependencies managed with
uv; do not add packages without explicit permission. - Backend logic stays in
backend/; do not import fromfrontend/into backend code. - Backend stack: Litestar, Strawberry GraphQL, Advanced Alchemy/SQLAlchemy async,
pydantic-settings.
- Add accurate type hints for public functions/methods.
- Prefer
X | Y, built-in generics, andcollections.abcfor interfaces. - Model dynamic data explicitly (e.g.,
TypedDict,Protocol) instead of lying to the type checker. - Avoid
from __future__ import annotationsunless already present or required.
- Use
async deffor request/DB/IO code. - Use context managers for sessions, files, locks, etc.
- Avoid blocking calls in async paths unless explicitly accepted by the task.
- Prefer existing session acquisition patterns (e.g.,
alchemy_config.get_session()or injectedAsyncSession). - Keep transactions explicit: use
flush()for DB-generated values;commit()only when finalizing changes. - Prefer SQLAlchemy expressions over raw SQL unless required.
- Any schema/model change should use the migration workflow.
- Don’t introduce new required env vars casually.
- If settings change, update
Settingsand keep docs/examples in sync (README,.env.example,backend/.env.example) as needed.
- Keep types/queries/mutations/inputs in existing modules under
backend/src/backend/apps/**/graphql/. - Resolvers should be thin; move workflows into
services.py. - For user-visible errors, raise
GraphQLErrorwith a safe message. - Prefer typing the GraphQL context.
- Relay IDs:
- GraphQL
IDvalues are Relay Global IDs. - Use
strawberry.relay.Nodewithrelay.NodeID[int]for persisted entities. - Prefer
*_by_id(id: strawberry.relay.GlobalID)orQuery.node(id: ID!)for details. - Prefer Relay connections for lists and use
node.idfor list → details.
- GraphQL
- Prefer cursor/keyset pagination for list endpoints.
- Contract: request
limit+ optionalcursor, response{ items, page: { next_cursor, limit, has_next } }. - Reject malformed/tampered cursors and cursor reuse after filter/sort changes.
- Do not swallow exceptions; catch only what you can handle and re-raise otherwise.
- Narrow exception: auth/password verification may return a safe failure value, but keep scope minimal and justify broad catches.
- Do not add
print()for non-trivial codepaths. - Prefer existing logging conventions; if none exist, use
loguru(no new deps). - Never log secrets.
- Add docstrings only for public APIs or non-obvious logic.
- Use
"""docstrings that describe behavior, inputs/outputs, side effects, and exceptions.
- Update/add tests when behavior changes (pytest + pytest-asyncio).
- Type annotations are optional in
tests/and scripts. - Before declaring backend work done, prefer:
task backend:format,task backend:lint,task backend:typecheck,task backend:test.