49 - Themes

Overview

OpenAlgo's React frontend supports theme customization with light/dark modes and 12 base colors. Theme preferences persist across sessions using Zustand with localStorage. The theme system also manages "App Mode" (live vs analyzer) with distinct visual states.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                           Theme Architecture                                  │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                         Theme Configuration                                  │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  Zustand Theme Store                                                 │   │
│  │                                                                      │   │
│  │  state: {                                                            │   │
│  │    mode: 'light' | 'dark',                                          │   │
│  │    color: 'zinc' | 'blue' | 'green' | 'violet' | ...               │   │
│  │    appMode: 'live' | 'analyzer',                                    │   │
│  │    isTogglingMode: boolean                                          │   │
│  │  }                                                                   │   │
│  │                                                                      │   │
│  │  actions: {                                                          │   │
│  │    setMode(mode),                                                   │   │
│  │    setColor(color),                                                 │   │
│  │    setAppMode(appMode),                                             │   │
│  │    toggleMode(),                                                    │   │
│  │    toggleAppMode(),   // async - calls backend                      │   │
│  │    syncAppMode()      // sync with backend state                    │   │
│  │  }                                                                   │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
│                                    │                                         │
│                                    │ persist to localStorage                 │
│                                    │                                         │
│                                    ▼                                         │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  localStorage                                                        │   │
│  │                                                                      │   │
│  │  openalgo-theme: {                                                  │   │
│  │    "state": {                                                       │   │
│  │      "theme": "dark",                                               │   │
│  │      "accentColor": "blue"                                          │   │
│  │    }                                                                │   │
│  │  }                                                                  │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘

                                     │ Apply to DOM


┌─────────────────────────────────────────────────────────────────────────────┐
│                            DOM Application                                   │
│                                                                              │
│  <html data-theme="dark" class="accent-blue">                              │
│    <body class="bg-base-100 text-base-content">                            │
│      <!-- DaisyUI components inherit theme -->                              │
│    </body>                                                                   │
│  </html>                                                                     │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  CSS Variables Applied                                               │   │
│  │                                                                      │   │
│  │  --primary: hsl(217, 91%, 60%)      /* Accent color */              │   │
│  │  --secondary: hsl(217, 33%, 17%)                                    │   │
│  │  --accent: hsl(217, 91%, 70%)                                       │   │
│  │  --base-100: hsl(0, 0%, 100%)       /* Light mode */                │   │
│  │  --base-100: hsl(220, 13%, 18%)     /* Dark mode */                 │   │
│  │  --base-content: hsl(220, 13%, 69%)                                 │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘

Theme Store Implementation

Zustand Store

DOM Application

Available Themes

Color Modes

Theme Colors (12 options)

Color
Use Case

Zinc

Default neutral gray

Slate

Blue-gray neutral

Stone

Warm gray neutral

Gray

Pure gray

Neutral

Balanced neutral

Red

Errors, sell actions

Rose

Soft pink accent

Orange

Warnings, attention

Green

Success, growth

Blue

Professional, primary

Yellow

Caution, pending

Violet

Creative accent

App Mode (Live vs Analyzer)

The theme store manages two distinct app modes with different visual states:

Implementation

Theme Settings UI

Theme Toggle Component

Color Picker Component

Settings Page Section

CSS Implementation

DaisyUI Theme Configuration

Accent Color CSS

System Preference Detection

Key Files Reference

File
Purpose

frontend/src/stores/themeStore.ts

Zustand theme store

frontend/src/components/ThemeToggle.tsx

Toggle button

frontend/src/components/AccentColorPicker.tsx

Color picker

frontend/src/styles/accent-colors.css

Accent CSS vars

frontend/tailwind.config.js

DaisyUI themes

Last updated