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: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/*(requiresuser_type = 'admin') - Learner routes:
/learner/*(requires authenticated user)
Data Flow
- Client Request → Server Component/API Route
- Authentication → Supabase Auth validates session
- Authorization → Row Level Security (RLS) enforces permissions
- Data Fetching → TanStack Query with cache management
- 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 accesscourses- Course metadata and settingslessons- Course content with video/resourcesenrollments- Student course enrollmentsprogress- Lesson completion trackingpayments- Payment recordscertificates- Generated certificatesquiz_questions,quiz_attempts,quiz_results- Assessment systemplatform_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
Recommended Setup
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
- Server Components: Reduce client-side JavaScript
- HLS Streaming: Adaptive bitrate video delivery
- Image Optimization: Next.js automatic image optimization
- Code Splitting: Dynamic imports for heavy components
- Database Indexes: Optimized queries on frequently accessed tables
- 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