Building an Online Course Platform (LMS) and Paid Learning Community on Habify Base
Build a leak-resistant online course backend: unlock curriculum automatically upon direct QR payment, protect videos and PDFs behind private signed links, track student completion, and host class discussions.

Educators, training centers, and course creators can operate an independent LMS on Habify Base without giving up 20% to 50% marketplace commissions. Build your custom learning UI on Next.js or React while Habify Base powers access control, private course materials, direct payments, and student Q&A.
Combining PostgreSQL enrollment policies with private object storage guarantees that only paid students can request short-lived links to downloadable slides, workbooks, and lesson media.
1. LMS & Paid Learning Community Architecture
Six native capabilities carry students cleanly from browsing public syllabi to completing paid lessons:
| LMS Capability | Habify Base Feature | Practical Benefit |
|---|---|---|
| Public course catalog | Anon RLS on course syllabus & free preview lessons | SEO-friendly course landing pages with open sample modules |
| Paid lesson gating | PostgreSQL RLS verifying active enrollment records | Blocks non-enrolled accounts at the database query layer |
| Private PDF & media assets | Private R2 storage + short-lived Signed URLs | Prevents static media URLs from circulating outside class |
| One-time or membership pay | Direct BYO Checkout or Project Billing Kit | Unlocks course enrollment immediately upon webhook arrival |
| Lesson completion tracking | Conflict-safe UPSERT on (user_id, lesson_id) | Keeps student progress percentages accurate across devices |
| Cohort Q&A channels | Built-in Realtime Chat & Notifications | Supports live mentor discussions without extra chat SaaS |
2. Gating Paid Lessons and Tracking Progress via RLS
Allow anonymous browsers to preview lessons marked is_free_preview = true while gating full modules behind an active row in public.enrollments:
CREATE TABLE public.enrollments (
user_id uuid NOT NULL,
course_id uuid NOT NULL,
status text NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'expired', 'refunded')),
enrolled_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (user_id, course_id)
);
ALTER TABLE public.enrollments ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.enrollments FORCE ROW LEVEL SECURITY;
CREATE POLICY enrollments_own_read ON public.enrollments
FOR SELECT USING (user_id::text = current_setting('app.current_user_id', true));
CREATE TABLE public.lessons (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
course_id uuid NOT NULL,
title text NOT NULL,
is_free_preview boolean NOT NULL DEFAULT false,
material_storage_path text
);
ALTER TABLE public.lessons ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.lessons FORCE ROW LEVEL SECURITY;
CREATE POLICY lessons_preview_or_enrolled ON public.lessons
FOR SELECT USING (
is_free_preview = true
OR EXISTS (
SELECT 1 FROM public.enrollments e
WHERE e.course_id = lessons.course_id
AND e.user_id::text = current_setting('app.current_user_id', true)
AND e.status = 'active'
)
);3. Minting Short-Lived Material Links and Saving Lesson Progress
When an enrolled student opens a PDF workbook or private video stream, your Route Handler checks their enrollment row and mints a 10-minute signed URL via habifyServer.storage.createSignedUrl(), while browser calls track completion via .upsert():
// 1. Server API Route: Cấp link tài liệu tạm thời khi học viên đã mua khóa
const { data: lesson } = await habifyServer.db
.from("lessons")
.withOptions({ accessToken: userJwt })
.from?.("lessons");
const { data: verifiedLesson } = await habifyPublic.db
.from("lessons")
.withOptions({ accessToken: userJwt })
.select("id,material_storage_path")
.eq("id", lessonId)
.single();
const { url } = await habifyServer.storage.createSignedUrl(
String(verifiedLesson.material_storage_path),
{ expires_at: new Date(Date.now() + 10 * 60 * 1000).toISOString() },
);
// 2. Browser: Đánh dấu hoàn thành bài học không trùng dòng
await habifyPublic.db.from("lesson_progress").upsert(
{
user_id: session.user.id,
lesson_id: lessonId,
completed: true,
updated_at: new Date().toISOString(),
},
{ onConflict: "user_id,lesson_id" },
);4. Automated Welcome Emails & Realtime Student Discussions
The moment checkout unlocks enrollment, send a branded onboarding email through your BYO domain and issue a tax-compliant receipt for individual learners or corporate training teams.
Use built-in Chat and Notification pipelines to power course-specific Q&A channels and announce newly published modules or live review sessions.
Frequently Asked Questions
Can students copy a lesson link and share it publicly outside the course?
No. Signed URLs created by createSignedUrl() carry cryptographic expiration timestamps (e.g., 10 minutes) and automatically stop working once expired.
Can I sell both lifetime one-off courses and monthly memberships?
Yes. Use direct BYO checkouts for one-time course purchases and Project Billing Kit for auto-renewing membership plans.
Does Habify Base handle concurrent students during course launches?
Yes. Per-project PostgreSQL 18 databases pool connections cleanly through PgBouncer with plan tiers scaling from 200 RPM upward plus optional Dedicated Compute Add-ons.
Need a SePay Merchant Account?
Customer VietQR transfers and Visa/Mastercard/JCB card payments settle directly into your own bank account. Register with SePay before connecting credentials in your project.
Related Documentation & Guides
Launch This Architecture in Free Sandbox in 3 Minutes
Spin up an isolated PostgreSQL 18 database, grab your hb_pk_* / hb_sk_* keys, and wire @habifybase/sdk.