<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alessio Pelliccione on Medium]]></title>
        <description><![CDATA[Stories by Alessio Pelliccione on Medium]]></description>
        <link>https://medium.com/@alessiopelliccione?source=rss-5ee0eac121ac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vvoiNZEUH5GwGPYqT-hzSw.png</url>
            <title>Stories by Alessio Pelliccione on Medium</title>
            <link>https://medium.com/@alessiopelliccione?source=rss-5ee0eac121ac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:49:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alessiopelliccione/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Angular Router: The Complete Internal Architecture — From URL Parsing to Component Rendering]]></title>
            <link>https://alessiopelliccione.medium.com/angular-router-the-complete-internal-architecture-from-url-parsing-to-component-rendering-0a80e0cdc038?source=rss-5ee0eac121ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a80e0cdc038</guid>
            <category><![CDATA[angular-architecture]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular-router]]></category>
            <category><![CDATA[angular-internals]]></category>
            <dc:creator><![CDATA[Alessio Pelliccione]]></dc:creator>
            <pubDate>Sun, 16 Nov 2025 21:07:59 GMT</pubDate>
            <atom:updated>2025-11-16T21:07:59.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular Router: The Complete Internal Architecture — From URL Parsing to Component Rendering</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AhwES3yyko5Tyubrw3-Yqg.png" /></figure><p>Angular’s router may look simple on the surface, but under the hood it follows a precise sequence of steps.<br>This article explains <em>how Angular processes a URL</em>, from the moment it appears in the browser until the final component is rendered.</p><h3>1. Browser → Angular Startup (initialNavigation)</h3><p>When the user writes or opens a URL in the browser, Angular is not active yet.<br>The browser handles the URL and calls your server, which returns the Angular application.</p><p>During bootstrap, Angular triggers <strong>initialNavigation</strong>, which:</p><ul><li>Reads the current URL from the browser</li><li>Creates all internal routing structures</li><li>Ensures the client and server (in SSR scenarios) stay in sync</li><li>Uses replaceState() to align history if necessary</li></ul><h3>2. Angular Cannot Trust window.location</h3><p>Angular is <em>not always running in a browser</em>.<br>It may run under:</p><ul><li>SSR</li><li>Web Workers</li><li>Non-browser environments</li></ul><p>In these contexts, window.location does <strong>not</strong> exist.<br>So Angular uses two layers of abstraction.</p><figure><img alt="Location abstraction" src="https://cdn-images-1.medium.com/max/1024/1*gOlWm5pxsQFJIG0Ybm89xQ.png" /></figure><h4>Responsibilities</h4><ul><li><strong>PlatformLocation</strong> → abstraction over window.location and browser events</li><li><strong>LocationStrategy</strong> → builds or interprets the URL (Path / Hash)</li><li><strong>Router</strong> → never talks directly to the browser; always through the layers above</li></ul><h3>3. Parsing the URL → UrlTree, UrlSegmentGroup, UrlSegment</h3><p>Given the URL:</p><pre>/products/electronics/tv/42/details;tab=specs?sort=price&amp;order=asc#reviews</pre><p>Angular converts it into an <strong>UrlTree</strong>, which represents the entire URL structure:</p><pre>UrlTree {<br>  root: UrlSegmentGroup {<br>    segments: [<br>      &#39;products&#39;,<br>      &#39;electronics&#39;,<br>      &#39;tv&#39;,<br>      &#39;42&#39;<br>    ],<br>    children: {<br>      details: UrlSegmentGroup {<br>        segments: [&#39;details&#39;],<br>        children: {}<br>      }<br>    }<br>  },<br>  queryParams: {<br>    sort: &#39;price&#39;,<br>    order: &#39;asc&#39;<br>  },<br>  fragment: &#39;reviews&#39;<br>}</pre><p>This gives Angular a structured representation it can match against your route config.</p><h3>4. Route Matching</h3><p>Angular now takes:</p><ul><li>The UrlSegmentGroup</li><li>Your app’s route configuration</li><li>A “segment index” representing where it is in the URL</li></ul><p>It starts matching:</p><ul><li>Tries the first route</li><li>If it matches, descends into children</li><li>If it fails, tries the next route</li><li>If all fail → falls back to **</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G6SKOvKbVXPgTy2K97rOhQ.png" /></figure><h4>Example:</h4><p>URL:</p><pre>/products/42/details</pre><p>Config:</p><pre>const routes: Routes = [<br>  {<br>    path: &#39;&#39;,<br>    component: LayoutComponent,<br>    children: [<br>      {<br>        path: &#39;products&#39;,<br>        children: [<br>          {<br>            path: &#39;:id&#39;,<br>            children: [<br>              { path: &#39;details&#39;, component: ProductDetailsComponent }<br>            ]<br>          }<br>        ]<br>      },<br>      { path: &#39;**&#39;, component: NotFoundComponent }<br>    ]<br>  }<br>];</pre><p>Matching result → Angular creates a chain like:</p><pre>[<br>  { route: &#39;&#39;, params: {} },<br>  { route: &#39;products&#39;, params: {} },<br>  { route: &#39;:id&#39;, params: { id: &#39;42&#39; } },<br>  { route: &#39;details&#39;, params: {} }<br>]</pre><h3>5. Lazy Loading (High-level Overview)</h3><p>If a matched route is lazy:</p><ul><li>Angular pauses matching</li><li>Loads the module/component</li><li>Resumes matching inside the lazy module</li></ul><p>Lazy routes behave like child routes, but loaded only when needed.</p><h3>6. Guards &amp; Resolvers (Decision Phase)</h3><p>After matching, Angular does <strong>not</strong> activate immediately.</p><h4>Guards</h4><p>Answer the question:</p><blockquote><em>“Is this navigation allowed?”</em></blockquote><p>They can:</p><ul><li>Allow</li><li>Block</li><li>Redirect</li></ul><h4>Resolvers</h4><p>Answer:</p><blockquote><em>“What data must be available before entering?”</em></blockquote><p>Resolvers run after guards and must complete before the navigation succeeds.</p><p>Both operate on <strong>ActivatedRouteSnapshot</strong>, an immutable object containing:</p><ul><li>Params</li><li>Query Params</li><li>Matched segments</li><li>Config</li><li>Resolved data</li></ul><h3>7. Activation Phase</h3><p>If guards and resolvers all succeed:</p><ul><li>Angular creates an <strong>ActivatedRouteSnapshot</strong> for each matched route</li><li>Assembles them into a <strong>RouterState</strong></li><li>Updates the browser URL via pushState or replaceState</li><li>Loads and activates the component of the final route</li></ul><h3>8. Rendering: <strong>How &lt;router-outlet&gt; Works in Angular</strong></h3><p>Once activated:</p><ul><li>Angular finalizes the navigation process:</li><li>Instantiates the route’s component.</li><li>Binds params and queryParams as reactive signals.</li><li>Runs change detection.</li><li>Renders the final view into the DOM.</li></ul><p>At this point, the navigation cycle is complete:<br>from typing a URL → to seeing the rendered view.</p><h4>How &lt;router-outlet&gt; Fits Into This Phase</h4><p>&lt;router-outlet&gt; is the <strong>mounting point</strong> where Angular inserts the component for the currently active route.</p><p>Key concepts:</p><ul><li>Angular walks through the <strong>matched route tree</strong> until it reaches the component associated with the active route.</li><li>That component is <strong>dynamically created</strong> and placed inside the nearest &lt;router-outlet&gt;.</li></ul><p>If the route has nested child routes:</p><ul><li>Angular finds the <strong>next router-outlet deeper in the component tree</strong>.</li><li>Each child route’s component is inserted into its corresponding outlet.</li><li>The result is a <strong>nested structure of dynamic views</strong>, controlled entirely by the router.</li></ul><p>In short:</p><ul><li>&lt;router-outlet&gt; is a <strong>placeholder</strong>.</li><li>The router decides <em>which component goes into it</em> based on the active URL.</li><li>Each navigation triggers a new component tree to be rendered inside the outlets.</li></ul><h3>Conclusion</h3><p>This article provided a high-level but accurate overview of how Angular Router processes a navigation.<br>Understanding this flow helps developers build more predictable, maintainable routing setups, especially in large applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ru2qpRXWsAN7iFYfsnfzQg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a80e0cdc038" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How modern dev servers decide what to rebuild — a minimal engine]]></title>
            <link>https://alessiopelliccione.medium.com/how-modern-dev-servers-decide-what-to-rebuild-a-minimal-engine-254f3c746419?source=rss-5ee0eac121ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/254f3c746419</guid>
            <category><![CDATA[vites]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[bundler]]></category>
            <category><![CDATA[hmr]]></category>
            <category><![CDATA[esbuild]]></category>
            <dc:creator><![CDATA[Alessio Pelliccione]]></dc:creator>
            <pubDate>Sat, 01 Nov 2025 17:27:46 GMT</pubDate>
            <atom:updated>2025-11-01T19:05:09.444Z</atom:updated>
            <content:encoded><![CDATA[<h3>How modern dev servers decide what to rebuild — a minimal engine</h3><p>Some days ago, I was writing a small dynamic script to trigger a build for a single file. While doing that, I suddenly wondered: <strong>how do modern build tools actually work under the hood</strong>?</p><p>That question led me to start building a minimal engine — something simple enough to grasp the core idea, but realistic enough to mirror how tools like <em>esbuild</em> or <em>Vite</em> handle rebuilds internally, deciding what to rebuild.</p><p>Let’s see the process step by step — from file watching to dependency graph validation — to see what really happens when you hit “Save”.</p><figure><img alt="Application bundle generation complete" src="https://cdn-images-1.medium.com/max/892/1*Xl8OUO0qBDXu_8AHzRQr4A.png" /></figure><h3><strong>What’s actually happening under the hood</strong></h3><p>When you hit “Save”, your dev server doesn’t rebuild the whole project.</p><p>Instead, it follows a smart and very fast chain of steps:</p><ol><li><strong>The file watcher fires an event</strong> — tools like <a href="https://github.com/paulmillr/chokidar">chokidar</a> detect which file changed.</li><li><strong>The server looks up that file in its dependency graph</strong> — a map of who imports what</li><li><strong>It invalidates the module and all the modules that depend on it</strong></li><li><strong>Only those affected modules are rebuild and reloaded</strong></li></ol><p>That’s it — no full recompilation, no waking through the entire codebase.</p><p>This is what makes tools like <em>Vite</em> and <em>esbuild</em> feel instant during development.</p><h3><em>Building a minimal smart rebuild engine (with TypeScript code)</em></h3><p>Let’s recreate the core idea behind the tools that I mentioned before — but in less than 40 lines of code. The requirements are simple:</p><ul><li>watch files</li><li>detect changes</li><li>compute their hashes</li><li>rebuild only what’s affected</li></ul><p><strong>Step 1 — Watch the filesystem</strong></p><p>We will use <a href="https://github.com/paulmillr/chokidar">chokidar</a> to detect changes in the <em>src/</em> directory:</p><pre>import chokidar from &#39;chokidar&#39;;<br><br>const watcher = chokidar.watch(&#39;src&#39;);<br><br>watcher.on(&#39;change&#39;, (file) =&gt; {<br>  console.log(&#39;🟡 File changed:&#39;, file);<br>});</pre><p>Every time you save a file, this watcher emits an event.</p><p><strong>Step 2 — Cache file hashes</strong></p><p>We don’t want to rebuild if the content didn’t really change (autoformatting, whitespace edits). So let’s keep a hash map of file contents:</p><pre>import crypto from &#39;crypto&#39;;<br>import fs from &#39;fs&#39;;<br><br>const cache = new Map&lt;string, string&gt;();<br><br>function hashFile(path: string) {<br>  const content = fs.readFileSync(path, &#39;utf-8&#39;);<br>  return crypto.createHash(&#39;sha1&#39;).update(content).digest(&#39;hex&#39;);<br>}</pre><p>Now we can compare the old and the new hash whenever a file changes.</p><p><strong>Step 3— Track dependencies</strong></p><p>We’ll store a simple <strong>dependency graph</strong> to know which files import which:</p><pre>const graph = new Map&lt;string, string[]&gt;(); // file → [importers]<br><br>// Example:<br>graph.set(&#39;src/utils/date.ts&#39;, [&#39;src/app.ts&#39;]);<br>graph.set(&#39;src/app.ts&#39;, [&#39;src/main.ts&#39;]);</pre><p>This tells us that if <em>date.ts</em> changes, <em>app.ts</em> and the <em>main.ts</em> should be invalidated.</p><p><strong>Step 4 — Invalidate affected modules</strong></p><p>Here’s the rebuild logic — recursive invalidation of dependents:</p><pre>function invalidate(file: string) {<br>  console.log(&#39;♻️ Rebuilding&#39;, file);<br>  const dependents = graph.get(file) || [];<br>  dependents.forEach(invalidate);<br>}</pre><p>Now we connect everything:</p><pre>watcher.on(&#39;change&#39;, (file) =&gt; {<br>  const newHash = hashFile(file);<br>  if (cache.get(file) !== newHash) {<br>    cache.set(file, newHash);<br>    invalidate(file);<br>  }<br>});</pre><p>And that’s it! You just build the hearth of a smart rebuild engine.</p><blockquote>The real implementation in my repo is a bit more advanced: it keeps a full dependency graph, incremental cache, and diagnostics for rebuild chains.</blockquote><blockquote>You can explore it here: <a href="https://github.com/alessiopelliccione/reboost">https://github.com/alessiopelliccione/reboost</a></blockquote><h3>Understanding HMR (Hot Module Replacement) propagation</h3><p>Now that our minimal engine knows which modules to rebuild, the next question is: <strong>how does the browser update so fast — without a full reload?</strong></p><p>That’s where <strong>HMR</strong> comes in.</p><h4><strong>The idea</strong></h4><p>Instead of refreshing the entire page, HMR lets the browser <strong>replace only the affected module at runtime</strong>. Thing of it like a “live patch” system for JavaScript.</p><p>When a file changes:</p><ol><li>The dev server detects it (our watcher)</li><li>It invalidates the affected modules</li><li>It sents a WebSocket message to the browser</li><li>The browser dinamically imports the new module</li><li>If the module accepts the update, it’s replaced in place — no full reload</li></ol><h4>How it connects back to <a href="https://github.com/alessiopelliccione/reboost">Reboost</a></h4><p>In <a href="https://github.com/alessiopelliccione/reboost"><strong>Reboost</strong></a>, this concept becomes even more transparent: each module knows who depends on it through the <strong>dependency graph</strong>, and when a file changes, the invalidation chain determines <em>how far the rebuild should go</em> before notifying the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SzTj5qGRUC4H4yyWLdxB7Q.png" /></figure><h3>Beyond this article</h3><p>This post only scratches the surface.</p><p>My project <a href="https://github.com/alessiopelliccione/reboost"><strong>Reboost</strong></a><strong> </strong>is a small experimental engine that goes a step further. It’s not meant to replace modern dev servers, but to <strong>understand</strong> how they work.</p><h3>Links</h3><p>GitHub: <a href="https://github.com/alessiopelliccione/reboost">https://github.com/alessiopelliccione/reboost</a></p><p>Topics: #vite #esbuild #hmr #javascript #bundler</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=254f3c746419" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>