Skip to main content

Overview

EaseLMS is built on a modern, scalable architecture leveraging Next.js 16 with the App Router, TypeScript for type safety, and a monorepo structure managed by Turborepo. The system is designed to be self-hostable while maintaining cloud-native capabilities.

Architecture Diagram

Tech Stack

Frontend

  • Framework: Next.js 16 with App Router
  • Language: TypeScript 5.0+
  • UI Library: React 19
  • Styling: Tailwind CSS
  • Components: Radix UI + shadcn/ui
  • State Management: TanStack Query (React Query)
  • Forms: React Hook Form + Zod validation
  • Video Player: Media Chrome for HLS streaming

Backend

  • Runtime: Node.js 18.0+
  • Database: Supabase (PostgreSQL)
  • Authentication: Supabase Auth with Row Level Security (RLS)
  • File Storage: AWS S3 + CloudFront/Azure Front Door CDN
  • Video Processing: AWS MediaConvert for HLS transcoding
  • Payments: Stripe & Flutterwave
  • Email: SendGrid
  • PDF Generation: PDFKit with custom fonts

Infrastructure

  • Monorepo: Turborepo
  • Package Manager: npm 10.0+
  • Deployment: Vercel (recommended) or self-hosted
  • CDN: CloudFront or Azure Front Door

Monorepo Structure

EaseLMS uses Turborepo to manage a monorepo with multiple applications:
easelms/ ├── apps/ │ ├── lms/ # Main LMS application │ │ ├── app/ # Next.js App Router │ │ │ ├── admin/ # Admin dashboard │ │ │ ├── learner/ # Learner interface │ │ │ ├── api/ # API routes │ │ │ └── auth/ # Authentication pages │ │ ├── components/ # React components │ │ ├── lib/ # Core libraries │ │ │ ├── aws/ # S3 & MediaConvert │ │ │ ├── supabase/ # Database & auth clients │ │ │ ├── payments/ # Payment integrations │ │ │ ├── certificates/ # PDF generation │ │ │ ├── email/ # Email service │ │ │ └── react-query/ # Query hooks & cache │ │ ├── hooks/ # Custom React hooks │ │ ├── utils/ # Utility functions │ │ ├── middleware.ts # Auth & CORS middleware │ │ └── supabase/ # Database migrations │ └── website/ # Marketing landing page ├── components/ # Shared components ├── package.json # Root workspace config └── turbo.json # Turborepo configuration

Turborepo Pipeline

turbo.json

Application Architecture

Middleware Layer

The middleware handles authentication, session management, and CORS:
apps/lms/middleware.ts

Route Protection

Routes are protected based on user type (admin, instructor, learner):
  • Public routes: /auth/*, /forgot-password
  • Admin routes: /admin/* (requires user_type = 'admin')
  • Learner routes: /learner/* (requires authenticated user)

Data Flow

  1. Client Request → Server Component/API Route
  2. Authentication → Supabase Auth validates session
  3. Authorization → Row Level Security (RLS) enforces permissions
  4. Data Fetching → TanStack Query with cache management
  5. Response → Server-rendered or JSON response

Database Schema

EaseLMS uses Supabase PostgreSQL with Row Level Security (RLS) policies:

Core Tables

  • profiles - User profiles with role-based access
  • courses - Course metadata and settings
  • lessons - Course content with video/resources
  • enrollments - Student course enrollments
  • progress - Lesson completion tracking
  • payments - Payment records
  • certificates - Generated certificates
  • quiz_questions, quiz_attempts, quiz_results - Assessment system
  • platform_settings - Branding and configuration

Row Level Security

All tables use RLS policies to enforce:
  • Admins can access all data
  • Instructors can access their courses
  • Learners can only access enrolled courses
  • Public can view published course listings

Caching Strategy

TanStack Query manages client-side caching with configurable stale times:
lib/react-query/cache-config.ts

Cache Invalidation

  • Mutations automatically invalidate related queries
  • Realtime subscriptions update cache on data changes
  • Manual invalidation for critical updates

Deployment Architecture

Scaling Considerations

  • Horizontal scaling: Next.js serverless functions auto-scale
  • Database: Supabase connection pooling
  • CDN: Global edge caching for video/assets
  • Video processing: Async job queue with MediaConvert

Performance Optimizations

  1. Server Components: Reduce client-side JavaScript
  2. HLS Streaming: Adaptive bitrate video delivery
  3. Image Optimization: Next.js automatic image optimization
  4. Code Splitting: Dynamic imports for heavy components
  5. Database Indexes: Optimized queries on frequently accessed tables
  6. CDN Caching: Static assets served from edge locations

Security Features

  • Authentication: Supabase Auth with email/password
  • Authorization: Row Level Security (RLS) policies
  • CORS: Configured middleware for cross-origin requests
  • Environment Variables: Secrets managed securely
  • Input Validation: Zod schemas for all forms
  • SQL Injection Protection: Parameterized queries via Supabase client

Development Workflow

Environment Setup

Each app requires its own .env.local file:
apps/lms/.env.local

Next Steps

Authentication

Learn about Supabase authentication implementation

File Storage

Explore AWS S3 and CDN integration

Video Processing

Understand video upload and HLS streaming