How emn90909/learnzurr works
Purpose and topology
Learnzur is a Kenya-first tuition platform for learners, parents, teachers, and administrators. It is a SvelteKit client/SSR application backed by a Go API, asynchronous Go worker, domain engines, Redis, and a single Supabase PostgreSQL database. Public traffic is split between page rendering and /api/*; engines are internal-only.
Runtime entry points
• Go API: backend/cmd/api/main.go, with routing and server composition in backend/cmd/api/routes.go and backend/cmd/api/server.go.
• Background worker: backend/cmd/worker/main.go, dispatching jobs via backend/cmd/worker/dispatcher.go.
• SvelteKit application entry/layout: frontend/src/+layout.svelte; browser-to-API boundary is frontend/src/lib/api.ts.
• Deployments run through the root Dockerfile; local multi-service composition is defined in docker-compose.yml.
Request, identity, and platform boundary
Frontend route groups serve public, learner, parent, teacher, and admin experiences, e.g. frontend/src/routes/(learner), frontend/src/routes/(teacher), and frontend/src/routes/(admin). Calls are centralized in frontend/src/lib/api.ts and must traverse the Go API rather than access engines or persistence directly. Authentication flows are separated under backend/cmd/auth/login.go, backend/cmd/auth/signup.go, and backend/cmd/auth/session.go; API middleware supplies auth, CORS, rate limiting, logging, compression, and recovery under backend/internal/middleware/.
Domain engines
Business capabilities are organized as Go engine packages with handler → service → repository boundaries:
• Classroom/live learning and WebRTC/board state: backend/engines/classroom/internal/classroom/service.go, backend/engines/classroom/internal/classroom/webrtc.go.
• LMS assessment and grading: backend/engines/lms/internal/lms/service.go, backend/engines/lms/internal/lms/grader.go.
• Payments, balances, payouts, and Daraja integration: backend/engines/mearn/internal/mearn/service.go, backend/engines/mearn/internal/mearn/daraja.go.
• Moderation/scanning and AI providers: backend/engines/flag/internal/flag/service.go, backend/engines/flag/internal/flag/ai_scanner.go, backend/engines/flag/internal/flag/providers/.
• Media conversion, PDFs, and storage: backend/engines/media/internal/media/encoder.go, backend/engines/media/internal/media/pdf.go, backend/engines/media/internal/media/storage.go.
Additional engines cover marketplace (lanmat), gamification (gamfy), notifications (notify), project sandboxing (san), and discovery (find).
Persistence, caching, and async flow
Supabase PostgreSQL is the authoritative persistent store; schema, RLS, functions, and operational views evolve through ordered migrations in supabase/migrations/. Database connectivity is centralized in backend/internal/db/connect.go. Redis provides cache, idempotency, and Redis Streams through backend/internal/cache/redis.go and backend/internal/queue/streams.go. API/domain actions can publish work; the worker consumes and dispatches email, encoding, moderation, gamification, payout, PDF, and push jobs (backend/cmd/worker/jobs/).
Security and external services
Security controls are shared across API and engines, including audit, blacklist, encryption, fraud, and sanitization in backend/internal/security/. Database RLS is a material authorization boundary. External integrations include Supabase/PostgreSQL, M-Pesa Daraja callbacks, SMTP email, VAPID web push, AI moderation providers (Claude, Gemini, OpenAI, or local), and Docker-backed sandbox execution (backend/engines/san/internal/san/docker.go). Nginx configuration exists for multi-container routing in docker/nginx.conf; the root deployment instead uses a Node reverse proxy around Go API and SvelteKit SSR.
Main entry points: routes.go API routing · streams.go Redis streams and cache · connect.go Database connector · service.go Mearn payments engine
Components 20
Client application
- SvelteKit SSR app · Public and role-specific learner, parent, teacher, and admin experiences.
frontend/src/+layout.svelte - Client API boundary
frontend/src/lib/api.ts
Go platform
- Container deployment · Builds the deployed frontend and Go services.
Dockerfile - Go API · Public /api boundary and domain composition point.
backend/cmd/api/main.go - API routing
backend/cmd/api/routes.go - Authentication flows · Login, signup, and session lifecycle.
backend/cmd/auth/login.go - API middleware · Applies authentication, CORS, rate limits, logging, compression, and recovery.
backend/internal/middleware/auth.go - Security controls · Shared audit, fraud, blacklist, encryption, and sanitization controls.
backend/internal/security/audit.go
Domain engines
- Classroom engine · Live learning, board state, and WebRTC.
backend/engines/classroom/internal/classroom/service.go - LMS engine · Assessment and grading workflows.
backend/engines/lms/internal/lms/service.go - Mearn payments engine · Balances, payouts, and Daraja payments.
backend/engines/mearn/internal/mearn/service.go - Flag moderation engine · Content scanning and AI-provider moderation.
backend/engines/flag/internal/flag/service.go - Media engine · Encoding, PDF generation, and storage.
backend/engines/media/internal/media/encoder.go - Supporting engines · Marketplace, gamification, notifications, sandboxing, and discovery.
backend/engines/san/internal/san/docker.go
Data and async
- Async worker · Consumes and dispatches background jobs.
backend/cmd/worker/main.go - Redis streams and cache · Cache, idempotency, and asynchronous streams.
backend/internal/queue/streams.go - Supabase PostgreSQL · Authoritative data store; RLS is an authorization boundary.
supabase/migrations/180_indexes_rls_triggers.sql - Database connector
backend/internal/db/connect.go
External services
- M-Pesa Daraja · Payment callbacks and processing integration.
backend/engines/mearn/internal/mearn/daraja.go - AI moderation providers · Claude, Gemini, OpenAI, or local scanning providers.
backend/engines/flag/internal/flag/providers/claude.go
Connections 29
- Container deployment → SvelteKit SSR app: runs
- Container deployment → Go API: runs
- SvelteKit SSR app → Client API boundary: uses
- Client API boundary → Go API: calls /api
- Go API → API routing: serves through
- API routing → API middleware: protected by
- API routing → Authentication flows: auth endpoints
- API middleware → Security controls: enforces
- API routing → Classroom engine: invokes
- API routing → LMS engine: invokes
- API routing → Mearn payments engine: invokes
- API routing → Flag moderation engine: invokes
- API routing → Media engine: invokes
- API routing → Supporting engines: invokes
- Classroom engine → Database connector: persists
- LMS engine → Database connector: persists
- Mearn payments engine → Database connector: persists
- Flag moderation engine → Database connector: persists
- Database connector → Supabase PostgreSQL: connects
- Supabase PostgreSQL → Security controls: RLS authorization
- Classroom engine → Redis streams and cache: caches and queues
- Mearn payments engine → Redis streams and cache: idempotency and jobs
- Media engine → Redis streams and cache: publishes jobs
- Flag moderation engine → Redis streams and cache: publishes jobs
- Redis streams and cache → Async worker: streams jobs
- Async worker → Supporting engines: dispatches jobs
- Mearn payments engine → M-Pesa Daraja: processes payments
- M-Pesa Daraja → API routing: payment callbacks
- Flag moderation engine → AI moderation providers: scans with