We Built an AI That Ships Patient Portals
How we replaced two weeks of integration work per partner with an AI assistant that generates complete, API-connected Next.js storefronts from a config file.
Every partner that signs onto a telehealth platform needs the same thing: a branded storefront where patients land, answer an intake questionnaire, get matched with a clinician, check out, and log in as members. The pages look different — different logos, colors, copy, state licensing — but the bones are identical. Landing page. Intake. Checkout. Dashboard.
We were spinning up these storefronts by hand. A designer would mock the partner's brand. A developer would clone a template repo, wire up API calls, tweak the questionnaire for whatever states the partner operated in, test the payment flow, and push it to staging. Two weeks minimum per partner, and every new one surfaced some edge case the template didn't account for.
The question wasn't whether AI could help. It was whether AI could ship the whole thing.
The shape of the problem
A patient storefront is deceptively simple on the surface. Four or five pages. A form. A Stripe checkout. But underneath:
- The intake questionnaire is clinical. It branches based on answers. Certain responses disqualify patients. Others trigger follow-up questions. The question set varies by condition, state, and partner configuration.
- Visit state is a pipeline. A patient moves through statuses —
intake_started,questionnaire_complete,clinician_review,prescribed,pharmacy_sent— and the frontend has to reflect each one. Polling, webhooks, optimistic UI. - Multi-state licensing is a maze. A partner operating in 8 states has different formularies, different provider networks, and different consent language per state. The storefront has to enforce all of it before a patient ever sees a clinician.
- Auth bridges two systems. The patient logs in with a one-time code sent to their email or phone. That token maps to an identity in the platform's backend, which stores visit history, prescriptions, and payment methods. The auth handoff has to be seamless.
None of this is exotic. But it's the kind of integration-heavy, config-driven work that eats developer weeks.
What we actually built
We built an assistant — powered by Claude — that could read our API schemas, understand our design system, and generate complete Next.js storefronts from a partner configuration. Not scaffolding. Not boilerplate. Working sites connected to real APIs.
The system had three layers:
1. The cookbook
A structured set of recipes that taught the model how our platform works. Not documentation — recipes. Each one described a specific capability (rendering a questionnaire, submitting an intake, polling visit status) with the exact API endpoints, request/response shapes, error codes, and UI patterns our storefronts used.
The cookbook was the single source of truth. When the API changed, we updated recipes, not prompts. When the model generated bad code, we traced it back to a recipe that was ambiguous or missing context, and fixed it there.

2. The schema layer
We fed the assistant our OpenAPI specs, TypeScript types, and component library. It didn't guess at API shapes — it read them. This eliminated an entire class of bugs where the model would hallucinate field names or invent endpoints that didn't exist.
The schema layer also encoded constraints: which states a partner was licensed in, which conditions they treated, which payment processor they used. The assistant consumed these as structured config, not free-text prompts.
3. The generation pipeline
A multi-step pipeline that produced a complete Next.js application:
- Parse the partner config (brand assets, states, conditions, API credentials)
- Plan the site structure (routes, components, API integrations needed)
- Generate each page as a React component with TypeScript, Tailwind, and real API calls
- Wire the pages together — navigation, auth flow, state management across the funnel
- Validate the output against our component library and API schemas
The output was a deployable Next.js project. Not pseudocode. Not a prototype. A site with a landing page, a branching intake questionnaire, Stripe checkout, clinician-review polling, and a member dashboard — all hitting production APIs.
Where it broke (and what we learned)
The first version was terrible. The model would generate plausible-looking components that called endpoints with wrong HTTP methods, or build forms that submitted data in a shape the API rejected. Three patterns fixed most of it:
Structured recipes over long prompts. Early on, we tried cramming everything into system prompts. The model would lose context halfway through a generation and start improvising. Breaking the knowledge into modular, focused recipes — one per capability — let the model retrieve exactly what it needed for each step.
Schema-first, not example-first. We initially gave the model example code from existing storefronts. It would copy patterns that were specific to one partner and apply them to another where they didn't fit. Switching to raw schemas plus the recipe for how to use them produced more consistent, correct output.
Validate early, not at the end. Running TypeScript compilation and linting after each generated file — not after the whole site — caught drift before it compounded. A wrong import in file three would cascade into broken types in files four through ten. Catching it immediately kept each step clean.
The hardest part wasn't generation
Generating code was the flashy part. The hard part was the state machine.
A patient visit in our system has roughly a dozen states. The frontend has to handle every transition: what the patient sees while waiting for clinician review, what happens if they're denied, what the dashboard shows after a prescription is sent to the pharmacy. Each state has different API calls, different UI, different copy.

Getting the model to correctly implement this state machine — including edge cases like expired sessions, partial completions, and race conditions between polling and webhook updates — took more iteration than everything else combined. The recipes for visit-state handling went through five revisions before they reliably produced correct code.
What it looks like now
A new partner storefront goes from configuration to deployed preview in a single session. The operator fills in a partner config — brand, states, conditions, payment details — and the assistant generates the full site. A developer reviews the output, runs the test suite, and pushes to staging.
The generated sites aren't throwaway prototypes. They serve real patients. The funnel works end-to-end: landing page, questionnaire, clinician matching, checkout, prescription tracking, member login. Every API call uses the real endpoints with proper auth.
The assistant doesn't replace the developer — it replaces the two weeks of integration work that was identical across every partner.
We still review every generated site before it goes live. The developer's time goes to reviewing, testing, and handling the genuinely novel requirements each partner brings.
Takeaways for anyone building something similar
Start with the cookbook, not the model. The quality of generated code is bounded by the quality of your recipes. Invest in structured, modular knowledge that the model can retrieve precisely. A great model with bad recipes produces bad code.
Treat the AI like a junior developer who has perfect memory but no judgment. It will follow your recipes exactly. If the recipe is wrong, the code is wrong. If the recipe is ambiguous, the code is unpredictable. Write recipes the way you'd write runbooks for an on-call engineer: explicit, unambiguous, with every edge case addressed.
Don't generate and pray. Validate incrementally. Compile after each file. Lint after each component. The cost of catching an error in step 3 is one retry. The cost of catching it in step 15 is starting over.
Schema-driven generation is non-negotiable for API-heavy apps. If your model is guessing at API shapes, you'll spend more time fixing hallucinated endpoints than you saved by generating code. Feed it the actual types. Feed it the actual OpenAPI spec. Make it impossible for it to invent fields that don't exist.