# ergonpy-backend

Backend Python para ERGON. Servir `app.ergonpy.com` (dashboard) y `api.ergonpy.com` (endpoints).

## Estructura esperada

Este repo recibe una copia/migracion del codigo actual desde:
```
D:/DG-2026_OFFICE/02_AREAS/02_CIVIL/02_HERRAMIENTAS/
  ├── servidor_local.py
  ├── PROTOTIPO_DG_CIVIL_v2.html
  ├── login.html
  ├── db/
  │   ├── init_db.sql
  │   ├── api_obras.py
  │   ├── alertas_engine.py
  │   ├── db_loader.py
  │   ├── parser_bitacora.py
  │   ├── parse_dispatcher.py
  │   ├── migrate_*.py
  │   ├── seed_*.py
  │   └── smoke_test_*.py
  ├── generate_dg_civil.py
  └── generate_informe_ergon.py
```

## Migracion pendiente (Sprint 5 Dia 1)

1. Copiar archivos seleccionados (sin contaminar con DG branding)
2. Renombrar `PROTOTIPO_DG_CIVIL_v2.html` -> `dashboard.html`
3. Eliminar todas las referencias a "DG_CIVIL", "Fortaleza", "FCAT1" en strings hardcoded
4. Reemplazar `servidor_local.py` con wrapper que exporta `make_app()` para waitress
5. Configurar CORS: origins solo `https://ergonpy.com` y `https://app.ergonpy.com`
6. Variables de entorno: ver `ergonpy-docs/STACK.md` §"Variables de entorno Railway"
7. Health endpoint `/health` para Railway healthcheck
8. Bridge Supabase JWT en `_require_session()`

## Build local

```bash
docker build -t ergonpy-backend .
docker run -p 8080:8080 -v $(pwd)/data:/data --env-file .env ergonpy-backend
```

## Deploy Railway

Push a main → Railway autobuild via Dockerfile. Volume `/data` persistente.
