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.
- Python 3.12+
- Node.js 18+
- PostgreSQL 14+ (or use Docker)
- Docker & Docker Compose (optional, for containerized setup)
# 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/docscp .env.example .env
docker-compose upVisit:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- SETUP.md - Detailed local development setup instructions
- ARCHITECTURE.md - Project structure, tech stack, design patterns
- DATABASE.md - Database schema, migrations, models
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
βββ
The application uses JWT (JSON Web Tokens) for stateless authentication:
- User signs up or logs in with email and password
- Backend validates credentials and returns a JWT token
- Frontend stores token in localStorage
- Frontend includes token in Authorization header for authenticated requests
- Backend validates token on each request using
CurrentUserdependency
See ARCHITECTURE.md for detailed flow.
- 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.
All endpoints documented with OpenAPI (Swagger UI):
- Interactive Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Quick reference:
POST /login/access-token- Login and get JWT tokenPOST /users/- Create new user (public signup)GET /users/- List all users (admin only)GET /items/- List current user's itemsPOST /items/- Create new itemGET /health- Health check
See API.md for full endpoint documentation.
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.
Build and run locally:
docker-compose up --buildcd backend
# Create new migration
alembic revision --autogenerate -m "migration description"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1# Backend
cd backend
ruff check .
ruff format .
# Frontend
cd frontend
npm run lintBackend:
- 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
[](https://railway.com/deploy/bmEgCZ?referralCode=uBTGZq&utm_medium=integration&utm_source=template&utm_campaign=generic)
- Create a feature branch:
git checkout -b feature/my-feature - Commit changes:
git commit -am 'Add my feature' - Push to branch:
git push origin feature/my-feature - Open a Pull Request
- Can't connect to database? See SETUP.md#troubleshooting
- Frontend can't reach API? Check SETUP.md#frontend-api-configuration
- Alembic migration fails? See DATABASE.md
For issues or questions:
- Check the documentation
- Review existing issues
- Create a new issue with details
Happy coding! π