# တောင်သူ့ရဲ့ခေါင် (FarmBot Myanmar)
Text-based farming NLP chatbot — Expo mobile app + FastAPI backend + Next.js admin portal.
```
FarmBotMyanmar/
├── mobile/ # Expo (React Native) chat app
├── web/ # Next.js 16 admin portal (login-gated; Knowledge CRUD, Feedback, Analytics)
├── backend/ # FastAPI + retrieval + OpenRouter RAG
├── data/ # legacy CSV KB (no longer read — SQLite web/dev.db is the source of truth)
├── docs/ # project documentation
└── prd.md # product requirements
```
## 1. Backend (FastAPI)
```bash
cd backend
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# Put your OpenRouter key in .env:
# OPENROUTER_API_KEY=sk-or-...
# Seed the knowledge base (25 Myanmar articles) into web/dev.db + rebuild vectors:
python seed_myanmar_agri.py
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```
- Health: `GET /health` (also reports SQLite vs Chroma sync state)
- Chat: `POST /chat` with `{ "message": "...", "history": [], "user_id": "..." }`
- Chat streaming (primary): `POST /chat/stream` — SSE `token` events + one `done` payload
- Register: `POST /auth/register` with `{ "username": "...", "password": "...", "displayName": "..." }`
- Login: `POST /auth/login` with `{ "username": "...", "password": "..." }`
- Google Sign-In: `POST /auth/google` with `{ "idToken": "..." }` (needs `GOOGLE_CLIENT_IDS` in `.env`)
- Feedback: `POST /feedback` with `{ "message": "...", "answer": "...", "useful": true, "source_ids": [] }`
- Sync knowledge: `POST /sync-knowledge` (reload articles from SQLite after admin CRUD)
- An `OPENROUTER_API_KEY` is **required** for answers — without it the API replies that the AI service is not configured (no anonymous mode).
- Flow per question: greeting check → intent+NER → semantic retrieval (ChromaDB + cross-encoder re-rank) → answer grounded ONLY in retrieved knowledge; no strong match gets one clarification ask or an hon …