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