Use when designing or editing aggregates and their repositories in a FastAPI + SQLAlchemy backend: files in app/models/ and app/repos/. Triggers on edits to those directories; on imports from sqlalchemy.ext.asyncio, sqlalchemy.orm; on user mentions of "aggregate", "repository", "consistency boundary", "ORM model with…
Use when considering a Java/GoF-shaped pattern that agents commonly generate in Python: Singleton, Abstract Factory, or Factory Method. Use when reviewing code defining class Singleton, class AbstractFactory, Factory.create(...), or when the user asks "is X a good idea in Python?" Encodes: which imported patterns…
Use when wrapping an external HTTP API (CRM, payment gateway, notification service, LLM provider, etc.) into a typed Python client class. Triggers on edits to app/clients/; on imports of httpx, tenacity; on user questions about HTTP clients, retries, mocking external APIs, MockTransport, client lifecycle. Encodes…
Use when scaffolding or modifying the structure of a FastAPI + SQLAlchemy backend service: setup.py, config.py, the db/, deps/, common/, api/ directories, the FastAPI app factory, lifespan, middleware, exception handlers. Triggers on edits to those files; on a new repo that's becoming a FastAPI service; on user…
Use when the service is event-driven: publishing or consuming events through a message broker (Kafka, RabbitMQ, Redis Streams, NATS, SQS), or using an in-process bus to decouple side effects from a use case. Triggers on edits to app/events/, app/handlers/, app/outbox/, app/consumers/; on imports of aiokafka, aio-pika…
Use ONLY when the project has an explicit app/domain/ directory, or the user explicitly asks for "DDD aggregate", "pure domain model", "framework-free invariants", "Cosmic Python style", "separate domain and ORM". Triggers on edits to app/domain/; on user mentions of Cosmic Python, ports and adapters, imperative SA…
Use when designing or editing services and schemas in a FastAPI + SQLAlchemy backend: files in app/services/ and app/schemas/. Triggers on edits to those directories; on definitions of class Service, class Command, class Get; on user mentions of "use case", "service layer", "Pydantic schema", "command", "response…
Use when iterating over collections, building lazy pipelines, or modeling tree / recursive structures (filesystems, ASTs, query builders, UI trees). Triggers on imports of itertools, collections.abc; on for ... yield ..., iter, generators; on tree-shaped data, leaf/composite distinctions, recursive traversal. Encodes…
Use when setting up logging or writing log calls in a Python service. Triggers on import logging, import structlog, edits to app/common/logging.py or app/api/middleware/, on user questions about logging, JSON logs, correlation IDs, structured logging, log levels. Encodes: structlog as the canonical logger…
Use when writing or organizing tests for a FastAPI + SQLAlchemy backend service. Triggers on edits to tests/, conftest.py, files in tests/fixtures/, tests/doubles/, tests/unit/, tests/integration/, tests/api/; on imports of pytestasyncio, httpx.ASGITransport, httpx.MockTransport; on user questions about test fixtures…
Use when writing or modifying typed Python code (any project — libraries, services, scripts). Triggers on .py files with type annotations; on imports from typing, typingextensions, collections.abc; on user questions about type hints, Protocol, generics, NewType, PEP 695. Encodes: Protocol over ABC for ports, Self for…
Use when defining domain primitives in any Python project — Money, EmailAddress, Color, Coordinates, IDs, anything where two instances with the same fields should be equal and where the values must satisfy invariants. Triggers on .py files defining @dataclass, on user questions about value objects, immutability…