A modern, production-ready template for building full-stack web applications with Next.js (frontend) and FastAPI (backend). Features automatic project configuration, Docker containerization, and seamless development workflow.
- π₯ Hot Reload: Both frontend and backend support hot reloading during development
- π³ Docker Ready: Fully containerized with separate dev/prod configurations
- π― Auto Configuration: Automatic project naming and environment setup
- π API Integration: Built-in API routes with proper error handling
- π± Modern Stack: Next.js 15, FastAPI, TypeScript, Tailwind CSS
- π§ Developer Friendly: Health checks, cleanup scripts, and helpful tooling
-
Clone and rename your project
git clone <this-repo> my-awesome-project cd my-awesome-project
-
Run setup (optional)
./setup.sh # Helps configure project name and environment -
Start development environment
./dev.sh
-
Access your application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
-
Clone the repository
git clone <this-repo> cd nextjs-fastapi-dockerized-template
-
Start development
./dev.sh
The template uses a .env file for configuration. Copy .env.example to .env and customize:
cp .env.example .envKey variables:
PROJECT_NAME: Your project name (auto-detected from directory if not set)DEV_FRONTEND_PORT: Development frontend port (default: 3000)DEV_BACKEND_PORT: Development backend port (default: 8000)PROD_FRONTEND_PORT: Production frontend port (default: 3001)PROD_BACKEND_PORT: Production backend port (default: 8001)DEV_API_URL,PROD_API_URL: Environment-specific internal API URLsDEV_NEXT_PUBLIC_API_URL,PROD_NEXT_PUBLIC_API_URL: Environment-specific public API URLs
Legacy variables (for backward compatibility):
FRONTEND_PORT,BACKEND_PORT: Used as fallbacks if environment-specific ports not set
./prod.sh # Starts production containers on ports 3001/8001You can run both environments simultaneously! The template uses different default ports:
- Development: Frontend :3000, Backend :8000
- Production: Frontend :3001, Backend :8001
./dev.sh # Development on localhost:3000
./prod.sh # Production on localhost:3001
# Both running at the same time!
## π Management Scripts
The template includes several helper scripts for easy project management:
### Core Scripts
- `./dev.sh` - Start development environment with hot reload
- `./prod.sh` - Start production environment
- `./setup.sh` - Initial project setup and configuration
- `./clean.sh` - Clean up containers, images, and volumes
### Features
- **Auto Project Detection**: Scripts automatically detect your project name from the directory
- **No Orphan Warnings**: Uses project-specific naming to avoid Docker conflicts
- **Health Checks**: Automatic verification that services are running
- **Environment Support**: Loads configuration from `.env` file if present
### Stop Containers
```bash
# Stop development environment
docker-compose -f docker-compose.dev.yml -p your-project-name-dev down
# Stop production environment
docker-compose -f docker-compose.yml -p your-project-name-prod down
# Or use the clean script for complete cleanup
./clean.shnextjs-fastapi-dockerized-template/
βββ backend/ # FastAPI backend
β βββ api/
β β βββ main.py # Main FastAPI application
β βββ Dockerfile # Production Dockerfile
β βββ Dockerfile.dev # Development Dockerfile
β βββ requirements.txt # Python dependencies
βββ frontend/ # Next.js frontend
β βββ app/ # Next.js app directory
β β βββ globals.css # Global styles
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Home page
β βββ public/ # Static assets
β βββ Dockerfile.dev # Development Dockerfile
β βββ Dockerfile.prod # Production Dockerfile
β βββ package.json # Node.js dependencies
β βββ next.config.js # Next.js configuration
β βββ tailwind.config.js # Tailwind CSS configuration
β βββ tsconfig.json # TypeScript configuration
βββ docker-compose.yml # Production docker compose
βββ docker-compose.dev.yml # Development docker compose
βββ .env.example # Environment variables template
βββ dev.sh # Development startup script
βββ prod.sh # Production startup script
βββ setup.sh # Project setup script
βββ clean.sh # Cleanup script
βββ README.md # This file
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe JavaScript
- Tailwind CSS - Utility-first CSS framework
- ESLint - JavaScript linting
- FastAPI - Modern, fast web framework for Python
- Python 3.11 - Programming language
- Uvicorn - ASGI server
- Docker - Containerization
- Docker Compose - Multi-container orchestration
The backend runs on port 8000 with hot reload enabled in development mode.
Key endpoints:
GET /- Health checkGET /health- Service statusGET /docs- Swagger API documentation
Adding new endpoints:
Edit backend/api/main.py to add new API routes.
The frontend runs on port 3000 with hot reload enabled in development mode.
Key files:
frontend/app/page.tsx- Main page componentfrontend/app/layout.tsx- Root layout componentfrontend/app/globals.css- Global styles
Development:
API_URL=http://backend:8000(for frontend container communication)
Production:
NEXT_PUBLIC_API_URL=http://backend:8000(for frontend to backend communication)
# Enter the frontend container
docker exec -it <frontend-container-name> /bin/bash
# Install packages
npm install <package-name>
# Or add to package.json and rebuild# Add to requirements.txt
echo "new-package==1.0.0" >> backend/requirements.txt
# Rebuild containers
docker-compose down
docker-compose up --buildThe production configuration is optimized for deployment with:
- Multi-stage Docker builds
- Optimized Next.js builds
- Production-ready FastAPI server
- Fork the repository
- Create a feature branch
- Make your changes
- Test in both development and production modes
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Port conflicts: Make sure ports 3000 and 8000 are not in use
- Docker permission errors: Ensure Docker daemon is running
- Module not found: Rebuild containers after adding dependencies
# View container logs
docker-compose logs frontend-dev
docker-compose logs backend
# Rebuild specific service
docker-compose up --build frontend-dev
# Clean up containers and volumes
docker-compose down -v
docker system prune -a