fastapi-templates

Create FastAPI project structures with async patterns, dependency injection, and repository layers.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill fastapi-templates-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-templates
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/fastapi-templates
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill fastapi-templates-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up a new FastAPI backend from scratch involves repetitive decisions about project layout, async database sessions, authentication, and error handling. This Skill provides complete, working code patterns so you can scaffold a well-structured API without reinventing the architecture each time. ## Core Features & Use Cases - Layered Project Structure: Provides a standard layout separating API routes, services, repositories, models, and Pydantic schemas. - Async Database & DI Patterns: Includes async SQLAlchemy session management, dependency injection with Depends, and lifespan-based startup/shutdown handling. - Auth & CRUD Templates: Ships JWT authentication, password hashing with bcrypt, a generic base repository, and full CRUD endpoint examples. - Use Case: When starting a new microservice, ask for a FastAPI project and receive a complete structure with user registration, login, protected endpoints, and pytest async test fixtures ready to adapt. ## Quick Start Create a new FastAPI project with async PostgreSQL support, JWT authentication, and a user CRUD module following the repository pattern.

Frequently Asked Questions about fastapi-templates

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

FAQPage Schema
How do I structure a FastAPI project for production?

Organize code into layers: api/ for routes and dependencies, core/ for config and database setup, models/ for SQLAlchemy models, schemas/ for Pydantic types, services/ for business logic, and repositories/ for data access. This separation keeps endpoints thin and logic testable.

How to use async database sessions in FastAPI with SQLAlchemy?

Create an async engine with create_async_engine and an AsyncSession sessionmaker, then expose a get_db dependency that yields sessions with commit, rollback, and close handling. Inject it into routes using Depends(get_db).

How do I implement JWT authentication in FastAPI?

Use python-jose to encode tokens with a secret key and expiry, passlib with bcrypt for password hashing, and OAuth2PasswordBearer to extract tokens. A get_current_user dependency decodes the JWT and loads the user from the database.

What is the repository pattern in FastAPI and when should I use it?

The repository pattern wraps database queries in a generic class with get, create, update, and delete methods, keeping SQLAlchemy logic out of services and routes. Use it when multiple endpoints share data access logic or you need testable data layers.

How do I test async FastAPI endpoints with pytest?

Use httpx AsyncClient with the FastAPI app, override the get_db dependency to point at an in-memory SQLite database via aiosqlite, and mark tests with pytest.mark.asyncio. Fixtures create tables and yield sessions per test.