Explains the mental model and architecture of the code under `packages/core`. You MUST use this skill any time you plan to work with code in `packages/core`
packages/core) Mental ModelThis document outlines the architecture and mental model for packages/core, the heart of the Angular framework.
packages/core contains the runtime logic for Angular. Its primary responsibilities are:
The rendering engine (located in packages/core/src/render3) uses an instruction-based approach.
Instructions: The Angular compiler transforms templates into a sequence of instruction calls (e.g., ɵɵelementStart, ɵɵtext, ɵɵproperty). These instructions are executed at runtime to create and update the view.
packages/core/src/render3/instructionsLView (Logical View): An array containing the state of a specific view instance. It holds:
RElement, RText).packages/core/src/render3/interfaces/view.tsTView (Template View): An array containing the static structure of a view. It is shared across all instances (LViews) of the same component/template. It holds:
packages/core/src/render3/interfaces/view.tsMemory Layout: LView and TView are parallel arrays. Index i in LView corresponds to metadata at index i in TView.
HEADER: Fixed size, contains context (Parent, Host, etc.).DECLS: Static nodes (elements, text, pipes).VARS: Binding values.EXPANDO: Dynamic data (host bindings, injectors).LView.LView. If changed, they update the DOM.DI in Angular is hierarchical and split into two systems that interact:
R3Injector)@NgModule.providers or providedIn: 'root'.R3Injector instances.packages/core/src/di/r3_injector.ts@Component.providers or @Directive.providers.LView ("Expando" section).TView.data) to quickly check if a token is present at a specific node index before traversing up the tree.Default: Checks everything.OnPush: Checks only if inputs change, events fire, or signals update.src/render3: The Ivy rendering engine.
instructions: The runtime instructions called by compiled code.interfaces: LView, TView, TNode definitions.src/di: Dependency injection system.src/change_detection: Change detection logic.src/zone: Zone.js integration.src/signal: Signals implementation (if present in this version, otherwise likely in primitives).ɵ.getLView()) during instruction execution to avoid passing context arguments everywhere. This is for performance and code size.src/render3/instructions.LView/TView Impact: If adding state, understand where it fits in the LView array.