Section650

Writing

TopicArchitecture
Reading7 min

Do You Need a UI Mockup Before Building the Backend?

Wait for a rough wireframe, not a polished mockup. Write the API contract from it, model the data on the domain, and build the React frontend and the Python backend at the same time.

By Ka Lun Chan · Architecture / Delivery

Do you need a UI mockup before building the backend?

You need a rough one, not a polished one. Wait for a wireframe that shows the screens and the fields on them, then write the API contract from it. Once the contract exists, the React frontend and the Python backend can be built at the same time, and neither side has to guess what the other needs.

Colors, spacing and copy change constantly, and almost none of it touches the API. What the backend needs from design is a list of screens, what each one shows, and what the user can do there. A whiteboard sketch usually answers that.

Three things support that answer:

  1. Building the backend on a guess usually means building parts of it twice.
  2. Once the API contract is written, both sides can start.
  3. The database should be modeled on the domain. The screens only shape the API responses.

What does it cost to build the backend first and guess?

A round of rework for every gap. Endpoints built around what the UI might need come up short when the real screens arrive, and each missing field becomes a request, a fix and a wait.

The usual pattern is that the backend starts first because the design isn’t ready. When the frontend arrives, a field is missing, a list needs a filter nobody planned, or one screen needs data from three endpoints.

LaunchDarkly’s write-up on contract-first design describes exactly this: a frontend developer finds that an endpoint lacks a field the UI needs, the backend developer fixes it the next day, and the back and forth stretches over a couple of weeks. Its conclusion is that the missing piece was an API contract agreed before implementation started.

Each fix is cheap on its own. The cost is the loop. Every round trip blocks someone for a day, and the API ends up shaped by whichever screen complained last.

What is contract-first API design?

Contract-first API design, also called design-first or schema-first, means defining the API’s interface before writing application code. In practice that’s an OpenAPI file with the endpoints, request and response shapes, error formats and an example response for each one.

Phil Sturgeon’s guide to API design-first lists what that buys you:

  • Frontend and backend can work in parallel, because both build against the same document from the start.
  • Feedback comes early. A mock server can serve the example responses straight from the spec, so people can click through the UI before an endpoint exists.
  • There’s less hand-written glue, since docs, client code and parts of the implementation can be generated from the spec.

The part I value most is the review. The frontend developer can read the contract and confirm the data they need will be there before anyone writes the endpoint. Reading a contract is quick. Finding the same gap after the endpoint ships costs another round trip.

Where does the wireframe fit?

The wireframe is an input to the API contract and can be drawn while the contract is sketched. It doesn’t have to be finished before the API work starts.

Parth Infotech’s guide on where to start enterprise builds suggests this order:

  1. Sketch the domain: the entities, how they relate and the rules that must always hold.
  2. Sketch the API contract, with UI wireframes drawn alongside it.
  3. Finalize the database schema once the contract is clear.
  4. Build the backend and frontend in parallel against the contract.

The same guide describes three starting points. UI-first designs the API to serve the screens and the database to serve the API. API-first treats the contract as the source of truth. Database-first treats the API as a projection of the data model. Each fits a different project. Database-first earns its place in domains like finance or logistics, where the data and its validation rules are the product. UI-first is fine for a prototype you expect to throw away, which is the case for validating an idea before building it properly. For most product work, I’d start from the domain and the contract.

Wait for a polished, clickable prototype only when the interaction itself is the uncertain part, such as a drag-and-drop planner or a multi-step flow where you don’t yet know which steps exist. Then the screens really do change what the API has to do, and a prototype is cheaper than a reworked contract.

Should the database schema come from the UI?

No. Model the database on the domain, then check that it can serve each screen’s API response efficiently. Tables designed from screens copy today’s layout and turn the next redesign into a migration.

UI-first work tends to do the most damage here. A dashboard card becomes a table, a wizard step becomes a group of columns, and the schema ends up describing a layout instead of the business.

An order, a customer and a shipment exist whatever the screens look like, so model those. Then walk through the contract endpoint by endpoint and look for:

  • Responses that join many tables on every request, which may justify a view, a read model or a cached projection.
  • Lists that filter or sort on a column with no index.
  • Nested responses that will turn into N+1 queries in the ORM.

