<?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 Md.Ariful Islam on Medium]]></title>
        <description><![CDATA[Stories by Md.Ariful Islam on Medium]]></description>
        <link>https://medium.com/@ariful.sec?source=rss-617dbb7dd500------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YQ3dFYBtGVy4Nr6HifcQeQ.png</url>
            <title>Stories by Md.Ariful Islam on Medium</title>
            <link>https://medium.com/@ariful.sec?source=rss-617dbb7dd500------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:05:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ariful.sec/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[System Design Series — Part 2: Application Performance]]></title>
            <link>https://medium.com/@ariful.sec/system-design-series-part-2-application-performance-63d02bf0a537?source=rss-617dbb7dd500------2</link>
            <guid isPermaLink="false">https://medium.com/p/63d02bf0a537</guid>
            <dc:creator><![CDATA[Md.Ariful Islam]]></dc:creator>
            <pubDate>Fri, 13 Nov 2026 11:09:37 GMT</pubDate>
            <atom:updated>2026-11-13T11:09:37.345Z</atom:updated>
            <content:encoded><![CDATA[<p>In Part 1, we built our app as a modular monolith to ship fast. Users came, traffic grew, and now the app feels slow. The client is unhappy.</p><p>The quick fix is to buy more servers. But first, there’s a cheaper step: make the app itself faster.</p><h3>What is performance?</h3><p>Performance means <strong>how fast and how well your app works</strong>. Users feel it as speed and smoothness. You measure it as response time, stability, and how well the app uses CPU, memory, disk, and network.</p><p>Performance always depends on two things: <strong>how much work</strong> the app gets (data and requests) and <strong>what machine</strong> it runs on. “The app is fast” only means something when you say at what load.</p><h3>How do you know it’s slow?</h3><p>Watch for these signs:</p><ul><li><strong>Numbers:</strong> response times go up, errors go up, CPU or memory spikes.</li><li><strong>People:</strong> users complain and support tickets increase.</li><li><strong>Tests:</strong> load tests and profilers show weak spots before users do.</li><li><strong>Screens:</strong> spinners take too long and buttons feel laggy.</li></ul><p>One slow page isn’t a problem. Slowness that keeps happening is.</p><h3>The big idea: slowness is waiting in line</h3><p>Think of a traffic jam. The road isn’t broken; more cars arrive than it can move, so they wait. Apps work the same way. <strong>When requests come in faster than the app can handle them, they wait in a line (a queue).</strong> That waiting is the slowness users feel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*377ksjyZrphtRFR_opUUOA.png" /></figure><p>Lines usually form in four places:</p><ul><li><strong>Network:</strong> data travels slowly or gets lost.</li><li><strong>Database:</strong> slow queries, or all connections busy.</li><li><strong>Server:</strong> CPU at 100% or memory full.</li><li><strong>Code:</strong> slow logic, or tasks stuck waiting on each other.</li></ul><p>And there are only three reasons a line forms:</p><ol><li><strong>Slow work:</strong> each task simply takes too long.</li><li><strong>One at a time:</strong> tasks must take turns using something shared, like a database connection.</li><li><strong>Not enough power:</strong> the machine is too small for the load.</li></ol><h3>How to measure it</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYcef-0i58OyQCwhsitadQ.png" /></figure><p><strong>Don’t trust the average.</strong> Say 980 requests take 0.1 seconds and 20 take 3 seconds. The average is 0.16 seconds and looks fine, but 1 in 50 users waits 3 seconds. That’s why teams track <strong>p99</strong>: the time within which 99% of requests finish. If p99 keeps growing, a line is forming somewhere.That is called Tail Latency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_hrBfc-FOhPSgxpT_GblQ.png" /></figure><h3>Three ways to fix it</h3><p>Each fix matches one of the three reasons a line forms.</p><ol><li><strong>Do the work faster (efficiency).</strong> Fixes slow work. Use better code and smarter database queries, add indexes, and cache results you need often.</li><li><strong>Do more work at the same time (concurrency).</strong> Fixes one-at-a-time waiting. Use all CPU cores, don’t let code sit idle while waiting for the database, and avoid locks that force tasks to take turns.</li><li><strong>Get a bigger machine (capacity).</strong> Fixes not enough power. Add CPU, memory, faster disks, or bandwidth.</li></ol><p>Try them in this order. Better code is cheap and lasts. Bigger machines cost money and only hide the problem.</p><h3>Where time gets lost</h3><p>Not all operations cost the same. Reading memory is very fast. Going to disk or across the internet is thousands of times slower.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wgB45s7LdWwFoCySIfapbQ.png" /></figure><p>So the rule is simple: <strong>avoid slow trips.</strong> Here’s how in each area:</p><ul><li><strong>Network:</strong> reuse connections instead of opening new ones, cache data close to users (a CDN), compress responses, and make fewer calls.</li><li><strong>Memory:</strong> keep only the data you need, and pick a garbage collector that doesn’t pause the app for long.</li><li><strong>Disk:</strong> cache frequent database results, add indexes, write logs in the background, and use SSDs.</li><li><strong>CPU:</strong> use efficient code, don’t block threads while waiting, and don’t run more threads than the CPU can handle.</li></ul><h3>A simple plan</h3><p>Next time someone says “the app is slow”:</p><ol><li><strong>Measure:</strong> check latency, p99, throughput, errors, and saturation.</li><li><strong>Find the line:</strong> see what’s full or growing.</li><li><strong>Find the reason:</strong> slow work, one at a time, or not enough power.</li><li><strong>Fix it:</strong> faster code first, then concurrency, then bigger machines.</li><li><strong>Test again:</strong> run a load test and keep watching.</li></ol><p>Performance isn’t a one-time job. It’s a habit.</p><p><em>In Part 3, we’ll cover scalability: what to do when one fast server is still not enough.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63d02bf0a537" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design Series — Part 1: Understanding Software Architectures]]></title>
            <link>https://medium.com/@ariful.sec/system-design-series-part-1-understanding-software-architectures-4c85fb242803?source=rss-617dbb7dd500------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c85fb242803</guid>
            <dc:creator><![CDATA[Md.Ariful Islam]]></dc:creator>
            <pubDate>Thu, 12 Nov 2026 07:10:03 GMT</pubDate>
            <atom:updated>2026-11-12T08:20:28.824Z</atom:updated>
            <content:encoded><![CDATA[<p>Every great app starts with an idea. But turning that idea into a system that scales, stays reliable, and is still pleasant to change two years later takes something more: the right architecture.</p><p>Architecture is simply how you organize your code, your services, and your data, and how those pieces talk to each other. Get it right and growth feels natural. Get it wrong and every new feature feels like surgery.</p><p>In this first part of the series, we will walk through the most common architectural styles, what each one is good at, and how to pick between them.</p><p>Here are the nine architectures we will cover:</p><ol><li>Monolithic architecture</li><li>2-tier architecture</li><li>3-tier / N-tier architecture</li><li>Modular monolith</li><li>Microservices architecture</li><li>Event-driven architecture (EDA)</li><li>Cloud-native architecture</li><li>Serverless architecture</li><li>Vertical slice architecture</li></ol><h3>The foundations: monoliths and tiers</h3><h3>1. Monolithic architecture</h3><ul><li><strong>What it is:</strong> one codebase, deployed as one unit, usually with one shared database.</li><li><strong>Strengths:</strong> fast to build, simple to run and debug.</li><li><strong>Weaknesses:</strong> components become tightly coupled; one failure can take down the whole app.</li><li><strong>Use it for:</strong> MVPs, proofs of concept, small teams, simple applications.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUC8eu1NM4F1EkSGUQBB_Q.png" /></figure><p>All layers live inside one deployable app that reads and writes one shared database.</p><h3>2. 2-tier architecture</h3><ul><li><strong>What it is:</strong> a client (presentation tier) talking directly to a server that holds the data, like a desktop app connected to a database.</li><li><strong>Strengths:</strong> very simple setup.</li><li><strong>Weaknesses:</strong> the server is a single point of failure, and business rules tend to leak into the client.</li><li><strong>Use it for:</strong> small internal tools with few users.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-kex3ZfDET0qioXskpu82Q.png" /></figure><p>The client sends requests directly to the database server, so if that server goes down, the app stops.</p><h3>3. 3-tier / N-tier architecture</h3><ul><li><strong>What it is:</strong> separate layers, each with one job:</li><li>Presentation layer (UI or API)</li><li>Business logic layer (rules and workflows)</li><li>Data access layer (database operations)</li><li>Integration layer, optional (external systems)</li><li><strong>Strengths:</strong> clear separation, easier testing; the classic enterprise pattern.</li><li><strong>Weaknesses:</strong> one feature often touches every layer.</li><li><strong>Use it for:</strong> traditional business applications with moderate complexity.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gi9BH3PogGLrcu-eZQyUZQ.png" /></figure><p>Each request flows layer by layer; the optional integration layer connects business logic to outside systems.</p><h3>4. Modular monolith</h3><ul><li><strong>What it is:</strong> one codebase and one deployment, split into independent modules by business domain, such as Product, Order, Customer, Payment, and Shipping.</li><li><strong>Public API per module:</strong> each module exposes a small contract (interfaces, DTOs) and hides everything else as internal. Other modules use only that contract.</li><li><strong>Schema per module:</strong> modules share one database server, but each owns its own schema (orders.*, payments.*, shipping.*). No module reads another&#39;s tables, and there are no cross-schema joins or foreign keys. Need customer data in Orders? Ask the Customer module&#39;s API.</li><li><strong>Enforcing boundaries:</strong> separate projects per module, internal access modifiers, and architecture tests (NetArchTest, ArchUnit) that fail the build when a module reaches into another.</li><li><strong>Strengths:</strong> monolith simplicity (one deploy, easy debugging, no network calls) with microservice-like structure.</li><li><strong>Weaknesses:</strong> modules still share one runtime and scale together; boundaries erode without discipline.</li><li><strong>Use it for:</strong> most growing products. It is also the safest path to microservices: a module with its own schema and event-based communication can be extracted into a service with little rework.</li></ul><pre>src/<br>  Modules/<br>    Orders/<br>      Orders.Contracts/   -&gt; public API (IOrderModule, OrderDto, OrderPlaced)<br>      Orders.Core/        -&gt; internal logic, owns schema &quot;orders&quot;<br>    Payments/<br>      Payments.Contracts/<br>      Payments.Core/      -&gt; owns schema &quot;payments&quot;<br>  Host/                   -&gt; single deployable app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fp_Hz4BMDGObzQLgS-2oaQ.png" /></figure><p>Modules talk through APIs or events, and each one reads and writes only its own schema.</p><p><strong>Note: </strong>An <strong>in-process event bus</strong> lets modules notify each other inside one running app, and the <strong>outbox pattern</strong> makes sure those notifications are never lost. They solve two halves of the same problem.</p><h3>In-process event bus</h3><p>An in-process event bus is a small dispatcher that lives inside your application’s memory. Think of it as an internal notice board. One module posts “an order was placed”, and any module that cares reacts, without the two modules knowing about each other.</p><p>It works in three parts:</p><ol><li><strong>Handlers register at startup.</strong> Each module registers handlers for the events it cares about, usually through dependency injection. For example, the Payments module registers a handler for OrderPlaced.</li><li><strong>A module publishes an event.</strong> The Orders module calls something like bus.Publish(new OrderPlaced(orderId)).</li><li><strong>The bus calls each handler.</strong> It looks up every handler registered for that event type and calls each one as a normal method call.</li></ol><p>There’s no network or external broker involved; it’s ordinary method calls in one process. Common implementations include MediatR notifications in .NET, Spring’s ApplicationEventPublisher in Java, or a small custom IEventBus.</p><p><strong>The weakness is that events live only in memory.</strong> That creates the classic <em>dual-write problem</em>: you need to save the order to the database and also publish the event, and those are two separate actions that can’t succeed or fail together.</p><ul><li>If the app crashes after saving the order but before publishing, Payments never hears about the order. The order exists but is never charged.</li><li>If you publish first and the database save then fails, Payments charges for an order that doesn’t exist.</li></ul><h3>Outbox pattern</h3><p>The outbox pattern fixes the dual-write problem by turning “publish an event” into “save a row”. It works like this:</p><ol><li><strong>Save the event with the business data.</strong> In the same database transaction as the order, the Orders module inserts the event into an outbox table in its own schema, for example orders.outbox_messages. Both writes commit together or roll back together, so you can never end up with one without the other.</li><li><strong>A background worker reads the outbox.</strong> Every few seconds it picks up rows that haven’t been processed yet.</li><li><strong>The worker publishes and marks the row done.</strong> It publishes each event to the event bus, then marks the row as processed.</li><li><strong>If something crashes, nothing is lost.</strong> The row is still unprocessed, so the worker picks it up again on the next run.</li></ol><h3>How they fit together</h3><p>The outbox is the mailbox and the event bus is the mail carrier. The module drops its letter in the mailbox safely, as part of its own transaction. The carrier then delivers it to everyone who subscribed.</p><pre>// Orders module: one transaction<br>db.Orders.Add(order);<br>db.OutboxMessages.Add(new OutboxMessage(&quot;OrderPlaced&quot;, Serialize(evt)));<br>await db.SaveChangesAsync();          // both saved, or neither</pre><pre>// Background worker<br>foreach (var msg in await db.OutboxMessages.Where(m =&gt; m.ProcessedAt == null).ToListAsync())<br>{<br>    await bus.Publish(Deserialize(msg));   // Payments and Shipping handlers run<br>    msg.ProcessedAt = DateTime.UtcNow;<br>    await db.SaveChangesAsync();<br>}</pre><p>There’s one important consequence. If the worker crashes after publishing but before marking the row done, the event gets delivered again. This is called <em>at-least-once</em> delivery, so <strong>handlers must be idempotent</strong>, meaning they can safely run twice. The usual fix is an <em>inbox</em> table: each module records the IDs of events it has already handled and skips any it has seen before.</p><h3>Why this matters for your architecture</h3><p>This combination is what makes a modular monolith easy to split up later. When you extract Payments into a microservice, you replace the in-process bus with RabbitMQ or Kafka. The outbox table, the worker, and the idempotent handlers all stay exactly the same.</p><h3>Splitting things apart: microservices and events</h3><h3>5. Microservices architecture</h3><ul><li><strong>What it is:</strong> small, independently deployable services, each owning one business capability and its own data.</li><li><strong>How it works:</strong> clients call an API Gateway, which routes requests to the right service; services talk over REST or gRPC.</li><li><strong>Key characteristics:</strong></li><li>Independent, loosely coupled services</li><li>Lightweight technologies and frameworks</li><li>Decentralized data management (database per service)</li><li>Independent deployment and continuous delivery</li><li><strong>Strengths:</strong> teams ship on their own schedule; scale only what needs scaling.</li><li><strong>Weaknesses:</strong> network failures, distributed data, and far more to deploy and monitor.</li><li><strong>Use it for:</strong> multiple business domains, independent scaling needs, or several teams in one codebase.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWtMzaA1APvWaGI2-hqrwA.png" /></figure><p>The API Gateway routes each request to the right service, and every service keeps its own database.</p><h3>6. Event-driven architecture (EDA)</h3><ul><li><strong>What it is:</strong> components announce what happened through events instead of calling each other directly.</li><li><strong>Three roles:</strong></li><li><strong>Producers</strong> publish events.</li><li><strong>Broker</strong> receives and distributes them (RabbitMQ, Apache Kafka, Azure Service Bus).</li><li><strong>Consumers</strong> subscribe to the events they care about.</li><li><strong>Example:</strong> Order publishes OrderCreated; Inventory, Payment, and Notification each react independently, and Order does not need to know they exist.</li><li><strong>Strengths:</strong> loose coupling, asynchronous processing, easy scaling.</li><li><strong>Weaknesses:</strong> harder debugging and eventual consistency.</li><li><strong>Use it for:</strong> workflows where one action triggers many independent reactions; pairs naturally with microservices.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YsFcGEOTy8g4FxoQF4ejEw.png" /></figure><p>The producer publishes once; the broker delivers the event to every subscribed consumer.</p><h3>Built for the cloud: cloud-native and serverless</h3><h3>7. Cloud-native architecture</h3><ul><li><strong>What it is:</strong> a way of building software designed to run in the cloud from day one.</li><li><strong>Key principles:</strong></li><li>Microservices</li><li>Containers (Docker, orchestrated by Kubernetes)</li><li>Continuous delivery and automation</li><li>Declarative APIs and configuration</li><li>Immutable infrastructure (replace servers, never patch by hand)</li><li>Observability through logs, metrics, and traces</li><li><strong>Strengths:</strong> resilient, scales on demand, deploys many times a day.</li><li><strong>Weaknesses:</strong> steep learning curve and heavy tooling.</li><li><strong>Use it for:</strong> systems that must scale and evolve continuously in the cloud.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UEjpul2k8R35EkxzGgBzyQ.png" /></figure><p>Every change flows automatically into containers on Kubernetes, and observability feeds what happens back to the team.</p><h3>8. Serverless architecture</h3><ul><li><strong>What it is:</strong> you write functions; the cloud provider runs and scales them. An API Gateway can route requests to functions such as AWS Lambda or Azure Functions.</li><li><strong>Key characteristics:</strong></li><li>Pay for execution and resources used (per your provider’s pricing model)</li><li>Automatic scaling</li><li>Event-driven execution</li><li>Stateless functions</li><li><strong>Strengths:</strong> no servers to manage; cost follows usage.</li><li><strong>Weaknesses:</strong> cold starts, execution time limits, vendor lock-in.</li><li><strong>Use it for:</strong> background processing, scheduled jobs, event handlers, lightweight APIs, and spiky workloads.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bkUPmTfiaEyptwEMZ6M2gg.png" /></figure><p>A function runs only when an HTTP request or an event arrives, and the provider handles the servers.</p><h3>Organizing by feature: vertical slices</h3><h3>9. Vertical slice architecture</h3><ul><li><strong>What it is:</strong> code organized by business feature (use case) instead of by technical layer.</li><li><strong>The problem it solves:</strong> in layered code, one feature such as “cancel order” is spread across controllers, services, and repositories, and shared classes like OrderService grow until every change risks breaking another feature.</li><li><strong>The idea:</strong> each slice cuts through all layers and holds everything one use case needs: request, validation, logic, data access, and response.</li><li><strong>Example features:</strong> CreateOrder, UpdateOrder, CancelOrder, GetOrderDetails.</li><li><strong>Each slice chooses its own approach:</strong> a read slice can use a fast SQL query, while a write slice uses a rich domain model.</li><li><strong>Strengths:</strong> high cohesion, low coupling, easy to find and change a feature; fits naturally with CQRS (each slice is a command or a query), often using MediatR in .NET.</li><li><strong>Weaknesses:</strong> some duplication between slices (fine until a real pattern emerges); needs team conventions to stay consistent.</li><li><strong>Use it for:</strong> apps with many distinct use cases and frequent feature changes. It pairs well with a modular monolith: modules set the big boundaries, slices organize the features inside.</li></ul><pre>Layered                      Vertical slices<br>Controllers/OrderController  Features/Orders/<br>Services/OrderService          CreateOrder/   (endpoint, handler, validator)<br>Repositories/OrderRepository   CancelOrder/   (endpoint, handler)<br>Models/OrderDto                GetOrderDetails/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEqXVHa9w2OU3R65k1_2fg.png" /></figure><p>Layers still exist, but code is grouped by the feature column, so one change stays inside one slice.</p><h3>How do you choose?</h3><p>There is no perfect architecture, only the right one for your context. Weigh these four factors:</p><ol><li><strong>Project requirements:</strong> complexity, scalability, performance, maintainability, security, and how often things will change.</li><li><strong>Team expertise:</strong> microservices and Kubernetes demand skills a small team may not have yet.</li><li><strong>Budget:</strong> development, infrastructure, deployment, and long-term maintenance all cost money.</li><li><strong>Timeline:</strong> a tight deadline favors simpler designs you can ship quickly.</li></ol><p>A useful rule of thumb: start simple. A well-structured modular monolith, organized internally with vertical slices, serves most products for a long time. Move to microservices, events, or serverless when a concrete need such as independent scaling or team autonomy justifies the extra complexity, not before.</p><p>Architecture is a tool, not a trophy. Pick the one that solves today’s problems while leaving room for tomorrow’s.</p><p><em>In Part 2 of this series, we’ll explore Application Performance.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c85fb242803" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication Explained Simply: Sessions, Cookies, JWT, OAuth 2.0, OIDC & API Keys]]></title>
            <link>https://medium.com/@ariful.sec/authentication-explained-simply-sessions-cookies-jwt-oauth-2-0-oidc-api-keys-c04ec96e5fab?source=rss-617dbb7dd500------2</link>
            <guid isPermaLink="false">https://medium.com/p/c04ec96e5fab</guid>
            <dc:creator><![CDATA[Md.Ariful Islam]]></dc:creator>
            <pubDate>Thu, 08 Oct 2026 12:46:55 GMT</pubDate>
            <atom:updated>2026-10-08T12:46:55.918Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How modern web applications know who you are, what you’re allowed to do, and how all these authentication terms fit together.</em></p><p>If you’ve worked with web development for a while, you’ve probably heard terms like:</p><p><strong>Cookies, Sessions, Tokens, JWT, OAuth 2.0, OIDC, Auth0, API Keys…</strong></p><p>At first, they can feel like a collection of unrelated technologies.</p><p>They’re not.</p><p>Most of them exist because of one simple problem:</p><blockquote><strong><em>HTTP has no memory.</em></strong></blockquote><p>Once you understand that, authentication becomes much easier to understand.</p><p>Let’s break it down using a simple example: an online shopping application.</p><h3>1. The Problem: HTTP Has No Memory</h3><p>Imagine you open an online store and log in.</p><p>You enter:</p><pre>Email: arif@example.com<br>Password: ********</pre><p>The server verifies your credentials and says:</p><blockquote><em>“Yes, this is Arif.”</em></blockquote><p>Now you click:</p><p><strong>Add to Cart</strong></p><p>Then:</p><p><strong>Checkout</strong></p><p>The problem is that HTTP treats every request as a new request.</p><p>The server receives something like:</p><pre>Request 1:<br>POST /login</pre><pre>Request 2:<br>POST /cart</pre><pre>Request 3:<br>POST /checkout</pre><p>Without some mechanism to maintain identity, the server doesn’t automatically know that all three requests came from the same person.</p><p>The server needs some way to answer:</p><blockquote><strong><em>“Who is making this request?”</em></strong></blockquote><p>That’s where authentication mechanisms come in.</p><p>Cookies, sessions, tokens, JWTs, OAuth, and OIDC are different pieces of the solution.</p><h3>2. Authentication vs Authorization</h3><p>Before going further, there’s an important distinction.</p><p>These two words are often confused:</p><h3>Authentication</h3><p><strong>Authentication answers:</strong></p><blockquote><em>“Who are you?”</em></blockquote><p>For example:</p><ul><li>Username and password</li><li>Fingerprint</li><li>Face recognition</li><li>Google login</li><li>Microsoft login</li></ul><h3>Authorization</h3><p><strong>Authorization answers:</strong></p><blockquote><em>“What are you allowed to do?”</em></blockquote><p>For example:</p><p>A normal customer might be allowed to:</p><pre>View products<br>Place orders<br>View their own orders</pre><p>But an administrator might also be allowed to:</p><pre>Delete products<br>Manage users<br>View reports<br>Change prices</pre><p>A simple way to remember this is:</p><blockquote><strong><em>Authentication = Who are you?</em></strong><em><br></em><strong><em>Authorization = What can you do?</em></strong></blockquote><p>Think about a hotel.</p><p>The receptionist checks your passport and confirms your identity.</p><p>That’s <strong>authentication</strong>.</p><p>Your room key allows you to enter your room but not someone else’s room.</p><p>That’s <strong>authorization</strong>.</p><p>This distinction becomes especially important when we talk about OAuth 2.0 and OIDC.</p><h3>3. Cookies: The Browser’s Envelope</h3><p>Let’s start with something very familiar:</p><p><strong>Cookies.</strong></p><p>A cookie is simply a small piece of data that a browser stores and automatically sends back to the same website.</p><p>A cookie itself is <strong>not a login system</strong>.</p><p>Think of it as an envelope.</p><p>The application decides what to put inside the envelope.</p><p>For example, after login, the server might send:</p><pre>Set-Cookie: sid=7f3a9c; HttpOnly; Secure; SameSite=Lax; Max-Age=3600</pre><p>Later, the browser automatically sends:</p><pre>Cookie: sid=7f3a9c</pre><p>The important part is:</p><pre>sid=7f3a9c</pre><p>The server can use that value to recognize the browser.</p><h3>Why are those flags important?</h3><p>You’ll often see cookie settings such as:</p><h3>HttpOnly</h3><p>JavaScript running in the browser cannot directly read the cookie.</p><p>This helps reduce the impact of certain XSS attacks.</p><h3>Secure</h3><p>The browser sends the cookie only over HTTPS.</p><h3>SameSite</h3><p>Controls when the browser sends the cookie with requests initiated from other websites.</p><p>This helps reduce CSRF-related risks.</p><h3>Max-Age / Expires</h3><p>Controls how long the cookie should remain valid.</p><p>So cookies solve a simple problem:</p><blockquote><strong><em>How can the browser automatically send some information back to the server on future requests?</em></strong></blockquote><p>But what should that information actually represent?</p><p>That’s where sessions come in.</p><h3>4. Sessions: The Server Remembers You</h3><p>A <strong>session</strong> keeps the user’s state on the server.</p><p>Imagine you log in.</p><p>The server creates something like:</p><pre>Session ID: 7f3a9c</pre><pre>User ID: 42<br>Role: Customer<br>Cart: Laptop</pre><p>The browser doesn’t need to carry all that information.</p><p>It only receives:</p><pre>sid=7f3a9c</pre><p>So the flow looks like this:</p><pre>Browser<br>   |<br>   | Login<br>   v<br>Server<br>   |<br>   | Creates session<br>   v<br>Session Store<br>   |<br>   | 7f3a9c → User 42<br>   |<br>   v<br>Browser receives:<br>sid=7f3a9c</pre><p>On the next request:</p><pre>Cookie: sid=7f3a9c</pre><p>The server looks up that session and discovers:</p><pre>User = 42<br>Role = Customer</pre><p>Now the server knows who is making the request.</p><h3>Why are sessions useful?</h3><p>One big advantage is control.</p><p>Suppose you want to log a user out immediately.</p><p>The server can simply delete the session:</p><pre>7f3a9c → deleted</pre><p>The cookie may still exist in the browser, but it no longer represents a valid session.</p><p>This makes things like:</p><ul><li>Logout</li><li>Force logout</li><li>Logout from all devices</li><li>Session revocation</li></ul><p>relatively straightforward.</p><h3>The downside</h3><p>The server needs to store session information.</p><p>Imagine you have several application servers:</p><pre>Load Balancer<br>          /     |      \<br>         /      |       \<br>     Server A Server B Server C</pre><p>A user logs in through Server A.</p><p>If Server A keeps the session only in its own memory, Server B may not know about it.</p><p>You can solve this with:</p><ul><li>Sticky sessions</li><li>Shared databases</li><li>Redis</li><li>Another shared session store</li></ul><p>But that adds infrastructure and complexity.</p><p>This is one reason stateless tokens became popular for APIs, mobile applications, and distributed systems.</p><h3>5. Tokens: The Client Carries the Proof</h3><p>Tokens change the approach.</p><p>With a session:</p><blockquote><em>The server remembers you.</em></blockquote><p>With a token:</p><blockquote><strong><em>You carry the proof with you.</em></strong></blockquote><p>After successful login, the server gives the client a token.</p><p>The client then sends that token with future API requests.</p><p>For example:</p><pre>Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...</pre><p>The word <strong>Bearer</strong> is important.</p><p>It essentially means:</p><blockquote><em>Whoever possesses this token can use it.</em></blockquote><p>Think of it like cash.</p><p>If someone steals your cash, they can spend it.</p><p>Similarly, if someone steals a valid bearer token, they may be able to use it until it expires or is otherwise invalidated.</p><h3>6. Access Tokens and Refresh Tokens</h3><p>Modern systems commonly separate tokens into two types.</p><h3>Access Token</h3><p>The access token is usually short-lived.</p><p>For example:</p><pre>5–15 minutes</pre><p>It’s sent with API requests.</p><p>Example:</p><pre>GET /api/orders</pre><pre>Authorization: Bearer &lt;access-token&gt;</pre><h3>Refresh Token</h3><p>A refresh token is longer-lived.</p><p>Its purpose is to obtain a new access token when the current one expires.</p><p>Conceptually:</p><pre>Login<br>  ↓<br>Access Token<br>  ↓<br>API calls<br>  ↓<br>Access Token expires<br>  ↓<br>Refresh Token<br>  ↓<br>New Access Token</pre><p>This gives us an important security advantage.</p><p>If an access token is stolen, its useful lifetime can be relatively short.</p><h3>7. JWT: A Format for Tokens</h3><p>Here’s where another common term appears:</p><p><strong>JWT — JSON Web Token.</strong></p><p>A JWT is not a completely different authentication system.</p><p>It’s a <strong>format for representing information inside a token</strong>.</p><p>A JWT usually looks like:</p><pre>header.payload.signature</pre><p>For example:</p><pre>eyJhbGciOiJIUzI1NiJ9<br>.<br>eyJzdWIiOiI0MiIsInJvbGUiOiJjdXN0b21lciJ9<br>.<br>signature</pre><p>The payload might contain claims such as:</p><pre>{<br>  &quot;sub&quot;: &quot;42&quot;,<br>  &quot;role&quot;: &quot;customer&quot;,<br>  &quot;exp&quot;: 1767225600<br>}</pre><p>The server can verify the signature and trust that the token hasn’t been modified.</p><h3>8. One Important JWT Misunderstanding</h3><p>Here’s something every developer should remember:</p><blockquote><strong><em>A JWT is signed, not automatically encrypted.</em></strong></blockquote><p>That means you should not put sensitive information inside a JWT just because it is encoded.</p><p>For example, don’t put:</p><pre>{<br>  &quot;password&quot;: &quot;MySecretPassword&quot;<br>}</pre><p>inside a JWT.</p><p>A JWT can be decoded and its payload read.</p><p>The signature protects the <strong>integrity</strong> of the token.</p><p>It doesn’t automatically provide <strong>confidentiality</strong>.</p><p>Another important point:</p><blockquote><strong><em>JWT does not automatically mean “more secure.”</em></strong></blockquote><p>JWT is mainly a token format.</p><p>Whether the overall authentication design is secure depends on how you issue, store, transmit, validate, expire, and revoke those tokens.</p><h3>9. OAuth 2.0: Let Another App Access Your Data</h3><p>Now we reach one of the most misunderstood terms:</p><p><strong>OAuth 2.0.</strong></p><p>OAuth is primarily about <strong>authorization</strong>, not authentication.</p><p>Imagine you build a photo-printing application.</p><p>Your application wants to access a user’s photos stored in Google Photos.</p><p>You could ask the user:</p><blockquote><em>“Give us your Google username and password.”</em></blockquote><p>That would be a terrible idea.</p><p>Your application would potentially have far more access than it needs.</p><p>Instead, OAuth lets the user grant limited permission.</p><p>The flow looks roughly like this:</p><pre>User<br>  |<br>  | &quot;I want PrintShop to access my photos&quot;<br>  v<br>PrintShop<br>  |<br>  | Redirect<br>  v<br>Google<br>  |<br>  | &quot;Allow PrintShop to view your photos?&quot;<br>  v<br>User approves<br>  |<br>  v<br>Google gives PrintShop an access token<br>  |<br>  v<br>PrintShop calls Google Photos API</pre><p>The permission might be limited to something like:</p><pre>photos.read</pre><p>The application gets access to what it needs without receiving the user’s Google password.</p><p>This is the key idea behind OAuth:</p><blockquote><strong><em>Allow one application to access another service on your behalf without sharing your password.</em></strong></blockquote><h3>10. The Four Roles in OAuth</h3><p>OAuth becomes easier to understand if you know the four main roles.</p><h3>Resource Owner</h3><p>Usually the user.</p><p>They own the data.</p><h3>Client</h3><p>The application requesting access.</p><p>For example:</p><pre>PrintShop</pre><h3>Authorization Server</h3><p>The system that authenticates the user and issues authorization tokens.</p><p>For example:</p><pre>Google</pre><h3>Resource Server</h3><p>The API containing the protected data.</p><p>For example:</p><pre>Google Photos API</pre><p>So:</p><pre>User<br>  ↓<br>PrintShop<br>  ↓<br>Google Authorization Server<br>  ↓<br>Access Token<br>  ↓<br>Google Photos API</pre><h3>11. OAuth Is Not Login</h3><p>This is one of the most important things to remember.</p><p>OAuth answers:</p><blockquote><strong><em>“Can this application access this resource?”</em></strong></blockquote><p>It does not primarily answer:</p><blockquote><strong><em>“Who is this user?”</em></strong></blockquote><p>That’s where <strong>OIDC</strong> comes in.</p><h3>12. OIDC: Login on Top of OAuth</h3><p><strong>OpenID Connect (OIDC)</strong> adds an identity layer on top of OAuth 2.0.</p><p>A simple way to remember it:</p><blockquote><strong><em>OAuth = authorization</em></strong><em><br></em><strong><em>OIDC = authentication/identity</em></strong></blockquote><p>When you see:</p><blockquote><strong><em>Sign in with Google</em></strong></blockquote><p>or:</p><blockquote><strong><em>Sign in with Microsoft</em></strong></blockquote><p>you’re commonly dealing with OIDC.</p><p>With OIDC, the identity provider can return an <strong>ID token</strong>.</p><p>The ID token is typically a JWT containing identity-related claims.</p><p>For example:</p><pre>{<br>  &quot;iss&quot;: &quot;https://accounts.google.com&quot;,<br>  &quot;sub&quot;: &quot;10987&quot;,<br>  &quot;email&quot;: &quot;ana@example.com&quot;,<br>  &quot;aud&quot;: &quot;printshop-app&quot;<br>}</pre><p>Your application can validate the token and learn:</p><pre>Who logged in?<br>Which application was the token issued for?<br>Has the token expired?<br>Was it issued by the expected identity provider?</pre><p>This is why OIDC is useful for:</p><ul><li>Sign in with Google</li><li>Sign in with Microsoft</li><li>Sign in with Apple</li><li>Corporate Single Sign-On</li><li>Enterprise applications</li></ul><h3>13. What Is Single Sign-On?</h3><p>Imagine a company has these applications:</p><pre>Jira<br>Slack<br>Internal HR System<br>Reporting System<br>Customer Portal</pre><p>Without SSO, employees might have separate accounts and passwords for each system.</p><p>With SSO:</p><pre>Company Identity Provider<br>                       |<br>        +--------------+--------------+<br>        |              |              |<br>       Jira           Slack        HR System</pre><p>The user signs in through the company’s identity provider.</p><p>The applications trust that identity provider.</p><p>This is one of the common real-world uses of OIDC.</p><h3>14. Auth0: Authentication as a Service</h3><p>Now let’s talk about <strong>Auth0</strong>.</p><p>Auth0 is not a protocol.</p><p>It is a hosted identity platform that implements standards such as OAuth 2.0 and OIDC.</p><p>Other platforms can play a similar role, including:</p><ul><li>Keycloak</li><li>Microsoft Entra ID</li><li>AWS Cognito</li><li>Firebase Authentication</li></ul><p>Imagine you’re building a startup application.</p><p>You need:</p><ul><li>Email/password login</li><li>Google login</li><li>Microsoft login</li><li>MFA</li><li>Password reset</li><li>Roles</li><li>Account recovery</li><li>Protection against brute-force attacks</li></ul><p>Building all of this yourself can take a lot of time and requires careful security work.</p><p>With a service such as Auth0, much of that infrastructure is handled for you.</p><p>Your application can redirect the user to the identity provider:</p><pre>Your App<br>   |<br>   | Login<br>   v<br>Auth0<br>   |<br>   | Authentication<br>   v<br>Auth0 returns tokens<br>   |<br>   v<br>Your App</pre><p>Your backend can then validate the tokens.</p><p>The major advantage is that you don’t have to build and maintain all the sensitive authentication infrastructure yourself.</p><p>But there are trade-offs.</p><p>You become dependent on:</p><ul><li>The provider</li><li>Its pricing</li><li>Its availability</li><li>Its configuration</li><li>Its ecosystem</li></ul><p>Migration away from a provider can also be difficult.</p><h3>15. API Keys: When Machines Talk to Machines</h3><p>Not every authentication scenario involves a human.</p><p>Sometimes one application needs to communicate with another.</p><p>For example:</p><pre>Your Backend<br>     |<br>     | API request<br>     v<br>Weather API</pre><p>Or:</p><pre>Your Backend<br>     |<br>     v<br>Payment Provider</pre><p>Or:</p><pre>Nightly Job<br>     |<br>     v<br>Internal Service</pre><p>For simple machine-to-machine scenarios, an <strong>API key</strong> may be enough.</p><p>For example:</p><pre>x-api-key: sk_live_4f9a2b...</pre><p>The server checks the key and identifies the calling application.</p><p>API keys are simple and useful for:</p><ul><li>Server-to-server communication</li><li>Internal services</li><li>Usage tracking</li><li>Rate limiting</li><li>Billing</li></ul><p>But API keys have an important weakness:</p><blockquote><strong><em>They don’t tell you which human user is making the request.</em></strong></blockquote><p>They identify the application or client.</p><p>Also, API keys are often long-lived.</p><p>If someone accidentally commits this:</p><pre>x-api-key: sk_live_4f9a2b...</pre><p>to GitHub, the key could be abused.</p><p>So API keys should be:</p><ul><li>Kept secret</li><li>Stored securely</li><li>Scoped as narrowly as possible</li><li>Rotated regularly</li></ul><h3>16. So How Are These Things Related?</h3><p>This is where everything starts to make sense.</p><p>These technologies aren’t necessarily competitors.</p><p>They can work together.</p><p>For example, a modern application might use:</p><pre>OIDC<br>                  ↓<br>            User Login<br>                  ↓<br>               Auth0<br>                  ↓<br>             JWT Tokens<br>                  ↓<br>             Your API<br>                  ↓<br>          Third-party APIs<br>                  ↓<br>              API Keys</pre><p>Or a traditional server-rendered application might use:</p><pre>Username + Password<br>        ↓<br>     Session<br>        ↓<br> HttpOnly Cookie<br>        ↓<br>     Web Server</pre><p>A mobile application might use:</p><pre>OIDC Login<br>    ↓<br>Access Token<br>    ↓<br>REST API</pre><p>The important thing is to understand <strong>what problem each component solves</strong>.</p><h3>17. A Simple Comparison</h3><p>TechnologyWhat is it?Common useMain concern<strong>Cookie</strong>Browser storage mechanismSending session/token dataCSRF, browser-specific<strong>Session</strong>Server-side user stateTraditional web applicationsNeeds shared storage when scaling<strong>Token</strong>Credential carried by clientAPIs, mobile apps, SPAsRevocation can be difficult<strong>JWT</strong>Standard token formatStateless authenticationReadable payload, stale claims<strong>OAuth 2.0</strong>Authorization frameworkAccess another service’s dataComplex to implement correctly<strong>OIDC</strong>Identity layer on OAuth 2.0Login and SSORequires correct token validation<strong>Auth0</strong>Hosted identity platformOutsourced authenticationCost and vendor dependency<strong>API Key</strong>Static application secretMachine-to-machine callsLeaks and long lifetimes</p><h3>18. Which One Should You Use?</h3><p>There isn’t one answer for every application.</p><p>A useful rule of thumb is:</p><h3>Building a traditional web application?</h3><p>Consider:</p><pre>Session + HttpOnly Cookie</pre><p>This is simple and gives the server strong control over sessions.</p><h3>Building a mobile app or API?</h3><p>A common approach is:</p><pre>Short-lived Access Token<br>+<br>Refresh Token</pre><p>JWT is one possible format for the access token.</p><h3>Want “Sign in with Google” or enterprise SSO?</h3><p>Look at:</p><pre>OIDC</pre><p>You can implement it yourself or use an identity provider.</p><h3>Your application needs access to another service?</h3><p>For example:</p><pre>Your App → Google Photos</pre><p>That’s where:</p><pre>OAuth 2.0</pre><p>comes into play.</p><h3>Machines need to communicate?</h3><p>For a simple server-to-server scenario:</p><pre>API Key</pre><p>may be appropriate.</p><p>For more complex systems, other mechanisms such as OAuth client credentials may be more suitable.</p><h3>19. The Easiest Mental Model</h3><p>If all these terms still feel confusing, remember this:</p><h3>Cookie</h3><blockquote><strong><em>“Here, browser, keep this small piece of information and send it back later.”</em></strong></blockquote><h3>Session</h3><blockquote><strong><em>“The server remembers who you are.”</em></strong></blockquote><h3>Token</h3><blockquote><strong><em>“Here is proof that you can present on future requests.”</em></strong></blockquote><h3>JWT</h3><blockquote><strong><em>“Here is a standard format for that token.”</em></strong></blockquote><h3>OAuth 2.0</h3><blockquote><strong><em>“Allow this application to access something on my behalf.”</em></strong></blockquote><h3>OIDC</h3><blockquote><strong><em>“Tell this application who I am.”</em></strong></blockquote><h3>Auth0</h3><blockquote><strong><em>“Let a service handle much of the identity infrastructure for me.”</em></strong></blockquote><h3>API Key</h3><blockquote><strong><em>“This application is allowed to call your API.”</em></strong></blockquote><p>Once you think about them this way, the terminology becomes much less intimidating.</p><h3>20. One Final Example</h3><p>Let’s put everything together with a realistic application.</p><p>Imagine you’re building an e-commerce platform.</p><p>A customer opens your website.</p><h3>Step 1 — Login</h3><p>The user signs in using Google.</p><p>You use:</p><pre>OIDC</pre><p>Google authenticates the user.</p><h3>Step 2 — Your application receives identity information</h3><p>Your application receives an ID token and validates it.</p><p>Now your application knows:</p><pre>User = Arif</pre><h3>Step 3 — Access the API</h3><p>Your frontend needs to call:</p><pre>GET /api/orders</pre><p>It sends an access token:</p><pre>Authorization: Bearer &lt;access-token&gt;</pre><h3>Step 4 — API validates the token</h3><p>Your backend validates the token and determines:</p><pre>User ID = 42</pre><p>It then checks authorization:</p><pre>Can user 42 view this order?</pre><h3>Step 5 — Call another service</h3><p>Your backend needs to send payment information to a payment provider.</p><p>It uses a credential such as an API key or another appropriate machine-to-machine authentication mechanism.</p><p>So one application can use several authentication technologies at the same time.</p><p>That’s completely normal.</p><h3>21. The Big Picture</h3><p>The most important lesson is that these technologies solve <strong>different problems</strong>.</p><p>The confusion usually comes from treating them as alternatives when they are often building blocks.</p><p>Think of authentication as a chain:</p><pre>WHO ARE YOU?<br>                      |<br>                     OIDC<br>                      |<br>                      ↓<br>                Identity Provider<br>                      |<br>                      ↓<br>                Access Token<br>                      |<br>                      ↓<br>                 Your API<br>                      |<br>                      ↓<br>              Authorization<br>                      |<br>                      ↓<br>                Your Resource</pre><p>And when your API needs to talk to another service:</p><pre>Your API<br>   |<br>   | API Key / OAuth<br>   v<br>External API</pre><p>The exact architecture depends on your application.</p><h3>Conclusion</h3><p>Authentication doesn’t need to be a collection of mysterious acronyms.</p><p>Start with the basic problem:</p><blockquote><strong><em>HTTP doesn’t remember who you are.</em></strong></blockquote><p>Then everything else becomes easier to understand.</p><p><strong>Cookies</strong> help the browser carry information.</p><p><strong>Sessions</strong> let the server remember users.</p><p><strong>Tokens</strong> let clients carry proof of identity or authorization.</p><p><strong>JWT</strong> provides a standard format for tokens.</p><p><strong>OAuth 2.0</strong> allows applications to access resources on a user’s behalf.</p><p><strong>OIDC</strong> adds identity and enables modern login and SSO.</p><p><strong>Auth0</strong> and similar platforms provide authentication infrastructure as a service.</p><p><strong>API keys</strong> provide a simple way for applications to authenticate with other services.</p><p>And most importantly:</p><blockquote><strong><em>These technologies are not necessarily rivals. They are tools that can be combined depending on the problem you’re solving.</em></strong></blockquote><p>Once you understand <strong>where the state lives, who holds the proof, and what that proof is allowed to do</strong>, the entire authentication landscape becomes much easier to reason about.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c04ec96e5fab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple, Scalable Architecture for Angular Projects]]></title>
            <link>https://medium.com/@ariful.sec/a-simple-scalable-architecture-for-angular-projects-ecb9d26583ac?source=rss-617dbb7dd500------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecb9d26583ac</guid>
            <category><![CDATA[angular-architecture]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[modern-architecture]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Md.Ariful Islam]]></dc:creator>
            <pubDate>Tue, 06 Oct 2026 11:25:52 GMT</pubDate>
            <atom:updated>2026-10-06T15:06:41.736Z</atom:updated>
            <content:encoded><![CDATA[<p>Ten <em>rules any team can follow, from the first component to the thousandth.</em></p><p>Every Angular project feels tidy at ten files. At a thousand, the folder structure decides whether a change takes ten minutes or a whole afternoon.</p><p>The fix isn’t more patterns. It’s a few simple rules that tell every developer where code goes and what each file is allowed to do. Here they are.</p><h3>1. Organize by feature, not by file type</h3><p>Don’t put all components in one folder and all services in another. Group code by the business area it belongs to.</p><pre>src/<br>├── app/        # App shell(header, sidebar, menus) and root routes<br>├── core/       # App-wide services: auth, guards, interceptors, config<br>├── shared/     # Generic, reusable UI and helpers<br>├── features/   # One folder per business area<br>└── assets/     # Images, fonts, static files</pre><p><strong>App </strong>folder is the frame around every screen: it sets up the app, draws the shared header and menus, and shows the right feature for each URL.</p><p><strong>Core </strong>contains application-wide functionality.</p><p><strong>Shared </strong>stores reusable UI elements.</p><p><strong>Features </strong>contain business-specific functionality.</p><h3>2. Keep shared/ small</h3><p>Before you move something into shared/, ask three questions:</p><ol><li>Is it generic?</li><li>Do two or more features use it?</li><li>Is it free of business logic?</li></ol><p>All three yes? It goes in shared/. Otherwise, it stays in its feature.</p><p><strong>Shared:</strong> button, input, table, modal, loading spinner, generic pipes.</p><p><strong>Not shared:</strong> customer dashboard, invoice summary, pricing card.</p><h3>3. Put everything for a feature in one folder</h3><p>A feature folder holds its page, service, models, routes, and helpers. Keep it flat.</p><pre>features/<br>└── orders/<br>    ├── order-list-page/<br>    ├── order-details/<br>    ├── models/<br>    ├── orders.service.ts<br>    ├── orders.routes.ts<br>    └── orders.utils.ts</pre><p>Anyone should find the page, service, and routes in seconds. Working on orders should rarely mean touching another feature.</p><h3>4. Give every file one job</h3><p>Components show data and react to the user. They don’t calculate, validate business rules, or call APIs.</p><ul><li><strong>Component:</strong> displays data, handles clicks and input.</li><li><strong>Service:</strong> talks to the API and manages feature data.</li><li><strong>Model:</strong> describes the shape of data.</li><li><strong>Utility:</strong> pure functions for business logic.</li><li><strong>Pipe:</strong> formats values for display.</li><li><strong>Guard:</strong> decides who can open a route.</li><li><strong>Interceptor:</strong> handles common HTTP work, like auth headers and errors.</li></ul><p>Small, single-purpose files are easier to read, test, and change.</p><h3>5. Use the simplest state tool that works</h3><p>You rarely need a state library.</p><ul><li><strong>Signals</strong> for local UI state: loading flags, selected tabs, open modals</li></ul><pre>loading = signal(false);<br>selectedTab = signal(&#39;details&#39;);</pre><p>Add a state library only when you have a real need for one.</p><h3>6. Only services call the API</h3><p>Data always flows the same way: <strong>Component → Service → API</strong>.</p><p>Components never inject HttpClient. Put API response types in the feature&#39;s models/ folder. Shared HTTP concerns like auth and error handling go in interceptors inside core/.</p><h3>7. Lazy-load every feature</h3><p>Don’t load the whole app on startup. Give each feature its own routes file and load it only when the user needs it.</p><pre>{<br>  path: &#39;orders&#39;,<br>  loadChildren: () =&gt;<br>    import(&#39;./features/orders/orders.routes&#39;).then(m =&gt; m.routes)<br>}</pre><p>The result is a faster first load and smaller bundles.</p><h3>8. Agree on coding standards early</h3><p>Consistent code is faster to review. Write these rules down before the first feature:</p><ul><li>Use standalone components, not NgModules.</li><li>Use one selector prefix for the whole app (e.g. app-).</li><li>Use kebab-case file names, and end page components with -page.</li><li>Keep one component per file and keep services small.</li><li>Turn on strict TypeScript.</li><li>Prefer composition over inheritance.</li><li>Avoid deeply nested folders.</li></ul><h3>9. Build for performance from day one</h3><p>Small habits add up to a fast app:</p><ul><li>Use OnPush-friendly patterns.</li><li>Track items in lists (@for (item of items; track item.id)).</li><li>Avoid unneeded subscriptions.</li><li>Optimize images and fonts.</li><li>Remove unused dependencies regularly.</li></ul><h3>10. Test, lint, and build before you merge</h3><p>Code that keeps logic in services and utilities is easy to test. Write unit tests for utilities, services, guards, interceptors, and pipes.</p><p>Then make every change pass three checks, in this order:</p><ol><li><strong>Unit tests:</strong> npm test</li><li><strong>Lint, with zero warnings:</strong> npm run lint</li><li><strong>Production build:</strong> npm run build</li></ol><h3>A quick checklist for every pull request</h3><ul><li>Is the code in the right feature folder?</li><li>Is anything in shared/ truly generic and used by 2+ features?</li><li>Does it avoid importing from other features?</li><li>Do components only handle display and user interaction?</li><li>Are API calls in a service, and is business logic in utilities?</li><li>Is local state handled with Signals?</li><li>Does it use modern APIs (inject(), input(), @if/@for)?</li><li>Is the feature lazy-loaded?</li><li>Does it work with a keyboard?</li><li>Do tests, lint, and the production build all pass?</li></ul><h3>Final thoughts</h3><p>The best architecture isn’t the one with the most folders. It’s the one your whole team understands and follows.</p><p>Organize by feature, keep shared code generic, give each file one job, and check every change before it merges. Write these rules in your README so new developers can follow them from day one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecb9d26583ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>