Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## 2026-11-21 - version 1.4.0

- **Interactive lessons in Thoughts**: a thought can now carry a lazily loaded lesson page under its prose. `thoughts-content/lessons/lessons.ts` maps slugs to loaders, and the reader loads the page through a `resource()` so SSR waits for it. The prerendered `/thoughts/angular-01-project-structure` HTML contains the whole lesson, demo included, not an empty slot. Each lesson is its own lazy chunk (lesson 01 is 13 kB), and the initial bundle is unchanged at 372.98 kB
- **Angular guide, lesson 01: project structure**. The first of thirteen lessons I'm writing so I can learn Angular properly and talk about it in depth. Each goes simple → intermediate → expert → pitfalls → interview questions, and the code samples are real code from this repo. This one has a live "may this file import that one?" checker built on the same rules the architecture spec enforces
- **Architecture fitness spec**: `src/app/architecture.spec.ts` fails if anything outside `apps/` statically imports from `apps/` (lazy `import()` is allowed, since that is the code-splitting seam), or if an `@NgModule` appears. It found three real violations on its first run
- **Settings state moved to `shared/settings/`**: `app.ts`, `dock/dock.ts` and `menu-bar/menu-bar.ts` were all importing `SettingsService`/`AppearanceService` out of the `apps/settings/` feature folder. State the whole desktop reads isn't a feature's private business. The System Preferences screen stays in `apps/settings/`; only the services moved
- Bootstrap files (`main.ts`, `app.config.ts`, `app.config.server.ts`) are annotated with `[ng-01]` comments, so `grep -rn "ng-01" src` finds every example the lesson refers to

## 2026-08-16 - version 1.3.7

