Docs App Mode Preference — Local vs Cloud Toggle
Store docsAppMode in user_preferences (backend-api) for clear, persistent local/cloud switching
Docs App Mode Preference — Local vs Cloud Toggle
Problem
The docs-angular app has no clear, persistent way to switch between local (filesystem) and cloud (MongoDB) documentation sources. Current behavior is implicit and scattered:
- Config editor: Tries backend-docs-api first, falls back to assets — no user control
- Project selection: Always loads from
assets/docs-folders-config.json— ignores cloud - CloudTransferService.isCloudMode: Only set after a successful transfer — not a preference
- No single source of truth for "I want local" vs "I want cloud"
Goal
Provide an explicit, user-controlled toggle stored in gograb-api.user_preferences, so:
- Users can easily switch between local and cloud mode
- Preference persists across sessions and devices (when logged in)
- All docs-angular consumers (project list, config editor, etc.) respect the same setting
- Anonymous users default to local (no preference = local)
Architecture
Data Flow
User toggles "Local" / "Cloud"
↓
PUT /api/users/me/preferences { docs: { appMode: 'local' | 'cloud' } }
↓
backend-api → user_preferences (MongoDB)
↓
docs-angular: On load, GET /api/users/me/preferences
↓
docsAppMode signal → project-selection, config-editor, etc.
Preference Location
Collection: gograb-api.user_preferences
Field: docs.appMode — new sub-document for docs-specific preferences
// New sub-schema
@Schema({ _id: false })
export class DocsPreferences {
@Prop({
type: String,
enum: ['local', 'cloud'],
default: 'local',
})
appMode: 'local' | 'cloud';
}
// In UserPreferences
@Prop({ type: DocsPreferences, default: () => ({ appMode: 'local' }) })
docs: DocsPreferences;
Rationale: Separate docs sub-schema (like chromeExtension, chat) keeps docs preferences extensible (e.g. defaultProject, sidebarCollapsed later).
Default by role (Session 218):
- executive, developer, system → default
local(they can switch to cloud) - Others (readers, etc.) → default
cloud(they cannot access local filesystem)
Backend Changes (backend-api / libs-api)
1. Schema (libs/libs-api/backend-core)
- Add
DocsPreferencesclass withappMode: 'local' | 'cloud' - Add
docs: DocsPreferencestoUserPreferences - Add to
UpdatePreferencesInput:docs?: Partial<DocsPreferences> - Add to
PreferencesResult:docs: DocsPreferences - Add to
getDefaultPreferencesandtoPreferencesResult - Update
updatePreferencesto handleinput.docs
2. API
- GET
/api/users/me/preferences— already returns full preferences; will includedocs - PUT
/api/users/me/preferences— already accepts partial updates; adddocssupport
No new endpoints. Existing preferences API is sufficient.
Frontend Changes (docs-angular)
1. Docs App Mode Service (new)
File: apps/docs-angular/src/app/services/docs-app-mode.service.ts
docsAppMode = signal<'local' | 'cloud'>('local')loadFromPreferences()— GET /api/users/me/preferences, set signalsetMode(mode: 'local' | 'cloud')— PUT preferences, update signal- Fallback: If not authenticated or request fails →
'local' - APP_INITIALIZER or early in app bootstrap: call
loadFromPreferences()
2. Project Selection State
File: apps/docs-angular/src/app/state/project-selection.state.ts
- Inject
DocsAppModeService - In
LoadAvailableProjects:- If
docsAppMode() === 'cloud': fetch fromDocsApiService.getFoldersConfig()(via backend-docs-api) - If
docsAppMode() === 'local': fetch fromassets/docs-folders-config.json(current behavior)
- If
- When mode changes, re-run
LoadAvailableProjects(or expose aRefreshProjectsaction)
3. Config Editor
File: apps/docs-angular/src/app/admin/config-editor/config-editor.component.ts
- Inject
DocsAppModeService - In
loadConfiguration(): usedocsAppMode()to decide source (cloud first vs local first) - Replace implicit "try cloud, fallback local" with explicit: if cloud → only cloud; if local → only local
- Add mode toggle UI in header/settings area
4. Settings UI
Location: Admin area — either in Config Editor header or a dedicated Settings page
UI: Toggle or segmented control:
- Local — Use documentation from your project files (
docs/,assets/docs-folders-config.json) - Cloud — Use documentation from MongoDB (backend-docs-api)
Visibility: Only show when user is authenticated. Anonymous users always use local.
5. API Base for Preferences
- docs-angular uses
backendApiUrl(proxy/api→ backend-api:3000) GET /api/users/me/preferencesandPUT /api/users/me/preferencesrequire JWT- Auth interceptor already adds token for
/api/routes
Edge Cases
| Scenario | Behavior |
|---|---|
| User not logged in | Always local; no toggle shown |
| Cloud mode, backend-docs-api down | Show error; suggest switching to local |
| Local mode, assets missing | Current behavior (empty projects) |
| First-time user (no prefs) | Default docs.appMode: 'local' |
| User switches to cloud, never transferred | Config may be empty; show "Transfer to Cloud" CTA in config editor |
Implementation Order
- Backend: Add
DocsPreferencesschema + service support - DocsAppModeService: Create service, load on init
- Project selection: Use mode to choose config source
- Config editor: Use mode + add toggle UI
- Admin dashboard: Optional quick link to toggle (or keep in config editor only)
Files to Create/Modify
| File | Action |
|---|---|
libs/libs-api/backend-core/.../user-preferences.schema.ts |
Add DocsPreferences, docs field |
libs/libs-api/backend-core/.../user-preferences.service.ts |
Handle docs in get/update/defaults |
apps/docs-angular/.../docs-app-mode.service.ts |
New — mode state + API |
apps/docs-angular/.../project-selection.state.ts |
Use DocsAppModeService for source |
apps/docs-angular/.../config-editor.component.ts |
Use mode, add toggle |
apps/docs-angular/.../app.config.ts |
Provide DocsAppModeService, init on bootstrap |
apps/docs-angular/.../docs-app-mode-toggle.component.ts |
New — reusable toggle UI (optional) |
Success Criteria
- User can toggle Local/Cloud in docs admin
- Preference persists in MongoDB
user_preferences.docs.appMode - Project list and config editor both respect the mode
- Anonymous users default to local with no errors
- Clear visual indicator of current mode (e.g. badge: "Local" / "Cloud")