# LaksyaShrimp deployment

## Public URL

The application is publicly mounted at:

`https://ciba.res.in/laksyashrimp`

The Flask process remains an internal service on port `5899`. **Port 5899 and
server IP addresses must never be embedded in QR codes or customer links.**

The project centralizes this in `config.py`:

- `PUBLIC_BASE_URL=https://ciba.res.in/laksyashrimp`
- `PUBLIC_PATH=/laksyashrimp`
- `FLASK_HOST=0.0.0.0`
- `FLASK_PORT=5899`

## Install

```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

## Test Flask directly

```bash
source venv/bin/activate
python app.py
```

The internal test endpoint is normally:

`http://127.0.0.1:5899/`

For a real deployment, users should not be sent to that address.

## Production with Gunicorn

```bash
gunicorn --workers 2 --bind 127.0.0.1:5899 wsgi:application
```

A systemd service can run the same command from the project directory.

## Apache reverse proxy

The reverse proxy must **strip** `/laksyashrimp/` before forwarding to Flask.
The trailing slash on both paths is important:

```apache
ProxyPreserveHost On

ProxyPass        /laksyashrimp/ http://127.0.0.1:5899/
ProxyPassReverse /laksyashrimp/ http://127.0.0.1:5899/

RequestHeader set X-Forwarded-Prefix "/laksyashrimp"
```

After enabling the required Apache proxy modules, reload Apache.

## Nginx reverse proxy alternative

```nginx
location /laksyashrimp/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Prefix /laksyashrimp;

    # The trailing slash strips /laksyashrimp/ before Flask receives the path.
    proxy_pass http://127.0.0.1:5899/;
}
```

## QR generation

Run:

```bash
python generate_qr_for_blocks.py
python export_blocks_to_json_and_qr.py
python generate_plate_qr.py
```

`generate_qr_for_blocks.py` now uses the actual blockchain `data_id` and stage
for feedback QR codes, so the scan target matches the dashboard's clickable
feedback target.

## Verification

Run:

```bash
python verify_qr_setup.py
```

Also check that no source/data file contains a legacy host:

```bash
grep -RIn --exclude='*.db' --exclude='*.png' \
  -E '14\.139\.181\.163|115\.240\.192\.141|localhost:5899' .
```

The command should return no legacy public URL.

## Important URL behavior

Internal Flask routes remain root routes, for example:

`/lineage_block/vannamei/1`

The public reverse proxy exposes them as:

`https://ciba.res.in/laksyashrimp/lineage_block/vannamei/1`

The application generates the latter for QR codes and customer-facing links.


## Static QR / link policy

Customer-facing QR targets and their clickable links are intentionally STATIC. They are pre-generated at packaging time and stored in `static/json/static_links.json` and `static/qr/`. The Flask request path does not generate or rewrite customer-facing QR URLs. If the underlying blockchain data is intentionally changed, regenerate the static assets offline and redeploy the updated package.
