Typorithm · easy

Modular Architecture

modular-architecturearchitecturemodulesencapsulationpublic-api
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Modular Architecture

0%

App Patterns

A module exposes a small public API through a barrel index and keeps its helpers private. Re-export only what callers need; everything else stays an internal detail, giving low coupling and high cohesion.

A module groups related code behind a clear boundary: a public API that callers use, and internals that nobody outside should touch.

A barrel index.ts is that boundary — it re-exports only the public surface, like createUser and the User type, while validate and hash stay unexported and therefore private.

Hiding internals keeps coupling low (consumers depend only on the stable API) and cohesion high (everything inside the module works toward one purpose).

01

The barrel re-exports only the public API.

02

Unexported helpers stay private internals.

03

Low coupling, high cohesion follow from the boundary.

// index.ts — the module's barrel: only the public surface
export { createUser } from "./create-user";
export type { User } from "./types";
// helpers like ./validate and ./hash stay private

Read the implementation

Connect each part of the code to the concept before you type.

1. Barrel file

A barrel index.ts is the single entry point; it defines exactly what the module exposes.

// index.ts — the module's barrel: only the public surface

2. Re-export the public function

Only createUser is re-exported, so it becomes part of the module's public API.

export { createUser } from "./create-user";

3. Re-export the public type

The User type is published too, while its internal construction stays hidden.

export type { User } from "./types";

4. Hidden internals

Files not re-exported from the barrel remain implementation details no consumer can reach.

// helpers like ./validate and ./hash stay private

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Modular Architecture: Lesson & Practice · Typorithm | ApplyDjinn