← Back to the Forge
Shipped Next.jsFintechMulti-tenantLegacy migration

Cirene — affiliate and commission SaaS.

A multi-tenant platform where merchants run coupon campaigns, affiliates earn per sale through a running current account, and a commercial rep hierarchy is paid on its own quota structure. Rebuilt from a legacy Oracle APEX system that never reached production.

Client
Cirene
Period
2026
Role
Architect & lead developer

Domain models

56

Application code

~44.5k LOC

Role hierarchies

4

Legacy replaced

14 PL/SQL pkgs

cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br
cirene.com.br

The problem

The business had spent more than a year building on Oracle APEX — fourteen PL/SQL packages, an Oracle database on OCI, ORDS REST endpoints and three Docker microservices — and still had nothing in front of a customer. The stack was not the failure by itself; the problem was that nobody could ship a change to it fast enough to learn anything.

The one advantage of that situation: there was no production data to migrate. The rewrite could be a clean cut.

The solution

A full rewrite as a single Next.js application, delivered as four distinct portals over one domain model: admin, merchant, affiliate and commercial representative — the last one with its own sub-agents, quotas and monthly closing.

  • Coupon and receipt images are generated server-side with satori and resvg, replacing the Puppeteer microservice the legacy stack needed for the same job.
  • Contracts and terms are edited in a rich-text editor with variable interpolation, and acceptance is recorded with a signature trail.
  • Support tickets, impersonation with an audit log and a public product catalogue round out what the operation actually uses day to day.

Architecture

A Next.js monolith on Server Actions, Prisma over PostgreSQL, fifty-six models covering the whole commercial chain. It ships as a multi-stage Docker image with standalone output alongside a compose file, so it can be self-hosted rather than locked to one platform.

  • Payments. Asaas end to end — subscription checkout, Pix, detached Pix authorisation, webhook ingestion with replay tooling for debugging.
  • Finance. An income statement, accounts payable, and OFX bank-statement import reconciled against booked entries.
  • Messaging. WhatsApp Cloud API with scripted template lifecycle management — creation, verification and documentation generation — because template approval is the slowest link in that chain.
  • Four cron endpoints handle Pix subscription renewal, expiring subscriptions, rep monthly closing and trial expiry.

Results

The system reached production and a staging environment inside the same year the rewrite started, against a legacy stack that had not shipped in over a year. Commercial, financial and affiliate sides all run on one database with one permission model, and onboarding a new merchant no longer requires a developer.

Full stack

Next.js 16 (App Router)React 19TypeScriptPrisma 7PostgreSQL 16Auth.js v5 + OTPTailwind v4Tiptapsatori + resvgAsaasWhatsApp Cloud APIDocker (standalone)Vitest
João Afonso Assumpção Systems Architect · Automation Engineer · Solution Builder
© 2026 · All rights reserved. Built with SvelteKit