Skip to content

Commit 08b05f0

Browse files
committed
Agents.md
1 parent ac3dd7c commit 08b05f0

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Repository Guide for AngularFire (`@angular/fire`)
2+
3+
This document provides architectural context, build pipeline details, codebase navigation, and testing/release guidelines for AI agents and developers working in the AngularFire repository.
4+
5+
---
6+
7+
## 1. Architecture & Core Concepts
8+
9+
AngularFire ([package.json](./package.json)) is the official Angular library for Firebase. It provides reactive, zone-aware bindings for Firebase JS SDK modules and RxFire.
10+
11+
### Key Architectural Pillars
12+
13+
1. **Modular Architecture & Secondary Entry Points**
14+
- The library is structured into secondary package entry points (managed by `ng-packagr` via [src/ng-package.json](./src/ng-package.json)) corresponding to Firebase SDK modules (e.g., `auth`, `firestore`, `database`, `storage`, `functions`, `analytics`, `messaging`, `remote-config`, `performance`, `app-check`, `ai`, and `data-connect`).
15+
- Each entry point exports zone-wrapped functions and observables from the modular Firebase JS SDK (`firebase/*`) and reactive RxFire helpers (`rxfire/*`).
16+
17+
2. **Zone & Injection Context Management ([src/zones.ts](./src/zones.ts))**
18+
- Firebase SDK async operations can trigger unwanted synchronous change detection or happen outside Angular's lifecycle.
19+
- [ɵzoneWrap](./src/zones.ts#L124-L193) wraps Firebase and RxFire functions so that:
20+
- Callback registration and execution run within or outside Angular zones appropriately using [ɵAngularFireSchedulers](./src/zones.ts#L70-L86) and [ɵZoneScheduler](./src/zones.ts#L38-L65).
21+
- Execution verifies an Angular `EnvironmentInjector` context or logs dev-mode warnings when called outside injection context.
22+
- Observables are piped to subscribe outside Angular zones and re-enter Angular zones on emission.
23+
24+
3. **Core Dependency Injection ([src/core.ts](./src/core.ts))**
25+
- Provides utilities like [ɵgetDefaultInstanceOf](./src/core.ts#L17-L29) and [ɵgetAllInstancesOf](./src/core.ts#L31-L43) to retrieve Firebase service instances (`FirebaseApp`, `Auth`, `Firestore`, etc.) from dependency injection containers or default Firebase instances.
26+
27+
4. **Compatibility Layer ([src/compat](./src/compat))**
28+
- Houses the legacy class-based AngularFire API (version 5/6 style AngularFire modules like `AngularFireAuthModule`, `AngularFirestoreModule`).
29+
30+
---
31+
32+
## 2. Where Code Lives
33+
34+
| Path | Description |
35+
| :--- | :--- |
36+
| [src/core.ts](./src/core.ts) | Core Angular DI helpers, version metadata, and Firebase app container instance lookups. |
37+
| [src/zones.ts](./src/zones.ts) | Angular Zone management, scheduler implementations ([ɵZoneScheduler](./src/zones.ts#L38-L65)), and the core [ɵzoneWrap](./src/zones.ts#L124-L193) decorator function. |
38+
| `src/<module>/` | Individual modular Firebase service wrappers (e.g., `src/auth`, `src/firestore`, `src/storage`). Contains autogenerated `firebase.ts` and `rxfire.ts` exports along with Angular providers/modules. |
39+
| [src/compat/](./src/compat) | Legacy AngularFire compatibility modules and wrapper classes. |
40+
| [src/schematics/](./src/schematics) | Angular CLI Schematics for `ng add @angular/fire`, framework setup, migrations, and automated deployment builders (`ng deploy`). |
41+
| [tools/build.ts](./tools/build.ts) | Main build script that autogenerates zone wrappers, builds the library, and bundles schematics. |
42+
| [tools/jasmine.ts](./tools/jasmine.ts) | Entry point runner for Node/SSR unit tests using ServerTestingModule. |
43+
44+
---
45+
46+
## 3. Build Process
47+
48+
The project is built using `npm run build`, which invokes [tools/build.ts](./tools/build.ts) (or [tools/build.sh](./tools/build.sh) in CI environments).
49+
50+
### Build Pipeline Steps
51+
52+
1. **Autogenerating Zone Wrappers ([zoneWrapExports](./tools/build.ts#L64-L257))**
53+
- Prior to library compilation, [build.ts](./tools/build.ts) inspects exports of `firebase/*` and `rxfire/*` SDK packages using `ts-transformer-keys`.
54+
- It autogenerates `firebase.ts` and `rxfire.ts` inside each service directory (`src/<module>/firebase.ts`).
55+
- Functions are wrapped in [ɵzoneWrap](./src/zones.ts#L124-L193) with appropriate logging and blocking behavior.
56+
57+
2. **Angular Library Compilation (`ng build`)**
58+
- Uses `@angular-devkit/build-angular:ng-packagr` configured in [angular.json](./angular.json) to compile the source tree into `dist/packages-dist`.
59+
60+
3. **Schematics Compilation ([compileSchematics](./tools/build.ts#L300-L340))**
61+
- Uses `esbuild` to bundle schematics (`add`, `deploy`, `setup`, `update`) into CommonJS targets inside `dist/packages-dist/schematics`.
62+
- Copies schematic metadata schemas (`collection.json`, `builders.json`, `versions.json`).
63+
64+
4. **Version & Asset Sync ([replacePackageCoreVersion](./tools/build.ts#L264-L274))**
65+
- Replaces `ANGULARFIRE2_VERSION` placeholders with the actual version from [package.json](./package.json) and synchronizes peer dependency versions in schematic JSONs.
66+
67+
---
68+
69+
## 4. Testing & Release Process
70+
71+
### Testing
72+
73+
Tests run against compiled outputs or directly in browsers using local Firebase Emulators (configured in `test/`).
74+
75+
- **Unit Tests (Node / SSR)**:
76+
- Run via `npm run test:node` or `npm run test:node-esm`.
77+
- First compiles Jasmine test files (`npm run build:jasmine` using [tsconfig.jasmine.json](./tsconfig.jasmine.json)), then executes tests in Node using [tools/jasmine.ts](./tools/jasmine.ts).
78+
- **Browser & Emulator Tests**:
79+
- Run via `npm run test:chrome-headless` (or `test:firefox-headless`).
80+
- Uses the Firebase CLI to spin up local emulators: `firebase-tools emulators:exec --project=demo-123 "ng test --watch=false --browsers=ChromeHeadless"`.
81+
- Uses Karma ([karma.conf.js](./karma.conf.js)) to run Jasmine specs inside the browser against emulated backends.
82+
83+
### Release Pipeline
84+
85+
Automated through GitHub Actions ([.github/workflows/test.yml](./.github/workflows/test.yml)):
86+
87+
1. **Continuous Integration Matrix**:
88+
- Every pull request or push to `main` executes `build`, followed by concurrent unit and browser test matrices across Node 20/22/24 and Ubuntu/macOS/Windows.
89+
2. **Tagging & Packaging ([tools/build.sh](./tools/build.sh))**:
90+
- Resolves the npm tag based on Git branch/tag info:
91+
- Commit builds on `main`: tagged as `canary` (`<version>-canary.<short-sha>`).
92+
- Tag builds: tagged as `latest` or `next`.
93+
- Generates an executable `publish.sh` script inside `./dist/packages-dist`.
94+
3. **Publishing**:
95+
- When triggered by a publish release event or branch merge to `main`, `./dist/packages-dist/publish.sh` runs using the authenticated `NODE_AUTH_TOKEN` secret to release to npm.

0 commit comments

Comments
 (0)