Skip to content

Haki-Hub/haki-backend

Repository files navigation

Haki Backend

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.

Project Structure

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

Getting Started

Prerequisites

  • Python 3.9
  • Conda/Venv
  • PostgreSQL

Setup

  1. Clone the repository:

    git clone https://github.com/haki-hub/haki-backend.git ; cd haki-backend
  2. 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
  3. Install dependencies:

    pip install -r requirements.txt
  4. 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/
  5. Run the application:

    python run.py

Project Structure Details

  • 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.

Running Tests

To run the tests, use the following command:

python -m unittest discover -s tests

Deployment

To deploy the application, follow these steps:

  1. Set up the environment variables on the server.
  2. Install the dependencies using pip install -r requirements.txt.
  3. Use a WSGI server like Gunicorn to serve the Flask application.
  4. Set up a reverse proxy using Nginx or Apache to forward requests to the WSGI server.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •