https://github.com/daluisgarcia/flask-modular-architecture-template
A flask modular architecture template that uses strategy pattern to create and subscribe modules to the app. This allows to have a good folder structure in your project
https://github.com/daluisgarcia/flask-modular-architecture-template
flask flask-application flask-sqlalchemy flask-template folder-structure modular-architecture modularization python python3 strategy-pattern
Last synced: about 1 year ago
JSON representation
A flask modular architecture template that uses strategy pattern to create and subscribe modules to the app. This allows to have a good folder structure in your project
- Host: GitHub
- URL: https://github.com/daluisgarcia/flask-modular-architecture-template
- Owner: daluisgarcia
- License: mit
- Created: 2023-08-07T23:54:56.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-23T00:14:18.000Z (almost 3 years ago)
- Last Synced: 2025-05-29T19:42:52.486Z (about 1 year ago)
- Topics: flask, flask-application, flask-sqlalchemy, flask-template, folder-structure, modular-architecture, modularization, python, python3, strategy-pattern
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask Modular Architecture Template
This is a template for a Flask project using a modular architecture. This project facilitates the creation of a Flask
project with a modular architecture, allowing the creation of new modules by extending a class and adding it to a set.
This template has some flask extension installed, such as: `flask_login`, `flask_principal`, `flask_sqlalchemy` and
`flask_migrate`; any other extension can be installed by being added to the `core/extensions.py` file, inside the
`install_extensions` function.
# Project structure
- `admin/`: An module example for an administration panel. **CAN BE EDITED OR DELETED**
- `blogs/`: An example module of the blogs tutorial project from the old *Flask Quickstart Guide*. **CAN BE EDITED OR DELETED**
- `core/`: Core module of the application. This module contains the core code of the project and orchestrates the
features of the template. This module contains the base templates and the static folder, also the authentication
and permissions features. **BE CAREFUL WHEN EDITING THE CODE INSIDE THIS FOLDER, THIS ACTION CAN BREAK THE PROJECT**
- `migrations`: Contains all the migrations of the database. **DO NOT MODIFY** Should be modified using the `flask-migrate`
extension commands defined later in this file.
- `web_page/`: An example module for the landing page. This folder contains the minimum code to create a module.
**CAN BE EDITED OR DELETED**
- `app.py`: Main file of the application. This file is the one that must be executed to run the application. **DO NOT MODIFY**
- `modules.py`: File that contains a set with the modules of the application. Only modify to add new modules to the set.
# Project installation
To install the project package, run the following command `pip install -r requirements.txt`
# Module creation
To create a new module, you only need to create a new folder with a `module.py` file inside it. This file must contain a
class extending the `core.AppModule` class and implementing the `__init__` method defining the `self.bluprint` attribute
with the blueprint of the module, the `self.permission_names` attribute with at least an empty set and the `self.template_folder`
with the path to the module's templates folder. Also, you need to call the super `__init__` method with the module name
as the parameter (You can see an example in `admin/module.py` file).
To subscribe the module to the application, you need to import the module class in the `modules.py` file and add it to the
`APP_MODULES` set in it. This will allow the application to load the module when it starts.
# Project usage
## Setting environment variables
Before running the project, you must create a `.env` file in the root directory of the project as a copy of `.env.example`.
## Creating the database
Thanks to the `flask_migrate` extension, the database can be created and updated automatically. To create the database,
you must run the following command: `flask db migrate`. **If you make any change to the models or add a new one** you
must run the `flask db migrate` command again and then `flask db upgrade` to update the database.
If you want to renew the database migrations, you can delete the `migrations` folder and run the `flask db init` command.
Then you can run the `flask db migrate` command to create the database tables.
## Running the project
To run the project you can use either the command `python app.py` or `flask run`
# Contributing
To contribute to this project, you can fork the repository and create a pull request with your changes. Also, you can
open an issue with your suggestion or bug report. I will be happy to review your contributions.