Frontend Architecture
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The OpenAlgo frontend is a modern, single-user algorithmic trading dashboard built using React 19 and TypeScript. It serves as the primary interface for strategy design, execution monitoring, and portfolio management. The architecture is designed to be self-hosted, providing a responsive and type-safe environment that communicates with a Flask-based backend through RESTful APIs and real-time WebSockets.
The frontend encompasses several specialized surfaces, including a visual Flow Editor for no-code strategy building, an API Playground for endpoint testing, and a comprehensive Diagnostics suite for system monitoring. It leverages a robust stack of libraries such as Tailwind CSS 4.0 for styling, TanStack Query for server state, and Zustand for lightweight client-side state management.
Sources: README.md:14-25, README.md:188-204, CLAUDE.md:10-25
Core Technology Stack
The frontend is built on a modular stack focused on performance and developer experience.
| Category | Technology | Purpose |
|---|---|---|
| Framework | React 19, TypeScript | Core UI library and type safety |
| Build Tool | Vite 8 | Fast development server and bundling |
| Styling | Tailwind CSS 4, shadcn/ui | Utility-first styling and accessible components |
| State (Server) | TanStack Query v5 | Data fetching, caching, and synchronization |
| State (Client) | Zustand | Global application state (Auth, Theme, Flow) |
| Routing | React Router v7/8 | Declarative client-side routing |
| Real-time | Socket.IO Client | Live updates for orders, trades, and logs |
| Visualization | xyflow/React Flow, TradingView | Node-based editors and financial charts |
Sources: frontend/package.json:62-97, README.md:214-239
Component and Data Flow
The application follows a standard React unidirectional data flow, augmented by TanStack Query for server synchronization and Zustand for cross-component communication.
Application Layout and Providers
The root of the application is wrapped in providers that manage theme, authentication, and query client instances.
State Management Strategy
- Server State: Managed by
@tanstack/react-query. It handles fetching system info, workflow data, and error logs. - Global Client State: Managed by
zustand. This includesuseAuthStorefor session info,useThemeStorefor Light/Dark/Analyze mode toggles, anduseFlowWorkflowStorefor the visual editor state. - Form/Local State: Standard React
useStatefor transient UI interactions (e.g., search queries, tab management).
Sources: frontend/src/pages/flow/FlowEditor.tsx:105-125, frontend/src/pages/Playground.tsx:160-180, frontend/src/pages/Setup.tsx:45-60
Visual Strategy Builder (Flow Editor)
The Flow Editor (/flow) is a complex module utilizing @xyflow/react to enable no-code algorithmic strategy design.
Architecture of the Flow Editor
The editor maintains a complex internal state via useFlowWorkflowStore to track nodes, edges, and modifications (dirty states).
Key Editor Features
- Revision Tracking: The
isModifiedflag prevents navigating away with unsaved changes and ensuresRun Nowtriggers a save of the latest revision. - Node Management: Nodes are initialized with
DEFAULT_NODE_DATAand identified via anode_ncounter. - Serialization: Supports
Export to JSONandReplace from JSONfor strategy portability.
Sources: frontend/src/pages/flow/FlowEditor.tsx:68-88, frontend/src/pages/flow/FlowEditor.tsx:210-230, frontend/src/pages/flow/FlowEditor.tsx:470-490
Security and Authentication
The frontend implements several security layers to protect sensitive broker credentials and trading operations.
Authentication Flow
OpenAlgo uses a dual-layered authentication approach:
- User Authentication: Managed via standard login/session cookies with CSRF protection.
- API Security: The
/apikeypage manages a hashed/peppered API key used for external platform integrations (TradingView, Amibroker).
Order Execution Modes
The frontend provides a toggle between Auto Mode (immediate execution) and Semi-Auto Mode (approval required in the Action Center). This is persisted via the /apikey/mode endpoint.
Sources: frontend/src/pages/ApiKey.tsx:128-165
System Diagnostics and Monitoring
The Diagnostics page (/admin/diagnostics) provides high-level observability into the self-hosted instance.
Monitored Subsystems
The frontend aggregates data from multiple backend probes to display:
- Host Information: OS release, architecture, and Docker status.
- Hardware: CPU count, memory usage, and disk availability for
log/anddb/directories. - Databases: Status and size of the six isolated SQLite/DuckDB databases.
- Connectivity: Real-time latency probes for DB, loopback, and active broker endpoints.
Sources: frontend/src/pages/admin/Diagnostics.tsx:160-260, frontend/src/pages/admin/Diagnostics.tsx:325-360
API Playground
The Playground (/playground) is a developer tool for testing REST and WebSocket interfaces without external clients.
Capabilities
- REST Testing: Supports GET/POST requests with automatic API key injection and syntax-highlighted JSON responses.
- WebSocket Tester: Provides a dedicated panel for subscribing to real-time market data feeds (LTP, Quote, Depth).
- cURL Generation: Automatically generates executable cURL commands from the current request configuration for debugging.
Sources: frontend/src/pages/Playground.tsx:320-360, frontend/src/pages/Playground.tsx:470-500
Conclusion
The OpenAlgo Frontend Architecture leverages a decoupled, component-based design to provide a robust trading environment. By centralizing state management in Zustand and utilizing TanStack Query for backend synchronization, it maintains high performance even during complex visual strategy editing and real-time data streaming. The inclusion of comprehensive diagnostic tools and a built-in API playground ensures that the platform is not only powerful for trading but also transparent and maintainable for self-hosting users.