Platform
GRAMA
AI-focused learning engine and LMS for teacher training across multiple institutions, built for Industrias Roland Print S.A.C. and in production since June 2026. A RAG learning assistant on Google Gemini, MCP integration and auto-generated course content, on top of a hexagonal/DDD modular monolith with a multi-tenant PostgreSQL schema secured by Row Level Security.
The Problem
Industrias Roland Print needed a single training platform for teachers across several institutions. Generic LMSs like Moodle needed heavy configuration and still lacked the custom progression rules, institutional analytics and AI assistance the client wanted. The challenge was to build a production-grade platform that could serve many institutions from one deployment, keep each tenant’s data isolated, and scale to tens of thousands of users on a lean infrastructure budget.
Key Decisions
Hexagonal architecture and DDD with 12 bounded contexts
Courses, progress, assessments, analytics, AI and tenancy each change for different reasons. Modelling them as bounded contexts inside a modular monolith keeps the domain logic independent from Next.js and Supabase behind ports and adapters, so each context can be tested and evolved on its own without paying the operational cost of microservices.
Multi-tenancy enforced by Row Level Security, not only by application code
With several institutions and roles sharing one database, a single missing WHERE clause would leak data across tenants. Row Level Security policies make PostgreSQL itself reject rows outside the caller’s institution and role, and every server action still re-derives the role from the session instead of trusting client claims. The schema was sized for 30,000 users and 8,000 concurrent peaks and validated with k6 load tests.
pgvector in the same Postgres instance for the RAG assistant
A dedicated vector database would have meant another service to provision, secure and pay for. Embeddings are always queried together with relational data such as enrollment and tenant, so keeping them in Postgres lets the assistant join similarity search with permission checks in one query, under the same RLS policies.
Analytics on PostgreSQL aggregates and RPCs
Institution dashboards aggregate completion and progression data across many users. Computing those aggregates inside the database and exposing them through RPCs avoids shipping raw rows to the server and keeps the heavy queries close to the data, behind the same access rules as the rest of the platform.
Server Components for reads, client state only where it adds value
Rendering pages with data already fetched on the server avoids loading waterfalls, so teachers see a populated page immediately. Client-side state is reserved for interactive flows such as quiz submissions, progress updates and the streaming assistant.
Outcome
GRAMA has been in production since June 2026, serving teacher training for multiple institutions. Beyond the features, the project taught me how much reliability comes from decisions made early: clear domain boundaries, security enforced in the database, and load testing before real traffic arrives.
Features
Architecture
- Hexagonal / DDD modular monolith with 12 bounded contexts
- Multi-tenant schema with role-based access and Row Level Security
- Sized for 30,000 users and 8,000 concurrent peaks, load-tested with k6
- Legacy data migrated with idempotent loaders
AI Layer
- RAG learning assistant on Google Gemini with streaming and tool calling
- Semantic search with pgvector, scoped by enrollment and tenant
- MCP integration
- Auto-generated course content
Learning Engine
- Course → Module → Lesson → Item hierarchy with multiple content types
- Sequential gatekeeping: a lesson unlocks when the previous one is completed
- Automated grading tied to progress updates
Analytics & Infra
- Analytics module on PostgreSQL aggregates and RPCs
- Deployed on Vercel with Supabase (PostgreSQL, Auth, Storage)
- Cloudflare DNS and edge caching