A production-ready full-stack application boilerplate with FastAPI backend and React+Vite frontend, featuring modern development practices, Docker containerization, and comprehensive tooling.
- β Modern Python: Python 3.12+ with async/await patterns
- β FastAPI Framework: High-performance async API with automatic OpenAPI docs
- β Service Layer Architecture: Clean separation of concerns (routes β services β models)
- β JWT Authentication: Ready-to-use authentication with JWT tokens
- β SQLAlchemy ORM: Async SQLAlchemy 2.0+ with PostgreSQL
- β Database Migrations: Alembic for schema migrations
- β Testing: pytest with async support and example tests
- β Package Management: UV for fast, reliable dependency management
- β Code Quality: Ruff for linting and formatting
- β React 18: Latest React with TypeScript
- β Vite: Lightning-fast build tool with HMR
- β TypeScript: Full type safety across the application
- β React Router: Client-side routing
- β Axios: HTTP client with interceptors
- β Custom Hooks: Reusable API hooks with loading/error states
- β Path Aliases: Clean imports with @ alias
- β Package Management: pnpm for efficient dependency management
- β Docker: Multi-stage builds for optimized images
- β Docker Compose: Development and production configurations
- β Hot Reload: Both backend and frontend support hot-reload in dev mode
- β Nginx: Production-ready reverse proxy with SPA routing
- β Makefile: Convenient commands for common operations
- β Health Checks: Container health monitoring
python-fullstack-boilerplate/
βββ backend/ # FastAPI backend
β βββ app/
β β βββ api/ # API routes
β β β βββ v1/
β β β βββ endpoints/ # Route handlers
β β β βββ router.py # Route aggregation
β β βββ core/ # Core utilities
β β β βββ dependencies.py
β β β βββ exceptions.py
β β β βββ security.py # JWT auth
β β βββ db/ # Database layer
β β β βββ models.py # SQLAlchemy models
β β β βββ session.py # DB session config
β β βββ models/ # Pydantic schemas
β β βββ services/ # Business logic
β β βββ config.py # Settings
β β βββ main.py # FastAPI app
β βββ tests/ # Backend tests
β βββ Dockerfile
β βββ pyproject.toml # UV dependencies
β βββ .env.example
β
βββ frontend/ # React + Vite frontend
β βββ src/
β β βββ components/ # React components
β β βββ hooks/ # Custom hooks
β β βββ pages/ # Page components
β β βββ services/ # API services
β β βββ types/ # TypeScript types
β β βββ utils/ # Utilities
β β βββ App.tsx # Root component
β β βββ main.tsx # Entry point
β βββ Dockerfile
β βββ nginx.conf
β βββ vite.config.ts
β βββ tsconfig.json
β βββ package.json
β βββ .env.example
β
βββ docker-compose.yml # Development setup
βββ docker-compose.prod.yml # Production setup
βββ Makefile # Helper commands
βββ .gitignore
βββ README.md
- Docker and Docker Compose (recommended for easiest setup)
- OR for local development:
-
Clone the repository
git clone <your-repo-url> cd python-fullstack-boilerplate
-
Start the development environment
make dev # Or: docker-compose up -
Access the applications
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
-
Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh -
Create virtual environment and install dependencies
cd backend uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv pip install -e .
-
Set up environment variables
cp .env.example .env # Edit .env with your database credentials -
Start PostgreSQL (using Docker is easiest)
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:16-alpine
-
Run the backend
fastapi dev app/main.py
-
Install pnpm (if not already installed)
npm install -g pnpm
-
Install dependencies
cd frontend pnpm install -
Set up environment variables
cp .env.example .env
-
Start the development server
pnpm dev
make help # Show all available commands
make dev # Start development environment
make build # Build all containers
make up # Start all services in detached mode
make down # Stop all services
make logs # View logs from all services
make logs-backend # View backend logs only
make logs-frontend # View frontend logs only
make clean # Stop and remove all containers and volumes
make test # Run backend tests
make backend-shell # Open shell in backend container
make frontend-shell # Open shell in frontend container
make db-shell # Open PostgreSQL shell
make prod-build # Build production containers
make prod-up # Start production environment
make prod-down # Stop production environment# Run tests
docker-compose exec backend pytest -v
# Run specific test file
docker-compose exec backend pytest tests/test_users.py -v
# Format code with ruff
docker-compose exec backend ruff format app/
# Lint code
docker-compose exec backend ruff check app/
# Create database migration
docker-compose exec backend alembic revision --autogenerate -m "description"
# Apply migrations
docker-compose exec backend alembic upgrade head# Install dependencies
docker-compose exec frontend pnpm install
# Build for production
docker-compose exec frontend pnpm build
# Lint code
docker-compose exec frontend pnpm lint
# Preview production build
docker-compose exec frontend pnpm previewCreate backend/.env from backend/.env.example:
PROJECT_NAME="FastAPI Backend"
DEBUG=True
DATABASE_URL=postgresql+asyncpg://postgres:postgres@db:5432/app
SECRET_KEY=your-secret-key-here # Change in production!
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
CORS_ORIGINS=["http://localhost:5173","http://localhost:3000"]Create frontend/.env from frontend/.env.example:
VITE_API_URL=/api/v1The backend includes pytest tests with async support:
# Run all tests
make test
# Run with coverage
docker-compose exec backend pytest --cov=app tests/
# Run specific test
docker-compose exec backend pytest tests/test_users.py::test_create_user -vFrontend testing structure is ready. Add tests using Vitest:
cd frontend
pnpm add -D vitest @testing-library/react @testing-library/jest-domOnce the backend is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /api/v1/users/register- Register new userPOST /api/v1/users/login- Login and get JWT tokenGET /api/v1/users/- List all usersGET /api/v1/users/{id}- Get specific userDELETE /api/v1/users/{id}- Delete user
POST /api/v1/items/- Create itemGET /api/v1/items/- List all itemsGET /api/v1/items/{id}- Get specific itemPUT /api/v1/items/{id}- Update itemDELETE /api/v1/items/{id}- Delete item
make prod-build-
Create production environment file
cp docker-compose.prod.yml .env.prod
-
Set production environment variables
POSTGRES_USER=prod_user POSTGRES_PASSWORD=secure_password_here POSTGRES_DB=prod_db SECRET_KEY=very-secure-secret-key-here CORS_ORIGINS=["https://yourdomain.com"]
-
Start production services
docker-compose -f docker-compose.prod.yml up -d
- Change all default passwords
- Generate secure
SECRET_KEY(useopenssl rand -hex 32) - Set
DEBUG=Falsein backend - Configure proper CORS origins
- Set up SSL/TLS certificates
- Configure database backups
- Set up monitoring and logging
- Configure firewall rules
- Use environment-specific
.envfiles - Review and update security headers in nginx
Request β FastAPI Router β Endpoint Handler β Service Layer β Database
β
Pydantic Validation
β
Response Serialization
Key Patterns:
- Service Layer: Business logic separated from routes
- Dependency Injection: FastAPI dependencies for database sessions, auth
- Async/Await: Fully async database operations
- Type Safety: Pydantic models for validation and serialization
Component β Service β API Client β Backend API
β
Custom Hook β State Management
β
TypeScript Types
Key Patterns:
- Service Pattern: API calls abstracted in service files
- Custom Hooks: Reusable logic with
useApihook - Type Safety: Full TypeScript coverage
- Axios Interceptors: Centralized auth and error handling
- User registers via
/api/v1/users/register - User logs in via
/api/v1/users/loginβ receives JWT token - Frontend stores token in localStorage
- Axios interceptor adds token to all requests
- Backend validates token on protected routes
- Create Pydantic model in
backend/app/models/ - Create SQLAlchemy model in
backend/app/db/models.py - Create service in
backend/app/services/ - Create endpoint in
backend/app/api/v1/endpoints/ - Register router in
backend/app/api/v1/router.py - Add tests in
backend/tests/
- Create TypeScript types in
frontend/src/types/ - Create service in
frontend/src/services/ - Create page component in
frontend/src/pages/ - Add route in
frontend/src/App.tsx
# Check if database is running
docker-compose ps db
# View database logs
docker-compose logs db
# Connect to database
make db-shell# View backend logs
make logs-backend
# Check if dependencies are installed
docker-compose exec backend pip list# Clear node_modules and reinstall
docker-compose exec frontend rm -rf node_modules
docker-compose exec frontend pnpm install
# Check for TypeScript errors
docker-compose exec frontend pnpm buildIf ports 5173, 8000, or 5432 are already in use, modify the port mappings in docker-compose.yml.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI - Modern Python web framework
- React - UI library
- Vite - Build tool
- UV - Python package manager
- pnpm - Node.js package manager
For issues and questions:
- Open an issue on GitHub
- Check existing documentation
- Review the API docs at
/docs
Happy Coding! π