- **Changelog guard**: `src/changelog.spec.ts` asserts the top entry is the version `package.json` is on, that it has bullets under it, that no version gets two headings, that versions and dates both run newest first, and that every `## ` heading parses as `YYYY-MM-DD - version X.Y.Z`. Ported from the `changelogEntry.test.ts` in `paul-explore` and `portfolio_api`, which have had this for a while — this repo was the one without it
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paul",
"version": "1.3.7",
"version": "1.4.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.config.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// [ng-01 structure] Server-only providers, merged over the browser config.
// mergeApplicationConfig keeps one source of truth (app.config.ts) and layers
// the server bits on top, so the two configs can't drift apart.
// main.server.ts bootstraps with this; main.ts bootstraps with appConfig.
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, withRoutes } from '@angular/ssr';
import { appConfig } from './app.config';
Expand Down
17 changes: 17 additions & 0 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// [ng-01 structure] Application-wide providers. This file replaces what an
// AppModule's `imports: [...]` and `providers: [...]` used to do.
//
// Simple: every `provideX()` registers a feature for the whole app.
// Intermediate: the order mostly doesn't matter, but each provider is
// app-scoped (root injector). Anything you add here is created once and
// shared — put per-feature providers on routes or components instead.
// Expert: `provideX(withY(), withZ())` is the "feature function" pattern.
// The with* functions are tree-shakable options: if you never call
// withIncrementalHydration(), that code never ships. Prefer this shape when
// you design your own library's providers too.
import {
ApplicationConfig,
provideBrowserGlobalErrorListeners,
Expand All @@ -15,10 +26,16 @@ import {

export const appConfig: ApplicationConfig = {
providers: [
// Routes uncaught errors and unhandled rejections to Angular's ErrorHandler.
provideBrowserGlobalErrorListeners(),
// No Zone.js: change detection runs off signals and template events.
// Covered properly in lesson 09.
provideZonelessChangeDetection(),
// HttpClient backed by fetch() instead of XHR — required for good SSR.
provideHttpClient(withFetch()),
provideRouter(routes),
// SSR hydration: reuse server-rendered DOM instead of re-creating it.
// Lesson 12.
provideClientHydration(withEventReplay(), withIncrementalHydration()),
],
};
2 changes: 1 addition & 1 deletion src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Desktop } from './desktop/desktop';
import { DesktopIconsComponent } from './desktop-icons/desktop-icons';
import { Dock } from './dock/dock';
import { MenuBar } from './menu-bar/menu-bar';
import { AppearanceService } from './apps/settings/appearance.service';
import { AppearanceService } from './shared/settings/appearance.service';
import { AppLauncherService } from './shared/app-launcher.service';
import { DockService } from './shared/dock.service';
import { KeyboardShortcutService } from './shared/keyboard-shortcut.service';
Expand Down
2 changes: 1 addition & 1 deletion src/app/apps/settings/system-preferences.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { vi } from 'vitest';
import { SystemPreferencesApp } from './system-preferences';
import { SettingsService } from './settings.service';
import { SettingsService } from '../../shared/settings/settings.service';

describe('SystemPreferencesApp', () => {
let fixture: ComponentFixture<SystemPreferencesApp>;
Expand Down
2 changes: 1 addition & 1 deletion src/app/apps/settings/system-preferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, inject, signal } from '@angular/core';
import { SettingsService } from './settings.service';
import { SettingsService } from '../../shared/settings/settings.service';

type Pane = 'appearance' | 'dock' | 'general';

Expand Down
73 changes: 73 additions & 0 deletions src/app/architecture.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { readdirSync, readFileSync, statSync } from 'node:fs';
import { join, relative, resolve, dirname, sep } from 'node:path';

/**
* [ng-01 structure] Architecture fitness tests.
*
* Folder conventions only hold while someone enforces them. In a team, "we put
* shared state in shared/" lives in a wiki nobody reads, and six months later a
* feature folder is quietly a dependency of the whole app. These tests make the
* convention executable: break the rule and CI goes red with the file name.
*
* The layering this repo uses (see docs/angular-guide/01-project-structure.md):
*
* shell app.ts, menu-bar/, dock/, desktop/, window-manager/, ...
* shared/ services and building blocks anyone may use
* apps/ feature folders — one per desktop "app", lazy loaded
*
* Arrows only point down: shell → shared, apps → shared. Nothing outside
* apps/ may *statically* import from apps/. A static import drags the feature
* into the initial bundle and couples the shell to its internals. Dynamic
* `import()` is allowed — that IS the lazy-loading seam.
*/
const APP_ROOT = resolve(process.cwd(), 'src/app');

function sourceFiles(dir: string): string[] {
return readdirSync(dir).flatMap((name) => {
const full = join(dir, name);
if (statSync(full).isDirectory()) return sourceFiles(full);
return full.endsWith('.ts') && !full.endsWith('.spec.ts') ? [full] : [];
});
}

/** Static `import … from './x'` / `export … from './x'` specifiers, never `import('./x')`. */
function staticRelativeImports(file: string): string[] {
const source = readFileSync(file, 'utf-8');
const specifiers = [...source.matchAll(/^\s*(?:import|export)\b[^;]*?\bfrom\s+'(\.[^']+)'/gm)];
return specifiers.map((match) => resolve(dirname(file), match[1]));
}

const isInside = (file: string, folder: string) =>
relative(join(APP_ROOT, folder), file).split(sep)[0] !== '..';

describe('[ng-01] architecture', () => {
const files = sourceFiles(APP_ROOT);

it('finds the source tree (guards against the walker silently matching nothing)', () => {
expect(files.length).toBeGreaterThan(30);
});

it('the parser sees static imports and ignores dynamic import()', () => {
const app = join(APP_ROOT, 'app.routes.ts');
// app.routes.ts only has lazy `import()` calls into features plus one package import.
expect(staticRelativeImports(app)).toEqual([]);
});

it('nothing outside apps/ statically imports from apps/', () => {
const violations = files
.filter((file) => !isInside(file, 'apps'))
.flatMap((file) =>
staticRelativeImports(file)
.filter((target) => isInside(target, 'apps'))
.map((target) => `${relative(APP_ROOT, file)} → ${relative(APP_ROOT, target)}`),
);
expect(violations).toEqual([]);
});

it('has no NgModules — every component, directive and pipe is standalone', () => {
const withNgModule = files
.filter((file) => /@NgModule\s*\(/.test(readFileSync(file, 'utf-8')))
.map((file) => relative(APP_ROOT, file));
expect(withNgModule).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion src/app/dock/dock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, computed, inject, signal } from '@angular/core';
import { SettingsService } from '../apps/settings/settings.service';
import { SettingsService } from '../shared/settings/settings.service';
import { AppLauncherService } from '../shared/app-launcher.service';
import { DockItem, DockService } from '../shared/dock.service';

Expand Down
2 changes: 1 addition & 1 deletion src/app/menu-bar/menu-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { vi } from 'vitest';
import { SettingsService } from '../apps/settings/settings.service';
import { SettingsService } from '../shared/settings/settings.service';
import { MenuBar } from './menu-bar';
import { MenuBarService } from './menu-bar.service';

Expand Down
2 changes: 1 addition & 1 deletion src/app/menu-bar/menu-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PLATFORM_ID,
signal,
} from '@angular/core';
import { SettingsService } from '../apps/settings/settings.service';
import { SettingsService } from '../shared/settings/settings.service';
import { MenuBarItem, MenuBarService } from './menu-bar.service';

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// [ng-01 structure] Why this lives in shared/ and not apps/settings/:
// the dock (icon size), the menu bar (clock format) and the root shell (theme)
// all read it. State that the whole app depends on is not a feature's private
// business. It sat in apps/settings/ until architecture.spec.ts flagged three
// shell files importing it. The *screen* that edits it (system-preferences.ts)
// stays in the feature folder. The *state* moved down a layer.
import { effect, Injectable, PLATFORM_ID, inject, signal } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

Expand Down
52 changes: 52 additions & 0 deletions src/app/thoughts-content/lessons/code-block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Component, input } from '@angular/core';

/**
* A labelled, scrollable code sample for lesson pages.
*
* The code arrives as a string input rather than as template text on purpose:
* Angular would try to compile `{{ }}`, `@if` and `<tags>` inside a template,
* so a code sample has to be data, not markup. Interpolating a string is also
* safe by default — Angular escapes it, so nothing in a sample can inject HTML.
*/
@Component({
selector: 'app-code-block',
template: `
<figure class="code-block">
<figcaption class="code-block-label">{{ label() }}</figcaption>
<!-- tabindex makes a horizontally scrollable region reachable by keyboard (axe: scrollable-region-focusable) -->
<pre tabindex="0"><code>{{ code() }}</code></pre>
</figure>
`,
styles: `
.code-block {
margin: 12px 0 16px;
border: 1px solid var(--border-primary, rgba(255, 255, 255, 0.1));
border-radius: 8px;
overflow: hidden;
background: var(--surface-secondary, rgba(0, 0, 0, 0.25));
}
.code-block-label {
padding: 4px 12px;
font-size: 11px;
color: var(--text-secondary, rgba(255, 255, 255, 0.6));
border-bottom: 1px solid var(--border-primary, rgba(255, 255, 255, 0.1));
}
pre {
margin: 0;
padding: 12px;
overflow-x: auto;
font-family: var(--font-mono, ui-monospace, monospace);
font-size: 12.5px;
line-height: 1.55;
color: var(--text-primary, #fff);
}
pre:focus-visible {
outline: 2px solid var(--focus-ring, #4da3ff);
outline-offset: -2px;
}
`,
})
export class CodeBlock {
readonly code = input.required<string>();
readonly label = input('TypeScript');
}
66 changes: 66 additions & 0 deletions src/app/thoughts-content/lessons/lesson-01-structure.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import * as axeMatchers from 'vitest-axe/matchers';
import { axe } from '../../../test/a11y';
import { checkImport, Lesson01Structure } from './lesson-01-structure';

expect.extend(axeMatchers);

describe('checkImport — the layering rules the lesson demonstrates', () => {
it('lets the shell and features depend on shared/', () => {
expect(checkImport('shell', 'shared', false).allowed).toBe(true);
expect(checkImport('feature', 'shared', false).allowed).toBe(true);
});

it('forbids shared/ reaching up into the shell or a feature', () => {
expect(checkImport('shared', 'shell', false).allowed).toBe(false);
expect(checkImport('shared', 'feature', false).allowed).toBe(false);
});

it('forbids the shell statically importing a feature, but allows lazy import()', () => {
expect(checkImport('shell', 'feature', false).allowed).toBe(false);
expect(checkImport('shell', 'feature', true).allowed).toBe(true);
});

it('forbids one feature importing another', () => {
expect(checkImport('feature', 'other-feature', false).allowed).toBe(false);
});
});

describe('Lesson01Structure', () => {
let fixture: ComponentFixture<Lesson01Structure>;
let el: HTMLElement;

beforeEach(async () => {
await TestBed.configureTestingModule({ imports: [Lesson01Structure] }).compileComponents();
fixture = TestBed.createComponent(Lesson01Structure);
fixture.detectChanges();
el = fixture.nativeElement as HTMLElement;
});

it('teaches at three levels, then pitfalls and interview questions', () => {
const headings = [...el.querySelectorAll('h2')].map((h) => h.textContent?.trim());
expect(headings).toEqual(
expect.arrayContaining(['Simple', 'Intermediate', 'Expert', 'Pitfalls', 'Interview questions']),
);
});

it('shows real code in code blocks', () => {
expect(el.querySelector('app-code-block pre code')?.textContent).toContain('bootstrapApplication');
});

it('updates the verdict live when the import checker changes', async () => {
const from = el.querySelector<HTMLSelectElement>('#import-from')!;
const to = el.querySelector<HTMLSelectElement>('#import-to')!;
from.value = 'shared';
from.dispatchEvent(new Event('change'));
to.value = 'feature';
to.dispatchEvent(new Event('change'));
await fixture.whenStable();

expect(el.querySelector('[role="status"]')?.textContent).toContain('Not allowed');
});

it('has no axe violations', async () => {
expect(await axe(el)).toHaveNoViolations();
});
});
Loading
Loading