Production Release, 2026

Roshd — Multi-Tenant B2B SaaS Platform

A unified, schema-isolated educational ecosystem powering Academies and Teachers via Strategy Patterns and dynamic CNAME/Sub-domain routing.

Next.js 14Django 5.2PostgreSQLRedisCeleryWebRTCLiveKitTurborepoDockerCI/CD

Video Demonstration Showcase

Interactive Video Showcase Coming Soon

We are recording a voice-over walk-through of Roshd's primary features, dashboard modules, and server operations. In the meantime, explore the complete system architecture details below!

Project Overview

Roshd was engineered to address a common B2B SaaS challenge: powering structurally distinct products (a hierarchical Academy with multi-level supervisor workflows and an autonomous Teacher platform) using a single, shared backend engine. Instead of maintaining separate codebases or duplicating database tables, I designed a unified Strategy Pattern + Product Registry alongside a capability-based access layer to toggle features dynamically based on tenant subscription plans. To enforce strict privacy and security for corporate clients, the platform adopts a PostgreSQL schema-per-tenant model. When a tenant is registered, an asynchronous Celery pipeline automatically provisions a dedicated DB schema, runs migrations, and configures default rules in under 30 seconds. In addition, the system fully supports wildcard sub-domains (e.g., academy.roshed.tech) and custom white-labeled domains (e.g., learn.clientname.com) mapping directly to respective tenant schemas.

Key Capabilities

PostgreSQL Schema Isolation

Security

Enforced physical data isolation by routing each tenant organization to a dedicated PostgreSQL schema, preventing cross-tenant data leaks.

Strategy Pattern Product Registry

Architecture

Shared a single core Django backend to serve two fundamentally different operational modes (Academy and Teacher platforms) without code duplication.

Concurrency-Safe Internal Wallet

FinTech

Designed a double-entry ledger database schema where balance mutations are guarded with unique idempotency keys and row-level locking (`select_for_update`) to prevent race conditions during billing transactions.

Asynchronous Provisioning Pipeline

DevOps

Implemented a Celery/Redis background worker system that spins up new tenants, creates schemas, executes migrations, and configures default RBAC data in under 30 seconds.

Next.js 14 Turborepo Monorepo

Frontend

Developed a monorepo workspace containing 4 client applications, sharing core authentication, UI styling packages, and custom ESLint security plugins.

Real-Time Systems & WebRTC

Streaming

Integrated WebRTC for live lectures and Server-Sent Events (SSE) for instant, lightweight client-side notifications and status alerts.

Automated Subdomain & Custom CNAME Provisioning System

How Roshd dynamically routes requests to isolated PostgreSQL tenant schemas based on the request host name:

01

DNS Routing

The server configures a wildcard DNS record (*.roshed.tech) pointing all subdomains to our central application proxy.

02

Custom Domain Binding

Users can add their custom domains (e.g., learn.myacademy.com) by pointing a CNAME record to cname.roshed.tech.

03

Django Host middleware

On every incoming request, middleware parses the HTTP Host header, resolves it against the tenant domain registry, and fetches the associated tenant metadata.

04

Dynamic Search-Path Switcher

The middleware invokes a custom DB router which sets the PostgreSQL connection search path (`SET search_path TO tenant_schema_name`), routing all SQL queries to that tenant's database in real-time with zero overhead.

05

Automatic SSL Provisioning

The platform utilizes a Cloudflare/Nginx reverse-proxy setup that dynamically provisions Let's Encrypt SSL certificates for newly mapped custom domains.

Interactive Architecture Flow

Hover or click on the system modules to inspect their dynamic interactions and roles within the product stack:

external

Cloudflare DNS Proxy

Handles incoming wildcards (*.roshed.tech) and custom CNAME mappings dynamically.

Blueprint Sketch

System Architecture Diagram Sketch
System Design Blueprint

Technical Challenges & Resolutions

Problem

Preventing race conditions and balance discrepancies in concurrent wallet mutations.

Resolution

Implemented a double-entry accounting ledger system. Every transaction flows through a centralized balance service wrapping DB transactions with row-level locks (SELECT FOR UPDATE) and unique idempotency keys generated on the client. If a request is retried, the system returns the cached transaction result without modifying the wallet balance twice.

Problem

Managing database migrations across hundreds of tenant schemas without downtime.

Resolution

Wrote a custom Django management wrapper that executes migrations sequentially or in parallel batches. The system utilizes Celery workers to run migrations schema-by-schema during off-peak hours, keeping track of migration states in a central control plane and pausing automatically if a schema migration fails.

Development timeline & Story

Phase 1: Architecture & System Design

Conceptualizing Multi-Tenancy

Researched multi-tenancy models (Shared DB vs. Separate DB vs. Schema Isolation). Chose the schema-per-tenant design to provide strict security for enterprises while keeping maintenance simple. Designed the strategy-pattern classes.

Phase 2: Database & Domain Middleware

Building the Routing Core

Coded the Host middleware in Django to intercept requests, parse domains/subdomains, and update PostgreSQL search paths. Configured Nginx proxy rules to test wildcard routing locally.

Phase 3: Core SaaS Features & Wallet

Developing Wallet and Billing

Built the double-entry accounting ledger, subscription cycles, CRM leads tracker, and RBAC matrix. Integrated WebRTC for interactive class rooms.

Phase 4: Frontend Monorepo & Deployment

Turborepo Setup & CI/CD

Configured pnpm workspaces and Turborepo for Next.js 14 apps. Orchestrated Docker files, Docker Compose, and Github Actions pipelines to deploy automatically to staging environments.

Interested in discussing similar system integrations?