How the components work together
┌─────────────────────────────────────────────────────────────────┐
│ User Interface │
├─────────────────────────────────────────────────────────────────┤
│ React Frontend (localhost:5173) │
│ • Query input with real-time progress │
│ • Structured insight display │
│ • Optional conversation limits via Settings │
│ • Server-Sent Events for live updates │
└─────────────────┬───────────────────────────────────────────────┘
│ HTTP/SSE
┌─────────────────▼───────────────────────────────────────────────┐
│ Web Backend │
├─────────────────────────────────────────────────────────────────┤
│ FastAPI Server (localhost:8000) │
│ • /api/analyze/stream - Real-time analysis │
│ • /api/health - Health checks │
│ • Global exception handling │
│ • Session tracking and logging │
└─────────────────┬───────────────────────────────────────────────┘
│ Python imports
┌─────────────────▼───────────────────────────────────────────────┐
│ Core Engine │
├─────────────────────────────────────────────────────────────────┤
│ QueryProcessor │
│ • Orchestrates full workflow │
│ • Progress callbacks for real-time updates │
│ • Simple conversation limits (no smart limits) │
│ • Error handling and logging │
└─────────┬───────────────────┬───────────────────────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────────────────────────────────┐
│ Intercom Client │ │ AI Client │
├─────────────────┤ ├─────────────────────────────────────────────┤
│ • REST API │ │ • Timeframe interpretation │
│ • Pagination │ │ • Structured JSON analysis │
│ • Rate limiting │ │ • Fallback to legacy parsing │
│ • Conversation │ │ • Cost tracking │
│ filtering │ │ • OpenAI GPT-4 integration │
└─────────────────┘ └─────────────────────────────────────────────┘
Role: Main orchestrator
Responsibilities:
- Coordinate timeframe interpretation → conversation fetching → AI analysis
- Provide real-time progress updates via callbacks
- Handle simple conversation limits (user-specified or unlimited)
- Manage costs and performance metrics
Role: Data fetching
Responsibilities:
- Fetch conversations via Search API with pagination
- Handle rate limiting (83 requests/10 seconds)
- Parse and filter conversations
- Support unlimited fetching when no limit specified
Role: Intelligence extraction
Responsibilities:
- Parse natural language timeframes ("last 24 hours")
- Generate structured JSON insights from conversations
- Fallback to legacy text parsing if structured fails
- Track token usage and costs
Role: User interface backend
Responsibilities:
- Serve React frontend static files
- Provide real-time streaming API via Server-Sent Events
- Handle API key validation and session management
- Global exception handling with structured error responses
User Query → Timeframe Parsing → Date Range → Conversation Filters
Intercom Search API → Paginated Results → Parsed Conversations → Limited Set
Conversations + Query → OpenAI GPT-4 → Structured JSON → Formatted Results
Progress Callbacks → SSE Stream → Frontend Updates → User Feedback
- No smart limits: User controls conversation limits or sets no limit
- Direct data flow: AI → JSON → Frontend (no complex parsing)
- Clear error handling: Structured errors with user-friendly messages
- Streaming responses: Real-time progress via Server-Sent Events
- Efficient pagination: Batch fetching from Intercom API
- Cost tracking: Monitor and optimize OpenAI usage
- Predictable behavior: Exact timeframes, no automatic overrides
- Optional controls: Settings available but not required
- Clear feedback: Progress bars and status messages
- User submits query via React frontend
- Frontend sends request to
/api/analyze/stream - Backend validates API keys and request format
- QueryProcessor starts with progress callback setup
- Timeframe interpreted by AI (e.g., "last 24 hours" → date range)
- Conversations fetched from Intercom with pagination
- Progress updates sent via SSE during fetching
- AI analysis generates structured insights
- Results streamed back to frontend in real-time
- Frontend displays insights with customer details
src/
├── cli.py # Command-line interface
├── query_processor.py # Main orchestration logic
├── intercom_client.py # Intercom API integration
├── ai_client.py # OpenAI integration
├── models.py # Data structures
├── config.py # Configuration management
├── logging.py # Structured logging
└── web/
└── main.py # FastAPI web application
frontend/src/
├── components/ # React UI components
├── store/ # Zustand state management
└── lib/ # Utilities
Last updated: June 20, 2025