0Pricing
Angular Academy · Lesson

Public API and Entry Points

Design a clean library surface.

Public API and Entry Points is a free Angular Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Public API Surface

A library should expose only what consumers are meant to use. The public API is the curated set of exports; everything else stays internal. In Angular libraries this surface is defined by public-api.ts.

public-api.ts as a Barrel

public-api.ts re-exports the symbols you want consumers to access. If something is not exported here, it is effectively private, even if it exists in the source.

// projects/ui-kit/src/public-api.ts
export * from './lib/button/button.component';
export * from './lib/theme.service';
// internal helpers are intentionally NOT exported

Why Hide Internals

Keeping helpers private means you can refactor them freely without breaking consumers. A small, deliberate public API is easier to document, version, and maintain than exporting everything.

Exporting Types and Tokens

The public API includes not just components but the interfaces, types, and injection tokens consumers need to use them correctly.

export { ButtonComponent } from './lib/button/button.component';
export type { ButtonVariant } from './lib/button/button.types';
export { THEME_CONFIG } from './lib/theme.tokens';

Secondary Entry Points

Large libraries split into secondary entry points so consumers import only what they need (better tree-shaking). For example ui-kit/testing separate from ui-kit.

import { ButtonComponent } from 'ui-kit';
import { provideUiKitTesting } from 'ui-kit/testing';

Creating a Secondary Entry Point

A secondary entry point is a subfolder with its own ng-package.json and public-api.ts. ng-packagr discovers it automatically and builds it as a separate import path.

projects/ui-kit/
  testing/
    ng-package.json   # marks a secondary entry point
    src/public-api.ts

The Main Entry Point Mapping

The library's ng-package.json points its entryFile at public-api.ts, telling the build which file is the main public surface.

// projects/ui-kit/ng-package.json
{
  "lib": { "entryFile": "src/public-api.ts" }
}

Designing for Stability

Treat the public API like a contract: removing or renaming an export is a breaking change. Add new exports freely, but deprecate before removing so consumers have time to migrate.

Avoiding Deep Imports

Because only public-api.ts is the contract, consumers should never deep-import internal paths like ui-kit/lib/button/internal. Exporting through the barrel keeps a single stable import surface.

Re-Exporting Third-Party Types

If your API method returns a type from another package, re-export that type so consumers do not need a separate dependency just to name it. This keeps the public surface self-sufficient.

Documenting the Surface

Add JSDoc comments to exported symbols. Because only public-api items are visible to consumers, documenting them gives users IntelliSense and clear usage guidance.

Quick Check

What defines what consumers can import?

Recap

The public API is curated in public-api.ts, which re-exports components, types, and tokens; everything else stays private and refactorable. Use secondary entry points for large libraries, point ng-package.json at the entry file, avoid deep imports, and treat the surface as a stable, documented contract.

Frequently asked questions

Is the “Public API and Entry Points” lesson free?

Yes — the full text of “Public API and Entry Points” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.

What will I learn in “Public API and Entry Points”?

Design a clean library surface. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Angular Academy?

No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Public API and Entry Points” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Angular Academy lesson?

Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Creating a Library with ng generate
  2. Public API and Entry Points
  3. Building with ng-packagr
  4. Publishing to npm
← Back to Angular Academy