How longbatman09/r2p-enterprise works
Purpose and Entry Points
R2P Enterprise is a multi-tenant school platform that converts unstructured student reports into extracted marks, charts, and optional presentation decks, while offering isolated per-student textbook RAG. Its production boundary is the FastAPI MCP backend: mcp_backend/main.py, with dashboard REST endpoints and authenticated MCP JSON-RPC/SSE access. Schools primarily consume it through r2p_school_sdk/client.py.
API, Identity, and Tenant Boundary
The backend supports Supabase email/password sessions for dashboard users and sk_... API keys for SDK/MCP callers. JWT/API-key authentication is unified at the MCP boundary; service credentials can be stored for users, with AES-GCM protection when configured. School, student, key, invoice, and report entities are scoped to the school tenant.
• mcp_backend/auth_routes.py
• mcp_backend/auth_supabase.py
• mcp_backend/school_routes.py
• mcp_backend/database.py
• supabase/schema.sql
Report Analysis Pipeline
A caller uploads a report through an MCP tool. The UI orchestration layer coordinates prescan/upload analysis; vision extraction invokes Gemini to identify exam, student, subject, marks, and attendance from PDFs or images. Local pipeline agents merge extracted file/page results into student-oriented JSON, then chart/PPT rendering produces user-facing artifacts.
• mcp_servers/ui_orchestrator.py
• mcp_servers/vision_extractor.py
• agents/orchestrator.py
• agents/local_mem.py
• mcp_servers/plot_renderer.py
Retrieval-Augmented Textbook Service
Textbook ingestion and question answering are separate from report extraction. Content is embedded using NVIDIA NIM and stored/searchable in Pinecone namespaces partitioned by student, preventing cross-student retrieval. The MCP RAG module is the service-side implementation; the SDK exposes the school-facing call shape.
• mcp_servers/rag_system.py
• r2p_school_sdk/rag/manager.py
• r2p_school_sdk/rag/pinecone_helper.py
• migrate_rag_supabase.sql
School SDK and Commercial Integrations
r2p_school_sdk is the thin Python integration layer: it sends authenticated report and RAG requests to the backend rather than exposing MCP mechanics to schools. It also contains administrative/dashboard access and Stripe invoicing support. Backend persistence remains authoritative for tenant data and API-key lifecycle.
• r2p_school_sdk/client.py
• r2p_school_sdk/admin/dashboard.py
• r2p_school_sdk/invoicing/stripe_service.py
Runtime and Deployment
The primary runtime is Python/FastAPI/Uvicorn in Docker, deployed via Render. Supabase provides Auth and Postgres; Google Gemini provides document extraction; NVIDIA NIM and Pinecone provide RAG; Stripe handles invoices. Local composition and Render provisioning define the backend deployment path.
• mcp_backend/Dockerfile
• mcp_backend/requirements.txt
• docker-compose.yml
• render.yaml
Secondary Agent Runtimes
Two Google Agents CLI/ADK applications appear to be independently deployable agent runtimes, likely for conversational/orchestration and scanning roles. They are separate from the primary FastAPI MCP service but include telemetry and Terraform deployment definitions.
• my-agent/app/agent_runtime_app.py
• scan-agent/app/agent_runtime_app.py
• my-agent/deployment/terraform/single-project/service.tf
Main entry points: main.py FastAPI MCP service · vision_extractor.py Vision extraction · rag_system.py RAG MCP service · auth_routes.py Auth and tenant routes
Components 20
School clients
- School SDK · School-facing authenticated integration layer.
r2p_school_sdk/client.py - SDK dashboard admin
r2p_school_sdk/admin/dashboard.py - SDK invoicing
r2p_school_sdk/invoicing/stripe_service.py
MCP backend
Primary FastAPI production boundary.
- FastAPI MCP service · Dashboard REST and authenticated MCP entry point.
mcp_backend/main.py - Auth and tenant routes · Unifies Supabase sessions and sk_ API keys.
mcp_backend/auth_routes.py - School API routes
mcp_backend/school_routes.py - Tenant persistence · Authoritative school, student, report, key, and invoice records.
mcp_backend/database.py
Report analysis
- Upload orchestration · Coordinates prescan and report upload analysis.
mcp_servers/ui_orchestrator.py - Vision extraction · Extracts exam, student, subjects, marks, and attendance.
mcp_servers/vision_extractor.py - Report merge agents · Merges file and page results into student JSON.
agents/orchestrator.py - Chart and PPT renderer
mcp_servers/plot_renderer.py
Textbook RAG
- RAG MCP service · Ingests textbooks and answers student-scoped questions.
mcp_servers/rag_system.py - SDK RAG manager
r2p_school_sdk/rag/manager.py
Secondary agent runtimes
Independently deployable ADK applications.
- Conversational agent runtime
my-agent/app/agent_runtime_app.py - Scanning agent runtime
scan-agent/app/agent_runtime_app.py
Managed platform
- Supabase · Authentication and tenant schema provider.
supabase/schema.sql - Google Gemini
- NVIDIA NIM + Pinecone · Pinecone namespaces isolate each student's retrieval.
r2p_school_sdk/rag/pinecone_helper.py - Stripe
- Docker / Render deployment
render.yaml
Connections 19
- School SDK → FastAPI MCP service: authenticated report and RAG requests
- SDK dashboard admin → FastAPI MCP service: administration
- SDK invoicing → Stripe: invoices
- FastAPI MCP service → Auth and tenant routes: authenticates callers
- FastAPI MCP service → School API routes: serves dashboard APIs
- Auth and tenant routes → Supabase: email/password sessions
- School API routes → Tenant persistence: tenant-scoped records
- Tenant persistence → Supabase: persists via
- FastAPI MCP service → Upload orchestration: report upload tool
- Upload orchestration → Vision extraction: prescan and extraction
- Vision extraction → Google Gemini: PDF/image analysis
- Vision extraction → Report merge agents: file/page results
- Report merge agents → Chart and PPT renderer: student JSON
- FastAPI MCP service → RAG MCP service: RAG tools
- SDK RAG manager → RAG MCP service: school RAG calls
- RAG MCP service → NVIDIA NIM + Pinecone: embed and student-scoped search
- Docker / Render deployment → FastAPI MCP service: deploys
- Conversational agent runtime → FastAPI MCP service: separate runtime
- Scanning agent runtime → FastAPI MCP service: separate runtime