This project is the backend for the Haki Hub, handling the main backend functionality and communicating with the Wagtail CMS microservice for content management. It is built using Flask and interfaces with a PostgreSQL database.
The project is organized using a Modular Paradigm as follows:
.
│
├── app
│ ├── __init__.py # Initialize the Flask application and register blueprints
│ ├── routes/
│ │ ├── __init__.py # Init file for routes module
│ │ ├── main.py # Main routes for the application
│ │ ├── wagtail.py # Routes for Wagtail API communication
│ ├── models.py # Database models
│ ├── services/
│ │ ├── __init__.py # Init file for services module
│ │ ├── wagtail_service.py # Service functions for Wagtail API communication
│
├── migrations/ # Database migration files
│
├── tests/
│ ├── test_basic.py # Basic tests for the application
│
├── config.py # Configuration settings
├── requirements.txt # List of dependencies
├── run.py # Entry point to run the Flask application
│
├── .env # Environment variables
├── .gitignore # Git ignore file
├── README.md # Project documentation
- Python 3.9
- Conda/Venv
- PostgreSQL
-
Clone the repository:
git clone https://github.com/haki-hub/haki-backend.git ; cd haki-backend
-
Create and activate a Conda environment:
conda create --name haki_backend python=3.9 conda activate haki_backend
Or for Venv:
python3 -m venv haki_backend
- To activate environment in windows type:
haki_backend/Scripts/activate
- To activate environment in Linux type:
source haki_backend/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up the environment variables:
Create a
.env
file in the project root directory:SECRET_KEY=your_secret_key DATABASE_URL=postgresql://username:password@localhost/dbname WAGTAIL_API_BASE_URL=https://your-wagtail-site.com/api/v2/
-
Run the application:
python run.py
-
app/init.py: Initializes the Flask application, sets up the configuration, and registers the blueprints for routes.
-
app/routes/:
main.py
: Contains the main routes for the application, including the home and index routes.wagtail.py
: Contains routes for communicating with the Wagtail CMS API.
-
app/models.py: Defines the database models for the application.
-
app/services/:
wagtail_service.py
: Contains functions to interact with the Wagtail API.
-
migrations/: Directory for database migration files, managed by Flask-Migrate.
-
tests/:
test_basic.py
: Contains basic tests to ensure the application is working correctly.
-
config.py: Contains configuration settings for the Flask application, including database URI and Wagtail API base URL.
-
requirements.txt: Lists the dependencies required for the Flask application.
-
run.py: Entry point to run the Flask application.
To run the tests, use the following command:
python -m unittest discover -s tests
To deploy the application, follow these steps:
- Set up the environment variables on the server.
- Install the dependencies using
pip install -r requirements.txt
. - Use a WSGI server like Gunicorn to serve the Flask application.
- Set up a reverse proxy using Nginx or Apache to forward requests to the WSGI server.
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
This project is licensed under the MIT License.