/claude-kit:design-patterns-and-conventionsfrom Claude Kit SDLC
Enforces consistent design patterns, naming, folder layout, and anti-patterns for production Python/FastAPI backends. Use when architecting services, refactoring, reviewing structure, or debugging session leaks.
Ships in Claude Kit SDLC. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Enforce consistent design patterns, naming conventions, and architectural decisions across FastAPI backends, derived from real-world production services.
Depends() for injecting context (database sessions, configuration, event emitters).async def get_connection_handler_for_app() -> AsyncGenerator[ConnectionHandler, None] yields a handler, then closes it in finally.Depends.loaded_config instance (a Pydantic BaseSettings) everywhere.from config.docker_config import loaded_config then access loaded_config.POSTGRES_READ_WRITE.Singleton metaclass:
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]
class ConnectionManager(metaclass=Singleton). Do NOT create duplicate instances elsewhere.get_app() or create_app() constructs the FastAPI instance, applies middleware, wires routers, and returns it.APIRoute class.CustomRequestRoute inherits fastapi.routing.APIRoute, overrides get_route_handler(), wraps the original handler with try/except, logs request/response JSON, and returns a uniform ResponseData envelope.api_router = APIRouter(route_class=CustomRequestRoute).{"success": bool, "data": Any, "message": str, "errors": list[str]}.ResponseData with class methods .ok(data, message) and .error(errors, message).MODE environment variable selects the main function in entrypoint.py:
if loaded_config.MODE == "server":
server_main()
elif loaded_config.MODE == "consumer":
consumer_main()
elif loaded_config.MODE == "temporal_worker":
worker_main()
snake_case (e.g., connection_handler.py, get_session_factory()).PascalCase (e.g., ConnectionManager, ResponseData).global_utils/, data_category_field/).src/supplier/, src/webhook/, each with its own router.py, service.py, dao.py, models.py.app/ or src/ for application codeconfig/ for settings, logging, uri parsingservices/ for infrastructure integrations (Kafka, Temporal, GCS)global_utils/ or core/ for shared utilities (metaclasses, exceptions, HTTP clients)alembic/ or migrations/ for DB migrationsv1/, v2/ as path prefixes; may group all v1 routers under api/v1/router.py.# app/connection.py
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_scoped_session
from sqlalchemy.orm import sessionmaker
from asyncio import current_task
from global_utils.metaclasses import Singleton
from config.docker_config import loaded_config
class ConnectionManager(metaclass=Singleton):
def __init__(self):
self._db_engine, self._db_session_factory = self._setup_db()
@staticmethod
def _setup_db():
db_url = str(loaded_config.POSTGRES_READ_WRITE)
async_db_url = db_url.replace("postgresql://", "postgresql+asyncpg://")
engine = create_async_engine(async_db_url, echo=loaded_config.DB_ECHO, pool_pre_ping=True)
session_factory = async_scoped_session(
sessionmaker(engine, expire_on_commit=False, class_=AsyncSession),
scopefunc=current_task,
)
return engine, session_factory
def get_session_factory(self):
return self._db_session_factory
# app/utils.py
from pydantic import BaseModel, Field
from typing import Any
class ResponseData(BaseModel):
success: bool = False
data: Any = None
message: str = ""
errors: list[str] = Field(default_factory=list)
@classmethod
def ok(cls, data: Any = None, message: str = "Success"):
return cls(success=True, data=data, message=message)
@classmethod
def error(cls, errors: list[str] | None = None, message: str = "Error"):
return cls(success=False, errors=errors or [], message=message)
# entrypoint.py (multi-mode pattern)
from config.docker_config import loaded_config
from app.main import main as server_main
from services.kafka.consumer.consumer import main as consumer_main
from services.temporal.run_workers import worker_main
if loaded_config.MODE == "server":
server_main()
elif loaded_config.MODE == "consumer":
consumer_main()
elif loaded_config.MODE == "temporal_worker":
worker_main()
See references/anti-patterns.md for the full catalogue. Key examples:
allow_origins=["*"] in production (restrict to known origins)._commit scattered; prefer context managers and rollback on exception).include_router calls).@app.on_event("startup") instead of lifespan; migrate to lifespan context managers).async_scoped_session with current_task).Starting a new FastAPI service?
get_app() or create_app()) to construct the FastAPI instance.loaded_config from Pydantic BaseSettings).async_scoped_session(scopefunc=current_task).get_connection_handler_for_app) for database sessions..ok() for success, .error() for errors).Organizing code by feature/domain?
router.py, service.py, dao.py, models.py inside.Need to run multiple roles (server/consumer/worker) from one image?
loaded_config.MODE in entrypoint.py.Integrating Kafka for event-driven messaging?
aiokafka for async FastAPI services; avoid mixing Kafka libraries.Orchestrating long-running workflows?
Need a globally shared resource (connection pool, event bus)?
Common pitfalls to avoid:
README.md (opens in a new tab)references/anti-patterns.md (opens in a new tab)references/htn-design-a-vending-machine.md (opens in a new tab)references/htn-lld-concepts.md (opens in a new tab)references/htn-validation-transformation-controllers-middlewares.md (opens in a new tab)references/naming-and-layout.md (opens in a new tab)references/patterns-catalog.md (opens in a new tab)references/repo-evidence.md (opens in a new tab)references/testing-patterns.md (opens in a new tab)references/troubleshooting.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ajyadav013/claude-kit --plugin claude-kit127 skills in this plugin
/accessibility-reviewUI accessibility (WCAG) review — keyboard operability, focus, ARIA semantics, color contrast, touch targets. Returns prioritized fixes. Distinct from performance/visual review./alembic-migrationsAlembic migration setup and patterns for async SQLAlchemy — async engine + run_sync in env.py, autogenerate, RLS/multi-tenant migrations. Use for alembic init, writing migrations, or debugging migration errors./anthropic-vertex-integrationClaude on Vertex AI via the AnthropicVertex SDK — lazy ADC client init, env-based project/region resolution, async helpers, backoff retry. Use when calling Claude via GCP Vertex AI (not direct Anthropic API)./api-and-interface-designStable API and interface design patterns. Use when designing REST/GraphQL endpoints, module boundaries, type contracts between modules or frontend/backend, or changing public interfaces./api-integrationWire the app to a backend API — data fetching, caching, error handling, loading states. Use when connecting to an endpoint, adding a fetch layer, or fixing API error and loading behaviour. React-query detail lives in tanstack-react-query-patterns./api-pagination-filtering-sortingHTTP query parameter conventions for pagination, filtering, sorting, and search with standardized response metadata. Use when designing list endpoints or building repositories that turn query params into SQL.Other plugins' skills for the same job