Playbook

Feature architecture

The Third Wave Coffee app is organised as 38 features. These are the rules I set for it, and what each one costs.

Features first. The code is organised by feature, not by kind of file: the menu’s data, logic and screens live under the menu. Finding the code behind a screen starts in one folder. The cost is that shared code needs a deliberate home, or features start reaching into each other.

Layers are earned. 28 of the 38 features are split into data, domain and presentation. The other ten are smaller on purpose: some are UI only, some are logic with no screen of their own. A screen with no logic gains nothing from three layers but extra files.

Each section loads on its own. The home page fetches only a skeleton from the server: an ordered list of section names. Each section has its own bloc, starts its own request and shows its own loading state; if one fails, it steps aside and the rest of the page carries on. A section name the app does not recognise renders nothing, so the server can add a new type without breaking older versions. The cost is one request per section instead of one per page.

Choose where each bloc lives. Most blocs are lazy providers at the app root, so the page can coordinate them. Some screens, like the wallet, create their own and close them on the way out, and small widgets like product rows own theirs. I wrote about the trade-offs in Where a BLoC should live.

Wire it by hand. Dependencies are registered with get_it, written by hand: one injection file per feature, in one folder, called in order by a single container. It reads top to bottom with no code generation. The cost: forget to register something and the app still compiles. It only fails when a screen first asks for it.

Cross-cutting concerns live in one place. HTTP clients are Retrofit on Dio, one per backend base URL, all sharing the same interceptors: request headers, a forced logout when the session expires, and a response cache backed by Hive. Anything sensitive goes in secure storage.

Tune outside the build. Values that need adjusting, like a polling interval or how often to ask for a rating, live in Firebase Remote Config, so they change without a release.