This guide will walk you through setting up a full-stack application with a Flask backend and a Vite frontend using PostgreSQL as the database. You will have two options for setting up the project:
- Local Setup (without Docker)
- Dockerized Setup
- Flask: Python-based backend framework.
- Vite: Frontend tool for React + TypeScript.
- PostgreSQL: Remote database (or local if required).
- Docker: For containerization (optional).
First, let's create environment variables for both the backend and frontend.
FLASK_ENV=development
SECRET_KEY=your_secret_key_here
JWT_SECRET_KEY=your_jwt_secret_key_here
DATABASE_URL=postgresql://username:password@remote-host:port/database_name
FLASK_APP=run.py
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your_email@gmail.com
SMTP_PASSWORD=your_smtp_password
REDIS_URI=rediss://default:your_redis_url
OTP_EXPIRATION=300
CORS_ALLOWED_ORIGINS=http://localhost:5173,https://application-url.com
VITE_API_URL=http://localhost:5000/api
-
Install Python and Virtual Environment
Ensure that you have Python installed. If not, install Python 3.10+.
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # Unix/macOS venv\Scripts\activate # Windows
-
Install Dependencies
pip install -r requirements.txt
-
Run Migrations
Initialize and apply the database migrations:
flask db init flask db migrate -m "Initial migration" flask db upgrade
-
Run the Flask Server
Start the Flask development server:
flask run --host=0.0.0.0 --port=5000
-
Install Node.js and Dependencies
Ensure you have Node.js installed. Navigate to the
frontend/
directory and run:npm install npm run dev
-
Access the Application
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000/api
-
Build and Run Containers
In the project root, run:
docker-compose up --build
-
Access the Application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000/api
-
Build and Start Services:
docker-compose up --build
-
Stop Containers:
docker-compose down