Layouts & Navigation Drawers
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Layout and Navigation system in OpenChat provides a structured, responsive shell for the AI personal assistant. It is built using TanStack Start and TanStack Router, employing a root shell pattern (__root.tsx) to manage global application state, authentication guards, and the primary user interface structure. The layout is designed to be mobile-first, utilizing persistent sidebars and context-driven drawers for settings and navigation.
The system emphasizes accessibility and performance, following strict design guidelines to prevent layout shifts (CLS) and ensure consistent theme application across SSR and hydration cycles. Key components include the LayoutApp shell, which wraps the application content, and the SidebarProvider which manages the state of navigation elements.
Sources: src/routes/__root.tsx, CLAUDE.md:73-82, agent_rules/design_guidelines.md:89-95
Core Architecture
The layout architecture follows a nested provider pattern to ensure that state—such as user authentication, sidebar visibility, and theme settings—is available throughout the component tree.
The Root Document
The RootDocument serves as the entry point, handling critical SSR tasks such as theme flash prevention. It executes an inline script before React hydration to read theme preferences from localStorage and apply the correct CSS variables and classes to the document element.
Layout Components
The primary layout is managed by the LayoutApp component, which serves as the visual container for the application. It coordinates the display of the sidebar, the main chat area, and various navigation drawers.
| Component | Description | File Path |
|---|---|---|
LayoutApp | The main wrapper for the application; handles high-level layout structure. | src/components/layout/layout-app.tsx |
ChatSidebar | Manages chat history, pinning, and navigation links. | src/components/layout/chat-sidebar.tsx |
DrawerSettings | A slide-out panel for user preferences and application configuration. | src/components/layout/settings/drawer-settings.tsx |
Sources: CLAUDE.md:73-82, src/routes/__root.tsx:216
Navigation Drawers & Sidebars
Navigation in OpenChat is primarily handled through a responsive sidebar that adapts to different screen sizes.
Sidebar Management
The SidebarProvider (located in src/providers/sidebar-provider) controls the visibility and state of the navigation panel. On desktop, the sidebar is typically persistent or togglable via keyboard shortcuts (e.g., ⌘+B), while on mobile, it behaves as a slide-over drawer to maximize screen real estate for the chat interface.
Design Guidelines for Drawers
The project follows specific interaction rules for drawers and modals to ensure a high-quality user experience:
- Overscroll Behavior: Drawers MUST use
overscroll-behavior: containto prevent scrolling the underlying page. - Focus Management: Drawers MUST manage focus by trapping focus within the drawer when open and returning it to the trigger element upon closing.
- Hit Targets: Interactive elements within drawers MUST have a hit target of at least 44px on mobile devices.
- Touch Actions: Drawers utilize
touch-action: manipulationto prevent accidental double-tap zooming.
Sources: agent_rules/design_guidelines.md:5-20, README.md:65, CLAUDE.md:120
Visual Consistency & Theme Integration
The layout system is tightly integrated with the theme engine to ensure a seamless visual experience.
To prevent Content Layout Shift (CLS), the layout uses skeletons that mirror the final content structure. Theme variables, including fonts and border radii, are applied globally at the root level so that navigation drawers and sidebars maintain a consistent aesthetic with the main chat interface.
Sources: src/routes/__root.tsx:32-60, agent_rules/design_guidelines.md:103-104
Summary
Layouts and Navigation Drawers in OpenChat form a robust, accessible framework for the AI assistant. By leveraging TanStack's routing and state management alongside a custom theme initialization strategy, the project achieves a high-performance UI that remains consistent across device types. The combination of persistent sidebars for history and contextual drawers for settings provides an intuitive navigation flow while adhering to strict mobile-first design standards.