# Back-End Setup Guide

Welcome to the Furniture Delivery App back-end development setup guide. This document provides step-by-step instructions for setting up the development environment and running the server.

## **Prerequisites**

Before proceeding, ensure you have the following prerequisites installed:

1. **PGadmin4**: GUI to interface with Postgres Database ([https://www.pgadmin.org/download/](https://www.pgadmin.org/download/)),
2. **Docker**: Application containerization system ([https://www.docker.com/products/docker-desktop/](https://www.docker.com/products/docker-desktop/)),
3. **Docker-Compose**: Toolchain that helps interface with Docker and simplifies running containers and their setup ([https://github.com/docker/compose](https://github.com/docker/compose)),
4. **Python 3.11**: The language in which the back-end is implemented ([https://www.python.org/](https://www.python.org/)),
5. **Pyenv:** Python environment utility, separate development workspace into Python Environments ([https://github.com/pyenv/pyenv](https://github.com/pyenv/pyenv)).
6. **Homebrew:** Only required for Mac users ([https://brew.sh/](https://brew.sh/)),
7. **Postman (Optional)**: Use to test API endpoints ([https://www.postman.com/](https://www.postman.com/)).

<aside>
💡 Pyenv is not natively supported by Windows, there is a separate Github repository that works around this. [https://github.com/pyenv-win/pyenv-win](https://github.com/pyenv-win/pyenv-win)

</aside>

## **Step-by-Step Setup**

### 1. Environment Setup

If you are developing on a mac, open your terminal and run the following command:

```jsx
<project root>/scripts/core.sh -c
```

The [core.sh](http://core.sh) script contains many useful scripts that help automate things such as first-time setup, running the server, installing dependencies, amongst some other features.

After running the above command, you will now be able to run the script by doing:

```jsx
ukay -h
```

The ukay command is added as an alias to your ~/.zshrc file.

<aside>
💡 Unfortunately, this script does not run on Windows or Linux machines. For those, you will have to perform a manual setup for Python and Pyenv.

</aside>

Once all software is installed, cd to the project root and run the following:

```bash
pyenv install 3.11.0;
pyenv global 3.11.0;
pyenv virtualenv ukay-delivery-backend;
pyenv activate ukay-delivery-backend;
pip install -r requirements.txt;
```

This code block with create a Python environment with Python 3.11, activates the environment, and installs all the required modules for the server.

### 2**. Running the App**

- **Start the Database**:
    - Navigate to the <project root>/docker directory
    - Execute the following command:

```bash
docker-compose up -d
```

This command will pull a Postgres Docker image, and run the container. The default credentials are found in the compose.yaml file. 

<aside>
💡 Once the container is running, enter into the database using PGAdmin and run **all** of the queries that are in the <project root>/scripts/init.sql file.

</aside>

- Start **the Server**:
    - If you are on a Mac, run the following:

```bash
ukay -r
```

For all other platforms, run: 

```bash
cd <project root>/app
    python .
```

The server will run using the following address:
http://localhost:21000/

You may view the API Documentation by visiting the following link in your web browser:

http://localhost:21000/********docs********

Additionally, there is a JSON representation of the documentation in <project root>/api/openapi.json

## **Additional Notes**

- **Dependencies**: If any dependencies must be updated, ensure you generated a new requirements.txt file by doing: pip freeze > requirements.txt
- **Environment Variables**: If the project uses any environment variables (like API keys or secret tokens), ensure they are correctly set up in the development environment.

This guide should provide you with a comprehensive setup for starting backend-end development on the Furniture Delivery App. For more specific instructions or troubleshooting, refer to the official FastAPI, Python, and Docker documentation or contact the project maintainers.