Mainloop uses a main thread + sessions pattern where your continuous conversation spawns background sessions that appear inline as threaded replies.
┌─────────────────────────────────────────────────────────────┐
│ User Devices │
│ (phone, laptop, etc.) │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Cloudflare Access │
│ (authentication + CDN) │
└─────────────────────────┬───────────────────────────────────┘
│
┌───────────────┴───────────────┐
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Frontend │ │ Backend │
│ (SvelteKit) │◄──────────►│ (FastAPI) │
│ │ │ │
│ - Chat + inline │ │ - DBOS workflows│
│ sessions │ │ - Main thread │
│ - Notifications │ │ - Session queue │
└──────────────────┘ └────────┬─────────┘
│
┌────────────────────┼────────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Session 1 │ │ Session 2 │ │ Session N │
│ (Claude) │ │ (Opus) │ │ (varies) │
│ │ │ │ │ │
│ research │ │ code work │ │ any task │
└──────────────┘ └──────────────┘ └──────────────┘
- Mobile-first responsive UI with chat and sessions tabs
- Main thread: Continuous conversation with inline session blocks
- Inline threading: Session messages appear as Slack-style notifications in timeline
- Session views: Expand inline or zoom to fullscreen conversation
- Notifications: Toast alerts when sessions need attention
- Main Thread Workflow: Per-user conversation that spawns sessions
- Session Workflows: Background work with their own conversations
- PostgreSQL: Durable workflow state and conversation history
- SSE: Real-time session updates and notifications
Sessions are the unified model for all background work:
- Simple sessions: Research, analysis, or any conversation-based task
- Dev sessions: Code work with their own K8s namespace for isolation
Each session has:
- Its own conversation (separate from main thread)
- A color for visual distinction in timeline
- Status tracking (active, waiting, completed, etc.)
- Anchor to the main thread message that spawned it
- User sends message via frontend
- Backend adds to main thread conversation
- Main thread (Claude) decides if session needed
- If spawning: creates session anchored to user message
- Session appears inline in main thread timeline
- Session messages surface as thread notifications
- User can respond inline or zoom into session
- Completed sessions post summary back to main thread
| Component | Model | Purpose |
|---|---|---|
| Main thread | Sonnet | Coordination, spawning decisions |
| Sessions | Opus (default) | Complex tasks, code generation |
| Sessions | Sonnet/Haiku | Can be specified per-session |
Sessions can use different models based on task complexity.