Skip to content

avibebuilder/claude-prime / .claude/starter-skills/backend-fastapi-python

backend-fastapi-python

Verified

Use this skill for any Python backend work in this project: building FastAPI endpoints, writing service functions, defining Pydantic/SQLModel schemas, running Alembic migrations, or debugging 422 errors. Essential for authentication and authorization patterns — setting up get_current_user, is_superuser checks, admin-only guards, role-based access, and dependency injection chains like Depends(). Also covers middleware, background tasks, async SQLAlchemy sessions, ORM relationship loading, and request/response design. Activate whenever the question involves Python API code, FastAPI patterns, or backend architecture in this codebase. Not for frontend, Docker, CI/CD, or infrastructure.

FileKindSize
SKILL.mdskill md3.9 KB
references/auth.mdmarkdown5.5 KB
references/configuration.mdmarkdown3.5 KB
references/database.mdmarkdown3.9 KB
references/dependencies.mdmarkdown4.4 KB
references/error-handling.mdmarkdown4.7 KB
references/file-structure.mdmarkdown3.8 KB
references/middleware.mdmarkdown4.9 KB
references/models.mdmarkdown3.9 KB
references/routing.mdmarkdown4.5 KB
references/schemas.mdmarkdown4.3 KB
references/services.mdmarkdown5.1 KB

references/configuration.md

View on GitHub
# Configuration

## pydantic-settings Pattern

Use `pydantic-settings` for type-safe configuration with environment variable support.

### Global Settings

```python
# src/core/config.py
from typing import Literal

from pydantic import Field, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=".env",
        case_sensitive=True,
        env_ignore_empty=True,
        extra="ignore",
    )

    # App
    ENVIRONMENT: Literal["development", "production"] = "development"
    HOST: str = "0.0.0.0"
    PORT: int = 8000

    # Computed fields for derived values
    @computed_field
    @property
    def DEBUG(self) -> bool:
        return self.ENVIRONMENT == "development"

    @computed_field
    @property
    def LOG_LEVEL(self) -> str:
        return "debug" if self.ENVIRONMENT == "development" else "info"

    # Database
    POSTGRES_HOST: str
    POSTGRES_PORT: int = 5432
    POSTGRES_USER: str
    POSTGRES_PASSWORD: str
    POSTGRES_DB: str

    @computed_field
    @property
    def DATABASE_URL(self) -> str:
        return f"postgresql+asyncpg://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"

    # CORS - handle comma-separated string
    CORS_ORIGINS_STR: str = Field(default="", alias="CORS_ORIGINS")

    @computed_field
    @property
    def CORS_ORIGINS(self) -> list[str]:
        if not self.CORS_ORIGINS_STR:
            return []
        return [i.strip() for i in self.CORS_ORIGINS_STR.split(",") if i.strip()]


# Singleton instance
settings = Settings()  # type: ignore
```

### Module-Specific Config

Each module can have its own settings class:

```python
# src/modules/auth/auth_config.py
from pydantic_settings import BaseSettings, SettingsConfigDict

from src.core.config import settings


class AuthConfig(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=".env",
        case_sensitive=True,
        env_ignore_empty=True,
        extra="ignore",
    )

    # JWT
    JWT_SECRET_KEY: str
    JWT_ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 15
    REFRESH_TOKEN_EXPIRE_DAYS: int = 7

    # OAuth
    GOOGLE_CLIENT_ID: str
    GOOGLE_CLIENT_SECRET: str

    # Computed from global settings
    @property
    def GOOGLE_REDIRECT_URI(self) -> str:
        return f"{settings.BASE_URL}/auth/google/callback"


auth_settings = AuthConfig()  # type: ignore
```

## Best Practices

### Use computed_field for Derived Values

```python
# Good - computed from other settings
@computed_field
@property
def DATABASE_URL(self) -> str:
    return f"postgresql+asyncpg://..."

# Bad - duplicating logic
DATABASE_URL: str  # Would need to be set manually
```

### Handle Complex Types

```python
# Comma-separated list from env
CORS_ORIGINS_STR: str = Field(default="", alias="CORS_ORIGINS")

@computed_field
@property
def CORS_ORIGINS(self) -> list[str]:
    return [i.strip() for i in self.CORS_ORIGINS_STR.split(",") if i.strip()]
```

### Type Annotations

```python
# Use Literal for constrained values
ENVIRONMENT: Literal["development", "production"] = "development"

# Use Optional with defaults
DEBUG: bool = False
```

### Environment File

```bash
# .env.example
ENVIRONMENT=development
HOST=0.0.0.0
PORT=8000

# Database
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=secret
POSTGRES_DB=myapp

# CORS (comma-separated)
CORS_ORIGINS=http://localhost:3000,http://localhost:5173

# Auth
JWT_SECRET_KEY=your-secret-key-here
```
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 319kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 117kUpdated Claude CodeCodexVerifiedInstall