Overview
Every user interaction in OpenSail follows a consistent request/response pattern that flows through the frontend, orchestrator, database, and (optionally) the container runtime. This page documents the lifecycle of each major flow: general API requests, agent chat, file operations, container management, Git operations, deployments, and streaming patterns. If you are new to the codebase, start with the General API Request Flow to understand the common pattern, then explore the specific flows relevant to your work.General API Request Flow
All user interactions follow this eight-step lifecycle.User interaction
Frontend sends request
Authorization: Bearer {jwt} header or session cookie.Orchestrator validates auth
Database query or update
Perform operation
- File operation: Container filesystem (direct in Docker, pod exec in K8s)
- Container operation: Docker Compose or Kubernetes API
- AI chat: LiteLLM proxy to OpenAI/Anthropic
- Deployment: Vercel/Netlify/Cloudflare API
Build response
Return to frontend
UI update
Request Flow Diagram
Agent Chat Flow
The agent chat is the most complex data flow, involving LLM calls, tool execution, and real-time streaming to the frontend via Server-Sent Events (SSE).User types a message
Frontend opens SSE connection
POST /api/chat/stream with { project_id, message, chat_id } and opens an EventSource for streaming.Load chat history
Create agent instance
agent/factory.py instantiates a tesslate-agent with the appropriate system prompt, available tools (read_file, write_file, bash_exec, etc.), and LLM model.Agent execution loop
tesslate-agent enters a loop:- Call the LLM with system prompt + conversation history
- If the LLM returns tool calls, execute them (e.g.,
write_file,bash_exec) - Stream each tool execution event to the frontend
- Call the LLM again with tool results
- Repeat until the LLM produces a final text response
Stream final response
Agent Tool Execution Example
User prompt: “Create a React component for a todo list”Available Agent Tools
File Operations Flow
File reads and writes differ depending on deployment mode. In Docker mode, the orchestrator accesses the filesystem directly. In Kubernetes mode, it executes commands inside the file-manager pod.- Read File
- Write File
Container Operations Flow
Container start and stop operations are non-blocking. The Orchestrator returns immediately and the frontend polls for status updates.Start Project Containers
User clicks Start
POST /api/projects/{id}/start.Validation and background task
{ "status": "starting" } immediately.Frontend polls for status
GET /api/projects/{id}/status every 2 seconds.Background task executes (Kubernetes mode)
- Create namespace (
proj-{uuid}) - Create PVC (shared storage, e.g. 10Gi RWO)
- Restore from VolumeSnapshot if hibernated (or hydrate from S3 for legacy projects)
- Create file-manager pod (always running)
- For each container: create Deployment + Service + Ingress
- Create NetworkPolicy for isolation
- Update project status in database to “running”
- Return container URLs
Frontend detects running state
Stop Project Containers
User clicks Stop (or navigates away)
POST /api/projects/{id}/stop.Background task: dehydrate and delete
- Create VolumeSnapshot from PVC (under 5 seconds)
- Wait for snapshot readiness
- Delete namespace (cascades to all resources: Deployments, Services, Ingress, PVC, NetworkPolicy)
- Update project status to “hibernated”
Frontend detects stopped state
Git Operations Flow
Clone Repository
Commit and Push
Deployment Flow (External Providers)
External deployments to Vercel, Netlify, or Cloudflare follow a consistent non-blocking pattern.User initiates deployment
POST /api/deployments with provider name, project ID, and configuration.Retrieve OAuth credentials
DeploymentCredential for the chosen provider.Background build and deploy
- Build the project locally (e.g.,
npm run build) - Push to Git if needed (create/update GitHub repo)
- Call provider API to create deployment
- Poll provider API until deployment status is “READY”
- Save deployment record to database
Notify frontend
WebSocket and SSE Streaming Patterns
OpenSail uses two streaming mechanisms for real-time communication.- Server-Sent Events (Agent Chat)
- Polling (Status Checks)
- WebSocket (Bidirectional)
Performance Optimizations
Non-Blocking Operations
Non-Blocking Operations
Database Query Optimization
Database Query Optimization
selectinload() to prevent N+1 queries and load related objects in a single query.Streaming vs. Polling Decision Guide
Streaming vs. Polling Decision Guide