Convert Figma logo to code with AI

fastapi logofull-stack-fastapi-template

Full-stack web application template with FastAPI, React, SQLModel, PostgreSQL, Vite, Tailwind CSS, shadcn/ui, FastAPI Cloud, and Docker Compose.

46,041
9,150
46,041
12

Top Related Projects

Full-stack web application template with FastAPI, React, SQLModel, PostgreSQL, Vite, Tailwind CSS, shadcn/ui, FastAPI Cloud, and Docker Compose.

101,604

FastAPI framework, high performance, easy to learn, fast to code, ready for production

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

A curated list of awesome things related to FastAPI

Quick Overview

The fastapi/full-stack-fastapi-template is a comprehensive project template for building full-stack web applications using FastAPI, PostgreSQL, and React. It provides a solid foundation for developing modern, scalable web applications with a robust backend API and a responsive frontend interface.

Pros

  • Includes a complete setup for both backend (FastAPI) and frontend (React) development
  • Incorporates best practices for project structure, security, and deployment
  • Provides pre-configured Docker setup for easy development and deployment
  • Includes user authentication and authorization out of the box

Cons

  • May be overwhelming for beginners due to its comprehensive nature
  • Requires knowledge of multiple technologies (FastAPI, React, PostgreSQL, Docker)
  • Some users may find the opinionated project structure limiting
  • Regular maintenance is needed to keep dependencies up-to-date

Code Examples

  1. Creating a new API endpoint:
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app import crud, schemas
from app.api import deps

router = APIRouter()

@router.post("/items/", response_model=schemas.Item)
def create_item(
    item: schemas.ItemCreate,
    db: Session = Depends(deps.get_db),
    current_user: schemas.User = Depends(deps.get_current_active_user),
):
    return crud.item.create_with_owner(db=db, obj_in=item, owner_id=current_user.id)
  1. Defining a database model:
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from app.db.base_class import Base

class Item(Base):
    id = Column(Integer, primary_key=True, index=True)
    title = Column(String, index=True)
    description = Column(String, index=True)
    owner_id = Column(Integer, ForeignKey("user.id"))
    owner = relationship("User", back_populates="items")
  1. Creating a React component:
import React from 'react';
import { useQuery } from 'react-query';
import { getItems } from '../api';

const ItemList = () => {
  const { data, isLoading, error } = useQuery('items', getItems);

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <ul>
      {data.map((item) => (
        <li key={item.id}>{item.title}</li>
      ))}
    </ul>
  );
};

export default ItemList;

Getting Started

  1. Clone the repository:

    git clone https://github.com/tiangolo/full-stack-fastapi-postgresql.git
    cd full-stack-fastapi-postgresql
    
  2. Create a .env file with your environment variables:

    cp .env.example .env
    
  3. Start the development environment using Docker:

    docker-compose up -d
    
  4. Access the API documentation at http://localhost:8000/docs and the frontend at http://localhost:3000.

Competitor Comparisons

Full-stack web application template with FastAPI, React, SQLModel, PostgreSQL, Vite, Tailwind CSS, shadcn/ui, FastAPI Cloud, and Docker Compose.

Pros of full-stack-fastapi-template

  • More comprehensive and feature-rich, including frontend and backend components
  • Includes Docker setup for easier deployment and development
  • Provides a complete project structure with user authentication and database integration

Cons of full-stack-fastapi-template

  • May be overly complex for simple projects or beginners
  • Requires more setup and configuration due to its full-stack nature
  • Potentially harder to customize or modify due to its extensive structure

Code Comparison

full-stack-fastapi-template:

from fastapi import FastAPI, Depends
from app.api.deps import get_current_active_user

app = FastAPI(title="MyApp")

@app.get("/users/me")
def read_users_me(current_user = Depends(get_current_active_user)):
    return current_user

full-stack-fastapi-template:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

The code comparison shows that full-stack-fastapi-template includes more advanced features like user authentication, while full-stack-fastapi-template provides a simpler starting point. The full-stack version offers a more structured approach with dependencies and user management, whereas the other template focuses on basic FastAPI functionality.

101,604

FastAPI framework, high performance, easy to learn, fast to code, ready for production

Pros of FastAPI

  • Lightweight and focused on core API functionality
  • Extensive documentation and examples for API development
  • Highly performant and designed for asynchronous operations

Cons of FastAPI

  • Lacks built-in full-stack features and frontend integration
  • Requires additional setup for database management and authentication
  • Less opinionated structure for larger applications

Code Comparison

FastAPI (basic route):

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

Full-Stack FastAPI Template (route with dependencies):

