Wintura's architecture decisions, and the reasons recorded for them

By Alvi Lika, Founder, Soatech

· · 8 min read

The engineering decision record behind wintura.ai: tenant scoping, schema-constrained model output, a human review gate, sealed signatures and idempotent payments, with the trade-offs each one carries.

The main case study for wintura.ai is at /wintura. This article is the engineering companion to it: the decisions that shape how the product handles tenant data, model output, signatures and payments, why each was made, and what each one costs.

Wintura turns a client brief (a forwarded email, a pasted Slack thread or a PDF) into a branded proposal, a statement of work and a staged invoice schedule, for teams that quote scoped work. Everything below is taken from the Wintura codebase and its decision log, which starts on 3 March 2026.

Correction. Earlier versions of this article described a different audience (window-installation sales teams), a Supabase and Row-Level Security architecture, Sentry monitoring, a test count, time-saved figures and production performance numbers. None of that matches the codebase, and none of it should have been published. This version replaces it.

The stack, briefly

LayerWhat Wintura uses
FrameworkNext.js 16 (App Router), React 19, TypeScript
DatabasePostgres on Neon, queried with raw SQL through @neondatabase/serverless
AuthAuth.js (NextAuth v5, still a beta release) with the Neon adapter; Google and email sign-in
ModelsClaude models in several tiers (Opus, Sonnet and Haiku) for different stages of generation
PaymentsStripe, including US bank account (ACH) payments
Files and PDFsCloudflare R2 for sealed PDFs; PDF rendering in a separate Puppeteer service on Railway
TestsPlaywright end-to-end suites covering auth, proposals, invoices, onboarding and accessibility audits
AnalyticsPostHog for product events

The reasons behind the vendor and library choices are in five stack decisions from the Wintura build. The rest of this article covers decisions about correctness: what the system must never do, and how the code stops it from doing it.

Decision 1: scope every tenant query in the data layer

Every table that holds tenant data carries an agency_id column, and every query that reads or writes that data filters on it. Queries live in lib/db/, and the project rules forbid inline SQL anywhere else. A simplified example of the pattern:

// lib/db/proposals.ts (simplified)
export const getRecentProposalLinks = async (agencyId: string, limit = 5) => {
  return sql`
    SELECT id, title, client_name
    FROM proposals
    WHERE agency_id = ${agencyId}
    ORDER BY updated_at DESC NULLS LAST
    LIMIT ${limit}
  `;
};

What this does not do: Wintura does not use PostgreSQL Row-Level Security. Isolation is enforced by the application, not by the database. That has one clear weakness: a new query that forgets the agency_id filter would not be caught by Postgres. The protections against that are convention (all SQL lives in one directory, and tenant-owned queries take the tenant or owning user as an argument), code review, and end-to-end tests that sign in as a real tenant.

When RLS is worth adding: if more than one team writes queries, or if any code path connects to the database outside the data layer, policies give you a second line of defence. They are not unconditional either. Table owners and roles with BYPASSRLS skip policies unless you configure otherwise, so the roles your application connects with need testing (PostgreSQL documentation).

Decision 2: constrain model output with a schema, and retry only what retrying can fix

The first generation stage analyses the brief. Its response shape is constrained by a JSON schema through structured outputs (output_config.format), so the code does not depend on the prompt alone to produce valid JSON. The constraint covers normal completed responses: a refusal or a response cut off at the token limit may not match the schema (structured outputs documentation). The step detects truncation by name and falls back to a generic plan marked for manual review whenever a response does not parse.

The retry policy is deliberately narrow. Rate limits (429), server errors (5xx) and connection faults are retried. A 400 caused by a malformed request is not, because retrying it uses up the time budget and fails the same way. Every attempt runs inside a fixed overall deadline, and a retry only starts if enough time is left for it to finish. The comments in lib/ai/stage-1-analysis.ts explain the reasoning. A capacity error fails within seconds and is worth retrying immediately. A timeout has already used most of the budget.

The trade-off: a strict deadline means some slow but valid generations are abandoned. Wintura accepts that because an unbounded generation tied up behind a user's request is worse.

Decision 3: commercial conflicts go to a person, not to the model

Some problems in a brief are commercial, not technical. The client's deadline can't be met, or the price is above the stated budget. Wintura does not let the model quietly settle these. It stores them as review_advisories on the proposal for a person to resolve, along with the verdict from the quality gate.

On the automated outbound demo path, any document that fails the quality gate is held in a needs_review stage and is not sent automatically. The cost is throughput, since some documents wait for a human. The benefit is that a confident but wrong proposal never reaches a prospect on its own.

Decision 4: proposal and SOW render from one agreement

The proposal and the statement of work are produced from the same structured agreement, so they cannot drift apart. Pricing is stored as structured data rather than extracted from generated text. The decision log records the change: invoice line items used to depend on a model parsing pricing out of proposal HTML, and the log calls that "brittle and non-deterministic". Invoices are now built deterministically from the stored pricing.

This is the most transferable lesson in the build. If a value needs to be exact, store it as data and render it into text. Do not generate the text and then try to parse the value back out.

Decision 5: seal signed documents and make the seal tamper-evident

When a proposal is signed, Wintura:

  • writes audit rows that are hash-chained, so each row records the hash of the previous one (prev_audit_hash);
  • hashes the signer's IP address together with the tenant ID and a server-side pepper, so raw addresses are not stored;
  • seals a PDF and records the document hash;
  • rejects edits to a sealed proposal with HTTP 423 (Locked).

The scope is limited on purpose. The decision log states that the in-house e-signature is meant for agency–client proposal acceptance and does not claim to meet UETA/ESIGN requirements. Where a legally binding signature is required, a dedicated e-signature provider is the right tool.

Decision 6: make payment webhooks idempotent in the database

Stripe can deliver the same webhook more than once. Wintura's handlers guard against this in the SQL itself: updates are conditioned on the invoice not already being in a terminal state, so a repeated event cannot overwrite a paid or refunded invoice. The decision log gives the reason. An application-level check alone does not hold up when two deliveries race each other.

What the record does not show yet

  • Error monitoring. The observability module is a placeholder that does nothing in production. Errors are not yet reported to a monitoring service.
  • Unit tests. Testing is end-to-end only (Playwright, including accessibility checks across mobile, tablet and desktop viewports). Pure functions such as the pricing and schedule logic would get faster feedback from a unit-test layer.
  • Database-enforced isolation. See decision 1.

These gaps are listed here because a reference build is only useful if you can see where it stops.

Using this as a checklist for your own product

You can ask the same questions of any multi-tenant AI feature:

  1. Where is tenant isolation enforced, and what catches a query that forgets it?
  2. Is model output validated against a schema before it is stored or acted on?
  3. Which errors are retried, and what limits the total time spent?
  4. Which decisions does the model make, and which does it hand to a person?
  5. Are exact values (prices, dates, totals) stored as data, or parsed back out of generated text?
  6. Can a signed or paid record be changed afterwards, and would you be able to tell?

If you can't answer these for your own codebase, the Production Audit answers them in writing in three to five working days, without changing any code. If you are building a similar AI workflow into an existing product, that is the work an Embedded Architect engagement covers.

Want these questions answered for your codebase?

See the Production Audit

Working on a feature this article touches? A 30-minute call is the quickest way to scope it.

Discuss your project