File size: 5,693 Bytes
985f3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# πŸš€ ArunCore β€” Production Deployment Guide

> **Architecture:** Next.js static frontend on **Vercel** + FastAPI backend on **Railway** +
> custom domain **neuralarun.in** (GoDaddy). Monorepo is deployed from GitHub
> (`neural-arun/aruncore`).

```
Browser (https://neuralarun.in)
└── Vercel  (serves frontend/out static export)
      └── calls ──> Railway  (FastAPI, uvicorn, port $PORT)
                      β”œβ”€β”€ OPENAI / COHERE / GITHUB / TELEGRAM keys (env)
                      └── volume /app/data  (persists active-learning answers)
```

---

## Table of Contents
1. [Prerequisites](#1-prerequisites)
2. [Push repository to GitHub](#2-push-repository-to-github)
3. [Deploy backend on Railway](#3-deploy-backend-on-railway)
4. [Deploy frontend on Vercel](#4-deploy-frontend-on-vercel)
5. [Point neuralarun.in (GoDaddy) to Vercel](#5-point-neuralarunin-godaddy-to-vercel)
6. [Verification checklist](#6-verification-checklist)
7. [Security notes](#7-security-notes)
8. [Troubleshooting](#8-troubleshooting)

---

## 1. Prerequisites
- Accounts: [Railway](https://railway.app), [Vercel](https://vercel.com), [GoDaddy](https://godaddy.com) (domain `neuralarun.in`).
- All API keys available (from local `.env` β€” **never commit it**):
  - `OPENAI_API_KEY`, `COHERE_API_KEY`
  - `GITHUB_USERNAME`, `GITHUB_TOKEN`
  - `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID`
  - `TELEGRAM_ALERT_BOT_TOKEN`, `TELEGRAM_ALERT_CHAT_ID`
  - `TELEGRAM_PUBLIC_BOT_TOKEN`, `ADMIN_SECRET_KEY`
  - `APIFY_API_TOKEN`, `LINKEDIN_PROFILE_URL` (optional)

---

## 2. Push repository to GitHub
```bash
cd /home/arun/projects/profile
git add -A
git commit -m "chore: production deploy prep"
git push origin main
```
This pushes the whole monorepo (backend + frontend + `data/` + `tenants/`). Railway and
Vercel each build only the part they need. `.env`, `db/`, and `frontend/out/` are gitignored.

---

## 3. Deploy backend on Railway
1. **railway.app β†’ New Project β†’ Deploy from GitHub repo** β†’ `neural-arun/aruncore`.
2. Railway detects the **Dockerfile** and builds automatically.
   - Docker CMD already runs `uvicorn backend.app.main:app --host 0.0.0.0 --port $PORT`.
3. **Variables** tab β†’ add every key listed in [Prerequisites](#1-prerequisites).
   - Set `RUN_TELEGRAM_PUBLIC_BOT=true` only if you want the public Telegram bot process.
4. **Volumes** tab β†’ add a volume mounted at **`/app/data`**.
   - Persists `data/raw/unknown_questions.json` (AI-trained answers). Without it, every
     redeploy resets learned answers. First mount is empty (seed it later if needed).
5. **Deploy**, then open **`https://<your-app>.up.railway.app/health`**.
   - Expected: `{"status": "ok", "active_sessions": {...}, "telegram_alert_bot_preview": "...", ...}`
   - Copy this URL β€” you'll need it for Vercel.

---

## 4. Deploy frontend on Vercel
1. **vercel.com β†’ Add New β†’ Project** β†’ import `neural-arun/aruncore`.
2. **Root Directory** β†’ `frontend`.
3. **Framework Preset** β†’ Next.js. Output settings β†’ Output directory β†’ **`out`**
   (the project uses `output: "export"`; Vercel serves the static export).
4. **Environment Variables**:
   | Name | Value |
   | --- | --- |
   | `NEXT_PUBLIC_API_URL` | `https://<your-app>.up.railway.app` |
   | `NEXT_PUBLIC_TELEGRAM_ALERT_BOT_TOKEN` | your alert bot token |
   | `NEXT_PUBLIC_TELEGRAM_ALERT_CHAT_ID` | your alert chat id |
   - Without `NEXT_PUBLIC_API_URL` the chat falls back to `window.location.origin` and breaks.
5. **Deploy**. You get a `*.vercel.app` URL. CORS already allows `*` + all vercel.app subdomains.

---

## 5. Point neuralarun.in (GoDaddy) to Vercel
1. Vercel project β†’ **Settings β†’ Domains** β†’ add `neuralarun.in` and `www.neuralarun.in`.
2. Choose **Vercel DNS**; Vercel shows the exact records to create.
3. In **GoDaddy DNS Manager**, create/replace:
   ```
   A      @      76.76.21.21
   CNAME  www    cname.vercel-dns.com
   ```
   Delete any conflicting `@` A/CNAME (e.g., old forwarding rows).
4. Vercel auto-provisions HTTPS. Propagation: minutes β†’ up to 24h.

---

## 6. Verification checklist
- [ ] `https://<railway-url>/health` returns `status: ok`.
- [ ] `https://neuralarun.in` loads the hero card & tabs.
- [ ] Send a chat message β†’ reply arrives, and **Telegram alert** fires.
- [ ] `?tutor=ed_donner` demo mode loads Ed Donner branding.
- [ ] Voice note (TTS) plays from the client.
- [ ] Redeploy does **not** wipe admin-verified answers (volume mounted).

---

## 7. Security notes
- **No secrets in code.** The alert bot token is read from
  `NEXT_PUBLIC_TELEGRAM_ALERT_BOT_TOKEN` (client env) β€” set it in Vercel only.
- If any token was ever committed or deployed publicly, **rotate it immediately**
  (Telegram: BotFather β†’ revoke token), then update `Railway` + `Vercel` env.
- Future hardening: move client-side Telegram alerts behind a backend endpoint so the
  token never ships to the browser at all.

---

## 8. Troubleshooting
| Symptom | Fix |
| --- | --- |
| Chat calls Vercel URL, not Railway | Set `NEXT_PUBLIC_API_URL` on Vercel & redeploy |
| `/health` returns error on start | All Railway env vars present? `OPENAI_API_KEY` required at boot |
| Bot answers reset after redeploy | Volume `/app/data` not attached |
| Domain shows Vercel 404 | DNS not propagated / domain not added in Vercel settings |
| CORS errors in console | Backend `allow_origins=["*"]` already covers all; confirm deploy is newest |

---

## Optional upgrades
- Backend-only Dockerfile + `.dockerignore` β†’ faster Railway builds (skip frontend build).
- Branded API subdomain: `api.neuralarun.in` β†’ CNAME to your Railway app, then point
  `NEXT_PUBLIC_API_URL` at it.