Files

27 lines
4.3 KiB
Markdown

# Frontend principles
Applies to a project with a browser frontend.
General principles (KISS, DRY, …) live in `technical-principles.md` and apply here too.
## Foundational stances
| Principle | Explanation |
|-----------|-------------|
| Backend-agnostic | Tight coupling between front- and backend causes duplicated work. **Why?** The front- and/or backend should be replaceable independently of each other, to allow us to improve and/or modernize incrementally. |
| Prefer state in the URL first, backend second | State can be managed in the backend, in the URL, and in the browser (e.g. JavaScript memory, local storage, etc). We want to limit state management in the browser as much as possible and focus on the backend and the URL. **Why?** Working with state in the browser is difficult from a development perspective. It is not intuitive that the same URL yields different results on different devices or even different tabs. Centralized state can be shared across multiple separate frontends. |
| Prefer backend-based business logic | Centralized logic can be consumed by multiple separate frontends and minimizes duplication. **Why?** To avoid distributing logic and risking that different rules apply to the same thing, depending on where in the system it is done. |
| CSS > JavaScript | If something can be solved with CSS, solve it with CSS. If you can negotiate with product to achieve the same functionality in a way that can be solved with CSS instead of JavaScript, solve it with CSS. **Why?** CSS is significantly more performant than JS. CSS is declarative in contrast to JS, which makes it much more robust against bugs and issues. |
| Prefer established web standards over custom solutions | For example, use an HTML select instead of a cool library that renders a similar-looking select out of divs and CSS. HTML and CSS are managed by a committee that thinks long and hard before anything changes. Things are deprecated for years before they stop working, if they ever do. **Why?** Standards will always outlive the week's hottest framework and give us a more stable foundation to build on. Upgrading an entire framework is usually significantly more cumbersome than upgrading a single library. Frameworks push us toward doing what they want us to do rather than what we want to do ourselves. |
| Use semantic HTML | Use HTML elements for their meaning (`<button>`, `<nav>`, `<table>`, `<label>`), not `<div>`/`<span>` with behavior bolted on. **Why?** Semantic markup gives accessibility, keyboard support, and correct browser behavior for free, and reinforces "prefer established web standards" and "broad device support". |
## Quality attributes
| Principle | Explanation |
|-----------|-------------|
| Intuitive > Interactive, Functional > Fancy | Somewhat presumptuously, one can note that the users of our system are not very technically advanced. It is more important that it is clearly evident how the system works than that it is interactive and "modern". **Why?** We build and deliver our customers' primary business systems. A beautiful/fancy system that does not work has a massive impact on the customers' workday. |
| Testability | For example, by thinking about how a frontend should be optimally tested from the very beginning. **Why?** Good testability leads to fewer bugs, safer updates, and faster development. It also makes it easier for new developers to understand and contribute to the codebase. |
| Important features should have broad device support | Where interactivity and "fancy things" are implemented — and are part of an important flow — it should be done as progressive enhancement and be able to fall back to something that works even on devices that are not the latest model/version. Many of our field customers have rather poor hardware. **Why?** So that as many people as possible can use our system. |
| Responsive design | Functional in "all" screen sizes. Responsiveness should not be an afterthought but a focus from the start. **Why?** The use of handheld devices is constantly increasing. Our users are using more and more different devices to access our systems. |
| Consistent design | Use uniform components, colors, and typography. Creates recognition and a professional impression. **Why?** To not waste energy on non-value-creating discussions. Makes the system easier to maintain and avoids spending energy on non-value-creating development. |