# System Architecture Overview

## High-Level Architecture

```
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Web Client    │    │  Mobile Client  │    │   External API  │
└─────────┬───────┘    └─────────┬───────┘    └─────────┬───────┘
          │                      │                      │
          └──────────────────────┼──────────────────────┘
                                 │
                    ┌─────────────▼─────────────┐
                    │      API Gateway          │
                    │   (Rate Limiting, Auth)   │
                    └─────────────┬─────────────┘
                                 │
                    ┌─────────────▼─────────────┐
                    │     BFF Service           │
                    │   (Backend for Frontend)  │
                    └─────────────┬─────────────┘
                                 │
        ┌────────────────────────┼────────────────────────┐
        │                        │                        │
┌───────▼────────┐    ┌─────────▼────────┐    ┌────────▼────────┐
│  Auth Service  │    │   Content Service │    │   AI Service    │
└────────────────┘    └──────────────────┘    └─────────────────┘
        │                        │                        │
        └────────────────────────┼────────────────────────┘
                                 │
                    ┌─────────────▼─────────────┐
                    │      Data Layer           │
                    │ (PostgreSQL, Redis, S3)   │
                    └───────────────────────────┘
```

## Service Categories

### Core Services
- **Authentication Service** - User management, JWT tokens, permissions
- **Content Service** - Course materials, media, versioning
- **AI Service** - LLM orchestration, RAG, multi-agent systems
- **Conversation Service** - Chat history, threading, real-time

### Supporting Services
- **BFF Service** - Backend for Frontend aggregation
- **Media Service** - File storage, CDN, processing
- **Notification Service** - Push notifications, email, SMS
- **Moderation Service** - Content safety, policy enforcement

### Infrastructure Services
- **STT Service** - Speech-to-text processing
- **TTS Service** - Text-to-speech synthesis
- **Knowledge Service** - Graph database, semantic search
- **RAG Service** - Retrieval-augmented generation

## Data Architecture

### Primary Data Stores
- **PostgreSQL** - Primary relational database
- **Redis** - Caching and session storage
- **Neo4j** - Knowledge graph and relationships
- **S3/MinIO** - Object storage for media files

### Data Flow Patterns
1. **Write Path:** Client → API → Service → Database
2. **Read Path:** Database → Service → API → Client
3. **Cache Pattern:** Read-through/write-through caching
4. **Event Streaming:** Async processing for background tasks

## Security Architecture

### Authentication & Authorization
- **JWT Tokens** - Stateless authentication
- **RBAC** - Role-based access control
- **MFA** - Multi-factor authentication support
- **API Keys** - Service-to-service authentication

### Security Layers
1. **Network Level** - TLS, firewalls, VPC isolation
2. **Application Level** - Input validation, rate limiting
3. **Data Level** - Encryption at rest and in transit
4. **Monitoring** - Security event logging and alerting

## Deployment Architecture

### Container Strategy
- **Docker** - Containerized services
- **Kubernetes** - Orchestration and scaling
- **Helm Charts** - Package management
- **GitOps** - ArgoCD for continuous deployment

### Environment Strategy
- **Development** - Local development with Docker Compose
- **Staging** - Production-like environment for testing
- **Production** - Multi-zone high-availability deployment

---
*Auto-generated system architecture documentation*
