Define feature module boundaries
Separate a business feature from its implementation details
A feature module groups the behavior needed for a user-facing capability, such as viewing orders, rather than grouping every file by extension. A boundary defines which inputs, outputs and dependencies other modules may use. A modular application can still ship as one bundle or deployment. Start with a fictional operations dashboard: two orders, one open for 1,250 cents and one closed for 900 cents. The open-order summary should show one order and $12.50. The following three files form a small feature fixture; React 18+ and a TSX-capable workspace are proposed, not installed here.
export function summarizeOrders(orders) { let open = 0, totalCents = 0; for (const order of orders) { if (!Number.isSafeInteger(order.cents) || order.cents < 0 || !['open','closed'].includes(order.status)) throw new TypeError('Invalid order'); if (order.status === 'open') { open += 1; totalCents += order.cents; if (!Number.isSafeInteger(totalCents)) throw new RangeError('Total exceeds safe integer range'); } } return {open, totalCents};}The domain function accepts plain data and returns a small summary. It validates the status and amount, adds only open orders and rejects an unsafe integer total. It does not import React, access a global store or call a server. An empty list produces zero orders and zero cents. Integer cents avoid repeated fractional addition; the sample currency is USD and the input is assumed to have already been normalized to cents.
Introduce a data adapter
export function createOrderService(repository) { return { async list() { const rows = await repository.list(); return rows.map(({id, cents, status}) => ({id, cents, status})); } };}export function createMemoryRepository(rows) { const snapshot = rows.map(row => ({...row})); return {async list() { return snapshot.map(row => ({...row})); }};}The repository is any object with an asynchronous list method returning order records. The service projects only the required fields. The in-memory implementation copies its flat records so two independently created repositories do not share mutable state. A real repository would validate untrusted responses, authenticate requests and enforce access on the server. Projection is not authorization. The sample intentionally has no external API.
Keep rendering focused on presentation
import React from 'react';import {summarizeOrders} from './domain.mjs';export function OrderSummary({orders}) { const {open,totalCents}=summarizeOrders(orders); return <section aria-label="Order summary"> <h2>Open orders</h2><p>{open} orders</p> <p>{new Intl.NumberFormat('en-US',{style:'currency',currency:'USD'}).format(totalCents/100)}</p> </section>;}The component accepts orders, calculates the summary and formats the result. It can be rendered with different props without constructing a repository. A route module can coordinate the feature, data loading and navigation while a shared UI package supplies generic buttons and fields. A vertical slice groups order-related domain, data and UI files; a horizontal layered layout groups all domain files together; a modular monolith combines explicit feature boundaries with one coordinated release. Choose based on change patterns and ownership, not folder fashion. For a small feature start with a few files, extract a boundary only when the responsibilities diverge. Avoid a generic shared directory that becomes a dumping ground. Practice: sketch an inventory feature and identify which data and functions it should expose.