Rectory Project
SaaS platform for schools in Chile: one deployment serves several schools, each with its own users, data and modules. It covers student wellbeing, teacher coaching and public-fund accounting, with dashboards that turn day-to-day records into indicators and an in-house AI microservice that works on the school's real data. Laravel, FastAPI + Gemini and AWS.
Rectory: multi-school management platform
Rectory is a web platform for schools in Chile: one deployment serves several schools at once, each with its own users, data and modules. It covers everything from student wellbeing and teacher coaching to accounting for public funds, with dashboards that turn day-to-day records into indicators, and an AI layer that works on the school's real data.
I started it in March 2026. Since then it has grown into an ecosystem of four applications, and this is the technical overview of what I built.

| Overview | |
|---|---|
| Role | Lead full-stack developer (around 85% of Rectory's ~1,540 commits) |
| Also | Author of the AI microservice and the status page; co-developer of the Digital School Book, which we built as a team |
| Timeline | March 2026 – present, final stage of development |
| Type | Multi-tenant B2B SaaS for schools and school operators |
| Code | Private (proprietary software), so this case study uses screenshots and short snippets |
Stack
| Layer | Technologies |
|---|---|
| Backend | Laravel 13, PHP 8.3, MySQL, queue worker as a systemd service, scheduled tasks |
| Frontend | Blade + Alpine.js 3 + Tailwind CSS 4, Vite 7; React 19 only for Communications; Livewire 4 for three complex forms |
| Real time | Laravel Reverb (WebSockets) + Laravel Echo |
| AI | In-house Python/FastAPI (async) microservice on top of Google Gemini, including the Gemini Live API for voice |
| Documents | DomPDF with a custom design system for 100+ PDF views |
| Infrastructure | AWS EC2 + Caddy, Amazon RDS (MySQL), S3, systemd |
| Monitoring | In-house status page: Flask + Celery + Redis |
| Quality | PHPUnit (120+ test files), pytest on the AI service, architecture, deployment and DR documentation |
Ecosystem architecture
Browser (Blade + Alpine, React for the chat)
|
v
+-------------------------------+ per-action HMAC +------------------------+
| Rectory - Laravel 13 | ------------------> | ai-service - FastAPI |
| multi-school panel | | prompts -> Gemini |
+-------------------------------+ +------------------------+
| signed HTTP bridges ^
| (sync every 10 min, SSO, backups) | HMAC
v |
+-------------------------------+ |
| Digital School Book | --------------------------------+
| Laravel |
+-------------------------------+
status-rectory (Flask + Celery + Redis) ---- uptime checks ----> every service
Data: Amazon RDS | Files: S3 | Servers: EC2 + Caddy + systemd | Real time: Reverb
- Rectory is the core: a modular Laravel monolith with per-module controllers, a service layer and 230+ Eloquent models.
- ai-service is the only component that talks to Gemini. It is stateless: it receives prepared data, builds the prompt, calls the model and returns JSON.
- Digital School Book is a separate app that talks to Rectory through authenticated HTTP "bridges".
- status-rectory watches all of them from the outside.
Features by area
| Area | What it solves | Technical detail |
|---|---|---|
| School operators | See the whole school network and decide | Meta Dashboard with a 10-minute cache; Strategic Report generated every Friday and emailed as a PDF; AI lookup of the official Accounting Manual |
| Principal's office | Institutional goals, interviews, minutes, school calendar | Minutes and interviews with draft mode, external participants and a signed document (photo converted to PDF) |
| Academic coordination (UTP) | Teacher coaching and learning | Classroom walkthroughs, notebook reviews, reading plan with Digital School Book data via bridge, AI remedial reports |
| Student wellbeing | Cases, protocols and school climate | Case management, confidential reports, AI-generated protocols based on the school's internal rules, annual plan and annual report as PDF |
| PME–SEP | School Improvement Plan and SEP funds | Achievement clocks, alert center by due-date bands, strategy map, SEP resources |
| Discipline, Nursing, Front gate, Cafeteria | Day-to-day operations | Daily log, visits and accidents, AI ID-card scanning, student check-in and check-out, event-based cafeteria attendance |
| Surroundings | Infrastructure and safety incidents | Resolution traffic light, monthly success rate, materials and rooms |
| Inventories | IT equipment and library | Loans, overdue returns, reversible bulk imports from Excel |
| Communications | Internal coordination | SPA-style chat in React 19 on top of Reverb |
| Administration | Running the platform | Backups, online users, per-module help manuals, audit trail |

Deep dives
1. Multi-tenancy and permissions
School is the root of the data: almost everything hangs off a school_id, and each school enables its own modules. Permissions are a custom system, no ACL packages:
- A
SystemRoleenum with about 30 roles, each one listing the modules it can see. - A
module.access:{module}middleware that decides access based on the user's role, the modules enabled for their school, and whether it is a demo school. - Internal admin accounts are hidden from school listings with an explicit scope, not a global one, because a global scope would have broken login and relationships.
I chose to filter by school explicitly in every query. It is the most sensitive part of the system, so I documented it as a known risk and backed it up in the backup design (see section 5).
2. AI reports: the Strategy pattern
Every module that produces an AI report implements the same contract. The module only decides which data to collect and which PDF to render; the prompt and the model call live in the microservice.
interface AiReportStrategyContract
{
public function label(): string;
public function collectData(School $school, array $params): array;
public function pdfView(): string;
public function pdfViewData(): array;
}
There are 36 registered strategies. My favorite part of this design is that the same strategies are reused as tools (function calling) for the RectorIA assistant without duplicating a single query: when the assistant needs student wellbeing data, it calls the same strategy that builds the wellbeing report.

3. ai-service: a shared AI microservice
At first Rectory called Gemini directly. When the Digital School Book needed AI too, I moved everything into a FastAPI service organized by consumer: reports, assistant, protocols, regulations lookup, accounting manual, ID cards and surveys for Rectory; exam generation, remedial guides and a lesson-log assistant for the Digital School Book.
Each consumer signs its requests with an HMAC token derived from the action it calls, so a key leaked for one action is useless for another:
token = hmac.new(secret.encode(), action.encode(), hashlib.sha256).hexdigest()
# sent in the X-AI-Bridge-Token header
Some decisions I made here:
- The tool loop lives in Rectory, not in the service: the service does a single round trip to Gemini per call, with at most two tool calls per turn.
- Voice mode without exposing the key: the service hands out an ephemeral Gemini Live API token and the browser talks to the model directly, while Rectory validates and runs the tools.
- Explicit limits: each assistant refuses off-topic questions (trivia, programming, homework), and every PDF produced with AI help says so in its footer.
- Privacy: ID-card scanning at the front gate processes the photo in memory and never stores it.

4. Dashboards that answer questions
The PME achievement clocks define achievement as mandatory verification items with uploaded evidence (photo or PDF) over the total required. The needle shows what was expected by today based on each action's start and end dates, and the color compares both against gap thresholds (warning below 15 pp, critical below 30 pp). Each due-date band triggers an email alert to the owner, UTP, the principal and the school operator.

- Weekly Strategic Report: a command scheduled for Fridays at 08:00 takes a snapshot of each school, raises alerts, assigns who each alert escalates to, and sends a network-wide PDF.
- Reusable year and semester filters (a trait) applied across more than a dozen dashboards.
- Meta Dashboard with a 10-minute cache. The cache only stores plain values: I learned the hard way that caching dates and collections returned incomplete objects.

5. Security and backups
Brute-force protection uses two counters in the cache:
public const MAX_ATTEMPTS = 5; // per account, from any IP
public const IP_MAX_ATTEMPTS = 50; // per IP: a whole school shares one public IP
public const LOCKOUT_STEPS = [60, 300, 900, 1800, 3600]; // each lockout lasts longer than the last
During a lockout even the correct password is rejected, and the response is the same whether the account exists or not, so it never reveals which emails are registered. On top of that: two-factor authentication (TOTP), a password policy, session expiration and an audit trail on 100+ models that records who changed what and when, including the diff.
Per-school backups were the most interesting design problem. Every table in the database is classified by how it reaches a school: a direct column, a chain of joins, a polymorphic relation, a global catalog, or excluded with a stated reason. Any unclassified table is left out of the backup, because I'd rather have an incomplete backup than one that leaks another school's data. So that "incomplete" never goes unnoticed, a test fails as soon as a new unclassified table appears.
For disaster recovery, the databases run on RDS with point-in-time restore, a heartbeat every minute lets a drill measure how much data is actually lost, and a command produces the drill report. The documented target is a maximum data loss (RPO) of one hour or less.
6. Digital School Book and the bridges
The Digital School Book (attendance, lesson log, grades, grade-retention risk, parent and student portals, exports to the Ministry of Education's official formats) is a separate Laravel app we built as a team. On the Rectory side, the integration works like this:
- Automatic sync of classes, students and teachers every 10 minutes.
- Single sign-on from Rectory with a signed handoff token, no second login.
- Digital School Book backups coordinated from Rectory through the bridge.

7. status-rectory: an SLA you can verify
The requirement was monthly uptime of at least 99.5%, excluding announced maintenance, with a verifiable calculation. I built it as a separate Flask app:
- Celery workers with Redis run the checks; uptime is computed over time with interval arithmetic, so the same outage is never counted twice.
- A maintenance window is only excluded if it was announced at least 48 hours in advance; otherwise it counts as downtime.
- The monthly report is drafted automatically on the 1st, finalized with a SHA-256 seal, published with a PDF and an interval CSV to recompute it, and the checksum is re-verified on every view.
- Alerts via email, HMAC-signed webhooks, Slack, Discord, Teams and Telegram, with retries.
8. Frontend and product details
- Blade + Alpine.js for almost everything: server-rendered pages with targeted interactivity. React only where a SPA was justified.
- Online users through a private per-user Reverb channel: the panel queries Reverb's HTTP API instead of keeping its own state.
- PDF design system: shared header, logo and footer, with real "Page X of Y" numbering drawn through the Canvas API.
- Signed documents: a photo of the signed minutes is normalized and converted to PDF. The previous file is deleted only after the new one is saved, so a record is never left without a file if something fails halfway.
- Demo schools flagged with a banner, excluded from automatic emails and with sensitive modules locked, so the platform can be shown without touching real data.
- Responsive UI: discipline staff, nurses and gate staff work on their feet, not at a desk.

Challenges that taught me something
- A TRUNCATE that broke transactions. While testing the audit trail with scripts wrapped in a transaction, I found that in MySQL
TRUNCATEperforms an implicit commit: test data was really being saved even though the script ended withrollBack(). I now use regular deletes when everything needs to roll back. - Uploads failing for no obvious reason. Livewire uploaded straight from the browser to S3 with presigned URLs, and the bucket wasn't set up for that. I moved those forms to server-side uploads, like the rest of the system.
- Two Alpine.js instances. The app's JavaScript replaced the Alpine instance Livewire had already loaded, and selects stopped receiving values from the server with no visible error. The fix was one condition; finding it took much longer.
- 500 errors caused by the cache. Storing dates and collections in the database cache returned incomplete objects. Since then the cache only stores plain values.
By the numbers
| Metric | Value |
|---|---|
| Commits on Rectory (March – October 2026) | ~1,540, around 85% mine |
| Apps in the ecosystem | 4: Rectory, Digital School Book, ai-service and status-rectory |
| Modules / roles | 14 modules · ~30 roles |
| Eloquent models / migrations | 230+ / 280+ |
| AI report strategies | 36 |
| PDF views | 100+ |
| Test files | 120+ (PHPUnit) · 19 (pytest, ai-service) |
What I take away
Rectory pushed me beyond CRUD: multi-school permissions, privacy for data about minors, backups that must never leak data between schools, and an SLA that has to be provable. I also learned to use AI where it actually helps, with clear limits and real data behind it, and to write documentation for the next person who joins the team.
All screenshots come from demo schools with fictional data.
Project screenshots