A production-ready template for rapid deployment of full-stack Flask-React applications with Docker.
This template is perfect for:
- MVPs and prototypes - Get your idea up and running quickly
- Personal projects - Full-stack setup without the boilerplate
- Learning - Understand Docker, Flask, React integration
- Production applications - Built with production-ready configurations
- Client projects - Professional starting point with best practices
- Fast setup - Running in minutes with one command
- Hot reload - Both frontend and backend with instant feedback
- Dockerized - Consistent environment across all machines
- Nginx proxy - Production-ready reverse proxy setup
- Modular - Easy to add databases, auth, APIs, UI libraries
- Dev/Prod modes - Separate optimized configurations
- Well documented - Clear guides for requests, logs, architecture
- Purpose
- Getting Started with Template
- Architecture
- Project Structure
- Quick Start
- Development
- Common Commands
- Testing correct works of fullstack setup
- Extending the Template
- Security Notes
- Troubleshooting
- Contributing
This repository serves as a ready-to-use template for quickly scaffolding full-stack web applications. It provides:
- ✅ Complete Docker setup with development and production configurations
- ✅ Flask backend with hot reload and proper request logging
- ✅ React + Vite frontend with modern tooling and HMR
- ✅ Nginx reverse proxy configured for both dev and prod environments
- ✅ Extensible architecture - add features, routes, and components easily
Use this as a starting point and customize it for your specific application needs. The template is designed to be extended, not just used as-is.
Create your project from this template:
# Clone the repository
git clone https://github.com/davy1ex/ReactPythonTemplateFullstack
cd ReactPythonTemplateFullstack
# Setup environment variables
cp backend/env.example backend/.env
cp frontend/env.example frontend/.env
# Edit .env files if needed (optional for quick start)
# Start project
cd docker
docker-compose up --buildAccess your application at http://localhost
┌─────────────────────────────────────────────┐
│ Nginx (Port 80) │
│ ┌─────────────────┬───────────────────┐ │
│ │ / (Frontend) │ /api (Backend) │ │
│ └────────┬────────┴─────────┬─────────┘ │
└───────────┼──────────────────┼──────────────┘
│ │
┌──────▼──────┐ ┌─────▼──────┐
│ React │ │ Flask │
│ Vite │ │ Python │
│ Port 5173 │ │ Port 5001 │
└─────────────┘ └────────────┘
.
├── docker/
│ ├── docker-compose.yml # Development environment
│ ├── docker-compose.prod.yml # Production environment
│ └── nginx/
│ ├── Dockerfile
│ ├── nginx.dev.conf # Development config (proxy to Vite)
│ └── nginx.prod.conf # Production config (serve static files)
├── frontend/
│ ├── src/
│ │ ├── App.jsx
│ │ ├── App.css
│ │ ├── main.jsx
│ │ └── index.css
│ ├── public/
│ ├── Dockerfile
│ ├── package.json
│ ├── vite.config.js
│ ├── index.html
│ └── env.example # Environment variables template
└── backend/
├── server.py
├── requirements.txt
├── Dockerfile
└── env.example # Environment variables template
The project supports two modes:
- Development Mode - Hot reload for both frontend and backend, volume-mounted code for instant changes, Vite dev server with HMR
- Production Mode - Optimized production build, minified static files, Gunicorn WSGI server, Nginx serving built assets
Choose the mode based on your needs. Development mode is recommended for active development, while production mode is for testing the deployment setup or actual deployment.
# First time setup: Create .env files
cp backend/env.example backend/.env
cp frontend/env.example frontend/.env
# Start all services
cd docker
docker-compose up --build
# Access the application
# Frontend + Backend: http://localhost
# Frontend only (Vite): http://localhost:5173
# Backend only: http://localhost:5001Important:
.envfiles are required. Copy fromenv.examplefiles before first run.
The development environment includes:
- ✅ Hot reload for React (Vite dev server on port 5173)
- ✅ Hot reload for Flask (volume mounted)
- ✅ Nginx reverse proxy routing
- ✅ Volume mounting for live code changes
Frontend packages (no rebuild needed):
# Install directly on host machine
cd frontend
npm install <package-name>
# Changes are immediately available in container!Backend packages (rebuild required):
# Add to requirements.txt
cd backend
echo "requests==2.31.0" >> requirements.txt
# Rebuild backend container
cd ../docker
docker-compose up --build backend💡 Important: Frontend folder is mounted as volume, so
npm installworks directly. Backend code has hot reload, but new Python dependencies need container rebuild.
# Setup production .env files with production values
cp backend/env.example backend/.env
cp frontend/env.example frontend/.env
# Edit .env files: set FLASK_ENV=production, strong SECRET_KEY, etc.
# Build and start production services
cd docker
docker-compose -f docker-compose.prod.yml up --build
# Access the application at http://localhostImportant: For production, update
.envfiles with secure values (especiallySECRET_KEY).
The production environment includes:
- ✅ Optimized React build (static files)
- ✅ Gunicorn WSGI server for Flask
- ✅ Nginx serving static files + API proxy
- ✅ Production-ready configurations
The Flask server runs on port 5001 and provides API endpoints:
GET /api/health- Health checkGET /api/hello?name=YourName- Hello endpointPOST /api/data- Example POST endpoint
For adding dependencies, see Quick Start → Adding Dependencies.
The React app runs on Vite dev server (port 5173) with hot module replacement.
For adding dependencies, see Quick Start → Adding Dependencies.
-
Development (
docker/nginx/nginx.dev.conf):- Routes
/to Vite dev server (port 5173) with WebSocket support - Routes
/apito Flask backend (port 5001)
- Routes
-
Production (
docker/nginx/nginx.prod.conf):- Serves built React static files from
/usr/share/nginx/html - Routes
/apito Flask backend (port 5001) - Includes caching and security headers
- Serves built React static files from
# Navigate to docker folder
cd docker
# Start services
docker-compose up
# Start services in background
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs -f
# View logs for specific service
docker-compose logs -f backend
# Rebuild specific service
docker-compose up --build frontend
# Execute command in running container
docker-compose exec backend python -m pytest
docker-compose exec frontend npm test
# Access container shell
docker-compose exec backend sh
docker-compose exec frontend shAfter starting the development environment with docker-compose up:
- Open http://localhost in your browser
- Click "Test Backend Connection" button
- You should see a success message from the Flask backend
Test hot reload (Development only):
Frontend:
- Edit
frontend/src/App.jsx - Changes should appear immediately in the browser (Vite HMR)
Backend:
- Edit
backend/server.py - Flask will auto-reload automatically (may take a few seconds)
After starting the production environment with docker-compose -f docker-compose.prod.yml up:
- Open http://localhost in your browser
- The application will serve optimized, built static files
- Backend runs with Gunicorn (multi-worker production server)
Differences in Production:
⚠️ No hot reload - Changes require rebuild- ✅ Optimized frontend - Minified and bundled with Vite build
- ✅ Production server - Gunicorn instead of Flask dev server
- ✅ Better performance - Static file serving and caching headers
To rebuild after changes in production mode:
cd docker
docker-compose -f docker-compose.prod.yml up --buildThis template is designed to be easily extended. Here are common customizations:
Add new pages/routes:
cd frontend
npm install react-router-dom
# Create components in frontend/src/components/
# Update App.jsx with routing logicAdd UI library:
cd frontend
# Material-UI
npm install @mui/material @emotion/react @emotion/styled
# Or TailwindCSS
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -pAdd state management:
cd frontend
# Redux Toolkit
npm install @reduxjs/toolkit react-redux
# Or Zustand
npm install zustandExample: Add a new feature component
// frontend/src/components/UserProfile.jsx
export function UserProfile() {
const [user, setUser] = useState(null);
useEffect(() => {
fetch('/api/user/profile')
.then(res => res.json())
.then(data => setUser(data));
}, []);
return <div>{user?.name}</div>;
}Add new API endpoints:
# backend/server.py
@app.route('/api/users', methods=['GET'])
def get_users():
users = [{"id": 1, "name": "John"}, {"id": 2, "name": "Jane"}]
return jsonify(users)
@app.route('/api/users/<int:user_id>', methods=['GET'])
def get_user(user_id):
return jsonify({"id": user_id, "name": "John Doe"})Add authentication:
# Add JWT or Flask-Login
# Update backend/requirements.txt:
# flask-jwt-extended==4.6.0
# flask-login==0.6.3
docker-compose up --build backendStructure your backend with blueprints:
# backend/routes/users.py
from flask import Blueprint
users_bp = Blueprint('users', __name__)
@users_bp.route('/api/users')
def list_users():
return jsonify([])
# backend/server.py
from routes.users import users_bp
app.register_blueprint(users_bp)Add ORM for database:
# Add to requirements.txt:
# Flask-SQLAlchemy==3.1.1
# Flask-Migrate==4.0.5
# Create models in backend/models/
# Initialize database with Flask-MigrateBefore starting your project, customize:
- Create
.envfiles:cp backend/env.example backend/.envandcp frontend/env.example frontend/.env - Update
SECRET_KEYinbackend/.envfor production - Change
package.jsonname and version - Update frontend title in
frontend/index.html - Configure CORS settings in
backend/server.pyif needed - Update Nginx server names if deploying to custom domain
- Customize frontend styling and branding
- Add your API endpoints in backend
- Add your React components in frontend
Example with PostgreSQL:
- Add to
docker/docker-compose.yml:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: user
POSTGRES_PASSWORD: password
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- app-network
volumes:
postgres-data:- Update
backend/requirements.txt:
psycopg2-binary==2.9.9
SQLAlchemy==2.0.23
The project uses separate .env files for each service. Each service has an env.example file that works for both development and production.
Setup for Development:
# Copy example files
cp backend/env.example backend/.env
cp frontend/env.example frontend/.env
# Default values in env.example are ready for development!
# You can start immediately or customize if needed.Setup for Production:
# Copy example files
cp backend/env.example backend/.env
cp frontend/env.example frontend/.env
# Edit backend/.env for production:
# 1. Change FLASK_ENV=development to FLASK_ENV=production
# 2. Change FLASK_DEBUG=1 to FLASK_DEBUG=0
# 3. Generate strong SECRET_KEY: python -c "import secrets; print(secrets.token_hex(32))"
# 4. Update DATABASE_URL if using database
# Edit frontend/.env for production:
# 1. Change NODE_ENV=development to NODE_ENV=production
# 2. Update VITE_API_URL if neededBackend .env example:
FLASK_ENV=development # Change to 'production' for prod
FLASK_DEBUG=1 # Change to 0 for prod
SECRET_KEY=dev-secret-key # MUST change for prod!
DATABASE_URL=postgresql://... # OptionalFrontend .env example:
NODE_ENV=development # Change to 'production' for prod
VITE_API_URL=/api # API endpoint
CHOKIDAR_USEPOLLING=true # For dev hot reloadNote:
.envfiles are gitignored. Theenv.examplefiles contain inline comments explaining what to change for production.
For production deployment:
- Use environment variables for sensitive data
- Set up HTTPS with SSL certificates
- Configure proper CORS policies
- Use secrets management (Docker secrets, K8s secrets)
- Update security headers in Nginx config
- Set strong
SECRET_KEYfor Flask
# Find and kill process using port 80
lsof -ti:80 | xargs kill -9
# Or change port in docker-compose.yml
ports:
- "8080:80" # Use port 8080 instead# Ensure volumes are properly mounted
docker-compose down -v
docker-compose up --build- Check that all services are running:
docker-compose ps - Check Nginx logs:
docker-compose logs nginx - Verify network configuration
Feel free to submit issues and enhancement requests to improve this template!