Architecture
Table of contents
Overview
Batch-GPT follows a modular architecture with clear separation of concerns:
server/
├── db/ # Database interactions
├── handlers/ # HTTP request handlers
├── logger/ # Custom logging
├── models/ # Data models
└── services/ # Business logic
├── batch/ # Batch processing
├── cache/ # Response caching
├── client/ # OpenAI client
├── config/ # Configuration
└── utils/ # Common utilities
Core Components
Server Core
- Request routing and validation
- HTTP handlers
- Response formatting
Batch Orchestrator
- Request collection
- Batch timing management
- Response distribution
Cache System
- Request hashing
- Response storage
- Cache invalidation
Monitor Tool
- Status visualization
- Batch tracking
- Progress reporting
Database Layer
- MongoDB integration
- Persistence management
- Status tracking
Data Flow
- Request Reception
- Request validation
- Cache checking
- Hash generation
- Batch Processing
- Request collection
- Batch formation
- OpenAI submission
- Response Handling
- Response collection
- Cache updating
- Client delivery
- Monitoring
- Status tracking
- Progress updates
- Error logging
Component Interaction
graph TD
A[Client] --> B[Server Core]
B --> C[Cache System]
B --> D[Batch Orchestrator]
D --> E[OpenAI API]
D --> F[MongoDB]
C --> F
G[Monitor Tool] --> F
Design Decisions
Batch Processing
- Configurable batch windows
- Hash-based deduplication
- Async/sync flexibility
Caching Strategy
- MongoDB-based persistence
- Hash-based indexing
- Cross-session availability
Monitoring
- Real-time updates
- Interactive interface
- Status aggregation ```