Overview
LibreChat’s frontend uses React with TypeScript, organized into feature-based directories with strict architectural patterns for maintainability and scalability.Directory Structure
Component Organization
Feature-Based Structure
Components are grouped by feature domain rather than technical type:Component Example
Here’s a real component fromclient/src/components/Agents/AgentCard.tsx:1:
Key Patterns
1. Type Safety
- Never use
any- Always provide explicit types - Import shared types from
librechat-data-provider - Define component prop interfaces
- Use type imports with
import type
2. Localization
All user-facing text must useuseLocalize() from client/src/hooks/useLocalize.ts:1:
- Use semantic prefixes:
com_ui_,com_agents_,com_assistants_ - Only update English keys in
client/src/locales/en/translation.json - Other languages are automated externally
3. Accessibility
Components must include proper ARIA attributes:- Semantic HTML elements (
button,nav,main, etc.) - ARIA labels for interactive elements
- Keyboard navigation support
- Screen reader announcements via
LiveAnnouncer
4. Performance Optimization
Fromclient/src/components/SidePanel/Memories/MemoryCard.tsx:1:
- Use
useMemofor expensive computations - Use
useCallbackfor event handlers passed to children - Proper dependency arrays to avoid unnecessary re-renders
- Avoid nested component definitions
Context Providers
LibreChat uses React Context for feature-specific state. Providers are inclient/src/Providers/.
Using Context
Fromclient/src/Providers/ChatContext.tsx:1:
ChatContext- Chat state and helpersAgentsContext- Agent managementAssistantsContext- Assistant configurationFileMapContext- File upload trackingMessageContext- Individual message stateSidePanelContext- Side panel navigation
client/src/Providers/index.ts:1.
Import Order
From AGENTS.md, imports must follow this pattern:- Always use standalone
import type- never inlinetypein value imports - Package imports sorted by line length (
reactalways first) - Type imports sorted longest to shortest
- Local imports sorted longest to shortest
Component Testing
Tests are co-located with components in__tests__/ directories:
Test Structure
- Use
test/layout-test-utilsfor rendering - Mock data-provider hooks
- Cover loading, success, and error states
- Test keyboard navigation and accessibility
Code Style
From AGENTS.md:Never-Nesting
Functional Patterns
Performance Considerations
Next Steps
- State Management - React Query, Recoil, and Jotai usage
- Data Provider - API integration patterns
- Localization - i18n workflow and best practices