Draining the kitchen sink

Why broad domain modules become dumping grounds for unrelated code, and how decoupling the consumption site keeps consumers minimal and resilient.

By Eyal Ellenbogen October 8, 2026 5 min read

Shared abstractions make sense. When building an app, we naturally create an "auth", "billing", or "workspace" service to handle a couple of clear operations like signing in or checking session status. Over time, however, that same container becomes our default destination for user profile queries, role parsing, token refresh lifecycles, and permission checks.

Gathering domain plumbing in one place isn't inherently broken. The trap is when we expose that container directly as our public contract, forcing every consumer to depend on the entire kitchen sink.

In Angular, this pattern usually takes the form of a familiar root service:

@Injectable({ providedIn: 'root' })
export class AuthService {
	readonly user: Signal<User | null>
	login(credentials: Credentials): Promise<void>
	logout(): Promise<void>
	refreshToken(): Promise<void>
	hasPermission(permission: string): boolean
}

Grouping these operations in one place is convenient, but exposing them on a single injectable surface binds completely different lifecycles and consumer sets to the same contract.

Different concerns, shared surface

Whether managing authentication, billing, or workspace settings, a single public surface almost always bundles three fundamentally different kinds of work:

  • Commands with side effects: operations that initiate network requests, mutate remote data, or trigger route transitions (like login or logout). Yet even within this category, consumers rarely overlap. An unauthenticated login screen has no reason to import session teardown.
  • Core state: signals or observable data representing the primary entity or model (like the active user), consumed by navigational shells, headers, and profile displays.
  • Derived computations: pure evaluations that read existing state without triggering actions (like hasPermission or quota checks), consumed by feature views to enable actions or render conditional UI.

When we, as consumers, inject that single service for one of these concerns, we inherit dependencies we do not need. This runs counter to building components with clear responsibilities. A feature view such as a ReportsView might only need to verify whether the active account can generate an export:

@Component({
	selector: 'reports-view',
	template: `
		<section class="reports">
			<h1>Reports</h1>
			@if (canExport()) {
				<button (click)="exportReport()">Export</button>
			}
		</section>
	`,
})
export class ReportsView {
	private readonly auth = inject(AuthService)
	protected readonly canExport = computed(() => this.auth.hasPermission('reports:export'))

	protected exportReport(): void {
		// report generation logic
	}
}

The view requires a simple boolean evaluation, yet its contract is coupled to full session orchestration, including token refresh mechanics and credential submission.

Bundling setup, isolating consumption

The obvious response is to break the service apart. But if every split means another service or token to register manually, we've just traded a coupling problem for an ergonomics one.

Instead, we can bundle the wiring behind a single setup function and expose focused helpers for consumers:

// Private tokens: encapsulated and unexported
const SESSION_USER = new InjectionToken<Signal<User | null>>('SESSION_USER')
const LOGIN_COMMAND = new InjectionToken<(credentials: Credentials) => Promise<void>>('LOGIN_COMMAND')

// The bundle: wiring internal plumbing behind a single setup function
export function provideAuth(config: AuthConfig): EnvironmentProviders {
	return makeEnvironmentProviders([
		/* provide the tokens above, composed from internal services
		   like SessionStore and AuthClient */
	])
}

// Focused entry points for consumers
export const injectUser = () => inject(SESSION_USER)
export const injectLogin = () => inject(LOGIN_COMMAND)

export function injectHasPermission(permission: string): Signal<boolean> {
	const user = inject(SESSION_USER)
	return computed(() => user()?.roles.includes(permission) ?? false)
}

The application root wires the feature once with provideAuth(config), mirroring the idiom established by Angular APIs such as provideRouter.

Crucially, the tokens still exist, but they are no longer part of the public surface. The internal implementation can use focused classes or services, such as SessionStore and AuthClient, and none of them are exported. What changes is exposure. provideAuth registers them internally, while the exported inject* functions project or adapt only the narrow slices that consumers need. The internal plumbing stays encapsulated inside the provider.

Consumers then declare only the slice of the contract they actually evaluate:

export class ReportsView {
	protected readonly canExport = injectHasPermission('reports:export')
}

By decoupling consumption, the view no longer holds references to session lifecycle methods.

The command side reaps the exact same benefit. An unauthenticated dialog that initiates a sign-in only needs a trigger, not session teardown or permissions:

@Component({
	selector: 'login-dialog',
	template: `<button (click)="signIn()">Sign In</button>`,
})
export class LoginDialog {
	private readonly login = injectLogin()
	protected credentials: Credentials = { username: '', password: '' }

	protected signIn(): void {
		this.login(this.credentials)
	}
}

Neither component knows the other exists. ReportsView depends on a derived evaluation; LoginDialog depends on an action invocation. They cannot accidentally cross-contaminate each other or force shared refactors.

This is the Interface Segregation Principle (ISP) applied directly to UI architecture, where clients should not be forced to depend on methods they do not use. In modern frontend development, ISP does not require engineering vast class hierarchies or splitting abstract interfaces. It simply means shaping consumption entry points around what each consumer actually touches.

The testing dividend

Test setup should match the real dependency, not the whole neighborhood it lives in. As explored in testing a feature without the host, when consumption is decoupled from the kitchen sink, tests only satisfy the specific state a view actually reads, without maintaining mock factories for methods it never touches.

The same balance in other ecosystems

In React, wrapping authentication in a single useAuth() context creates the same coupling, and the framework makes the cost visible as every consumer re-renders when any field on the value changes, whether or not it reads that field. A ReportsView that only checks canExport is invalidated by a token refresh.

We can fix it with the same shape: wrap setup in one provider, split the internal contexts, and expose narrow hooks (useUser(), useLogin(), useHasPermission()). The render behavior improves as a side effect of the boundary improving, not as the goal.

Keeping the boundary intentional

At the end of the day, this is about protecting consumers and isolating components, not splitting code into microscopic pieces for the sake of it. If a capability is genuinely cohesive and its consumers use it together, leave it whole. How we wire the underlying pieces together internally should remain an implementation detail; consumers only need to see the narrow slices they actually use.

When we separate feature setup from consumption, we keep contracts minimal, test setups trivial, and our codebase resilient to everyday change.