ENVIRONMENT MODES ANALYSIS
Documentation for Plans
Environment Modes - Complete Analysis
🎯 Current Situation
We have 3 backend modes but only 2 are working:
| Mode | Status | Database | Use Case |
|---|---|---|---|
| Railway | ✅ WORKS | Railway MongoDB (Cloud) | Production testing, team collab |
| Local | ❌ BROKEN | Local MongoDB (Not running) | Local dev with MongoDB |
| Mock | ✅ WORKS | IndexedDB (Browser) | Offline-first, no backend needed |
🔴 The Problem with local Mode
What You're Seeing:
Environment: useMockApi: false, backendApiUrl: BACKEND_URLS.local
Backend API: http://localhost:3000/api ✅ Running
MongoDB: ??? ❌ NOT CONFIGURED
Why Guest Spaces Aren't Working:
- Backend starts on port 3000 ✅
- Backend tries to connect to MongoDB at
mongodb://localhost:27017❌ - No local MongoDB is running! ❌
- Backend creates spaces but they go to... nowhere? Or uses some fallback?
The MongoDB Connection:
// apis/backend-api/src/app/app.module.ts
MongooseModule.forRootAsync({
useFactory: async (configService: ConfigService) => ({
uri: configService.get<string>('MONGODB_CONNECTION_STRING'),
dbName: configService.get<string>('MONGODB_DATABASE', 'gograb-api'),
}),
})
Current State:
- ❌ No
.envfile inapis/backend-api/ - ❌ No
.envfile in repo root - ❌ No
MONGODB_CONNECTION_STRINGenvironment variable - ❓ Backend might be falling back to default
mongodb://localhost:27017 - ❌ MongoDB is NOT running on port 27017
✅ Working Modes
1. Railway Mode (Cloud MongoDB)
Config:
// apps/gograb-space/src/environments/environment.ts
useMockApi: false
backendApiUrl: BACKEND_URLS.railway
How It Works:
- Frontend → Railway Backend → Railway MongoDB ✅
- All data persists to cloud database
- Requires internet connection
- Guest spaces SHOULD work (if Railway backend has our new code)
Best For:
- Production testing
- Team collaboration
- Deploying to production
2. Mock API Mode (Offline-First)
Config:
// apps/gograb-space/src/environments/environment.ts
useMockApi: true
backendApiUrl: BACKEND_URLS.mock // Or any, it's ignored
How It Works:
- Frontend →
mockHttpInterceptor→ IndexedDB ✅ - NO backend API needed
- NO MongoDB needed
- 100% offline-first
- All data in browser's IndexedDB
Best For:
- Offline development
- No database setup needed
- Testing frontend features
- Guest users work perfectly (all local storage)
Limitations:
- No real authentication (uses mock auth)
- Can't test backend features
- Data doesn't sync between devices
🔧 How to Fix local Mode
Option A: Install Local MongoDB
1. Install MongoDB:
# macOS
brew install [email protected]
brew services start [email protected]
# Verify it's running
lsof -ti:27017 # Should show a process
2. Create .env file:
# In repo root or apis/backend-api/
MONGODB_CONNECTION_STRING=mongodb://localhost:27017
MONGODB_DATABASE=gograb-api-dev
JWT_SECRET=your-super-secret-key-change-this
JWT_EXPIRATION=7d
3. Restart backend:
npx nx serve backend-api
Option B: Use Railway Mode (Easiest)
1. Switch environment:
// apps/gograb-space/src/environments/environment.ts
backendApiUrl: BACKEND_URLS.railway
2. Deploy our fixes to Railway:
# Push to Railway (if you have it set up)
git push railway main
3. Guest spaces will work with our custom ID fix
Option C: Use Mock Mode for Development
1. Switch to pure offline mode:
// apps/gograb-space/src/environments/environment.ts
useMockApi: true
2. No backend needed!
- All data in IndexedDB
- Guest users work perfectly
- 100% offline
🎯 Recommended Approach
For Right Now (Testing Guest Spaces):
Use Mock API Mode:
useMockApi: true
backendApiUrl: BACKEND_URLS.mock
Why:
- ✅ NO MongoDB setup needed
- ✅ Works immediately
- ✅ Guest users work perfectly
- ✅ Can test all frontend features
- ✅ Data persists in IndexedDB
- ❌ Can't test backend authentication
- ❌ Can't test backend API integration
For Full Stack Development:
Option 1: Railway Mode (if backend is deployed with fixes)
useMockApi: false
backendApiUrl: BACKEND_URLS.railway
Option 2: Local Mode (after installing MongoDB)
useMockApi: false
backendApiUrl: BACKEND_URLS.local
# Plus: brew install mongodb-community && brew services start
📊 Feature Comparison
| Feature | Railway | Local (w/ MongoDB) | Mock API |
|---|---|---|---|
| Guest Spaces Custom IDs | ✅ | ✅ | ✅ |
| Universe Persistence | ✅ | ✅ | ✅ |
| Real Authentication | ✅ | ✅ | ❌ (Mock) |
| Offline Development | ❌ | ❌ | ✅ |
| No Setup Required | ✅ | ❌ | ✅ |
| Team Collaboration | ✅ | ❌ | ❌ |
| Internet Required | ✅ | ❌ | ❌ |
🚀 Quick Start
Test Guest Spaces NOW:
// apps/gograb-space/src/environments/environment.ts
export const environment = {
production: false,
useMockApi: true, // ✅ Change this
backendApiUrl: BACKEND_URLS.mock,
deploymentMode: DEPLOYMENT_MODES.development,
...SHARED_CONFIG,
};
- Save file
- Frontend hot-reloads
- Nuclear reset
- Guest spaces will work with IndexedDB storage
Test with Real Backend (Railway):
// apps/gograb-space/src/environments/environment.ts
export const environment = {
production: false,
useMockApi: false, // ✅ Real backend
backendApiUrl: BACKEND_URLS.railway, // ✅ Cloud MongoDB
deploymentMode: DEPLOYMENT_MODES.development,
...SHARED_CONFIG,
};
- Save file
- Frontend hot-reloads
- Nuclear reset
- Guest spaces create in Railway's MongoDB
- Check if Space ID is
space_temp-xxx(depends on Railway backend version)
❓ Questions to Answer
Is the Railway backend deployed with our latest fixes?
- Check:
https://backend-api-production-97c0.up.railway.app/api/health - If yes → Use Railway mode
- If no → Deploy fixes to Railway first
- Check:
Do you want to set up local MongoDB?
- Yes → Follow Option A above
- No → Use Railway or Mock mode
Do you need real backend for current work?
- Yes → Use Railway (easiest) or Local (after setup)
- No → Use Mock API (fastest, no setup)
Date: November 3, 2025
Status: Local mode broken (no MongoDB), Railway and Mock modes work
Recommendation: Use Mock API for immediate testing, Railway for full backend testing