# ZEN Temple
ZEN Temple is a FastAPI Application.

[![Type checker](https://github.com/ZEN-universe/ZEN-temple/actions/workflows/run-mypy.yml/badge.svg)](https://github.com/ZEN-universe/ZEN-temple/actions/workflows/run-mypy.yml)

## Installation

Create a new conda environment, activate it, and install all dependencies:

```bash
conda create --name <your-env-name> python==3.12
conda activate <your-env-name>
pip install -e .[mypy]
```

Then, create a new copy of `.env`.

```bash
cp .env.example .env
```

Modify the `SOLUTION_FOLDER` variable to the location of your solutions. This is the `outputs` folder generated by ZEN garden. Make sure that the path string uses `/` as a folder separator, and not `\`. Look at the page [Running a model](https://zen-garden.readthedocs.io/en/latest/files/user_guide/running_models.html#run-zen-garden-with-preexisting-datasets) of the ZEN garden documentation.

## Usage

Activate your conda environment and run the application with this command:

```bash
conda activate <your-env-name>
python -m zen_temple.main --reload
```

## Release workflow

To create a new release of ZEN-temple follow the following steps. The idea is that for each major release (from `v0.4.x` to `v0.5.0`) we sync the version number of ZEN explorer and ZEN temple

1. Bump version in ZEN explorer `bash scripts/bump_version.sh` and update its CHANGELOG.md.
2. Commit and upload the updated files to GitHub.
3. Create a new release for ZEN explorer:
https://github.com/ZEN-universe/ZEN-explorer/releases/new
4. Bump version in ZEN temple `bash scripts/bump_version.sh` and update [CHANGELOG.md](CHANGELOG.md).
5. Commit and upload the updated files to GitHub.
6. Create a new release for ZEN temple, e.g. `<version>`. For a pre-release also add a suffix `.dev1`, i.e. `<version>.dev1`, and mark the release as pre-release:
https://github.com/ZEN-universe/ZEN-temple/releases/new
7. (optional) Look at PyPI whether the new release has successfully been created:
https://pypi.org/project/zen-temple/#history

## Folder structure

The folder and file structure is the following:

### Explorer
`explorer` contains the html files for the frontend. 

> [!WARNING]  
> Do not edit the files in this folder. This folder is automatically generated by the frontend repository pipeline.


### Models
`models` contains the Pydantic-models that are used for the documetnation. Some of these models also include generators that create an instance of the model given the path of a solution. See https://fastapi.tiangolo.com/tutorial/body/#create-your-data-model

### Repositories
`repositories` contains the repositories for the data access. These provide an abstraction layer for the routers such that the data access is separtated from the data source. Arguably, the generators defined in the models should be part of the repository in order to separate the instanciation of the models from the way that the solutions are stored. For more information visit https://www.umlboard.com/design-patterns/repository.html

### Routers
`routers` contains the FastAPI routers which define the different paths of the API server. For more information visit https://fastapi.tiangolo.com/tutorial/bigger-applications/

### Config
`config.py` contains the config of the application.

### Main
`main.py` contains the setup of the FastAPI application. For more information visit https://fastapi.tiangolo.com/tutorial/bigger-applications/

## Releasing

In order to release a new version to Pypi you have to create a new tag in the correct semantic versioning form (i.e. `v[0-9]+.[0-9]+.[0-9]+`). Whenever such a tag is created, a new release is generated, the pyproject.toml file is updated and a new version is being published to Pypi.
