|
3 | 3 | This document explains the code layout in this repository. It is closely related to the [architecture](./architecture.md). |
4 | 4 |
|
5 | 5 | * `src/`: Contains the source code for the main `@firebase/firestore` package. |
6 | | - * `api/`: Implements the **API Layer** for the main SDK. |
7 | | - * `lite-api/`: Contains the entry point of for the lite SDK. |
8 | | - * `core/`: Contains logic for the **Sync Engine** and **Event Manager**. |
9 | | - * `local/`: Contains the logic the **Local Store**, which includes the **Mutation Queue**, **Remote Table**, **Local View**, **Overlays**, and the **Persistence Layer** |
10 | | - * `local_store.ts`: The main entry point for persistence operations. |
11 | | - * `query_engine.ts`: Implements the strategy selection logic (Scan vs. Index). |
12 | | - * `index_backfiller.ts`: The background task that updates Client-Side Indexes. |
13 | | - * `remote_document_cache.ts`: Manages the `remote_documents` table (base truth). |
14 | | - * `overlay_cache.ts`: Manages pending mutation queue. |
15 | | - * `remote/`: Contains the logic for the **Remote Store**, handling all network communication. |
16 | | - * `model/`: Defines the internal data models used throughout the SDK, such as `Document`, `DocumentKey`, and `Mutation`. These models are used to represent Firestore data and operations in a structured way. |
17 | | - * `platform/`: Contains platform-specific code to abstract away the differences between the Node.js and browser environments. This includes things like networking, storage, and timers. This allows the core logic of the SDK to be platform-agnostic. |
18 | | - * `protos/`: Contains the Protocol Buffer (`.proto`) definitions that describe the gRPC API surface of the Firestore backend. These files are used to generate the client-side networking code. |
| 6 | + * `api/`: **API Surface**. Implements the public API (e.g., `doc`, `collection`, `onSnapshot`). |
| 7 | + * `database.ts`: The entry point for the `Firestore` class. |
| 8 | + * `reference.ts`: Implements `DocumentReference` and `CollectionReference`. |
| 9 | + * `core/`: **Sync Engine**. Contains the high-level orchestration logic. |
| 10 | + * `sync_engine.ts`: The central coordinator. It manages the "User World" <-> "System World" bridge, `TargetID` allocation, and the main async queue. |
| 11 | + * `event_manager.ts`: Handles `QueryListener` registration, fan-out (deduplication of identical queries), and raising snapshot events to the user. |
| 12 | + * `query.ts`: Defines the internal `Query` and `Target` models. |
| 13 | + * `firestore_client.ts`: The initialization logic that wires up the components. |
| 14 | + * `local/`: **Storage and Query Execution**. Manages persistence, caching, and local execution. |
| 15 | + * `local_store.ts`: The main interface for the Core layer to interact with storage. It coordinates the components below. |
| 16 | + * `indexeddb_persistence.ts`: The implementation of the [Persistence Schema](./persistence-schema.md) using IndexedDB. |
| 17 | + * `local_documents_view.ts`: Implements the logic to assemble the user-facing view (`RemoteDoc` + `Mutation`). |
| 18 | + * `query_engine.ts`: The optimizer that decides how to scan the cache. |
| 19 | + * `lru_garbage_collector.ts` & `reference_delegate.ts`: Implements the Sequence Number logic to clean up old data. |
| 20 | + * `remote/`: **Network**. Handles gRPC/REST communication. |
| 21 | + * `remote_store.ts`: Manages the "Watch Stream" (listening to queries) and the "Commit Stream" (sending mutations). |
| 22 | + * `connection.ts`: Abstracts the underlying networking transport. |
| 23 | + * `serializer.ts`: Converts between internal model objects and the Protobuf format used by the backend. |
| 24 | + * `model/`: Defines the immutable data structures used throughout the SDK (e.g., `DocumentKey`, `FieldPath`, `Mutation`). |
| 25 | + * `util/`: General purpose utilities (AsyncQueue, Assertions, Types). |
19 | 26 | * `lite/`: Defines the entrypoint code for the `@firebase/firestore/lite` package. |
20 | 27 | * `test/`: Contains all unit and integration tests for the SDK. The tests are organized by component and feature, and they are essential for ensuring the quality and correctness of the code. |
21 | 28 | * `scripts/`: Contains a collection of build and maintenance scripts used for tasks such as bundling the code, running tests, and generating documentation. |
|
0 commit comments