1. System Overview & Engineering Scope
DBERT unifies a Flask learning portal (apps/portal), a Next.js 16.3.5 public website (apps/website), and a FastAPI + PostgreSQL API package (dbert-api-package) into a single platform covering course discovery, guided learning, mentorship, credential verification, and hiring workflows.
In `Yasharthpoddar/dbert` and upstream PR #2, I expanded the platform across 199 files (83 added, 116 modified) to introduce end-to-end course cohorts, a source-grounded Study Classroom, atomic payment and learning transactions, deployment-safe Next.js database initialization, and an automated offline verification suite.
2. Course Cohorts, Capacity Locks & Milestone Evidence
To connect group learning with verifiable completion criteria, I implemented `apps/portal/services/program_cohorts.py` and `apps/portal/services/cohort_progress.py`:
- Fair Seat Allocation & Waitlists: Tables
program_cohorts,program_cohort_memberships, andprogram_cohort_access_logserialize concurrent joins and promotions via_get_cohort(..., lock=True)before counting seats, promoting waitlisted learners inqueue_orderwhile rechecking active course enrollment. - Multi-Signal Milestone Rules: Cohorts evaluate four distinct milestone types (
quiz,project,question, andcourse) using deduplicatedDISTINCTqueries scoped to the cohort dates and the learner's enrollment window. - Capstone-Gated Completion: For courses marked
requires_project, thecoursemilestone explicitly verifies an approved entry inproject_submissionsso quiz completion alone cannot prematurely unlock cohort credentials.
3. Source-Grounded Study Classroom & Durable Study Trail
Adapting a three-panel workspace layout (Study Trail, Tutor Chat, Lecture) for DBERT's course database, `apps/portal/services/study_classroom.py` grounds Q&A directly in enrolled lesson content:
- Citation Extraction:
_LessonTextand_lesson_sectionsparse HTML lesson briefs into clean sections, returning up to three matching source excerpts per answer so learners can jump directly to the cited lesson passage. - Idempotent Study Trail & Optimistic Notes: Questions persist in
study_classroom_entrieswithUNIQUE(intern_id, course_id, request_id)to prevent duplicate retries, whilestudy_classroom_notestracks aversioncolumn to reject stale multi-tab overwrites. - Review Queue & Privacy-Safe Insights: Flagging an entry as
needs_reviewintegrates with the dashboard review workflow (study_classroom_review_attempts), while mentors see aggregate lesson demand and can poststudy_classroom_followupswithout exposing private learner text.
4. Transactional Integrity in Payments, Learning & Security
Across the portal's financial and assessment paths, operations that previously risked partial writes or browser tampering were moved behind server-side invariants:
- Separate Payment Claim Ledger: `apps/portal/services/enrollment_payment_claims.py` isolates unverified manual UPI submissions in
enrollment_payment_claims(pending,verified,rejected) so an unverified claim never credits enrollment prematurely. - Persisted Checkout Terms: `apps/portal/services/gateway_orders.py` records intended order terms in
gateway_payment_ordersbefore checkout and verifies every capture against the persisted record:
def validate_gateway_capture(order, capture, payment_id):
if not isinstance(capture, dict) or (
capture.get("id") != payment_id
or capture.get("order_id") != order["order_id"]
or type(capture.get("amount")) is not int
or capture["amount"] != order["amount_paise"]
or capture.get("currency") != order["currency"]
):
raise GatewayOrderError("The captured payment does not match the expected order.", 409)- CSP & Session Hardening: Replaced inline handlers blocked by Content Security Policy with dedicated scripts (
resume-checker.js,mentor-booking.js,study-classroom.js) and added scoped session revocation, credential lifecycle tracking, and opt-in verified CV portfolios.
5. Next.js Build Resilience & Offline Verification
Deploying the website onto serverless targets like Vercel failed when modules instantiated Prisma and pg.Pool eagerly at import time without a runtime database connection. Refactoring `apps/website/src/lib/db.ts` to lazily construct the client via getDb() across website pages and API routes—combined with pinning next to 16.3.5 for standalone packaging—unblocked clean production builds:
let db: PrismaClient | undefined;export function getDb(): PrismaClient { if (db) return db; db = globalThis.prismaGlobal ?? createPrismaClient(); if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = db; return db; } ```
Finally, I fixed the database service dependency override in dbert-api-package/docker-compose.override.yml and added `scripts/verify_offline.py` so core invariants can be verified locally without external services:
- Compose & Syntax Gates: Docker Compose dependency validation, Python AST parsing of
app.py, and Jinja2 template parsing across all portal templates pass. - Automated Test Coverage:
130offline Flask/SQLite pytest tests (1deselected live-app route test),4/4Node payment contract tests, and82website SEO metadata route checks pass.
Interested in building production AI & Full Stack systems with 1:1 mentorship and verified credentials? Explore the [DBERT AI Fellowship](https://lms.dbert.in).