# Vihar Sewa

Coordination platform for Jain saints' vihar (foot journeys). Phase 1 pilot — South Mumbai.

See `Vihar_Sewa_Design_v1.docx` (delivered separately) for the full design.

---

## Repo Layout

```
vihar-sewa/
├── apps/
│   ├── web/              Next.js 14 PWA (port 3001)
│   └── api/              NestJS backend (port 4001)
├── packages/
│   ├── db/               Prisma schema + client + seed
│   └── shared/           Zod schemas + DTOs + constants (used by both apps)
├── scripts/              Dev/deploy helpers
├── .env.example          Copy to .env and fill in
└── package.json          pnpm workspace root
```

## Prerequisites

- **Node.js** 20.x or later
- **pnpm** 8.x or later — `npm install -g pnpm`
- **MySQL** 8.0 running locally (port 3306)
- **Redis** 7.x running locally (port 6379) — optional in early dev
- A Google Cloud project with **Routes API** and **Places API (New)** enabled (see Section 9 of design doc)

## First-time setup

```bash
# 1. Clone and install
git clone git@github.com:mindforgeerp/vihar-sewa.git
cd vihar-sewa
pnpm install

# 2. Configure env
cp .env.example .env
# Edit .env - set DATABASE_URL, JWT_SECRET, GOOGLE_MAPS_*

# 3. Create the local database
mysql -u root -p < scripts/init-db.sql

# 4. Generate Prisma client + run migrations
pnpm db:generate
pnpm db:migrate

# 5. Seed pilot data (1 city, localities, samuday, default template, 1 captain)
pnpm db:seed

# 6. Start dev servers
pnpm dev
# Web:  http://localhost:3001
# API:  http://localhost:4001
```

## Environment variables

See `.env.example` for the complete list. Key ones:

| Variable | Purpose |
|---|---|
| `DATABASE_URL` | MySQL connection string |
| `JWT_SECRET` | Min 64 random chars — generate with `openssl rand -hex 64` |
| `GOOGLE_MAPS_BACKEND_KEY` | Routes API + Place Details (server-side only) |
| `NEXT_PUBLIC_GOOGLE_MAPS_FRONTEND_KEY` | Autocomplete only (referrer-restricted) |
| `CRON_SECRET` | Protects `/api/internal/auto-close` endpoint |

## Common commands

```bash
pnpm dev               # Run web + api in parallel
pnpm dev:web           # Just the frontend
pnpm dev:api           # Just the backend
pnpm db:studio         # Prisma Studio - visual DB browser
pnpm db:reset          # Drop + recreate DB and re-seed (DEV ONLY)
pnpm build             # Production build of both apps
pnpm lint              # Lint everything
```

## Initial captain login

After `pnpm db:seed`, log in with the credentials from your `.env`:

- Username: `SEED_CAPTAIN_USERNAME` (default: `captain1`)
- Password: `SEED_CAPTAIN_PASSWORD` (default: `Change@Me123` — change immediately)

## Build phases

All four foundation turns are complete. See:

- `TURN1_NOTES.md` — Repo + DB schema + shared types + seed
- `TURN2_NOTES.md` — NestJS backend (auth + all controllers + auto-close cron)
- `TURN3_NOTES.md` — Next.js frontend (login, role chooser, dashboard shells)
- `TURN4_NOTES.md` — Deployment artifacts + Claude Code task briefs

Feature work happens in Claude Code on your laptop, one task at a time. See
`docs/tasks/README.md` for the recommended order and how to run a brief.

## Production deployment

See `TURN4_NOTES.md` and `deploy/first-time-setup.sh` for kreonAI5 setup.

## License

Proprietary - Kreon Solutions / MindForge Innovations.
