Introduction
Jean provides a comprehensive HTTP and WebSocket API that allows external clients to interact with the application programmatically. The API supports both traditional HTTP request-response patterns and real-time bidirectional communication via WebSocket.Architecture
Server Components
The HTTP server is built on Axum, a modern Rust web framework. Key components include:- HTTP Server (
src-tauri/src/http_server/server.rs) - Main server implementation - WebSocket Handler (
src-tauri/src/http_server/websocket.rs) - Real-time communication - Command Dispatcher (
src-tauri/src/http_server/dispatch.rs) - Routes commands to handlers - Authentication (
src-tauri/src/http_server/auth.rs) - Token-based security
Server Lifecycle
The server starts on-demand and can be configured through the application settings:Base URLs
Default when
localhost_only = trueAvailable when
localhost_only = falseAPI Endpoints
Jean provides the following HTTP endpoints:Core Endpoints
| Endpoint | Method | Description |
|---|---|---|
/ws | GET | WebSocket upgrade endpoint |
/api/auth | GET | Token validation endpoint |
/api/init | GET | Initial data preload endpoint |
/* | GET | Static file serving (frontend SPA) |
WebSocket Commands
All application functionality is exposed via WebSocket commands (see Chat, Projects, Worktrees, Sessions).Communication Patterns
HTTP REST
Used for:- Authentication (
/api/auth) - Initial data loading (
/api/init) - Static file serving
WebSocket RPC
Used for:- All CRUD operations
- Real-time event streaming
- Bidirectional communication
Request Format
WebSocket Messages
All WebSocket messages use JSON format:Unique identifier for correlating requests with responses
Name of the command to execute (e.g.,
list_projects, send_chat_message)Command-specific parameters as a JSON object
Response Format
Success Response
Error Response
Event Messages
Server-initiated events (no request):Real-time Events
The WebSocket connection broadcasts real-time events for:- Project and worktree changes
- Session updates
- Chat message streaming
- Git status updates
- Background task completion
CORS Policy
The server uses a permissive CORS policy:Error Handling
All errors are returned as JSON with descriptive messages:- 400 Bad Request - Invalid command or parameters
- 401 Unauthorized - Invalid or missing token
- 500 Internal Server Error - Server-side errors
Versioning
The API does not currently use explicit versioning. The server maintains backward compatibility for data structures through:- Optional fields with
#[serde(default)] - Field aliases for renamed fields
- Migration logic in storage layer
Rate Limiting
No explicit rate limiting is implemented. The WebSocket connection is persistent and designed for interactive use.Best Practices
Use WebSocket for interactive clients
Use WebSocket for interactive clients
The WebSocket API provides real-time updates and eliminates polling overhead. HTTP endpoints are primarily for authentication and initial data loading.
Handle reconnection gracefully
Handle reconnection gracefully
If the WebSocket connection drops, reconnect and re-subscribe to events. The server does not maintain client-specific state between connections.
Use unique request IDs
Use unique request IDs
Generate UUIDs or timestamps for request IDs to avoid conflicts when multiple requests are in flight.
Monitor event lag
Monitor event lag
If the WebSocket receiver falls behind, the broadcast channel will skip events. Monitor for
RecvError::Lagged warnings.Next Steps
Authentication
Learn about token-based authentication
Projects API
Manage Git projects and repositories
Worktrees API
Create and manage Git worktrees
Sessions API
Handle chat sessions