{"canonical_url":"https://engineer.company/glossary/frontend/","content_markdown":"# Frontend\n\n## What it is\n\nA frontend is the part of a software system that people look at and operate: the pages, screens,\nforms and controls, along with the code that draws them and responds to input. It is also written\nfront end or front-end, and on the web the same territory is often called the client side.\n\nOn the web, a frontend is assembled from three languages a browser understands. HTML gives a page\nits structure and meaning, CSS decides how it looks, and JavaScript adds behaviour. The browser is\nwhat the W3C's Architecture of the World Wide Web calls a user agent, software acting on behalf of a\nperson, which retrieves data from servers and presents it. Everything a frontend sends to it ends up\non a device that belongs to someone else.\n\nIts partner is the backend, which stores data, applies the business rules and answers requests. The\ntwo talk over HTTP, usually through an API. It is tempting to draw the line between them where the\nnetwork is, but current frameworks blur it. In Next.js, pages and layouts are\n[Server Components](https://react.dev/reference/rsc/server-components) by default: they produce\nwhat the user sees and execute on a server. A `\"use client\"` directive at the top of a file marks\nthe boundary, and that file, its imports and the components it renders join the bundle sent to the\nbrowser. What makes code frontend is its job, presentation and interaction, and where it executes\nis a separate decision.\n\n## Why it matters\n\nThe first decision is where the work happens. The W3C architecture document describes a spectrum\nwith the client doing everything at one end and the server doing everything at the other, and\nobserves that most designs combine the two. Where an application belongs depends, in the document's\nterms, on the power of the client, the power and load of the server, and the bandwidth between them.\nIt names the trade-off from both sides: tailoring content on the server lowers caching efficiency,\nand when the number of possible clients is unbounded, pushing computation out to them scales better.\nThe usual positions are pages built once, pages rendered on a server per request, pages assembled in\nthe browser, and mixtures of these. A page that is the same for everyone is cheapest built once and\ncached. A page showing one customer's data is rendered per request somewhere, and choosing the\nbrowser means every reader downloads the code that does it.\n\nThe second decision is how far to trust it, and the working answer is that the server trusts none of\nit. Everything a frontend delivers can be read, edited and replayed by the person holding the\nbrowser. A hidden button or a form that refuses to submit is a courtesy to an honest user and a\nminor detour for anyone else, so every permission and validation that matters is repeated on the\nserver. Secrets follow the same rule: an API key that reaches the bundle is public, whatever the\nvariable is called. Content Security Policy narrows what an injected script can do, and its\nspecification presents it as defence in depth, never a substitute for validating input and encoding\noutput carefully.\n\nThe frontend is also where accessibility is won or lost. WCAG 2.2, the W3C Recommendation published\nin December 2024, sets testable success criteria, and many of them turn on frontend choices: whether\na control can be reached and operated from a keyboard and whether it exposes a name and a role to\nassistive technology. Native HTML elements meet several of them out of the box, and a custom widget\nhas to rebuild each one by hand.\n\nFinally, a frontend that knows how the database stores things has to change whenever the database\ndoes, while one that keeps to presentation lets each side move at its own pace.\n\n## What it looks like in practice\n\nWhere a frontend renders is decided part by part on one platform, whose Next.js 16 frontend\n[chooses a rendering mode for each part of the app](/portfolio/built-the-next-js-16-frontend-ssr-ssg-and-csr/).\nMarketing and public pages are generated statically, and the interactive parts are rendered in the\nbrowser. On the authenticated dashboard and the large directory listings, where the N+1 pattern\nturned one page into a cascade of round trips, a factory called `createPrefetchedServerPage` fetches\na page's data on the server and hands it to the client already filled in, and a cache-invalidation\nstrategy is documented for each data request. A page moved onto the factory loads in one round trip,\nand the next one to move inherits that behaviour. The migration is still in progress, with the rest\nof the authenticated app rendered on the client and queued behind it.\n\nThe founder's architecture contribution under NextMariner, a maritime platform,\n[gives its frontend one job and nothing else](/portfolio/a-maritime-platform-built-in-clean-layers/).\nThe Next.js frontend handles presentation and interactivity. A deliberately thin Go API, built with\nHuma over Fiber, routes and validates requests, applies security filtering and orchestrates, while\nthe business logic lives in PostgreSQL functions. The design puts a business-rule change in one\nlayer, in SQL, instead of requiring the same rule in all three. The boundaries were written down\nand then enforced in code review. The recorded result is that presentation, request handling and\nbusiness rules have separate responsibilities.\n\nThe work of hardening an application\n[starts from the assumption that the client is hostile](/portfolio/hardened-the-application-with-nonce-based-csp/).\nOn the frontend, the Next.js proxy middleware in `proxy.ts` sets a Content Security Policy with a\nnonce generated per request and `strict-dynamic`, along with HSTS and SameSite cookies. The boundary\nitself sits on the server. Entitlements, covering tier, role, organization and ship scoping, are\nchecked again on the server for every request, and the frontend's gates count as user experience\nonly: they shape what a person sees, and the server settles what that person may do.\n\n## Where it goes wrong\n\nFrontend failures tend to share a cause: something was decided in the browser that belonged on the\nserver, or the other way round.\n\n**An API key shows up in the JavaScript any visitor can download.** In Next.js, an environment\nvariable reaches the browser bundle only when its name starts with `NEXT_PUBLIC_`, and any other\nvariable read from client code is replaced with an empty string. A request that comes back\nunauthorised, followed by a quick rename to make it work, inlines the secret into a public file.\nKeep code that needs a secret on the server, and mark its module with the `server-only` package so\nthat importing it from a Client Component fails the build. Rotate any key that has already shipped.\n\n```ts\nimport \"server-only\";\nexport async function getInvoices(customerId: string) {\n    const url = `${process.env.BILLING_URL}/customers/${customerId}/invoices`;\n    const headers = { Authorization: `Bearer ${process.env.BILLING_KEY}` };\n    const res = await fetch(url, { headers });\n    return res.json();\n}\n```\n\n**A user reaches records the interface had hidden from them.** The permission check lived in the\nfrontend, as a route guard, a hidden menu entry or a disabled button. Anyone who reads the network\ntraffic can call the API directly with other parameters. Check every entitlement on the server for\nevery request, against the signed-in user and the specific record, and treat the frontend's checks\nas a convenience for honest users.\n\n**The page fills in one spinner at a time.** Each component fetches its own data after it renders,\nso a child's request waits for its parent's and the page arrives as a waterfall of round trips.\nFetch a page's data together and close to its source, on the server where the framework allows, and\npass it down.\n\n**Keyboard and screen-reader users get stuck on a custom control.** A clickable `div` gets the mouse\nbehaviour of a button and none of the rest: it takes no focus, ignores Enter and Space, and tells\nassistive technology nothing about what it is. WCAG 2.2 asks at level A that a keyboard can operate\nall functionality (success criterion 2.1.1) and that every component expose its name and role\n(4.1.2). Use `button`, `a`, `input` and `label` for what they are, and try each new screen with the\nkeyboard alone before it ships.\n\n## Further reading\n\n- [Architecture of the World Wide Web, Volume One](https://www.w3.org/TR/webarch/) — the W3C\n  Recommendation on user agents and on splitting work between client and server.\n- [HTML Standard](https://html.spec.whatwg.org/multipage/) — the WHATWG living standard for the\n  elements and browser APIs a web frontend is built from.\n- [Web Content Accessibility Guidelines (WCAG) 2.2](https://www.w3.org/TR/WCAG22/) — the W3C\n  Recommendation with the testable success criteria behind an accessible interface.\n- [Content Security Policy Level 3](https://www.w3.org/TR/CSP3/) — the W3C Working Draft that\n  defines nonces and `strict-dynamic`.\n- [Next.js: Server and Client Components](https://nextjs.org/docs/app/getting-started/server-and-client-components)\n  — how one framework divides a frontend's code between server and browser.\n\n\u003chttps://engineer.company/glossary/frontend/\u003e\n","date_modified":"2026-11-08T02:22:23Z","description":"What a frontend does, how to split rendering between the server and the browser, why the server re-checks what it allows, and where frontends break.","formats":{"gemtext":"https://engineer.company/glossary/frontend/index.gmi","gopher":"https://engineer.company/glossary/frontend/gophermap","html":"https://engineer.company/glossary/frontend/","json":"https://engineer.company/glossary/frontend/index.json","markdown":"https://engineer.company/glossary/frontend/index.md","pdf":"https://engineer.company/glossary/frontend/index.pdf"},"kind":"page","language":"en","title":"What is a frontend?","url":"https://engineer.company/glossary/frontend/","version":1}