A minimal Flask backend server designed to work with the Next.js frontend application.
server/
├── app.py # Main Flask application
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── routes/
├── __init__.py # Routes package
├── blueprint_registry.py # Centralized blueprint registration
├── hello.py # Hello endpoint
├── health.py # Health check endpoints
└── examples.py # Example endpoints
-
Create a virtual environment:
cd server python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp .env.example .env # Edit .env file as needed -
Run the server:
python app.py
The server will start on http://localhost:5000
GET /api/health- Health check endpointGET /api/hello- Simple hello endpoint (returns{"result": "world"})GET /api/test- Test endpoint for frontend integrationPOST /api/example- Example POST endpoint
The Flask app is organized with separate blueprint files for better scalability:
-
Create a new file in
routes/(e.g.,routes/users.py):from flask import Blueprint, jsonify, request users_bp = Blueprint('users', __name__) @users_bp.route('/users', methods=['GET']) def get_users(): return jsonify({'users': []}) @users_bp.route('/users', methods=['POST']) def create_user(): data = request.get_json() return jsonify({'message': 'User created', 'data': data})
-
Register the blueprint in
routes/blueprint_registry.py:from .users import users_bp BLUEPRINTS = [ (hello_bp, '/api'), (health_bp, '/api'), (examples_bp, '/api'), (users_bp, '/api'), # Add your new blueprint here ]
Add endpoints to existing files like routes/examples.py, routes/hello.py, etc.
The server is configured to accept requests from http://localhost:3000 (Next.js frontend). To modify CORS settings, edit the CORS configuration in app.py.
- The server runs in debug mode by default
- Auto-reloads on file changes
- CORS enabled for frontend integration
- Organized with Flask blueprints for scalability