Project Organization

Lesson 8: Modules and File Organization

Split larger TypeScript programs into clean, reusable files by using modules, imports, exports, and sensible project structure.

Why Modules Matter

As a project grows, putting everything in one file becomes hard to manage. Modules allow you to separate utilities, classes, types, and application logic into different files.

Exporting Code

export function add(a: number, b: number): number {
  return a + b;
}

Importing Code

import { add } from "./mathUtils";

console.log(add(5, 3));

Default Exports

export default class Product {
  constructor(public name: string, public price: number) {}
}
import Product from "./Product";

Folder Structure

src/
├── app.ts
├── utils/
│   └── mathUtils.ts
├── models/
│   └── Product.ts
└── types/
    └── types.ts
Tip: Organize files by responsibility. This makes your TypeScript projects much easier to maintain and scale.

Summary

Modules are essential for real-world TypeScript development. They let you split code into logical parts and keep larger projects clean and reusable.