# Tunisia Energy RAG
RAG pipeline for the Tunisian energy sector: PDF collection, Arabic/OCR ingestion,
LLM-based triage, ChromaDB vector retrieval, an async FastAPI backend, a React
frontend (Vite build served by Nginx), and an async SQLAlchemy/PostgreSQL layer for
conversations and the crowdsourced outage map.
## Quick start (Docker Compose)
`docker compose up` starts the full stack with **PostgreSQL** and **auto-seeding**:
| Service | Purpose | URL |
|---|---|---|
| `postgres` | PostgreSQL 16 (port `127.0.0.1:5433`, internal `postgres:5432`) | — |
| `db-seed` | One-shot seeder — runs `src/database/seed.py` once Postgres is healthy, then exits | — |
| `backend` | FastAPI (healthcheck on `/health`) |
localhost |
| `frontend` | React SPA (Vite build → Nginx, proxies `/api` to backend) |
localhost |
| `ngrok` | Public tunnel to the frontend (requires `NGROK_AUTHTOKEN`) |
localhost |
### Environment
```bash
cp .env.example .env # then fill in NGROK_AUTHTOKEN (and CUSTOM_API_KEY / OPENAI_BASE_URL)
docker compose up --build
```
The React frontend lives in `frontend/`: chat (SSE streaming from
`/api/chat/stream`), the outage map (`/api/outages`), and a solar ROI calculator.
Local dev:
```bash
cd frontend
npm install
npm run dev #
localhost, proxies /api to localhost:8000
```
### Database
- Connection string: `postgresql+asyncpg://postgres:postgres@postgres:5432/energie_tunisie`
(the `DATABASE_URL` env var is set automatically for `backend` and `db-seed`).
- Tables are created by the seeder; data is persisted in the `postgres_data` named volume.
- Reseed from scratch:
```bash
docker compose run --rm db-seed python -m src.database.seed --reset
```
- Connect from the host (e.g. `psql`): `postgresql://postgres:postgres@localhost:5433/energie_tunisie`
### Service healthchecks
- `postgres` → `pg_isready -U postgres -d energie_tunisie`
- `backend` → GET `
localhost`
- `frontend` → GET `/healt …