fastapi-conventions

Structure FastAPI apps with per-feature modules, routers, and reusable dependencies.

9|1|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/AratKruglik/antigravity-sdlc --skill fastapi-conventions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-conventions
Source: https://github.com/AratKruglik/antigravity-sdlc/tree/main/plugins/fastapi-plugin/skills/fastapi-conventions
Command: npx skills add https://github.com/AratKruglik/antigravity-sdlc --skill fastapi-conventions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamline the architecture of FastAPI projects by enforcing modular design, per-feature routers, and reusable dependencies to improve maintainability and scalability.

Core Features & Use Cases

  • APIRouter per feature module: Group related endpoints under a shared prefix and tags, reducing repetition and improving navigation.
  • Factory pattern with lifespan management: Use a create_app() factory with an async lifespan for startup/shutdown coordination.
  • Pydantic v2 schemas & validation: Leverage model_config and validators for robust data models and ORM integration.
  • Dependency injection & security: Build reusable dependencies (e.g., get_db, get_current_user) and compose them across routes.
  • OpenAPI customization & environment config: Centralize app settings via pydantic-settings and tailor OpenAPI output.

Quick Start

Create a FastAPI app using a create_app() factory, wire feature routers, and configure dependencies through environment settings.

Frequently Asked Questions about fastapi-conventions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a FastAPI project for better maintainability?

Structure FastAPI projects by enforcing modular design with per-feature modules, APIRouters, and reusable dependencies. This approach reduces endpoint repetition and improves navigation, making the API easier to maintain and scale.

What is the best way to manage FastAPI application lifespan and configuration?

Manage FastAPI lifespan and configuration by using a create_app() factory pattern with async lifespan for startup/shutdown coordination. Centralize environment-driven app settings via pydantic-settings to tailor OpenAPI output.

How do I use Pydantic v2 schemas for FastAPI data validation?

Use Pydantic v2 schemas for FastAPI validation by leveraging model_config and validators. This ensures robust data models and smooth ORM integration for your application's request and response payloads.

Can I use FastAPI dependency injection for authentication across feature routers?

Yes, you can compose reusable dependencies like get_current_user and get_db across feature routers. This FastAPI dependency injection approach centralizes security and database session logic for production-ready APIs.

Does this modular FastAPI architecture work for large production applications?

Yes, this modular FastAPI architecture is applicable to building robust, production-ready APIs across small to large projects. It enforces router-level dependencies, factory-based app creation, and OpenAPI customization for scalability.

How do I group related FastAPI endpoints under a shared prefix?

Group related FastAPI endpoints under a shared prefix and tags by using an APIRouter per feature module. This modular pattern reduces repetition and significantly improves API navigation.