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:

Goal

Provide an explicit, user-controlled toggle stored in gograb-api.user_preferences, so:

  1. Users can easily switch between local and cloud mode
  2. Preference persists across sessions and devices (when logged in)
  3. All docs-angular consumers (project list, config editor, etc.) respect the same setting
  4. 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):


Backend Changes (backend-api / libs-api)

1. Schema (libs/libs-api/backend-core)

2. API

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

2. Project Selection State

File: apps/docs-angular/src/app/state/project-selection.state.ts

3. Config Editor

File: apps/docs-angular/src/app/admin/config-editor/config-editor.component.ts

4. Settings UI

Location: Admin area — either in Config Editor header or a dedicated Settings page

UI: Toggle or segmented control:

Visibility: Only show when user is authenticated. Anonymous users always use local.

5. API Base for Preferences


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

  1. Backend: Add DocsPreferences schema + service support
  2. DocsAppModeService: Create service, load on init
  3. Project selection: Use mode to choose config source
  4. Config editor: Use mode + add toggle UI
  5. 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