# Fastapi Application Structure

> [Applies to: **/main.py] Defines the preferred file structure and component usage for FastAPI applications.

- Skill: `tryboy869/fastapi-application-structure` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tryboy869/fastapi-application-structure`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tryboy869/fastapi-application-structure/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: Tryboy869 (https://skillmd.com/u/tryboy869)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tryboy869/fastapi-application-structure

---


- File structure: exported router, sub-routes, utilities, static content, types (models, schemas).
- Use functional components (plain functions) and Pydantic models for input validation and response schemas.
- Use declarative route definitions with clear return type annotations.
- Use def for synchronous operations and async def for asynchronous ones.
- Minimize @app.on_event("startup") and @app.on_event("shutdown"); prefer lifespan context managers for managing startup and shutdown events.
- Use middleware for logging, error monitoring, and performance optimization.

