Local Editor Development Setup¶
Fast UI-iteration loop: run the Next.js editor on your laptop with Next's hot-reload (~1s per change) while the backend (AstraPBX, Pipecat gateway, Workflow engine) continues to run on the staging VPS. An SSH tunnel bridges the two.
Use this instead of editing on the VPS + ./scripts/dev-deploy.sh editor (which takes ~3-4 min per iteration because of the Next.js build).
Staging only — never tunnel to prod
Every port forward in this doc terminates on the staging VPS (94.136.188.221). Do not change the target to 89.116.31.109 — local hot-reload against prod backends is a footgun (a runaway useEffect can spam real PBX APIs).
When to use this¶
Use local dev when:
- You're iterating on UI / component styling and the 3-4 min VPS build cycle is painful
- The change is UI-only (no backend code, no Asterisk config, no DB migration)
- You want instant Fast-Refresh preview of React component edits
Stick with the VPS dev-deploy.sh editor flow when:
- You need to verify on the real
stageeditor.astradial.comdomain (e.g. testing Cloudflare Access interaction, production build output, CDN-cached assets) - You're touching
next.config.tsor middleware - You've changed backend code on the VPS that the editor needs to exercise
Architecture¶
Browser (localhost:3000)
│
▼
Next.js dev server (your laptop)
│ /api/pbx/* ──► localhost:8000 ─┐
│ /api/gateway/* ──► localhost:7860 ├─ SSH tunnel ─► VPS 94.136.188.221
│ /api/workflow/* ──► localhost:3002 ─┘ (staging backends)
│
└─ Firebase Auth + Firestore ──► Google (direct, not via tunnel)
The dev server serves the UI on localhost:3000 and proxies /api/* calls through the SSH tunnel to the corresponding port on the staging VPS. Firebase auth and Firestore reads/writes go directly from the browser to Google, scoped to the astrapbx_stage/… root via NEXT_PUBLIC_ASTRADIAL_ENV=staging.
Why tunnel, not point at stage* domains directly?¶
All stage* hostnames sit behind Cloudflare Access. The editor's next.config.ts rewrites /api/pbx/* etc. server-side — the Next dev server on your laptop would then need to forward those requests to stagepbx.astradial.com, and it has no Access cookie to attach. Every call would 302 to the Cloudflare login page and break.
A tunnel sidesteps Access entirely by reaching the backends on their private port via SSH.
Prerequisites¶
| Tool | Why | Where |
|---|---|---|
| Git | Clone the monorepo | https://git-scm.com/downloads |
| Node.js ≥ 20 LTS | Run Next.js 16 | https://nodejs.org |
| OpenSSH client | SSH tunnel | Built-in on Windows 10/11 and macOS; sudo apt install openssh-client on Linux |
SSH access to root@94.136.188.221 | Tunnel target | See Add SSH User |
One-time setup¶
1. Clone and branch¶
cd <your-projects-folder>
git clone https://github.com/astradial/astradial-platform.git
cd astradial-platform
# branch from staging — never from main or from whatever was checked out
git fetch origin
git checkout staging && git reset --hard origin/staging
git checkout -b <your-feature-branch>
2. Install editor deps¶
Expect 2-3 min on first install. Deprecation warnings and the audit count are noisy but not blocking.
3. Seed .env.local from the staging VPS¶
The editor needs Firebase client config plus a few server secrets. Rather than curate them by hand, copy the live staging .env:
Then open editor/.env.local and confirm these lines are present (add them if missing):
NEXT_PUBLIC_ASTRADIAL_ENV=staging
NEXT_PUBLIC_GATEWAY_URL=http://localhost:7860
NEXT_PUBLIC_PBX_URL=http://localhost:8000
NEXT_PUBLIC_WORKFLOW_URL=http://localhost:3002
NEXT_PUBLIC_ASTRADIAL_ENV=staging is mandatory
Without it the editor treats the Firestore root as prod (astrapbx/…) and any writes (creating an org, editing a user, saving an IVR) corrupt production data. Verify this line exists before running the dev server.
.env.local is gitignored — it will not be committed.
4. Authorize localhost in Firebase¶
The staging Firebase project is misssellerai. Authentication → Settings → Authorized domains must contain localhost, otherwise login fails with auth/unauthorized-domain. This is a project-wide setting, so once any dev has added it, all other devs are covered.
Everyday loop (two terminals)¶
Terminal 1 — SSH tunnel (leave running)¶
| Local port | Forwards to | VPS service |
|---|---|---|
| 8000 | VPS localhost:8000 | AstraPBX API |
| 7860 | VPS localhost:7860 | Pipecat gateway |
| 3002 | VPS localhost:3002 | Workflow engine |
Do not type in this shell — it is a pipe. Closing it breaks every API call from the editor with ECONNREFUSED.
Terminal 2 — Next.js dev server¶
Expected output:
Port is 3000, not 3001
PORT=3001 in .env.local is ignored by Turbopack — it reads PORT from the OS environment, not from dotenv. To force 3001, run with $env:PORT=3001; npm run dev (PowerShell) or PORT=3001 npm run dev (bash).
Open http://localhost:3000. Log in as admin@astradial.com with the password from .env.local (NEXT_PUBLIC_FB_AUTH_PASS).
Edit loop¶
- Edit any
.tsx/.ts/.cssundereditor/in your editor of choice. - Save. Turbopack Fast-Refreshes in ~1s. Component state preserved.
Hot reload does not cover next.config.ts, middleware.ts, .env.local, or a new dependency — Ctrl+C + npm run dev again for those.
Committing¶
Push your feature branch to GitHub when done:
cd <your-projects-folder>/astradial-platform
git add editor/ # add specific paths — never `git add -A`
git commit -m "ui: <what you changed>"
git push -u origin <your-feature-branch>
gh pr create --base staging --title "..."
Never push to staging or main directly — the staging branch is CI/CD-deployed, and main is prod.
Troubleshooting¶
| Symptom | Cause | Fix |
|---|---|---|
Browser: ECONNREFUSED localhost:8000 | SSH tunnel dropped | Restart Terminal 1 |
Login: auth/invalid-email | Email field empty | Type admin@astradial.com manually |
Login: auth/unauthorized-domain | localhost not in Firebase authorized domains | Step 4 above |
Login: auth/wrong-password | Your .env.local is stale vs VPS | Re-run the scp in step 3 |
Dev server: listen EADDRINUSE :::3000 | Port 3000 busy | Free it or start with PORT=3001 |
Dashboard loads but all data is 0 / empty | NEXT_PUBLIC_ASTRADIAL_ENV missing or set to prod | Step 3 — this is the exact symptom |
| Data looks like prod — real customer orgs visible | NEXT_PUBLIC_ASTRADIAL_ENV=staging missing or wrong | Stop immediately. Fix env, restart dev server. Any writes you made during this window landed in prod. |
Type errors after git pull | New dep in package.json | cd editor && npm install |
Environment quick-ref¶
| Staging (tunnel target) | Prod (do not tunnel) | |
|---|---|---|
| VPS | 94.136.188.221 | 89.116.31.109 |
| Editor domain | stageeditor.astradial.com | editor.astradial.com |
| PBX API | stagepbx.astradial.com | devpbx.astradial.com |
| Firestore root | astrapbx_stage/… | astrapbx/… |
| Branch | staging | main |
See also: Staging Environment, Staging Direct-Edit, CI/CD Pipeline.