Frontend Architecture
Relevant source files
The following files were used as context for generating this wiki page:
OpenChat utilizes a modern, full-stack React architecture centered around the TanStack ecosystem. The frontend is designed as a high-performance, type-safe Single Page Application (SPA) with Server-Side Rendering (SSR) capabilities, leveraging Vite for build tooling and Nitro as the universal server engine.
The architecture emphasizes real-time interactivity, accessibility, and a seamless developer experience through strict TypeScript enforcement and automated linting/formatting workflows.
Sources: CLAUDE.md:12-32, README.md:111-125
Core Tech Stack
The frontend is built upon a curated selection of frameworks and libraries to ensure scalability and performance:
| Category | Technology | Description |
|---|---|---|
| Framework | TanStack Start | Full-stack React framework with SSR support. |
| Routing | TanStack Router | Type-safe, file-based routing system. |
| Data Fetching | TanStack Query | Caching and server-state management. |
| State Management | Zustand / Context | Local and global client-side state. |
| Styling | Tailwind CSS v4 | Utility-first CSS with custom themes. |
| UI Components | Radix UI / shadcn/ui | Accessible, unstyled primitives and pre-built components. |
| Animations | Framer Motion | Fluid transitions and interactive animations. |
Sources: CLAUDE.md:14-30, AGENTS.md:14-30
Project Structure and Routing
OpenChat employs a file-based routing system located in src/routes/. The application shell is defined in __root.tsx, which handles global providers, meta tags, and critical initialization scripts.
Routing Pattern
The routing logic follows the TanStack Router pattern where file names dictate the URL path. API routes are represented as api.*.ts files within the routes directory.
The diagram shows the hierarchical structure of the frontend routing and layout system.
Sources: CLAUDE.md:86-90, src/routes/__root.tsx:165-210
State Management Architecture
The application bifurcates state management into three distinct layers to optimize performance and prevent unnecessary re-renders.
1. Server State
Managed via TanStack Query and Convex. A convexQuery() wrapper is used to sync real-time database updates from the Convex backend directly to the UI components.
Sources: CLAUDE.md:92-93, AGENTS.md:92-93
2. Complex Persisted State
Handled by Zustand stores located in src/lib/store/. This is primarily used for features like the Theme Editor and persistent UI configurations that must survive page reloads.
Sources: CLAUDE.md:91, src/routes/settings/customization.tsx:39-40
3. App-wide Context
React Context providers in src/providers/ manage session-specific data such as ChatSession, Sidebar state, and User profile information.
Sources: CLAUDE.md:94, src/routes/__root.tsx:188-190
Thematic and Visual System
OpenChat implements a robust theme system that prevents "theme flash" by executing a blocking inline script in the HTML head before React hydration occurs.
Theme Initialization Flow
The sequence diagram illustrates the early-stage theme application logic used to ensure visual consistency.
Sources: src/routes/__root.tsx:23-75, src/routes/settings/customization.tsx:280-310
UI Development Standards
All components follow functional patterns with strict TypeScript interfaces. Development is guided by several critical rules:
- Accessibility: Components MUST follow WAI-ARIA APG patterns. Focus rings must be visible using
:focus-visible. - Interactions: Mobile hit targets must be ≥44px. Double-tap zoom is prevented via
touch-action: manipulation. - Performance: Large lists must be virtualized (using
virtua). Layout reads/writes must be batched to avoid reflows. - Components: UI is built using
shadcn/uiprimitives. Modification of library code is discouraged; composition is preferred.
Sources: agent_rules/design_guidelines.md:5-25, CLAUDE.md:43-55
Build and Tooling Configuration
The project uses Vite 8 with specialized plugins to manage the full-stack environment.
- Nitro Integration: Used as the universal server engine, configured for Vercel deployment with a 300s function duration.
- Optimization:
optimizeDepsis used to pre-bundle heavy icon packages like@phosphor-icons/reactandlucide-reactto speed up dev server startup. - PWA:
VitePWAis configured for automatic updates and caching of Google Fonts and static assets.
Sources: vite.config.ts:22-35, vite.config.ts:104-120
Conclusion
The OpenChat Frontend Architecture is a sophisticated implementation of TanStack Start, prioritizing type safety, real-time data synchronization via Convex, and high-performance rendering. By combining early-stage theme injection with modern state management patterns, the system provides a responsive and accessible user experience suitable for a multi-model AI assistant.