In a modular second-hand marketplace mobile app, how should the listing feature open checkout without importing the checkout feature's screen?
answer
- a route is an interface
- contract module, not implementation
- the app shell maps routes to screens
- typed IDs, never objects
- public URLs outlive releases
basics
~20 sThrough a route contract: checkout publishes a small route type, checkout with a listing ID, in a contract module both features depend on, and the app shell maps routes to screens. Features exchange IDs, never screens or objects.
solid answer
~50 sImporting checkout's screen ties the listing feature to checkout's implementation: any change there rebuilds the listing feature, and as soon as checkout needs to link back to a listing the two depend on each other. Instead, treat a **route as an interface**. Checkout declares `checkout(listingId)` in a small **contract module** that holds no screens or logic; the listing feature depends only on that and asks the navigator for the route. The **app shell**, which owns the navigation graph and composes the features, is the only place that maps each route to the screen that implements it. Arguments are typed IDs, so a missing or wrong argument fails at build time, and the destination loads its data itself. The link and notification resolvers produce the same route types, so external entry points need no extra mapping. Public URL patterns outlive every release, so a path that has shipped keeps resolving.
code
pseudocode · 11 lines// checkout contract module: route declarations only
route Checkout(listingId: ID)
// listing feature depends on the contract, not on checkout's screens
function onBuyTapped(listing):
navigator.go(Checkout(listing.id))
// app shell: the only place that knows both sides
registry.register(Checkout, args -> checkoutScreen(args.listingId))
linkResolver.map("/l/{listingId}/buy", p -> Checkout(p.listingId)) // original path, kept
linkResolver.map("/item/{listingId}/buy", p -> Checkout(p.listingId)) // new pathgo deeper
Recall that one feature opens another by asking for a route with an ID, not by creating the other feature's screen itself.
Explain the contract module, the app shell's registry and why typed ID arguments catch mistakes at build time that string routes only reveal at runtime.
Show the long-lived consequences: public URL patterns that must keep resolving, links that only open screens, and one resolver feeding links and notifications into the same routes.
Set the team-wide rule and its cost: route contracts add a module per feature, which pays off with many teams and may be ceremony for a small app.
## The problem with importing a screen In a modular app, each feature, browse, listing, checkout, offers, lives in its own module, often owned by its own team. Sooner or later one feature must open another: the listing screen has a *Buy* button that opens checkout, and checkout shows a link back to the listing. The shortcut is to import the other feature's screen and construct it. That shortcut has three costs: - **Coupling to an implementation**: the listing feature now depends on checkout's internals, so every change to checkout rebuilds the listing feature, and a refactor in one team breaks another team's code. - **Cycles**: checkout links back to the listing, so the two features now need each other, which a clean module graph cannot express. - **Lost entry points**: a screen opened by a direct call is invisible to the link and notification resolvers, so the same destination ends up reachable two different ways with two different stacks. ## A route contract The alternative is to treat a **route as an interface** between features: | Approach | Coupling | How mistakes surface | |---|---|---| | Import the other feature's screen | To its implementation | Build breaks across teams; cycles | | Plain string routes such as `"checkout/123"` | None at build time | A typo or a renamed argument fails only at runtime | | **Typed route contracts in a contract module** | To a small, stable interface | Missing or mistyped arguments fail at build time | In the contract approach, checkout publishes a tiny **contract module** containing only route declarations, `checkout(listingId)`, and perhaps the result it can return. No screens, no logic. The listing feature depends on that module alone. Because the contract changes rarely, changes inside checkout no longer rebuild its callers, the same effect an API module has for any other dependency. ## Who owns what - **Each feature** owns its screens and declares the routes it accepts. - **The contract module** owns route names and argument types, nothing else. - **The app shell**, the module that owns the navigation graph and composes the features, is the only place that knows both sides: it registers which screen implements each route. It acts as the mediator between features that must not know each other. - **The entry-point resolver** in the app shell maps external URLs and notification payloads onto the same route types. Which module may depend on which, and how a large team enforces that, is the module-graph design; this question keeps the route as the thing that crosses the boundary. ## IDs, not objects A route argument is an **identifier**, `listingId`, never the listing object. Passing objects between features ties both to one model and creates a second copy of data that goes stale; passing an ID lets checkout load the listing from the shared data layer, which stays the single source of truth. It also keeps routes small enough to serialise, save and log. ## Public links are a contract you cannot recall Internal route names can be renamed in one release, because every caller ships in the same binary. **Public URL patterns cannot**: a link to `/l/123` pasted into a message last year will be tapped next year, by a build that may be newer or older than the one that created it. So: 1. Treat every shipped path pattern as permanent; when a path is renamed, keep the old pattern mapping to the same route. 2. Validate every parameter in the resolver and discard malformed links. 3. Let a route **open** a screen, never **perform** an action: one platform's guidance warns against letting a link delete content or reveal sensitive information directly. Accepting an offer happens on a screen the user confirms. 4. Give unknown paths a defined fallback, the start destination, rather than an error. ## A rule a team can hold The shape that survives many teams is short: features talk to each other only through routes; routes carry typed IDs; the app shell maps routes to screens; and every external entry point resolves to a route before anything is drawn.
- Why not use plain string routes like "checkout/123" and skip the contract module altogether?Strings remove the build-time dependency but also the build-time check. A typo, a renamed argument or a missing ID compiles fine and fails only when a user reaches that path, possibly through a rarely used link. For a small app that trade can be acceptable; across many teams, typed contracts turn those runtime surprises into build errors the owning team sees first.
- A product manager wants the listing URL path renamed from /l/ to /item/; what must stay in place?The old pattern. Links with /l/ already sit in messages, emails and search results, and installed builds of every age will receive them. The resolver maps both patterns to the same route, so old links keep working while new ones use the new path. Removing a shipped public path is a breaking change with no way to update the senders.
- Should a link be allowed to accept an offer directly, without opening a screen?No. Anyone can craft a URL and send it to a seller, so a link that performs an action is an attack surface. A route should only open a screen; the offer screen shows the current offer and the seller confirms. One platform's guidance says the same: validate link parameters and never let a link delete content or reveal sensitive information directly.
- Features can import each other's screens; cycles are only a build-tool problem.
- Pass the listing object in the route so checkout skips a fetch.
- Public URL paths can be renamed freely because the new release ships the mapping.
- A link route may perform an action directly, such as accepting an offer.
- Each feature should register its own routes with links when its screen first loads.