# TA-ATS — Windows (local development)

Local dev on the XAMPP box. All four services run on localhost; the FastAPI gateway
sits on :8000 and proxies to Django on :8002.

> Shell: use **Git Bash** or **PowerShell**. Paths below assume the repo at
> `E:\xampp\htdocs\python\TA-ATS-interns` with the MCP as a sibling
> `E:\xampp\htdocs\python\auth_mcp`.

---

## 0. Prerequisites (install once)
- **Python 3.12+**  — https://python.org  (tick "Add to PATH")
- **Node.js 20+ / 22** — https://nodejs.org  (`node -v`, `npm -v`)
- **PostgreSQL 15+** — running locally; create DB `ats_main` and `ats_mcp_db`
- **Git**

---

## 1. Create virtualenvs + install deps (once)
```powershell
# --- MCP (sibling folder) ---
cd E:\xampp\htdocs\python\auth_mcp
python -m venv venv
.\venv\Scripts\python.exe -m pip install -r requirements.txt

# --- Backend (Django) ---
cd E:\xampp\htdocs\python\TA-ATS-interns\backend
python -m venv venv
.\venv\Scripts\python.exe -m pip install -r requirements\base.txt

# --- Gateway (FastAPI) ---
cd E:\xampp\htdocs\python\TA-ATS-interns\gateway
python -m venv venv
.\venv\Scripts\python.exe -m pip install -r requirements.txt

# --- Frontend (Next.js) ---
cd E:\xampp\htdocs\python\TA-ATS-interns\frontend
npm install
```

---

## 2. Environment files
Create `backend\.env` (minimum):
```
SECRET_KEY=dev-secret-change-me
DEBUG=True
DB_NAME=ats_main
DB_USER=postgres
DB_PASSWORD=your_pg_password
DB_HOST=localhost
DB_PORT=5432
# IMPORTANT: 127.0.0.1 (one, not zero). This is the MCP the login flow calls.
MCP_URL=http://127.0.0.1:9000/mcp
```

Frontend dev needs no `.env` (defaults to `http://localhost:8000/api/v1`). If you set
one, it must be `frontend\.env.local`:
```
NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1
```

---

## 3. Migrate + seed the database (once, or after model changes)
The master seeder (`database\ats_seeder_akn.bat`) does migrations + ALL seed data:
```powershell
cd E:\xampp\htdocs\python\TA-ATS-interns\database
.\ats_seeder_akn.bat
```
Also seed the MCP's own store:
```powershell
cd E:\xampp\htdocs\python\auth_mcp
.\venv\Scripts\python.exe -c "import db; db.ensure_schema()"
```
Login after seeding: **ats@admin.com / ats@2468**

---

## 4. Run all services
Use the provided launcher (starts all four):
```powershell
cd E:\xampp\htdocs\python\TA-ATS-interns
.\run.bat
```
Or start them manually in separate terminals:
```powershell
# 1) MCP  (port 9000)
cd E:\xampp\htdocs\python\auth_mcp
.\venv\Scripts\python.exe server.py

# 2) Backend  (port 8002)
cd ..\TA-ATS-interns\backend
.\venv\Scripts\python.exe manage.py runserver 127.0.0.1:8002

# 3) Gateway  (port 8000)
cd ..\gateway
.\venv\Scripts\uvicorn.exe app.main:app --host 127.0.0.1 --port 8000

# 4) Frontend  (port 3000)
cd ..\frontend
npm run dev
```

Open **http://localhost:3000** → login `ats@admin.com` / `ats@2468`.

---

## 5. Common local checks
```powershell
# which ports are listening
netstat -ano | findstr ":9000 :8002 :8000 :3000"

# MCP healthy? (this JSON-RPC 'text/event-stream' notice = UP)
curl http://127.0.0.1:9000/mcp

# API up?
curl http://127.0.0.1:8000/api/docs/
```

If login says "MFA service unavailable" → MCP not running or `MCP_URL` wrong (see
TROUBLESHOOTING.md #2). If the UI can't reach the API → check the gateway on :8000.
