|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +pnpm start # Dev server (ng serve) |
| 9 | +pnpm build # Production build → www/ |
| 10 | +pnpm run build:prod # Ionic prod build with service worker (outputs to www/browser) |
| 11 | +pnpm test # Karma unit tests |
| 12 | +pnpm lint # ESLint |
| 13 | +``` |
| 14 | + |
| 15 | +Run a single test file by passing `--include` to karma or by modifying the test entry temporarily. There is no shorthand script for this. |
| 16 | + |
| 17 | +Deploy: `firebase deploy` (targets `www/browser/`) |
| 18 | + |
| 19 | +## Architecture |
| 20 | + |
| 21 | +**Stack**: Angular 21 + Ionic 8 + Firebase (PWA) |
| 22 | + |
| 23 | +### Routing & Modules |
| 24 | +All feature pages are lazy-loaded modules. Routes in `app-routing.module.ts`: |
| 25 | +- `''` → redirects to `today` |
| 26 | +- `today` / `day/:day` → `TodayPageModule` (main reading view) |
| 27 | +- `month/:month` → `MonthPageModule` (calendar view) |
| 28 | +- `notes` → `NotesPageModule` |
| 29 | +- `login` / `signup` → auth modules |
| 30 | + |
| 31 | +### Data Flow |
| 32 | +- **Reading content** (the actual Harvard Classics text) is static JSON loaded from `assets/index.json` via `MaterialService`. It is **not** in Firestore. |
| 33 | +- **User data** (completed days, favorites, notes) lives in Firestore at `/users/{userEmail}` and is subscribed to via `ReadingDbService` using RxJS `valueChanges()`. |
| 34 | +- **Auth state** is persisted in `localStorage` by `AuthService` (Firebase email/password + Google OAuth). |
| 35 | + |
| 36 | +### Inter-Component Communication |
| 37 | +A custom event bus (`Events` service, `services/events.service.ts`) uses a `Map`-based pub/sub pattern. Constants for event names are in `constants.ts`: |
| 38 | +- `EVENT_FINISHED_READING` — fired when scroll reaches 100% in TodayPage; consumed by `ReadingDbService` to mark the day read |
| 39 | +- `EVENT_USER_LOGIN` / `EVENT_USER_LOGOUT` — fired by AuthService |
| 40 | + |
| 41 | +### Key Services |
| 42 | +| Service | Responsibility | |
| 43 | +|---|---| |
| 44 | +| `ReadingDbService` | All Firestore reads/writes (days read, notes, favorites) | |
| 45 | +| `AuthService` | Firebase auth, localStorage session | |
| 46 | +| `MaterialService` | Loads/caches `assets/index.json` reading content | |
| 47 | +| `Events` | Pub/sub event bus between components | |
| 48 | + |
| 49 | +### TodayPage |
| 50 | +The main reading component. It: |
| 51 | +1. Loads content via `MaterialService` |
| 52 | +2. Tracks scroll progress — publishes `EVENT_FINISHED_READING` at 100% |
| 53 | +3. Uses `TextSelectEventDirective` to capture highlighted text for note creation |
| 54 | +4. Reads/writes notes and favorites to Firestore via `ReadingDbService` |
| 55 | + |
| 56 | +### Environments & Firebase |
| 57 | +Firebase config is in `src/environments/environment.ts` (dev) and `environment.prod.ts` (prod). Angular replaces the file at build time. The Firebase project is `harvardclassics365`. |
| 58 | + |
| 59 | +### PWA / Service Worker |
| 60 | +Service worker is only enabled in production builds (`build:prod`). Config is in `ngsw-config.json`. Versioned assets are cached long-term; `ngsw.json` itself is never cached (per `firebase.json` headers). |
0 commit comments