Skip to content
Client · Construction SaaS · 2026 in development

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
xgestão dashboard with active jobs, financial health and total budget
Job stages with progress on a phone
Job contract values on a phone
01. Context

Small Building Jobs Still Run on Notebooks and WhatsApp

A marketplace connects jobs and contractors, with progress billing and sandbox splits. xgestão brings stages and finances to phone and dashboard.
From applying for jobs to managing them with the marketplace and xgestão.

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 challenge

Make 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.

02. Decisions

The Choices That Held the Project Together

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

03. On mobile

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.

  1. 01 Dashboard. The dashboard on a phone, with indicators in a column.

  2. 02 Stages. Stages with owner, dates and progress, updated on site.

  3. 03 Finances. Contract and balance due in the palm of your hand.

  4. 04 Issues. Problems logged on the spot, with severity.

  5. 05 Showcase. The marketplace showcase on a phone.

  6. 06 Open job. Job detail and the invitation to send a proposal.

04. On desktop

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.

Dashboard. Contractor dashboard: active jobs, spend against budget and issues per job.
Schedule. Schedule built from stage dates, coloured by status.
Finances. Job finances: contract, change orders, balance due and real margin.
Issues. Issues with severity, author and date, so problems do not get lost in group chats.
Showcase. Marketplace: contractors filter open jobs and apply.
Open job. Open job detail, with timeline, estimated budget and complexity.

* Screenshots from a local copy with the project’s demo seed. Job, stages, amounts and people are fictitious.

05. Engineering

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
Five safeguards: 106 journeys, JWT sessions, Zod in 99 routes, Asaas webhook and reconciliation, 547 tests with a production lock.
Journeys, validation and tests support the system as it evolves.

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
06. Inside the code

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 routes

    Screens and API in the same App Router, with routes per profile (client, contractor, xgestão, admin).

  • Product as an additive entitlement

    features/xgestao · features/planos

    xgestão access is added to the account and tested separately from marketplace plans.

Data

  • Typed schema with Drizzle

    65 tables in shared/db/schema.ts

    Tables, enums and relations in one schema, with types inferred end to end.

  • Idempotent evolution

    33 bootstraps · 10 migrations

    Bootstraps that can run again without breaking anything, plus SQL migrations for what needs ordering.

  • Money without loose rounding

    tests/unit/profit-centavos.test.ts

    Job results computed down to the cent and covered by a dedicated test.

Types and Validation

  • Zod at the boundary

    safeParse in 99 routes

    Request bodies validated with safeParse before touching the database; the same schema drives the form.

  • Forms with React Hook Form

    zodResolver in 25 files

    Client-side validation through the Zod resolver, without duplicating rules.

  • Server state with TanStack Query

    useQuery in 97 files

    Caching, invalidation and loading standardised through domain hooks.

Security

  • In-house JWT auth

    server/auth.ts

    15-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.ts

    Honeypot field, minimum fill time and per-IP attempt limits.

  • 2FA for admins

    features/auth/api/totp*.ts

    TOTP with a configurable policy for the admin area.

Payments

  • Split and sub-accounts

    features/marketplace/split-service.ts

    The split between platform and contractor happens at the gateway, with one sub-account per company.

  • Reconciliation

    reconciliacao-split-job.ts

    A 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.ts

    Token validated and stripped from the log; retries inject it from the environment.

Tests

  • Integration with database state

    547 tests in 70 specs

    Every spec checks the HTTP status and what was stored, and cleans up only what it created.

  • Production lock

    tests/e2e/guards.ts

    A globalSetup that inspects the connection and aborts before the first test.

  • Gap radar

    npm run test:integration:gaps

    A 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/skills

    Guides the agent loads on trigger: backend, frontend, Postgres, security, debugging and writing.

  • Memory of pitfalls

    26 notes in .agents/memory

    Every costly mistake becomes a note the agent reads before repeating it, such as composite FKs on publish and secure cookies in tests.

07. Today

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.

Next step

Have a Similar Project in Mind?

I like problems with real people on the other side. Tell me what you need.