Flask Project Structure
A scalable and maintainable folder structure for Flask applications
File Structure
- myflaskapp
- __init__.py
- routes.py
- models.py
- templates
- base.html
- index.html
- about.html
- dashboard.html
- static
- css
- js
- images
- forms.py
- utils.py
- extensions.py
- blueprints
- auth
- __init__.py
- routes.py
- models.py
- api
- __init__.py
- routes.py
- tests
- __init__.py
- test_routes.py
- test_models.py
- config.py
- requirements.txt
- run.py
- .env
- .gitignore
- README.md
Directory Structure Explanation
myflaskapp/
The main application folder containing all Flask-related files and folders.
myflaskapp/__init__.py
Initializes the Flask application and sets up the app configuration.
myflaskapp/routes.py
Defines the routes and view functions for the Flask application.
myflaskapp/models.py
Defines the database models for the application.
myflaskapp/templates/
Contains HTML templates for rendering views, including a base template.
myflaskapp/templates/base.html
Base HTML template that other templates extend from for consistent layout.
myflaskapp/templates/index.html
HTML template for the home page.
myflaskapp/templates/about.html
HTML template for the about page.
myflaskapp/templates/dashboard.html
HTML template for the dashboard page.
myflaskapp/static/
Stores static files like CSS, JavaScript, and images used in the project.
myflaskapp/static/css/
Contains CSS files for styling the project.
myflaskapp/static/js/
Contains JavaScript files for client-side functionality.
myflaskapp/static/images/
Contains image files used in the project.
myflaskapp/forms.py
Defines forms for user input and validation.
myflaskapp/utils.py
Contains utility functions used across the application.
myflaskapp/extensions.py
Initializes Flask extensions like Flask-SQLAlchemy, Flask-Login, etc.
myflaskapp/blueprints/
Contains Flask blueprints for modularizing the application into components.
myflaskapp/blueprints/auth/
Blueprint for authentication-related routes, models, and logic.
myflaskapp/blueprints/api/
Blueprint for API-related routes and logic.
myflaskapp/tests/
Contains unit and integration tests for the application.
myflaskapp/tests/test_routes.py
Contains unit tests for the application's routes.
myflaskapp/tests/test_models.py
Contains unit tests for the application's models.
config.py
Contains configuration settings for the Flask app.
requirements.txt
Lists the Python dependencies required for the Flask project.
run.py
Entry point for running the Flask application during development.
.env
Stores environment variables for the Flask app.
.gitignore
Specifies files and directories that should be ignored by Git version control.
README.md
Documentation file providing an overview and instructions for the project.