5 min read

How I structure modern web apps

Web app architecture from production SaaS work: clients, APIs, data, auth, real-time sync and deployment boundaries that keep systems maintainable.

Layered web application architecture with browser clients, API services and data storage.

Architecture is not a diagram you draw once. It is the set of boundaries that let a team change one part of a product without breaking the rest. After building booking platforms, POS systems, marketplaces and mobile companions, the shapes I reach for are fewer than the buzzwords suggest.

This is the mental model I use when a new product starts — or when an existing one starts to hurt.

Advertisement

The five layers that actually matter

Almost every production system I work on separates into:

  1. Clients — web, mobile, sometimes partner portals
  2. Edge / delivery — CDN, reverse proxy, TLS, static assets
  3. Application API — business rules, auth, validation
  4. Data — primary database, cache, object storage
  5. Jobs / integrations — email, payments, webhooks, reports

If two of those layers share the same process “for speed,” you usually pay later with coupled deploys and unclear ownership.

Clients: one domain, multiple surfaces

IZYA is a useful example. Customers book on a client app. Professionals run a partner app. There are web dashboards around the same domain. The clients are different products. The domain (appointments, services, roles) is shared through an API.

That split avoids the trap of stuffing every role into one overloaded SPA. Each client can ship on its own schedule. The API remains the contract.

Rule of thumb:

  • Shared domain logic lives on the server
  • Clients own presentation and offline/UX concerns
  • Do not duplicate pricing, permissions or booking rules in three apps

API style: REST first, GraphQL when it earns its keep

Most of my backends are REST over HTTP with JSON. Mobile and web teams understand resources (/appointments, /services, /users/me). Status codes and pagination stay boring and debuggable.

I reach for GraphQL when many clients need very different slices of a wide graph and over-fetching becomes a real cost. I do not start there for a first MVP. A clean REST API with versioning discipline beats a half-designed schema.

A minimal API shape that ages well

POST   /auth/login
GET    /me
GET    /resources?cursor=&limit=
GET    /resources/:id
POST   /resources
PATCH  /resources/:id
DELETE /resources/:id

Add:

  • Idempotency keys for payments and booking creates
  • Consistent error bodies (code, message, details)
  • Request IDs in logs and responses for support

Auth and multi-tenant boundaries

SaaS products fail quietly when tenant isolation is an afterthought. Patterns that have worked for me:

  • Authenticate once (JWT or session), then authorize on every sensitive action
  • Role-based access for coarse roles (admin, partner, cashier)
  • Resource checks for “can this user touch this row?”
  • Row-level rules when the database can enforce them (Postgres RLS, carefully)

For consumer apps with partners (beauty, retail, logistics), never trust a businessId sent from the client without verifying membership server-side.

Data: pick the model for the access pattern

I have shipped MongoDB for flexible document workflows (profiles, catalogues that evolve weekly) and PostgreSQL when relationships and transactions dominate (orders, inventory, payments).

KioPOS needed strong consistency for stock and orders across terminals — PostgreSQL was the right centre of gravity. A content-heavy or rapidly changing catalogue can live happily in MongoDB if you are honest about the queries you will run.

Cache (Redis) sits beside the primary store for sessions, rate limits and hot reads — not as a second source of truth you invent on day one.

Real-time is a feature, not a default

Socket.io (or similar) earns its place when multiple devices must agree quickly: POS terminals, live order boards, collaborative dashboards. The pattern that kept KioPOS sane:

  • Write through the API (source of truth)
  • Broadcast events after a successful commit
  • Clients reconcile on reconnect instead of assuming the socket is perfect

If you only need “refresh every 30 seconds,” polling is simpler and cheaper.

Background work

Anything that can fail slowly should leave the request path:

  • invoice PDF generation
  • email / push notifications
  • image processing
  • third-party sync

A queue (even a simple one) protects user-facing latency. Returning 202 Accepted with a job id is often better product design than blocking a mobile client for eight seconds.

Deployment boundary

I treat “what ships together” as an architectural decision:

UnitShips whenTypical host
Marketing / docs siteContent changesStatic (Astro, Next static)
Web appUI releasesNode or static + API
APIDomain changesContainers on VPS / cloud
WorkersJob logic changesSame cluster, separate process

Blue-green or digest-pinned deploys (see my Docker/nginx and GitHub Actions articles) matter more once you have real users than which cloud logo is on the invoice.

A reference layout for a small SaaS

apps/
  web/          # Next.js or Vite React
  mobile/       # Expo / React Native
services/
  api/          # Node/Express or Django
  worker/       # queue consumers
packages/
  shared/       # types, zod schemas, UI tokens
infra/
  docker/
  ci/

Monorepo or polyrepo is secondary. Clear package boundaries are not.

Smells that mean the architecture is drifting

  • Business rules copied into mobile and web
  • Direct database access from the frontend
  • One deploy that must succeed for unrelated features
  • “God” services that know booking, billing and chat
  • No ownership of error budgets or request IDs

What I optimise for

Early: clear contracts and boring technology.
Growth: isolation between tenants, clients and deploys.
Scale: observability and back-pressure, not a rewrite for fashion.

What I would decide on a kickoff call

Before drawing boxes, I write down:

  • Clients in year one: web only, web + mobile, or mobile-first — that sets API ownership.
  • Tenancy model: single business vs many businesses on one install — that sets auth and data boundaries.
  • Source of truth for domain rules: always the API (or server), never duplicated in three clients.
  • Deploy units: what must roll back independently when booking works but marketing does not.
  • Real-time need: poll-first is the default; websockets only when a user-visible stale UI is unacceptable.

Modern web architecture is less about microservices slogans and more about honest boundaries. Draw those early, keep them visible in the repo, and the product can grow without becoming a single fragile ball of JavaScript.