from fastapi import APIRouter, Depends
from app import deps

router = APIRouter()

@router.get("/")
def read_root(
    db = Depends(deps.get_db),
    current_user = Depends(deps.get_current_active_user),
):
    return {"message": "Hello World"}

The Full-Stack FastAPI Template provides a more structured approach with pre-configured dependencies and database integration, while the core FastAPI focuses on simplicity and flexibility for API development.

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Pros of cookiecutter-django

  • More mature and established project with a larger community
  • Comprehensive documentation and extensive feature set
  • Built-in support for Docker and production-ready configurations

Cons of cookiecutter-django

  • Steeper learning curve due to its complexity and extensive features
  • Potentially slower development process for smaller projects
  • Less flexibility for customization compared to a more lightweight template

Code Comparison

cookiecutter-django:

from django.db import models
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    name = models.CharField(_("Name of User"), blank=True, max_length=255)

full-stack-fastapi-template:

from sqlalchemy import Column, Integer, String
from app.db.base_class import Base

class User(Base):
    id = Column(Integer, primary_key=True, index=True)
    full_name = Column(String, index=True)

The cookiecutter-django example shows a custom User model extending Django's AbstractUser, while the full-stack-fastapi-template uses SQLAlchemy for database models, demonstrating the different approaches to ORM and user management in these frameworks.

A curated list of awesome things related to FastAPI

Pros of awesome-fastapi

  • Comprehensive collection of FastAPI resources, tutorials, and tools
  • Regularly updated with community contributions
  • Serves as a valuable learning and reference hub for FastAPI developers

Cons of awesome-fastapi

  • Not a complete project template, requires more setup for a full-stack application
  • Lacks integrated frontend and backend components
  • May overwhelm beginners with too many options and resources

Code Comparison

awesome-fastapi doesn't provide direct code examples, as it's a curated list of resources. However, full-stack-fastapi-template offers a complete project structure:

# full-stack-fastapi-template
from fastapi import FastAPI
from app.api.api_v1.api import api_router

app = FastAPI()
app.include_router(api_router, prefix="/api/v1")

Summary

awesome-fastapi is an excellent resource for learning and discovering FastAPI tools, while full-stack-fastapi-template provides a ready-to-use project structure. The choice depends on whether you need a comprehensive reference or a complete project setup.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Full Stack FastAPI Template

Test Docker Compose Test Backend

Technology Stack and Features

  • ⚡ FastAPI for the Python backend API.
    • 🧰 SQLModel for the Python SQL database interactions (ORM).
    • 🔍 Pydantic, used by FastAPI, for the data validation and settings management.
    • 💾 PostgreSQL as the SQL database.
  • 🚀 React for the frontend.
    • 🧩 Built into the backend application and served by FastAPI on the same domain as the API.
    • 💃 Using TypeScript, hooks, Vite, and other parts of a modern frontend stack.
    • 🎨 Tailwind CSS and shadcn/ui for the frontend components.
    • 🤖 An automatically generated frontend client.
    • 🧪 Playwright for end-to-end testing.
    • 🦇 Dark mode support.
  • ☁️ FastAPI Cloud for deployment.
  • 🐋 Docker Compose for local services and self-hosted deployment.
    • 📞 Traefik as a reverse proxy with automatic HTTPS.
  • 🔒 Secure password hashing by default.
  • 🔑 JWT (JSON Web Token) authentication.
  • 📫 Email-based password recovery.
  • ✉️ React Email for email templates.
  • 📬 Mailpit for local email testing during development.
  • ✅ Tests with Pytest.
  • 🏭 CI (continuous integration) and CD (continuous deployment) based on GitHub Actions.

Dashboard Login

Dashboard login screenshot

Dashboard - Admin

Admin dashboard screenshot

Dashboard - Items

Items dashboard screenshot

Dashboard - Dark Mode

Dark mode dashboard screenshot

React Email Templates

Email templates screenshot

Mailpit - Local Email Testing

Mailpit screenshot

Interactive API Documentation

API docs

How to Use It

Click the Use this template button at the top of this page to create a new repository.

Backend Development

Backend docs: backend/README.md.

Frontend Development

Frontend docs: frontend/README.md.

Deployment

FastAPI Cloud deployment: deployment.md.

Self-hosted deployment with Docker Compose: deployment-docker-compose.md.

Development

General development docs: development.md.

This includes the local FastAPI and Vite workflow, Docker Compose services, .env configuration, and more.

Release Notes

Check the file release-notes.md.

License

The Full Stack FastAPI Template is licensed under the terms of the MIT license.