What problem does it solve?
It defines and enforces a cohesive set of API adapter design rules to ensure consistent, secure, and maintainable integration code across the repository.
Core Features & Use Cases
- Config Pattern: Always implement adapter configuration as a class inheriting from PydanticBaseEnvConfig with a standardized environment prefix.
- Retry Logic: Use tenacity for retries with a uniform decorator, ensuring proper handling of transient errors.
- Factory Pattern: Instantiate adapters via factory functions/classes when multiple implementations exist.
- Mock Clients: Provide dedicated mock adapters alongside real ones for deterministic testing.
- Client Class Structure: Encapsulate external API calls in a dedicated client class with a config object.
- Session Management: Pass database/session objects through method parameters; avoid storing them on adapters.
- Error Mapping: Map external errors to internal exceptions and log before re-raising.
- Adapter Boundaries: Route external calls through adapters; keep service layer free of direct external dependencies.
- Logging: Initialize module-level loggers and avoid exposing credentials; log outcomes for external calls.
- Context Enrichment: Use architecture guidance from smaller MCP rules for adapter design decisions.
Quick Start
Review and apply the api adapters rules to ensure code complies with standard patterns across adapters.