Skip to content

Repository files navigation

Sports-Hub Application Python Back-End

Project Description

This is a draft pet project for testing Generative AI on different software engineering tasks. It is planned to evolve and grow over time. Specifically, this repo will be a Python & FastAPI playground.

The application's legend is based on the sports-hub application description from the following repo: Sports-Hub.

Available Front-End applications

Dependencies

  • Docker
  • Docker Compose

The mentioned dependencies can be installed using the official documentation here. Read more about alternatives to Docker here.

Setup and Running the Application

Clone the Repositories

To run the web application with the React front-end, clone the following repositories within the same folder:

git clone git@github.com:dark-side/sports_hub_python_skeleton.git
git clone git@github.com:dark-side/sports_hub_react_skeleton.git
git clone git@github.com:dark-side/api_docs_genai_playground.git

Navigate to the back-end application directory

All commands should be run from the sports_hub_python_skeleton directory.

Create .env File

Copy the .env.example file to .env in the root of the project directory:

cp .env.example .env

Update the .env file with your local development credentials and secrets. Make sure not to commit this .env file to version control.

Run Docker Compose

Navigate to the back-end application directory and run (-d for detached mode to run in the background):

docker compose up -d

Attach to the Backend Container (Optionally)

Run docker ps and copy the backend application container ID. Then, connect to the container with the following command:

docker exec -ti <CONTAINER ID> /bin/bash

Reset the Database

Inside the backend application container, run the following command to reset the database if needed:

uv run alembic downgrade f2ee1e269afc
uv run alembic upgrade head

Running on Windows (Tips & Tricks)

While running the App on Windows 11 using WSL, you may face issues related to Unix-style line endings (especially if you are storing the project(s) under the host machine filesystem, not the WSL one (e.g., the project is cloned to the disc c: or any other disk you have instead of being cloned to the WSL filesystem). Working within the WSL filesystem is a best practice when developing on Windows, as it helps prevent line ending and permission issues that can arise when using the Windows filesystem. I'm just reminding you that this will save you time and headaches for future projects.

If you are still reading this, please ensure your host machine converts related script(s) to Unix-style line endings.

# Install dos2unix if not already installed
sudo apt-get install dos2unix

# Convert all files in the project directory to Unix-style line endings
find . -type f -exec dos2unix {} \;

# Convert one file (example)
dos2unix bin/docker-entrypoint

Also, if you face issues with bin directory files not being executable, you can fix it with the following commands:

# check current permissions on the file
ls -l bin/docker-entrypoint

# ensure the file is executable
chmod +x bin/docker-entrypoint

Accessing the Application

To access the application in a browser locally, open the following URL:

  • Mac, Linux - http://localhost:3000/
  • Windows - http://127.0.0.1:3000/

Local development environment setup

  1. Python 3.12 (See .python-version)
  2. Install uv Package Manager
  3. Create virtual environment and install dependencies:
uv sync

Run API Application

  1. (First run) Make sure DB is up
docker compose up postgres -d --wait
  1. (First run) Apply latest DB schema:
uv run alembic upgrade head
  1. Run the application:
uv run python -m api.main
  1. Open Open API Documentation: http://localhost:3002/docs

How to run tests

Make sure DB is up and running:

docker compose up postgres -d --wait

To run tests, run the following command:

uv run pytest tests/

How to run code checkers & formatter

uv run ruff format api/ tests/
uv run ruff check api/ tests/ --fix

License

Licensed under either of

Just to let you know, at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in your work, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Should you have any suggestions, please create an Issue for this repository

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages