Skip to content

Latest commit

 

History

History
225 lines (154 loc) · 8.44 KB

README.md

File metadata and controls

225 lines (154 loc) · 8.44 KB

Bloom 🌺 : A Self-Hosted CFP portal for Events


A Backend Server Written in 🐍 and FastAPI with 🐘 DB that powers the Self-Hosted CFP Management Service Bloom.

pre-commit.ci status pdm-managed GitHub issues GitHub forks GitHub stars GitHub license Open Source Love svg1 PRs Welcome contributions welcome GitHub contributors

Material Bread logo

🤔 Pre-requisites

  • python3
  • pdm
  • postgres

🐍 Python Version Support

This project is designed to be compatible with specific versions of Python for optimal performance and stability.

Supported Python Version

  • Python 3.11.0rc2

❗️ For the best experience and performance, it is recommended to use the version mentioned above.

Before diving into the project, ensure that you have the correct Python version installed. To check the version of Python you currently have, execute the following command in your terminal:

python --version

🐍 Installing Python 3.11.0rc2 with pyenv

Protip: Managing multiple Python versions is a breeze with pyenv. It allows you to seamlessly switch between different Python versions without the need to reinstall them.

If you haven't installed pyenv yet, follow their official guide to set it up.

Once you have pyenv ready, install the recommended Python version by running:

pyenv install 3.11.0rc2

When you navigate to this project's directory in the future, pyenv will automatically select the recommended Python version, thanks to the .python-version file in the project root.

📦 Setup

Local setup 🛠️ without Docker 🐳

Configuring your .env file

  1. Copying the .env.example file: Begin by creating a copy of the .env.example file and renaming it to .env.

    cp .env.example .env
  2. Filling in the Parameters:

    • SQLALCHEMY_DATABASE_URI: This is the connection string for your PostgreSQL database. The format is generally:

      postgresql://[user[:password]@][host][:port][/dbname]
      

      For example, if you have a local PostgreSQL server with the database mydb, username admin, and password password123, the connection string would be:

      SQLALCHEMY_DATABASE_URI="postgresql://admin:password123@localhost/mydb"
      
    • JWT_SECRET: This is a secret key used to encode and decode JWT tokens. It should be a random and long string to ensure the security of your tokens. You can generate one using various online tools or by running the following Python snippet:

      import secrets
      print(secrets.token_hex(16))
    • JWT_ALGORITHM: This specifies the algorithm used to sign the JWT tokens. The most common algorithm is HS256, which stands for HMAC using SHA-256. Depending on your requirements, you might use other algorithms, but for most applications, HS256 is sufficient. So, you can set it as:

      JWT_ALGORITHM="HS256"
      
    • ACCESS_TOKEN_EXPIRY_MINUTES: This is an integer that represents the number of minutes before a generated access token expires. For example, if you want the token to expire in 60 minutes (1 hour), you'd set:

      ACCESS_TOKEN_EXPIRY_MINUTES=60
      

Configuring PostgreSQL URI in alembic.ini

To set up the PostgreSQL connection for Alembic:

  • Locate the Configuration in alembic.ini:

    • Open the alembic.ini file and navigate to approximately line #63.
  • Add Your PostgreSQL URI: Find the following line:

    sqlalchemy.url = ...
    

    Replace it with your PostgreSQL URI. The format for the URI is generally:

    postgresql://[user[:password]@][host][:port][/dbname]
    

    For example, if you have a local PostgreSQL server with the database mydb, username admin, and password password123, update the line to:

    sqlalchemy.url = postgresql://admin:password123@localhost/mydb
    

❗️ Ensure that the database credentials provided have the necessary permissions for Alembic to perform migrations.

Setting Up the Project with PDM

PDM (Python Development Master) is utilized for dependency management in this project. To set up and run the project:

  • Installing PDM: Before you begin, ensure you have PDM installed. If not, refer to the official documentation to install PDM.

  • Clone the Repository: Get the project source code from GitHub:

    git clone https://github.com/blossomlabsio/Bloom-Backend.git
  • Navigate to the Project Directory:

    cd Bloom-Backend
  • Install Dependencies: Use PDM to install the project's dependencies:

    pdm install
  • Run Migrations: Create migrations with the specified message:

    pdm run makemigrations -m "init"
  • Apply Migrations: Apply the created migrations to the database:

    pdm run migrate
  • Start the Project: Use PDM to run the project:

    pdm run start
    • You can also use pdm run dev to start the dev server.

Setting Up and Testing the Project

To ensure the code quality and functionality of the project, follow the steps below:

Installing Git Hooks with pre-commit

Before making any commits, it's essential to ensure that your code meets the quality standards. This project utilizes pre-commit hooks to automatically check your changes before any commit.

Install the pre-commit hooks with the following command:

pre-commit install

Running Tests

To ensure the project's functionality, you should run all the provided tests. Execute the following command to run the tests:

pdm run test

Testing the Running Server

Once you have your server up and running, you can send requests to it from another terminal to test its responsiveness and functionality.

Here are a couple of GET requests you can make using curl:

curl http://127.0.0.1:8000/api/v1/healthz

curl http://127.0.0.1:8000/api/v1/readyz

These endpoints typically return the health status or readiness of the server, helping in diagnostics and monitoring.

🗒️ How to contribute

❗️Important: Please read the Code of Conduct and go through Contributing Guideline before contributing to Bloom-Backend.

  • Feel free to open an issue for any clarifications or suggestions.

  • If you still need help to get started, feel free to reach out on our community discord.

💪 Thanks to all Wonderful Contributors

Thanks a lot for spending your time helping Bloom 🌺 grow. Thanks a lot! Keep rocking 🍻

Contributors

🙏 Support++

This project needs your shiny star ⭐. Don't forget to leave a star ⭐️

forthebadge made-with-python forthebadge