A well-structured Python backend application using Flask.
.
├── app.py # Main application entry point
├── requirements.txt # Python dependencies
├── .env.example # Example environment variables
├── .gitignore # Git ignore file
├── README.md # This file
├── config/ # Configuration files
│ ├── __init__.py
│ └── config.py # Application configuration
├── src/ # Source code
│ ├── __init__.py
│ ├── api/ # API routes
│ │ ├── __init__.py
│ │ └── routes.py # API endpoints
│ ├── models/ # Data models
│ │ ├── __init__.py
│ │ └── example_model.py
│ ├── services/ # Business logic
│ │ ├── __init__.py
│ │ └── example_service.py
│ └── utils/ # Utility functions
│ ├── __init__.py
│ └── helpers.py
├── static/ # Static files
│ ├── css/ # Stylesheets
│ ├── js/ # JavaScript files
│ └── images/ # Images
├── templates/ # HTML templates
└── tests/ # Test files
├── __init__.py
└── test_api.py
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- Windows:
venv\Scripts\activate - Linux/Mac:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Copy
.env.exampleto.envand configure your environment variables:cp .env.example .env
-
Run the application:
python app.py
GET /- Welcome messageGET /health- Health checkGET /api/example- Get all examplesPOST /api/example- Create new exampleGET /api/example/<id>- Get example by ID
Run tests with pytest:
pytest tests/The project follows a modular structure:
- api/: Contains all API route definitions
- models/: Data models and schemas
- services/: Business logic layer
- utils/: Helper functions and utilities
- config/: Configuration management
- static/: Static assets (CSS, JS, images)
- templates/: HTML templates for rendering