If a screen can’t be served efficiently from a sound domain model, raise it with the frontend as a design question before bending the schema around one screen.

One call per screen, and when do you need a Backend for Frontend?

On first load, a screen should usually make one request and get back what it shows. A separate Backend for Frontend (BFF) service is worth it when several kinds of client need different APIs. For one web frontend, a few screen-shaped endpoints in the existing backend do the same job.

Microsoft’s Azure Architecture Center describes the BFF pattern as a separate backend service for each frontend interface, instead of one general-purpose backend for all of them. Sam Newman, who wrote up the pattern, prefers one BFF per type of client and credits the guideline “one experience, one BFF.” One per experience, such as web, mobile or a partner integration, keeps it from turning into a backend per screen.

Both are clear that it isn’t always worth it. Microsoft says the pattern may not fit when only one interface talks to the backend, or when the interfaces make similar requests. Newman says that for a web-only UI, a BFF makes sense only once the server has a significant amount of aggregation to do.

So for a small app with one React frontend, you probably don’t need a separate BFF service. Screen-shaped endpoints in the same Python backend give you the benefit without another service to deploy, monitor and keep in sync.

A workflow you can start this week

Fig. 747-1 A rough wireframe, one contract, three tracks in parallelEach track builds against the same OpenAPI file.

Wireframe and domain sketch become the API contract, with example responses

  • FrontendReact app built against a mock server and TypeScript types generated from the contractBuilds on the examples
  • BackendPython endpoints, tested against the spec in CIMust match the contract
  • DataSchema modeled on the domain, checked against each endpointServes the contract

Review the contract against real screens, then lock it

A change any track needs goes into the contract first.

  1. List the screens. For each one, write down the fields it shows and the actions the user can take. A wireframe or a shared doc is enough, and a clear user story often has most of it already.
  2. Write the OpenAPI contract with an example JSON response per screen. Keep it in the repository next to the code, so changes go through review like any other change.
  3. Mock it and build the UI. Serve the examples with a mock server such as Prism, and generate TypeScript types for the React app with a tool like openapi-typescript, so the frontend compiles against the contract.
  4. Implement the backend and test it against the spec. Schemathesis, for example, generates requests from the OpenAPI file and checks that the Python API’s responses match it.
  5. Draft the data model from the domain, then walk the contract endpoint by endpoint to check the model can serve it efficiently.
  6. Review the contract once real screens exist, then lock it. From there, run a breaking-change check such as oasdiff in CI so nobody changes a response shape by accident.

One caveat for Python teams. FastAPI generates the OpenAPI document from your code, so it’s code-first by default. You can still work contract-first with it: write the Pydantic request and response models first, agree on them in review, commit the generated openapi.json, and have CI fail when the generated file drifts from the committed one. The models become the contract.

Sources

Checked in November against LaunchDarkly, APIs You Won’t Hate, Parth Infotech, Microsoft’s Azure Architecture Center and Sam Newman’s pattern write-up. LaunchDarkly and Parth Infotech are vendor posts, so I use them for definitions and practice rather than evidence of outcomes. The workflow, the database checks and the opinions are mine.

Short answers

Should the frontend or the backend start first?

Neither should start alone. Agree the API contract from a rough wireframe first, then build the frontend against a mock server and the backend against the contract at the same time.

Do I need a polished UI mockup before writing the API?

No. A wireframe that lists each screen’s fields and actions is enough to write the API contract. Wait for a high-fidelity prototype only when the interaction itself is uncertain, because that’s when the screens change what the API has to do.

Do I need a Backend for Frontend (BFF) for a small app?

Usually not. With a single web frontend, a few screen-shaped endpoints in the existing backend give the same one-request-per-screen benefit. Microsoft and Sam Newman both suggest a separate BFF when several client types need different APIs or the server has to aggregate a lot of data.

Can I use FastAPI’s generated OpenAPI as the contract?

Yes, if you design the Pydantic models first and treat them as the contract. Commit the generated openapi.json and fail CI when it changes unexpectedly, so the contract is reviewed rather than whatever the code happens to produce.

Before the first endpoint

Can the frontend developer read the contract and point to every field each screen needs? If they can, both sides can start. If they can’t, fix the contract first, because that’s the cheapest place to find the gap.

Tell me what you’re building