XConstrução
A SaaS with two products in one codebase: a marketplace that connects people with a building job to the contractors who do it, with progress billing and split payments, and xgestão, where the contractor runs their own job from schedule to finances.
- Role
- Development, architecture and infrastructure
- When
- June 2026 to date
- Team
- Me and the client team, with AI agents in the code
- Status
- xgestão MVP in acceptance testing, payments in sandbox
- 92 screens across marketplace, xgestão and the admin area
- 274 routes of API in the same app, with Zod on write inputs
- 547 tests Playwright across 70 files, API and browser
- 106 journeys documented, each with a definition-of-done checklist
Small Building Jobs Still Run on Notebooks and WhatsApp
People who hire a renovation do not know whether it is on schedule or how much has been spent, and contractors track stages, purchases and labour in spreadsheets and messages. The client, a renovation company, wanted to solve both sides in one product.
The system was born on Replit with the platform’s own agent. I joined in June 2026: first comparing split-payment gateways and infrastructure costs, then in the code, organising the work into journeys and closing the xgestão MVP.
The challengeMake two products share the same code and database without one touching the plan, limits or data of the other, and keep evolving an already large system without breaking what was live.
The Choices That Held the Project Together
- 01
Two Products, One Access Rule
xgestão is an entitlement added to the contractor’s account, separate from marketplace plans. Subscribing to one never changes limits or tier in the other, and navigation carries the product context instead of guessing from the profile.
- 02
Journey Before Code
Every delivery starts from a written journey with scope, risks and a done checklist. It defines what the agent may touch, and anything left out becomes a dated line in the journey itself.
- 03
Split Payments on Asaas
I compared six gateways before choosing. Asaas does native splits between platform and contractor, with sub-accounts, webhook confirmation and a reconciliation job for events that arrive out of order.
- 04
Free Trial Without a New Table
The 90-day Pro trial is a subscription with a "trial" gateway. Expiry is checked on read and on boot, and the account falls back to Free on its own without losing any job.
- 05
Teams Isolated by Company
An invited collaborator only sees the jobs shared with them. I reviewed the 25 queries that filter by company before opening teams for use.
The Job in the Contractor’s Pocket
The contractor updates stages, logs issues and checks the job’s finances from the site, on the phone. Job tabs scroll sideways and cards stack in a column.
-
01 Dashboard. The dashboard on a phone, with indicators in a column.
-
02 Stages. Stages with owner, dates and progress, updated on site.
-
03 Finances. Contract and balance due in the palm of your hand.
-
04 Issues. Problems logged on the spot, with severity.
-
05 Showcase. The marketplace showcase on a phone.
-
06 Open job. Job detail and the invitation to send a proposal.
From the Job Dashboard to the Marketplace
In xgestão, the dashboard, schedule, issues and financial result of each job. In the marketplace, the showcase where contractors find open jobs to apply for.
* Screenshots from a local copy with the project’s demo seed. Job, stages, amounts and people are fictitious.
Under the Hood
This system handles other people’s money, job data and public access by link. Rules live on the server, and the payment path is double-checked.
Stack
- Next.js 16
- TypeScript
- PostgreSQL
- Drizzle ORM
- TanStack Query
- Zod
- Tailwind CSS 4
- shadcn/ui
- Asaas
- Cloudflare R2
- Brevo
- Sentry
- Replit
Safeguards
- Session as a signed JWT in an httpOnly cookie, with 15-minute access and refresh-token renewal
- Login with attempt limits, a honeypot field against bots and a minimum fill time
- Second factor (TOTP) available for the admin area
- Asaas webhook validated by token, without storing the token in the delivery log
- Photos and documents in a private bucket, served through signed URLs
- Boot-time warning if production is running with the gateway in sandbox
Tests and Quality
- Playwright
- node:test
- TypeScript
- Playwright in two projects: one calls the API directly and checks status and database state, the other runs in the browser
- A guard that aborts the suite if the database connection looks like production
- A coverage radar that lists write routes without an integration test
- Unit tests with node:test on calculation rules, such as job results and checklists by period
What You Would See in the Repository
The code belongs to the client and is private. Here is what it contains, with the path or number that backs each point, as a guide for a technical conversation.
Architecture
-
Folders by domain
22 folders in features/Each domain keeps its API, hooks, components, schemas and types in one folder. The page in app/ only assembles the screen.
-
Full stack on Next.js
92 pages · 274 API routesScreens and API in the same App Router, with routes per profile (client, contractor, xgestão, admin).
-
Product as an additive entitlement
features/xgestao · features/planosxgestão access is added to the account and tested separately from marketplace plans.
Data
-
Typed schema with Drizzle
65 tables in shared/db/schema.tsTables, enums and relations in one schema, with types inferred end to end.
-
Idempotent evolution
33 bootstraps · 10 migrationsBootstraps that can run again without breaking anything, plus SQL migrations for what needs ordering.
-
Money without loose rounding
tests/unit/profit-centavos.test.tsJob results computed down to the cent and covered by a dedicated test.
Types and Validation
-
Zod at the boundary
safeParse in 99 routesRequest bodies validated with safeParse before touching the database; the same schema drives the form.
-
Forms with React Hook Form
zodResolver in 25 filesClient-side validation through the Zod resolver, without duplicating rules.
-
Server state with TanStack Query
useQuery in 97 filesCaching, invalidation and loading standardised through domain hooks.
Security
-
In-house JWT auth
server/auth.ts15-minute access and rotating refresh tokens in httpOnly cookies. Google is only a login door and is exchanged for the app’s own session.
-
Bot defence on login
features/auth/api/anti-bot.tsHoneypot field, minimum fill time and per-IP attempt limits.
-
2FA for admins
features/auth/api/totp*.tsTOTP with a configurable policy for the admin area.
Payments
-
Split and sub-accounts
features/marketplace/split-service.tsThe split between platform and contractor happens at the gateway, with one sub-account per company.
-
Reconciliation
reconciliacao-split-job.tsA job that checks what the gateway says against what the database holds, for lost or out-of-order events.
-
Hardened webhook
features/planos/webhook-headers.tsToken validated and stripped from the log; retries inject it from the environment.
Tests
-
Integration with database state
547 tests in 70 specsEvery spec checks the HTTP status and what was stored, and cleans up only what it created.
-
Production lock
tests/e2e/guards.tsA globalSetup that inspects the connection and aborts before the first test.
-
Gap radar
npm run test:integration:gapsA script that crosses write routes with specs and points out what lacks coverage.
AI in the Process
-
Two agents, one owner
106 journeys in docs/The Replit agent and Claude Code over SSH implement; I write the journey, review the diff and decide what goes in.
-
Project skills
96 skills in .claude/skillsGuides the agent loads on trigger: backend, frontend, Postgres, security, debugging and writing.
-
Memory of pitfalls
26 notes in .agents/memoryEvery costly mistake becomes a note the agent reads before repeating it, such as composite FKs on publish and secure cookies in tests.
Where the Project Stands
The xgestão MVP is published for acceptance testing, with the 90-day free trial and payments still in the Asaas sandbox. Switching to real billing depends on finishing acceptance and the client’s sign-off.
In parallel there is a proposal to move the system off Replit to a dedicated VPS, with database, backups and automated deploys in the same pattern as the other projects I maintain.
Have a Similar Project in Mind?
I like problems with real people on the other side. Tell me what you need.