# Turn 4 — Deployment + Claude Code Task Briefs

This is the last turn from this conversation. After this, all feature work
moves to your laptop with Claude Code, one task brief at a time.

## What's new in this drop

```
deploy/
├── init-db.prod.sql          MySQL provisioning for kreonAI5
├── nginx-vihar.conf          Production Nginx vhost (HTTPS, /api proxy, PWA caching)
├── ecosystem.config.js       PM2 - already at repo root in earlier turns; updated
├── deploy.sh                 Pull, build, migrate, restart (zero-downtime)
├── first-time-setup.sh       Run once as root - creates user, clones, configures
└── cron-auto-close.sh        Belt-and-braces backup to in-process cron

.github/workflows/
└── ci.yml                    Lint + typecheck + build on PR

docs/tasks/
├── README.md                                                 Index + recommended order
├── 01-google-maps-integration.md                             Backend Google APIs
├── 02-location-autocomplete-component.md                     Frontend autocomplete
├── 03-vihar-create-form.md                                   Step 1
├── 04-vihar-allocate-step.md                                 Step 2
├── 05-vihar-share-sheet.md                                   WhatsApp share
├── 06-vihar-list.md                                          Captain list
├── 07-vihar-detail-captain.md                                Captain detail + actions
├── 08-vihar-detail-volunteer.md                              Volunteer detail
├── 09-volunteer-checkin.md                                   Check-in screen
├── 10-volunteer-checkout.md                                  Check-out + tolerance
├── 11-volunteer-master.md                                    Add/edit volunteers
├── 12-stats-aggregations.md                                  Real SQL for dashboards
├── 13-captain-dashboard-charts.md                            Recharts integration
├── 14-volunteer-history-stats-leaderboard.md                 Volunteer pages
└── 15-profile-change-password.md                             Password change form
```

## Production deployment steps (kreonAI5)

```bash
# As root on kreonAI5:

# 1. Provision MySQL
# Edit deploy/init-db.prod.sql - replace REPLACE_WITH_STRONG_PASSWORD twice
mysql -u root -p < /tmp/init-db.prod.sql

# 2. Run first-time setup (creates user, clones, prompts for env, etc.)
export VIHAR_DOMAIN=vihar.sanjaytextiles.com    # or whatever you decide
bash /tmp/first-time-setup.sh

# 3. Configure Nginx
sudo cp /www/wwwroot/vihar/deploy/nginx-vihar.conf /www/server/panel/vhost/nginx/
# Edit the file - replace <DOMAIN> with the real subdomain
sudo nginx -t
sudo nginx -s reload

# 4. Issue SSL via aaPanel or certbot directly
certbot --nginx -d vihar.sanjaytextiles.com

# 5. Test
curl https://vihar.sanjaytextiles.com/health
# Should return {"status":"ok",...}

# 6. Open in browser - login with seeded captain1
```

## Subsequent deploys

```bash
# As the vihar user, from anywhere with SSH access:
sudo -u vihar /www/wwwroot/vihar/deploy/deploy.sh
```

The script:
1. Pulls origin/main
2. Installs deps
3. Generates Prisma client
4. Runs migrations (deploy mode, no prompts)
5. Builds shared / api / web
6. PM2 reload (zero downtime)
7. Health check

## Build phases summary

| Phase | What | Where | Time |
|---|---|---|---|
| Turn 1 | Repo + DB | This chat | done |
| Turn 2 | Backend (NestJS) | This chat | done |
| Turn 3 | Frontend skeleton | This chat | done |
| Turn 4 | Deploy + task briefs | This chat | done (this turn) |
| Tasks 1–15 | Features | Claude Code on laptop | ~15 sessions @ 30–60 min each |
| Pilot | Smoke test, train captains, deploy | Mumbai | 1–2 weeks |
| GA | Onboard 300+ volunteers | Mumbai | 2 weeks |

## Working with Claude Code on your laptop

For each task in `docs/tasks/`:

1. `cd ~/projects/vihar-sewa`
2. `git checkout -b task/03-vihar-create-form`
3. `claude` (or your Claude Code shortcut)
4. Tell it: "Read `docs/tasks/03-vihar-create-form.md` and implement it. Keep
   `pnpm dev` running in another terminal so we can test as we go."
5. Claude Code reads the brief, asks any clarifying questions, then writes code.
6. Review the diff yourself before committing.
7. Run the Acceptance steps from the brief.
8. Commit + PR + merge.
9. Run `sudo -u vihar /www/wwwroot/vihar/deploy/deploy.sh` to push to kreonAI5.

## Things I deliberately deferred to Phase 2/3

The following were called out in our requirements conversation but
intentionally not built in Phase 1 to keep scope tight. Phase 1 schema is
ready for them.

- Volunteer accept/decline (Uber-driver style)
- Phone OTP login
- Auto-suggest volunteers by locality proximity
- Push notifications (web push, FCM)
- WhatsApp Business API for delivery receipts
- Hindi / Gujarati UI toggle
- Multi-city UI (super-admin role enabled, multiple captains across cities)
- Saint master (right now we just store head saint name as text)
- Offline-first check-in/out with sync
- Bulk import / recurring vihar templates
- GPS trail map visualization
- CSV/PDF export

## Open questions still to confirm

The 10 questions from Section 16 of the design doc are still open. None block
Phase 1 launch but you'll want answers before pilot:

1. Subdomain (vihar.sanjaytextiles.com? new domain?)
2. Final WhatsApp message wording (current is placeholder)
3. Initial seed data — confirm/edit locality + samuday lists
4. First captains — names + phones for onboarding
5. Vihar reopen window (defaulted to 24h)
6. Auto-close cron interval (defaulted to 30 min)
7. Distance attribution to multiple volunteers (defaulted to full-to-each)
8. Cancellation reason — free text vs master
9. Volunteer self-edit window before captain reviews
10. Conflict warning during allocation — block vs warn (defaulted to warn)

## Final note

The architecture and decisions are locked. The only meaningful changes from
here are filling in features (the 15 tasks) and tuning the pilot based on
real feedback. The schema, API, design language, deployment path — none of
those should need rework for Phase 1.

If you hit something the briefs don't cover or Claude Code goes off-track,
come back with: task name + step + error message. I'll patch the brief.

🙏
