Skip to content

lNamelessl/FastAPI-React-Postgres-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI + React + PostgreSQL Template

A full-stack web application template with a modern tech stack: FastAPI backend, React frontend, PostgreSQL database, and Docker containerization. Production-ready with authentication, API documentation, and Railway deployment support.

πŸš€ Quick Start

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • PostgreSQL 14+ (or use Docker)
  • Docker & Docker Compose (optional, for containerized setup)

Local Development (5 minutes)

# 1. Clone and setup
git clone <repo-url>
cd FastAPI-React-Postgres-Template

# 2. Backend setup
cd backend
uv sync
cp .env.example .env
# Edit .env with your PostgreSQL credentials
uv run alembic upgrade head  # Run migrations
uv run uvicorn app.main:app --reload

# 3. Frontend setup (in new terminal)
cd frontend
npm install
cp .env.local.example .env.local
npm run dev

# Visit http://localhost:5173 (React dev server)
# API available at http://localhost:8000
# Swagger UI at http://localhost:8000/docs

Using Docker Compose

cp .env.example .env
docker-compose up

Visit:

πŸ“š Documentation

  • SETUP.md - Detailed local development setup instructions
  • ARCHITECTURE.md - Project structure, tech stack, design patterns
  • DATABASE.md - Database schema, migrations, models

πŸ—οΈ Architecture Overview

FastAPI-React-Postgres-Template/
β”œβ”€β”€ backend/                 # FastAPI application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/            # API routes and dependencies
β”‚   β”‚   β”œβ”€β”€ core/           # Configuration, security, database
β”‚   β”‚   β”œβ”€β”€ models.py       # SQLModel ORM models
β”‚   β”‚   β”œβ”€β”€ crud.py         # Database operations
β”‚   β”‚   └── main.py         # FastAPI app initialization
β”‚   β”œβ”€β”€ alembic/            # Database migrations
β”‚   β”œβ”€β”€ Dockerfile          # Backend container
β”‚   β”œβ”€β”€ pyproject.toml      # Python dependencies
β”‚   └── .env.example        # Environment template
β”œβ”€β”€ frontend/               # React application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/     # Reusable React components
β”‚   β”‚   β”œβ”€β”€ pages/          # Page components
β”‚   β”‚   β”œβ”€β”€ services/       # API client
β”‚   β”‚   β”œβ”€β”€ context/        # React Context for state
β”‚   β”‚   β”œβ”€β”€ types/          # TypeScript types
β”‚   β”‚   └── utils/          # Helper functions
β”‚   β”œβ”€β”€ Dockerfile          # Frontend container
β”‚   β”œβ”€β”€ package.json        # Node.js dependencies
β”‚   β”œβ”€β”€ vite.config.ts      # Vite configuration
β”‚   └── .env.local.example  # Environment template
β”œβ”€β”€ nginx/                  # Nginx reverse proxy
β”‚   └── nginx.conf          # Nginx configuration
β”œβ”€β”€ scripts/                # Development scripts
β”‚   β”œβ”€β”€ setup-dev.sh        # Setup automation
β”‚   β”œβ”€β”€ run-local.sh        # Run all services
β”‚   └── db-reset.sh         # Database reset
β”œβ”€β”€ docker-compose.yml      # Local dev orchestration
└── docs/                   # Documentation
    β”œβ”€β”€ SETUP.md
    β”œβ”€β”€ ARCHITECTURE.md
    └── 

πŸ” Authentication

The application uses JWT (JSON Web Tokens) for stateless authentication:

  1. User signs up or logs in with email and password
  2. Backend validates credentials and returns a JWT token
  3. Frontend stores token in localStorage
  4. Frontend includes token in Authorization header for authenticated requests
  5. Backend validates token on each request using CurrentUser dependency

See ARCHITECTURE.md for detailed flow.

πŸ—„οΈ Database

  • PostgreSQL - Relational database
  • SQLModel - Python ORM combining SQLAlchemy and Pydantic
  • Alembic - Database migration tool

Models:

  • User - User accounts with email, password, roles
  • Item - User-owned items

See DATABASE.md for schema details.

πŸ“‘ API Endpoints

All endpoints documented with OpenAPI (Swagger UI):

Quick reference:

  • POST /login/access-token - Login and get JWT token
  • POST /users/ - Create new user (public signup)
  • GET /users/ - List all users (admin only)
  • GET /items/ - List current user's items
  • POST /items/ - Create new item
  • GET /health - Health check

See API.md for full endpoint documentation.

🚒 Deployment

Railway (Recommended)

Quick deployment to Railway:

# 1. Connect your GitHub repo to Railway
# 2. Add PostgreSQL plugin
# 3. Set environment variables (see DEPLOYMENT.md)
# 4. Deploy!

See DEPLOYMENT.md for detailed Railway instructions.

Docker

Build and run locally:

docker-compose up --build

πŸ› οΈ Development

Database Migrations

cd backend

# Create new migration
alembic revision --autogenerate -m "migration description"

# Apply migrations
alembic upgrade head

# Rollback migration
alembic downgrade -1

Code Formatting

# Backend
cd backend
ruff check .
ruff format .

# Frontend
cd frontend
npm run lint

πŸ“¦ Key Dependencies

Backend:

  • FastAPI 0.128+ - Web framework
  • SQLModel 0.0.31+ - ORM
  • Pydantic 2.x - Data validation
  • PyJWT - JWT tokens
  • Passlib + Bcrypt - Password hashing
  • Psycopg - PostgreSQL driver
  • Alembic - Database migrations

Frontend:

  • React 18+ - UI library
  • React Router 6+ - Routing
  • TypeScript 5+ - Type safety
  • Vite 4+ - Build tool

[Deploy on Railway](https://railway.com/deploy/bmEgCZ?referralCode=uBTGZq&utm_medium=integration&utm_source=template&utm_campaign=generic)

🀝 Contributing

  1. Create a feature branch: git checkout -b feature/my-feature
  2. Commit changes: git commit -am 'Add my feature'
  3. Push to branch: git push origin feature/my-feature
  4. Open a Pull Request

πŸ“ License

LISENSE

πŸ†˜ Troubleshooting

πŸ“§ Support

For issues or questions:

  1. Check the documentation
  2. Review existing issues
  3. Create a new issue with details

Happy coding! πŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors