# Backend
The Flask backend for Hipograf. It handles database interactions, API endpoints, authentication/authorization, and HIPPO AI requests.

## Requirements
- Python 3.14+
- pip
- MongoDB (running on `localhost:27017` by default)
- Groq API Key for HIPPO AI (required for HIPPO features)

## Setup
1. Create and activate a virtual environment:
```bash
python3 -m venv .venv
source .venv/bin/activate
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Create a `.env` file in the `backend/` directory (you can copy `.sample_env` as a starting point):
```env
MONGODB_URI=mongodb://localhost:27017
MONGODB_DB_NAME=hipograf
FLASK_ENV=development
FLASK_DEBUG=True
GROQ_API_KEY=your_groq_api_key_here
```
4. Run the server:
```bash
python run.py
```

## Linting
```bash
python -m pylint app/
```

## Folder Structure
- `/app` directory is where the app resides.
- `/app/config.py` contains the `Config` class, used for app-wide configuration.
- `/app/models` contains data models; defined for easy validation, serialization, and deserialization.
- `/app/repositories` contains database access logic, providing reusable interfaces.
- `/app/functionalities` contains more complicated functionality logic used in the application.
- `/app/static` directory contains static files to be served by the backend.

## Swagger Documentation
Swagger UI is available at the `/swagger` endpoint.

For an endpoint to appear in Swagger, document it using Flasgger-style docstrings. Example:

```python
@app.route("/users/<int:id>", methods=["GET"])
def get_user(id):
    """
    Get a user by ID
    ---
    parameters:
      - name: id
        in: path
        type: integer
        required: true
    responses:
      200:
        description: User data
    """
    ...
```

More information about Flasgger can be found here: https://pypi.org/project/flasgger/
