> ## Documentation Index
> Fetch the complete documentation index at: https://ihub.learnille.com/llms.txt
> Use this file to discover all available pages before exploring further.

# System Architecture Diagram

> Migrated from the previous Learnille internal documentation hub

## Overview

This document describes the high-level system architecture of the Learnille platform.

## Architecture Principles

* **Microservices**: Modular, independently deployable services
* **API-First**: All interactions through well-defined APIs
* **Scalability**: Horizontal scaling for high availability
* **Security**: Defense in depth with multiple security layers
* **Observability**: Comprehensive logging, monitoring, and tracing

## High-Level Architecture

```
┌─────────────────────────────────────────────────────────────────┐
│                    Client Layer                                 │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐ │
│  │   Web Client    │  │   Mobile App    │  │   Admin Panel    │ │
│  │   (React)       │  │   (React Native)│  │   (React)        │ │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                                   │
                                   ▼
┌─────────────────────────────────────────────────────────────────┐
│                   API Gateway Layer                              │
│  ┌─────────────────┐                                           │
│  │   API Gateway   │  (Rate limiting, Authentication, Routing) │
│  │   (Kong/Nginx)  │                                           │
│  └─────────────────┘                                           │
└─────────────────────────────────────────────────────────────────┘
                                   │
                                   ▼
┌─────────────────────────────────────────────────────────────────┐
│                   Service Layer                                  │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐ │
│  │   User Service  │  │ Course Service  │  │Consultation Svc  │ │
│  │   (Node.js)     │  │   (Node.js)     │  │   (Node.js)      │ │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘ │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐ │
│  │ Payment Service │  │Notification Svc │  │ Analytics Svc    │ │
│  │   (Python)      │  │   (Node.js)     │  │   (Python)       │ │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                                   │
                                   ▼
┌─────────────────────────────────────────────────────────────────┐
│                   Data Layer                                     │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐ │
│  │  PostgreSQL     │  │    Redis        │  │   OpenSearch  │ │
│  │ (Neon prod,     │  │ (Redis Cloud)   │  │ (Aiven search)   │ │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘ │
│  ┌─────────────────┐  ┌─────────────────┐                      │
│  │   InstantDB    │  │  Cloudflare R2  │                      │
│  │  (Realtime)    │  │ (Files/Media)   │                      │
│  └─────────────────┘  └─────────────────┘                      │
└─────────────────────────────────────────────────────────────────┘
                                   │
                                   ▼
┌─────────────────────────────────────────────────────────────────┐
│                   Infrastructure Layer                           │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐ │
│  │   Docker / Dokploy  │  │   Self-Hosted   │  │   Nginx Proxy   │ │
│  │ (Containerization│  │ (Linux VPS/Bare)│  │ (Reverse Proxy) │ │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘ │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐ │
│  │  New Relic APM  │  │ New Relic Logs  │  │   Security      │ │
│  │ (Performance)   │  │ (Aggregation)   │  │ (WAF, SSL)      │ │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
```

## Component Descriptions

### Client Layer

* **Web Client**: React-based single-page application for learners and instructors
* **Mobile App**: React Native application for iOS and Android
* **Admin Panel**: React-based dashboard for platform administrators

### API Gateway Layer

* **API Gateway**: Centralized entry point handling authentication, rate limiting, and request routing
* **Load Balancer**: Distributes traffic across service instances
* **CDN**: Content delivery network for static assets and media

### Service Layer

* **User Service**: Manages user accounts, authentication, and profiles
* **Course Service**: Handles course creation, management, and content delivery
* **Consultation Service**: Manages one-on-one and group consultation sessions
* **Payment Service**: Processes payments and manages subscriptions
* **Notification Service**: Handles email, SMS, and in-app notifications
* **Analytics Service**: Tracks user behavior and generates insights

### Data Layer

* **PostgreSQL**: Primary relational database for structured data
* **Redis**: In-memory cache for session data and frequently accessed information
* **OpenSearch**: Search engine for course content and user data
* **S3 Storage**: Object storage for files, images, and videos

### Infrastructure Layer

* **Docker / Dokploy**: Application containerization and production lifecycle management
* **Ingress**: Dokploy-managed routing and TLS termination
* **Cloudflare R2**: High-performance S3 API object storage with zero egress fees
* **New Relic**: Centralized APM, transaction tracing, and structured log management
* **Sentry**: Real-time exception tracking and error reporting

## Data Flow

1. **User Request**: Client sends request to API Gateway
2. **Authentication**: Gateway validates JWT token and user permissions
3. **Routing**: Request routed to appropriate microservice
4. **Business Logic**: Service processes request, interacts with databases
5. **Response**: Service returns data through gateway to client
6. **Caching**: Frequently accessed data cached in Redis
7. **Logging**: All requests logged for monitoring and debugging

## Security Architecture

* **Authentication**: JWT tokens with refresh mechanism
* **Authorization**: Role-based access control (RBAC)
* **Encryption**: TLS 1.3 for data in transit, AES-256 for data at rest
* **API Security**: Rate limiting, input validation, SQL injection prevention
* **Network Security**: VPC isolation, security groups, WAF

## Scalability Considerations

* **Horizontal Scaling**: Services can be scaled independently
* **Database Sharding**: Data partitioned across multiple database instances
* **CDN Integration**: Static content served from edge locations
* **Auto-scaling**: Services scale based on CPU/memory usage
* **Read Replicas**: Database read operations distributed across replicas

## Deployment Architecture

* **CI/CD Pipeline**: Automated testing and deployment
* **Blue-Green Deployment**: Zero-downtime deployments
* **Feature Flags**: Gradual feature rollout and rollback
* **Environment Isolation**: Separate environments for dev/staging/prod

## Monitoring and Observability

* **Metrics**: Application performance, error rates, user activity
* **Logging**: Structured logs with correlation IDs
* **Tracing**: Distributed tracing for request flow
* **Alerting**: Automated alerts for system issues
* **Dashboards**: Real-time monitoring dashboards

## Technology Stack

### Frontend

* React 18
* TypeScript
* Zustand
* React Router
* Axios

### Backend

* Node.js (Express/NestJS)
* Python (FastAPI)
* GraphQL/REST APIs
* JWT Authentication

### Database

* PostgreSQL 15
* Redis 7
* OpenSearch-compatible Aiven service
* Cloudflare R2 (Object Storage)

### Infrastructure

* Dokploy-managed Docker deployment
* Cloudflare/Dokploy ingress and TLS

### DevOps & Observability

* GitHub Actions CI/CD
* New Relic APM & Log Management
* Sentry Exception Tracking

## Future Considerations

* **Micro-frontend Architecture**: Independent frontend applications
* **Event-Driven Architecture**: Asynchronous communication between services
* **Multi-Cloud Deployment**: Hybrid cloud strategy
* **AI/ML Integration**: Machine learning for personalized learning
* **Blockchain**: Credential verification and NFT certificates


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.