<?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 Vivek Shaurya on Medium]]></title>
        <description><![CDATA[Stories by Vivek Shaurya on Medium]]></description>
        <link>https://medium.com/@vivek_shaurya?source=rss-7c3489346ce0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QXlAkYdYt5GANll7-oqZbw.jpeg</url>
            <title>Stories by Vivek Shaurya on Medium</title>
            <link>https://medium.com/@vivek_shaurya?source=rss-7c3489346ce0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 06:01:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vivek_shaurya/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[Universal Commerce Protocol (UCP): Turning AI Conversations into Transactions]]></title>
            <link>https://towardsdev.com/universal-commerce-protocol-ucp-turning-ai-conversations-into-transactions-bf0a54d02131?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf0a54d02131</guid>
            <category><![CDATA[ucp]]></category>
            <category><![CDATA[google-ucp]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[commerce]]></category>
            <category><![CDATA[conversational-commerce]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 15:56:00 GMT</pubDate>
            <atom:updated>2026-03-14T13:31:33.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXiAhFYChqJYTNJa2bj1TQ.png" /><figcaption>Image credit: Google Developers Blog (2026)</figcaption></figure><p>These days, before buying anything, what do we do?</p><p>We open ChatGPT or Gemini or some AI assistant.<br>We ask:</p><ol><li>“Best laptop under ₹80,000?”</li><li>“Compare iPhone 17 vs Samsung S25 Ultra.”</li><li>“Is this worth it?”</li><li>“Show me alternatives.”</li></ol><p>We research inside a conversation. <strong>“We compare. We evaluate. We ask follow-up questions.”</strong></p><p>But then something strange happens. After all that AI-powered intelligence…</p><p><strong>We leave.</strong></p><p>We go back to a website. We search again. Add to cart. Fill address. Enter payment details.</p><p>We drop from <strong>intelligent conversation </strong>back to <strong>manual checkout forms</strong>.</p><p>That friction is exactly where the future is changing.</p><h3>The Missing Layer in AI Commerce</h3><p>Search has evolved.</p><p>It used to be:</p><blockquote>Search → Click → Browse → Buy</blockquote><p>Now it looks like:</p><blockquote>Ask → Compare → Decide</blockquote><p>But one step is still missing:</p><blockquote>Ask → Compare → Decide <strong>→<em> Purchase</em></strong></blockquote><p>Right now, AI helps us decide. But it does not complete the transaction in a standardized, scalable way.<br>And this is where <strong>Universal Commerce Protocol (UCP)</strong> enters.</p><h3>What is Universal Commerce Protocol (UCP)?</h3><p>Universal Commerce Protocol (UCP) is a standardized commerce layer designed for agentic transactions.</p><p>It introduces a common language so that:</p><ul><li>Any AI agent</li><li>Any LLM-powered assistant</li><li>Any conversational interface</li></ul><p>Can securely connect to a merchant’s backend and execute real commerce operations.</p><p>Not by scraping websites. Not by simulating button clicks. Not by acting like a browser bot.</p><p>But by interacting directly with structured commerce capabilities exposed by the merchant.</p><p>In simple words:</p><blockquote><strong>UCP is the bridge between AI intelligence and merchant infrastructure.</strong></blockquote><h3>The Core Problem UCP Solves</h3><p>Today, integrations don’t scale.</p><p>If 10 AI agents want to integrate with 1,000 merchants, that becomes 10,000 custom integrations.</p><p>Every agent needs custom APIs. Every merchant builds custom logic. Every payment flow is slightly different. It’s fragmented.</p><p><strong>UCP reduces this N × N complexity into a standardized model.</strong></p><p>Merchants expose a <strong>UCP profile</strong> (usually via a <strong>./well-known/ucp</strong> endpoint).<br>Agents discover supported capabilities. And interaction happens in a uniform way.</p><p><strong>One integration. Interoperable everywhere.</strong></p><h3>How UCP Works (Architectural View)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qt8q5aI2A30LI3I-l6BN6g.png" /><figcaption>Image credit: Google Developers Blog ( (2026))</figcaption></figure><p>UCP structures commerce into modular capabilities.</p><p>Instead of saying “here is my checkout API,” a merchant says:</p><p><strong>“I support these capabilities.”</strong></p><p>For example:</p><ul><li>Product discovery</li><li>Cart management</li><li>Checkout session creation &amp; completion</li></ul><p>An AI agent first discovers the merchant’s UCP manifest.</p><p>From there:</p><ol><li>It understands what operations are supported.</li><li>It initiates a checkout session.</li><li>It adds products to cart.</li><li>It handles pricing validation.</li><li>It confirms payment.</li><li>It places the order.</li></ol><p>All using standardized protocol definitions. This makes commerce programmable. Not page-driven. Not UI-driven. Capability-driven.</p><h3>What This Enables in the Future</h3><p>Now imagine the possibilities:</p><ul><li>You compare 5 products in a conversation.</li><li>You say: “Buy the second one.”</li><li>The AI negotiates discounts.</li><li>Applies loyalty credits.</li><li>Chooses optimal payment method.</li><li>Confirms shipping.</li><li>Places the order.</li></ul><p>All without you leaving the conversation. This is not just “AI shopping.” This is programmable commerce.</p><p>In the future, we could see:</p><ul><li>Multi-agent price negotiation</li><li>Autonomous recurring purchases</li><li>Context-aware checkout</li><li>Cross-platform cart portability</li><li>Intelligent dynamic payment routing</li></ul><p>UCP becomes the foundation layer for all of it.</p><h3>Why This Matters Now</h3><p>AI is becoming the primary interface layer.</p><p>People don’t start with websites anymore. They start with questions. If commerce doesn’t evolve into something agents can understand natively, we create friction.</p><p><strong>UCP removes that friction.</strong></p><blockquote>It standardizes the language between:<br>- Intelligence and Transaction.</blockquote><h3>Final Thoughts</h3><p>Web commerce taught us how to sell online. Universal Commerce Protocol teaches us how commerce works when intelligence becomes the interface.</p><p>We are moving from:</p><blockquote>Search → Click → Buy</blockquote><p>To:</p><blockquote>Ask → Decide → Execute</blockquote><p>That execution layer needs structure. <strong>UCP is that structure. </strong>Websites were built for users. <strong>UCP is built for agents. </strong>And that difference defines the next decade of digital commerce.</p><p>In the next part <a href="https://medium.com/towardsdev/designing-a-ucp-server-from-protocol-to-production-5cec57c9084c">[Part-2]</a>, we stop discussing the vision. We start building it.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf0a54d02131" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/universal-commerce-protocol-ucp-turning-ai-conversations-into-transactions-bf0a54d02131">Universal Commerce Protocol (UCP): Turning AI Conversations into Transactions</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing a UCP Server: From Protocol to Production]]></title>
            <link>https://towardsdev.com/designing-a-ucp-server-from-protocol-to-production-5cec57c9084c?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cec57c9084c</guid>
            <category><![CDATA[ucp]]></category>
            <category><![CDATA[google-ucp]]></category>
            <category><![CDATA[commerce]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Wed, 04 Mar 2026 20:56:00 GMT</pubDate>
            <atom:updated>2026-03-14T13:30:37.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXiAhFYChqJYTNJa2bj1TQ.png" /><figcaption>Image credit: Google Developers Blog (2026)</figcaption></figure><p>In the previous article <a href="https://medium.com/towardsdev/universal-commerce-protocol-ucp-turning-ai-conversations-into-transactions-bf0a54d02131">[Part-1]</a>, we explored why UCP matters. Now we design it. Because understanding the protocol is one thing. Building a UCP-compliant backend is another. When an AI agent connects to your system, it does not browse. It executes structured commerce operations.That means your backend must be:</p><ul><li>Discoverable.</li><li>State-driven.</li><li>Idempotent.</li><li>Authoritative on pricing.</li></ul><p>At the center of everything lies one object: Checkout Session. <br><strong>Let’s build it.</strong></p><h3>Designing a UCP Server</h3><p>Now let’s move from theory to implementation.</p><p>If you want to build your own UCP-compliant server, what does it actually look like?</p><p>At the core of UCP is a stateful object: <strong>Checkout Session</strong>.</p><p>Everything revolves around it.</p><h3>The Checkout Session Object (Deep Structure)</h3><p>A checkout session is not just a cart. It is a transactional state machine.</p><p>A simplified version of a UCP checkout object may look like this:</p><pre>{<br>  &quot;checkout_session_id&quot;: &quot;cs_123456&quot;,<br>  &quot;status&quot;: &quot;PENDING&quot;,<br>  &quot;currency&quot;: &quot;USD&quot;,<br>  &quot;buyer&quot;: {<br>    &quot;name&quot;: &quot;John Doe&quot;,<br>    &quot;email&quot;: &quot;john@example.com&quot;<br>  },<br>  &quot;line_items&quot;: [<br>    {<br>      &quot;id&quot;: &quot;line_1&quot;,<br>      &quot;item&quot;: {<br>        &quot;id&quot;: &quot;prod_123&quot;,<br>        &quot;title&quot;: &quot;Sample Product&quot;<br>      },<br>      &quot;quantity&quot;: 2,<br>      &quot;unit_amount&quot;: 5000,<br>      &quot;total_amount&quot;: 10000<br>    }<br>  ],<br>  &quot;pricing&quot;: {<br>    &quot;subtotal&quot;: 10000,<br>    &quot;discount_total&quot;: 1000,<br>    &quot;tax_total&quot;: 900,<br>    &quot;grand_total&quot;: 9900<br>  },<br>  &quot;payment&quot;: {<br>    &quot;instruments&quot;: [],<br>    &quot;selected_instrument_id&quot;: null<br>  },<br>  &quot;order_id&quot;: null,<br>  &quot;created_at&quot;: &quot;2026-02-26T10:00:00Z&quot;,<br>  &quot;updated_at&quot;: &quot;2026-02-26T10:05:00Z&quot;<br>}</pre><p>Important things to notice:</p><ul><li>checkout_session_id → global transaction reference</li><li>status → controls lifecycle</li><li>line_items → structured product entries</li><li>pricing → recalculated after every mutation</li><li>payment → attached only during completion</li><li>order_id → null until finalized</li></ul><p>This object evolves. It is never <strong>static.</strong></p><h3>Status as a State Machine</h3><p>UCP checkout flows are state-driven.</p><p>Typical lifecycle:</p><blockquote>PENDING → READY_FOR_COMPLETE → COMPLETED</blockquote><p>Or:</p><blockquote>PENDING → VALIDATION_FAILED → UPDATED → READY_FOR_COMPLETE</blockquote><p>Nothing is implicit. The agent always reads the status before taking the next step.</p><p>This prevents:</p><ul><li>Double charges</li><li>Duplicate orders</li><li>Inconsistent pricing</li><li>Race conditions</li></ul><p>Your server is effectively implementing a controlled state machine.</p><h3>Required Headers: Why They Matter</h3><p>In your implementation, you correctly require:</p><ul><li>idempotency-key</li><li>request-id</li><li>ucp-agent</li></ul><p>This is not optional decoration. This is critical for distributed commerce.</p><blockquote><strong>Note: Idempotency-Key</strong></blockquote><blockquote>If an AI agent retries a request (network issue, timeout), the same idempotency key ensures: No duplicate session creation or order placement. Commerce must be safe under retries.</blockquote><h3>Core Endpoints a UCP Server Must Expose</h3><p>A UCP-compliant commerce backend is not just an API server. It must expose a predictable capability surface. At minimum, your server should implement:</p><h4>1. Discovery</h4><pre>GET /.well-known/ucp</pre><p>This is the entry point. When an AI agent wants to transact with your backend, it first calls this route.</p><p>Your response must declare:</p><ul><li>UCP version</li><li>Supported capabilities (e.g. checkout)</li><li>Endpoint URLs</li><li>Supported payment handlers</li><li>Capability identifiers</li><li>Version metadata</li></ul><p>This makes your backend discoverable.</p><p>No hardcoded integrations. No prior coordination. The agent learns dynamically what your server supports.</p><h4>2. Checkout Lifecycle</h4><p>Your server must support the full checkout session lifecycle:</p><pre>POST   /checkout-sessions<br>GET    /checkout-sessions/:id<br>PUT    /checkout-sessions/:id<br>POST   /checkout-sessions/:id/complete</pre><p>Each of these is not just a CRUD endpoint. They represent state transitions.</p><h4>3. Creating a Checkout Session</h4><p>When the agent detects purchase intent, it initiates:</p><pre>POST /checkout-sessions</pre><p>The payload usually includes:</p><ul><li>currency</li><li>buyer (guest or authenticated user)</li><li>initial line_items (optional)</li><li>contextual metadata</li></ul><p>Your server must:</p><ol><li>Validate request structure</li><li>Validate product IDs</li><li>Enrich pricing</li><li>Apply discounts</li><li>Calculate tax</li><li>Persist the session</li><li>Return the full checkout object</li></ol><blockquote>At this stage:<br><strong>status = PENDING</strong></blockquote><p>Nothing is committed. Inventory is not locked permanently. No order exists yet. This is only the beginning of the negotiation phase.</p><h4>4. The Negotiation Loop (PUT Updates)</h4><p>This is where UCP becomes powerful. The checkout session is mutable until completion.</p><p>Each time the user says:</p><ul><li>“Add one more.”</li><li>“Remove that.”</li><li>“Apply coupon SAVE10.”</li><li>“Change shipping address.”</li></ul><p>The agent sends:</p><pre>PUT /checkout-sessions/:id</pre><p>Your server must:</p><ul><li>Revalidate every line item</li><li>Recalculate totals</li><li>Re-evaluate discounts</li><li>Recompute tax</li><li>Update timestamps</li><li>Update status accordingly</li></ul><p>The session object is rewritten and returned.</p><blockquote>Important:</blockquote><blockquote>You are not placing an order. You are synchronizing state. <br>This can happen multiple times.<br>Commerce becomes a negotiation protocol instead of a one-click commit.</blockquote><h4>5. Transitioning to READY_FOR_COMPLETE</h4><p>At some point, your server should mark:</p><blockquote><strong>status = READY_FOR_COMPLETE</strong></blockquote><p>This means:</p><ul><li>All validations passed</li><li>Pricing is consistent</li><li>Required buyer information exists</li><li>Payment instrument is attached (if required)</li></ul><p>The agent reads the status. Only then should it move to finalization.</p><p>This protects your system from incomplete transactions.</p><h4>6. Completing the Checkout</h4><p>Completion must be explicit.</p><pre>POST /checkout-sessions/:id/complete</pre><p>Or in some implementations:</p><pre>PUT /checkout-sessions/:id<br>{<br>  &quot;action&quot;: &quot;complete&quot;,<br>  &quot;payment&quot;: {...}<br>}</pre><p>Now your backend must:</p><ol><li>Authorize payment</li><li>Validate payment token</li><li>Create order in your commerce system</li><li>Generate order_id</li><li>Persist order mapping</li><li>Lock the session</li><li>Set status = COMPLETED</li></ol><p>After this:</p><p>The session becomes immutable. No more PUT updates. No more recalculations.</p><p>It is a finalized commercial transaction.</p><h3>Payment Object Structure</h3><p>During completion, your payment object might look like:</p><pre>{<br>  &quot;payment&quot;: {<br>    &quot;instruments&quot;: [<br>      {<br>        &quot;id&quot;: &quot;card_1&quot;,<br>        &quot;type&quot;: &quot;card&quot;,<br>        &quot;handler_id&quot;: &quot;your_payment_handler&quot;<br>      }<br>    ],<br>    &quot;selected_instrument_id&quot;: &quot;card_1&quot;<br>  }<br>}</pre><p>Your server must validate:</p><ul><li>The instrument exists</li><li>It belongs to this session</li><li>The handler is supported</li><li>The amount matches the checkout total</li></ul><p>This prevents tampering between negotiation and payment.</p><h3>What Makes a Server Truly UCP-Compliant</h3><p>A UCP-compliant server must:</p><ul><li>Expose discovery manifest</li><li>Implement checkout lifecycle</li><li>Enforce idempotency</li><li>Maintain strict state transitions</li><li>Prevent duplicate finalization</li><li>Return structured error responses</li><li>Keep pricing authoritative on server side</li></ul><blockquote>The AI agent never decides totals. The backend is the single source of truth. Always.</blockquote><h3>The Full Technical Flow (System View)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oYWcAL_Qiqu82v_aa1rP_w.png" /></figure><p><strong>Everything is structured. Everything is idempotent. Everything is state-driven.</strong></p><h3>Final Conclusion</h3><p>Web commerce taught us how to sell online. Universal Commerce Protocol is teaching us how commerce will work in an AI-native future.</p><p>This shift is not about improving checkout pages — it is about redefining how transactions happen when intelligence becomes the interface.</p><p><strong>Websites </strong>were built for <strong>users</strong>. <strong>UCP </strong>is built for <strong>agents</strong>.</p><p>And that difference defines the next decade of digital commerce.</p><p>We are moving from:</p><ol><li>Clicking to purchase to instructing intelligence to execute</li><li>Designing pages to designing transactional protocols</li></ol><p>UCP represents that future — where commerce is structured, programmable, and interoperable across agents.</p><blockquote>Not website-first. Not app-first. Agent-first.</blockquote><p>And that future is already beginning.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cec57c9084c" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/designing-a-ucp-server-from-protocol-to-production-5cec57c9084c">Designing a UCP Server: From Protocol to Production</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Containers to Kubernetes: Understanding Deployments, Services, and Real Execution]]></title>
            <link>https://towardsdev.com/from-containers-to-kubernetes-understanding-deployments-services-and-real-execution-4c053964746f?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c053964746f</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[hands-on-tutorials]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Thu, 25 Dec 2025 10:06:01 GMT</pubDate>
            <atom:updated>2025-12-25T10:06:01.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZAy4spHskR7n3XmR-T4ZNQ.png" /><figcaption>From Containers to Kubernetes</figcaption></figure><p>In the previous article, <a href="https://medium.com/towardsdev/from-code-to-container-the-architecture-of-modern-apps-part-1-460135014dc1"><em>From Code to Container</em></a>, we focused on Docker — how applications are packaged into immutable, portable units that behave consistently across environments. Docker solves a critical problem: <strong>application packaging</strong>.</p><p>However, once an application is containerized, a new set of challenges immediately emerges: <em>how do we run these containers reliably, scale them, expose them to traffic, and recover from failures?</em></p><p>This is where Docker stops being enough.</p><p>Kubernetes does not replace Docker — it <strong>orchestrates</strong> <strong>containerized applications at runtime</strong>. This article explores that execution layer. We will work directly with <strong>raw Kubernetes manifests</strong>, not abstractions, and break down what each file and field means technically — not how to copy-paste it.</p><p>This is the layer where orchestration begins and deployment architecture starts to matter.</p><h3>1. Kubernetes Architecture: An Execution-Focused View</h3><p>At runtime, a Kubernetes cluster is divided into two logical parts:</p><ul><li><strong>The Control Plane</strong> — decides <em>what should happen</em></li><li><strong>Worker Nodes</strong> — make it <em>actually happen</em></li></ul><p>A critical mindset shift happens here:</p><blockquote><em>You never “run” containers directly in Kubernetes.</em></blockquote><p>Instead, you <strong>declare a desired state</strong>, and Kubernetes continuously reconciles the real system toward that state. If something drifts — a container crashes, a node disappears, a process exits — Kubernetes reacts automatically.</p><p>This <strong>reconciliation loop</strong> is the foundation behind every YAML file you will write.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gXPLRW5wdcvTMpGmQtLbwg.jpeg" /><figcaption>Architecture of kubernetes Cluster</figcaption></figure><h4>1.1 Control Plane: How Kubernetes Decides</h4><p>The control plane does not run containers. It enforces intent.</p><p>It consists of the <strong>API Server, etcd, Controller Manager, and Scheduler.</strong></p><p><strong>a. API Server</strong>: The API Server is the front door of the Kubernetes cluster.</p><p>• All requests go through it (kubectl, controllers, schedulers)</p><p>• Exposes a REST API over HTTPS</p><p>• Handles authentication, authorization, and validation</p><p>Every YAML file you apply is first validated and persisted through the API Server.</p><p><strong>b. etcd: </strong>It is a distributed key-value store that serves as the source of truth for the cluster.</p><p>• Stores desired state, actual state and metadata and configuration.</p><p>If etcd is unavailable, Kubernetes cannot make decisions.</p><p><strong>c. Controller Manager: </strong>The Controller Manager runs a set of background reconciliation loops.</p><p>Each controller continuously asks:</p><p>“Does the actual state match the desired state?”</p><p>This is where Kubernetes’ self-healing behavior comes from.</p><p><strong>d. Scheduler: </strong>The Scheduler decides where Pods should run.</p><p>• Evaluates resource requirements</p><p>• Considers constraints</p><p>• Assigns Pods to worker nodes</p><p>It does not start containers — it only makes placement decisions.</p><h4>1.2 Worker Nodes: Where Execution Happens</h4><p>Worker nodes are where containers actually run.</p><p>It consists of the <strong>Kubelet, Container Runtime, kube-proxy.</strong></p><p><strong>a. kubelet: </strong>kubelet is an agent running on every worker node.</p><p>• Watches Pod specifications from the API Server</p><p>• Ensures containers described in a Pod are running and healthy</p><p>• Reports status back to the control plane</p><blockquote><em>If a container crashes, kubelet ensures the Pod state is reconciled by restarting containers as needed.</em></blockquote><p><strong>b .Container Runtime: </strong>The container runtime is responsible for running containers.</p><p>Kubernetes interacts with the runtime through the Container Runtime Interface (CRI).</p><p><strong>c. kube-proxy: </strong>kube-proxy maintains network rules on each node.</p><p>• Implements Service networking</p><p>• Manages iptables / IPVS rules</p><p>• Enables Pod-to-Pod and Service communication</p><p>This is what allows Services to route traffic dynamically as Pods change.</p><h3>2. What a Kubernetes Deployment Really Is</h3><p>A common misconception is that a Deployment is simply a way to start containers. That is incorrect.</p><p>A <strong>Deployment is a declarative state machine</strong>. It defines <em>how many</em> instances of an application should exist, <em>which version</em> should be running, and <em>how transitions between versions should occur</em>. It is responsible for replica management, rolling updates, crash recovery, and version history.</p><p>You describe <strong>what should exist, while </strong>Kubernetes decides <strong>how to make reality match it</strong>.</p><h3>3. Hands-On: Running a Real Application on Kubernetes</h3><p>Up to this point, we’ve talked about <em>what</em> Kubernetes is and <em>how</em> it thinks.</p><p>Now it’s time to actually <strong>use it</strong>. Every real Kubernetes application — no matter how small — starts with the same two building blocks:</p><ul><li>a <strong>Deployment</strong> to define <em>how the application runs.</em></li><li>a <strong>Service</strong> to define <em>how the application is accessed.</em></li></ul><p>To keep the focus strictly on Kubernetes behavior, we’ll deploy <strong>NGINX</strong> — a simple, stateless web server that is widely used in production systems.</p><h4>3.1 Deployment File: Running NGINX Inside the Cluster</h4><p>Create a file named deployment.yaml.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>        - name: nginx<br>          image: nginx:latest<br>          ports:<br>            - containerPort: 80</pre><p>Apply the Deployment:</p><pre>kubectl apply -f deployment.yaml</pre><p>Check what Kubernetes created:</p><pre>kubectl get deployments<br>kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EXVnjBOhoDgKjSv04wdifQ.png" /></figure><p>At this stage, NGINX <strong>is running</strong>, but you cannot access it yet. That is intentional — and important.</p><p>Before exposing it, let’s understand what this file actually tells Kubernetes to do.</p><h4>3.2 What This Deployment File Really Means</h4><p>The first two lines define <strong>which controller owns this object</strong>.</p><pre>apiVersion: apps/v1<br>kind: Deployment</pre><p>This tells Kubernetes to hand this manifest to the <strong>Deployment controller</strong>, which is responsible for managing ReplicaSets and Pods. Kubernetes validates the file against the apps/v1 schema <em>before</em> anything is scheduled. If the schema is wrong, the object is rejected immediately.</p><h4>Identity Inside the Cluster</h4><pre>metadata:<br>  name: nginx-deployment</pre><p>This name uniquely identifies the Deployment within the namespace. Kubernetes uses it to:</p><ul><li>track rollout history</li><li>name ReplicaSets and Pods</li><li>allow tools like kubectl to reference it</li></ul><p>This name becomes part of the internal identity of everything created by this Deployment.</p><h4>Declaring Desired State, Not Starting Containers</h4><pre>spec:<br>  replicas: 2</pre><p>This does <strong>not</strong> mean “start two containers”.</p><p>It means: <em>At all times, exactly two Pods running this application must exist.</em></p><p>Kubernetes continuously enforces this rule:</p><ul><li>if a Pod crashes → a new one is created</li><li>if a node goes down → Pods are rescheduled</li><li>if a Pod is deleted manually → Kubernetes recreates it</li></ul><p>This is declarative execution — not imperative control.</p><h4>Labels and Selectors: The Most Important Contract</h4><pre>selector:<br>  matchLabels:<br>    app: nginx</pre><p>Deployments do not track Pods by name. They track Pods by <strong>labels</strong>.</p><p>This selector defines which Pods belong to the Deployment. If the selector does not match the labels applied to Pods, Kubernetes will keep creating Pods that the Deployment cannot “see”, resulting in uncontrolled Pod creation.</p><p>This selector–label relationship is one of the most critical rules in Kubernetes.</p><h4>Pod Template: How Pods Are Created</h4><pre>template:<br>  metadata:<br>    labels:<br>      app: nginx</pre><p>The Pod template defines how Pods should look <em>when Kubernetes needs to create one</em>. Every Pod created by this Deployment is generated from this template.</p><p>Kubernetes is effectively saying:</p><blockquote><em>“Whenever a Pod needs to exist, create it like this.”</em></blockquote><p>The labels here <strong>must</strong> match the selector above — this is what links Pods back to the Deployment.</p><h4>Container Execution Inside the Pod</h4><pre>containers:<br>  - name: nginx<br>    image: nginx:latest<br>    ports:<br>      - containerPort: 80</pre><p>A Pod can technically run multiple containers, but they share:</p><ul><li>the same network namespace</li><li>the same storage volumes</li><li>the same lifecycle</li></ul><p>Most application Pods run a single container.</p><p>Kubernetes does <strong>not</strong> build images. It only pulls and runs them. The containerPort field does not expose traffic — it serves as metadata for Kubernetes and is referenced later by Services and probes.</p><blockquote>Deployment File Recap</blockquote><pre>apiVersion: apps/v1          # Uses the stable Deployment API<br>kind: Deployment             # Tells Kubernetes to use the Deployment controller<br><br>metadata:<br>  name: nginx-deployment     # Unique identifier for this Deployment<br><br>spec:<br>  replicas: 2                # Desired number of Pods at all times<br><br>  selector:<br>    matchLabels:<br>      app: nginx             # Deployment tracks Pods using this label<br><br>  template:<br>    metadata:<br>      labels:<br>        app: nginx           # Must match selector labels exactly<br><br>    spec:<br>      containers:<br>        - name: nginx        # Container name inside the Pod<br>          image: nginx:latest # Docker image pulled from registry<br>          ports:<br>            - containerPort: 80 # Container listens on port 80 (not exposed)</pre><blockquote>This annotated version ties the entire Deployment file together. Every field contributes either to <strong>identity</strong>, <strong>desired state</strong>, or <strong>runtime execution</strong>. Once this file is applied, Kubernetes takes full ownership of keeping the declared state true — even in the presence of failures.</blockquote><h4>3.3 What Kubernetes Created for You</h4><p>After applying the Deployment, Kubernetes created the following hierarchy:</p><pre>Deployment<br> → ReplicaSet<br>   → Pods<br>     → Containers</pre><p>You never directly manage ReplicaSets or Pods. They are implementation details handled by the Deployment controller. Understanding this hierarchy is essential when debugging real systems.</p><h4>3.4 Service File: Exposing NGINX Correctly</h4><p>Even though NGINX is running, it is still <strong>not reachable</strong>.</p><p>Pods have IP addresses, but:</p><ul><li>Pod IPs are ephemeral</li><li>Pods can be recreated at any time</li><li>Hardcoding Pod IPs is invalid by design</li></ul><p>This is why Kubernetes introduces <strong>Services</strong>.</p><blockquote>Create a file named service.yaml.</blockquote><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: nginx-service<br>spec:<br>  type: NodePort<br>  selector:<br>    app: nginx<br>  ports:<br>    - port: 80<br>      targetPort: 80<br>      nodePort: 30007</pre><p>Apply it:</p><pre>kubectl apply -f service.yaml</pre><p>Verify:</p><pre>kubectl get services</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttWtYomzJOq0299qdnjYZg.png" /></figure><p>Now you can access the application at : <a href="http://localhost:30007/"><em>http://localhost:30007</em></a></p><p>You now have a fully working Kubernetes application:</p><ul><li>multiple replicas</li><li>self-healing</li><li>stable networking</li></ul><h4>3.5 What the Service File Actually Does</h4><p>A Service provides a <strong>stable virtual IP and DNS name</strong>, backed by a dynamic list of Pod endpoints. Internally, this is implemented using kube-proxy with iptables or IPVS rules.</p><pre>selector:<br>  app: nginx</pre><p>Services do not know about Deployments. They only care about <strong>labels</strong>.</p><p>They continuously scan the cluster for matching Pods and update routing automatically as Pods are created, destroyed, or replaced.</p><h4>Port Mapping and Abstraction</h4><pre>ports:<br>  - port: 80<br>    targetPort: 80</pre><ul><li>port is the Service-facing port</li><li>targetPort is the container port</li></ul><p>This abstraction allows container internals to change without breaking consumers — a small detail that becomes critical at scale.</p><h4>Why NodePort Is Used Here</h4><pre>type: NodePort</pre><p>NodePort exposes the Service on a fixed port across all nodes. It is ideal for:</p><ul><li>local clusters</li><li>learning</li><li>debugging</li></ul><p>In production systems, this is usually replaced by Ingress controllers, LoadBalancers, or service meshes.</p><blockquote>Service File Recap</blockquote><pre>apiVersion: v1               # Core Kubernetes Service API<br>kind: Service                # Creates a stable network abstraction<br><br>metadata:<br>  name: nginx-service        # Service identity inside the cluster<br><br>spec:<br>  type: NodePort             # Exposes Service on a node-level port<br><br>  selector:<br>    app: nginx               # Routes traffic to Pods with this label<br><br>  ports:<br>    - port: 80               # Port exposed by the Service<br>      targetPort: 80         # Port on the container<br>      nodePort: 30007        # Fixed port exposed on each node</pre><blockquote>This Service definition creates a stable access layer over ephemeral Pods. As Pods are recreated or scaled, the Service dynamically updates its endpoints without requiring any configuration changes from the consumer.</blockquote><h4><strong>3.6 How Services Can Be Exposed in Kubernetes</strong></h4><ol><li><strong>ClusterIP (default)</strong></li></ol><ul><li>Exposes the Service only inside the cluster</li><li>Used for internal communication between services</li></ul><p><strong>2. NodePort</strong></p><ul><li>Exposes the Service on a fixed port on every node</li><li>Useful for learning, debugging, and local clusters</li></ul><p><strong>3. LoadBalancer</strong></p><ul><li>Provisions an external load balancer (cloud-dependent)</li><li>Common in managed Kubernetes environments</li></ul><p><strong>4. Ingress (with ClusterIP)</strong></p><ul><li>Not a Service type, but a routing layer on top of Services</li><li>Enables host-based and path-based routing</li><li>Preferred for production HTTP workloads</li></ul><h4>3.7 What Happens When You Apply Everything</h4><p>When you run:</p><pre>kubectl apply -f deployment.yaml<br>kubectl apply -f service.yaml</pre><p>Kubernetes does not execute steps sequentially. Controllers reconcile state continuously:</p><ul><li>Pods are scheduled</li><li>endpoints are registered</li><li>routing rules are updated automatically</li></ul><p>This event-driven model is the core of Kubernetes’ reliability.</p><h3>4. Final Conclusion</h3><p>Docker explains how applications are packaged while Kubernetes explains how systems behave at runtime.</p><p>Kubernetes is not about running containers — it is about declaring intent and continuously reconciling reality. Deployments make availability a property of desired state, while Services ensure stable networking over inherently unstable workloads.</p><p>This represents a fundamental shift: <strong>from managing processes to designing self-healing, declarative systems.</strong></p><p>Orchestration is not control. It is alignment between intent and behavior.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c053964746f" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/from-containers-to-kubernetes-understanding-deployments-services-and-real-execution-4c053964746f">From Containers to Kubernetes: Understanding Deployments, Services, and Real Execution</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Raw Kubernetes YAML to Helm: Designing Scalable Deployment Systems (A Learning Deep-Dive)]]></title>
            <link>https://towardsdev.com/from-raw-kubernetes-yaml-to-helm-designing-scalable-deployment-systems-a-learning-deep-dive-5dad08676382?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dad08676382</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[helm-chart]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Tue, 23 Dec 2025 16:06:01 GMT</pubDate>
            <atom:updated>2025-12-23T16:06:01.545Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JP4VTurzDWHo-naHakp_nw.png" /><figcaption>From Raw Kuberenetes YAML to Helm</figcaption></figure><h3>Prerequisites</h3><p>This article assumes you already understand the following:</p><ul><li>Kubernetes core concepts (Pods, Deployments, Services)</li><li>How a Deployment YAML is written and applied</li><li>How Services and labels/selectors work</li><li>Basic autoscaling with HPA</li><li>Using kubectl to apply and inspect resources</li></ul><blockquote>Please Note: This is not a beginner Kubernetes tutorial. The focus here is deployment architecture and scaling deployment patterns.</blockquote><h3>1. Problem Context:</h3><p>When teams start deploying applications on Kubernetes, the most common and correct initial approach<em> </em>is to use raw Kubernetes YAML manifests.</p><p>For each service, we typically create:</p><ul><li>Deployment.yaml — pod lifecycle and container configuration</li><li>Service.yaml — networking and service discovery</li><li>HPA.yaml — autoscaling behavior</li><li>sometimes PVC.yaml — persistent storage</li></ul><p>This approach is explicit and transparent, which makes it ideal for learning Kubernetes fundamentals.</p><p>A real example of this structure can be seen in my <a href="https://github.com/MRPERFECT0603/SmartInbox/tree/main/Kuberenetes">SmartInbox</a> project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMcSRO7BhTUsSLB3Ib4_kg.png" /></figure><p>Each service is represented by multiple YAML files, each responsible for one concern.</p><p>This model is:</p><ul><li>explicit</li><li>easy to debug</li><li>closely aligned with Kubernetes internals</li></ul><p>And for small systems, it works well.</p><h3>2. What This Model Gets Right</h3><p>Working directly with Kubernetes YAML is an <strong>essential phase</strong>.</p><p>It builds the correct mental model for:</p><ul><li>how labels and selectors bind Deployments to Services</li><li>how Services discover Pods</li><li>how HPA interacts with Deployments</li><li>how Kubernetes reacts to misconfiguration</li><li>how changes propagate inside the cluster</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9EAKO0W0756ZSzMvPgITQ.png" /></figure><p>Skipping this phase makes Helm feel like magic.</p><h3>3. Where Raw YAML Breaks Down at Scale</h3><p>As the number of services grows, managing deployments using raw Kubernetes YAML becomes increasingly difficult — not because Kubernetes is insufficient, but because the deployment model lacks abstraction. Configuration such as <strong>labels</strong>, <strong>selectors</strong>, <strong>resource limits</strong>, <strong>probes</strong>, and <strong>scaling</strong> <strong>parameters</strong> is duplicated across multiple files and services, making even small changes time-consuming and error-prone. Environment-specific differences (<strong>dev</strong>, <strong>staging</strong>, <strong>production</strong>) further amplify this problem, as deployment logic and configuration remain tightly coupled.</p><p>In practice, a single logical service is fragmented across multiple manifests (<strong>Deployment</strong>, <strong>Service</strong>, <strong>HPA</strong>, <strong>PVC</strong>), which makes it harder to reason about, version, and operate as a cohesive unit. This fragmentation also increases the risk of human error — misaligned labels can silently break service discovery, and inconsistent scaling or resource configurations often surface only at runtime. At scale, this approach shifts engineering effort from system design to YAML maintenance, which does not scale operationally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ol3pd7DRqXfkmH2D0cQGBQ.png" /></figure><h3>4. Why Helm Exists</h3><p>At this point, Kubernetes itself is not the problem.</p><p>The real question becomes:</p><blockquote><strong>How do teams manage deployments when there are 20–50 services with </strong>each having multiple deployment environments (dev, staging, prod) <strong>?</strong></blockquote><p>The answer is not “write more YAML”.</p><p>The answer is:</p><ul><li>abstraction</li><li>reusability</li><li>parameterization</li><li>environment awareness</li></ul><p>This is exactly the gap Helm is designed to fill.</p><h3>5. What Helm Actually Is</h3><p>Helm is often introduced as:</p><blockquote><em>“A package manager for Kubernetes”</em></blockquote><p>That description is technically correct — but incomplete.</p><p>Helm actually provides:</p><ul><li>a templating engine</li><li>a configuration system</li><li>a way to define deployment logic once</li><li>a way to reuse and modify behavior safely</li></ul><p>In practice, Helm is <strong>infrastructure code for Kubernetes deployments</strong>. Beyond templating and configuration, Helm also introduces a <strong>release management</strong> layer for Kubernetes. It tracks <strong>deployment history, enables versioned upgrades, and supports controlled rollbacks</strong>, which are difficult to implement consistently with raw manifests. This shifts deployments from ad-hoc YAML application to a repeatable, auditable release process.</p><h3>6. Helm Core Concepts</h3><h4>6.1 Helm Chart</h4><p>A Helm chart is a directory that contains:</p><ul><li>Kubernetes templates</li><li>configuration values</li><li>metadata</li></ul><p>Example structure:</p><pre>my-chart/<br>├── Chart.yaml<br>├── values.yaml<br>├── templates/<br>│   ├── deployment.yaml<br>│   ├── service.yaml<br>│   └── ingress.yaml<br>└── _helpers.tpl</pre><p><strong>a. Templates: </strong>Templates are Kubernetes YAML files with placeholders.</p><pre>replicas: {{ .Values.replicaCount }}</pre><p>Helm replaces these placeholders during rendering.</p><p><strong>b. values.yaml: </strong>values.yaml defines the <strong>inputs</strong> to templates.</p><pre>replicaCount: 2</pre><pre>image:<br>  repository: my-service<br>  tag: &quot;1.0.0&quot;</pre><pre>resources:<br>  requests:<br>    cpu: &quot;100m&quot;<br>    memory: &quot;128Mi&quot;</pre><p>Templates define logic, Values define behavior.</p><h4>6.2 Rendering Process</h4><p>When you run:</p><pre>helm template my-chart -f values.yaml</pre><p>Helm:</p><ol><li>Reads templates</li><li>Injects values</li><li>Outputs pure Kubernetes YAML</li></ol><p>This output is exactly what Kubernetes applies.</p><h3>7. Applying These Concepts in a Real System: HelmFlow</h3><p>After understanding Helm conceptually, the next challenge was applying it <strong>correctly</strong> — not as a shortcut, but as a design tool.</p><p>For this, I created <a href="https://github.com/MRPERFECT0603/HelmFlow"><strong>HelmFlow</strong></a>.[Check the Github Repo for the coding part]</p><p>HelmFlow is <strong>not a new application</strong>. It is a <strong>deployment architecture refactor</strong>.</p><p>The goal was simple but strict:<br><em>Convert a real-world, multi-component Kubernetes deployment into a </em><strong><em>structured, reusable, environment-aware Helm-based system</em></strong><em>.</em></p><h4>7.1 Why HelmFlow Exists</h4><p>The intent behind HelmFlow was to answer a very practical question:</p><blockquote>If I were responsible for maintaining this system for months or years, how should it be deployed?</blockquote><p>Instead of thinking in terms of individual YAML files, HelmFlow forced a shift toward:</p><p>• deployable units</p><p>• standardized structure</p><p>• predictable behavior across environments</p><p>This mirrors how production platform teams think about deployments.</p><h4>7.2 Chart Structure and Responsibility Boundaries</h4><p>In HelmFlow, each logical service is represented as <strong>one Helm chart</strong>.</p><p>Example structure:</p><pre>charts/<br>└── wordpress/<br>    ├── Chart.yaml<br>    ├── values.yaml<br>    ├── values-dev.yaml<br>    ├── values-prod.yaml<br>    └── templates/<br>        ├── deployment-wordpress.yaml<br>        ├── service-wordpress.yaml<br>        ├── ingress.yaml<br>        ├── pvc.yaml<br>        └── _helpers.tpl</pre><p>This structure establishes clear boundaries:</p><ul><li>templates/<br>→ Deployment logic and Kubernetes structure</li><li>values*.yaml<br>→ Environment-specific behavior</li><li>Chart.yaml<br>→ Metadata and versioning</li></ul><p>A service is no longer fragmented across folders. It exists as one versioned deployment unit.</p><h4>7.3 Redefining What “One Service” Means</h4><p>With raw Kubernetes YAML, a service was conceptually scattered as Deployment, Service, HPA, PVC etc.</p><p>In HelmFlow, a service is defined as:</p><p>Everything required to run and operate that service in Kubernetes</p><p>This includes:</p><p>Deployment, Service, Ingress, Persistent storage (if required), Scaling configuration etc. All of it lives inside one chart.</p><p>This change alone dramatically improves:</p><ul><li>reasoning</li><li>maintainability</li><li>reuse</li></ul><h4>7.4 Eliminating Duplication Through Templates</h4><p>One of the first wins with HelmFlow was removing duplication.</p><p>Common patterns such as:</p><ul><li>labels and selectors</li><li>naming conventions</li><li>container ports</li><li>resource limits</li><li>image references</li></ul><p>were defined once and reused across templates.</p><blockquote>The <strong>_helpers.tpl </strong>file became a critical component — ensuring consistency across all Kubernetes objects without copy-pasting YAML.</blockquote><p>Instead of editing multiple manifests, changes now happen in one place.</p><h4>7.5 Environment-Aware Deployments Using Values</h4><p>HelmFlow enforces a clean separation between:</p><ul><li>deployment logic (templates)</li><li>configuration (values files)</li></ul><p>Environment differences are handled through:</p><ul><li>values.yaml → defaults</li><li>values-dev.yaml</li><li>values-prod.yaml</li></ul><p>Examples of environment-specific configuration:</p><ul><li>replica counts</li><li>resource requests and limits</li><li>ingress hosts</li><li>storage sizes</li></ul><p>The templates remain unchanged. This guarantees that:</p><ul><li>dev, staging, and production behave predictably</li><li>configuration drift is minimized</li><li>deployments are repeatable</li></ul><h3>7.6 Rendering as a Safety and Learning Tool</h3><p>Before applying anything to the cluster, HelmFlow relies on rendering:</p><pre>helm template charts/wordpress -f values-dev.yaml</pre><p>This step is essential.</p><p><strong>Rendering:</strong></p><ul><li>exposes the final Kubernetes YAML</li><li>validates assumptions</li><li>makes abstractions transparent</li></ul><p>HelmFlow treats rendering as a mandatory validation step, not an optional one. This preserves the explicitness of raw YAML while gaining the benefits of abstraction.</p><h3>7.7 What HelmFlow Changed in My Thinking</h3><p>HelmFlow was not just about Helm usage — it changed how I think about infrastructure.</p><p>It reinforced that:</p><ul><li>Infrastructure should be <strong>designed</strong>, not copied</li><li>Services should be <strong>self-contained deployment units</strong></li><li>Configuration should drive behavior, not rewrite logic</li><li>Deployment systems must scale <strong>organizationally</strong>, not just technically</li></ul><p>This mindset is what separates:</p><blockquote>running Kubernetes <em>from </em>operating systems on Kubernetes</blockquote><h3>Final Conclusion</h3><p>Working with raw Kubernetes YAML taught me <strong>how Kubernetes works but, </strong>Helm taught me <strong>how systems scale</strong>.</p><p>The transition from raw manifests to Helm was not about reducing YAML — it was about introducing <strong>structure, discipline, and intent</strong> into deployment design. Raw YAML is excellent for learning and small systems. Helm becomes essential when systems grow, environments multiply, and operational ownership matters.</p><p>This journey marked a clear shift from:</p><blockquote>deploying applications to designing deployment systems</blockquote><p>HelmFlow represents that shift — from configuration-heavy deployments to <strong>architecture-driven infrastructure</strong>.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dad08676382" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/from-raw-kubernetes-yaml-to-helm-designing-scalable-deployment-systems-a-learning-deep-dive-5dad08676382">From Raw Kubernetes YAML to Helm: Designing Scalable Deployment Systems (A Learning Deep-Dive)</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Code to Container: The Architecture of Modern Apps[Part-1]]]></title>
            <link>https://towardsdev.com/from-code-to-container-the-architecture-of-modern-apps-part-1-460135014dc1?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/460135014dc1</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[virtualization]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Sat, 20 Dec 2025 14:08:22 GMT</pubDate>
            <atom:updated>2025-12-20T14:08:22.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Containers have transformed how we build and deploy applications, making them more portable, efficient, and scalable. At the heart of this revolution is <strong>Docker</strong>, an easy-to-use tool that allows developers to package applications into containers that can run anywhere — whether on a local machine or in the cloud.</p><p>In this article, we’ll explore the basics of Docker, its core components, and how it simplifies application development. Whether you’re a beginner or just looking to learn more, this guide will get you started with Docker and show you why it’s a must-have tool for modern development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RrH5BJLeoaN3JgmnmGrbag.png" /><figcaption>Docker Containers</figcaption></figure><h3><strong>1. Introduction to Docker</strong></h3><p>In recent years, Docker has become synonymous with containers, bringing portability, scalability, and efficiency to the software development process. Docker allows you to package your applications and all their dependencies into containers, making it easier to deploy them in any environment — whether it’s on your local machine, in a cloud, or in a production system.</p><p>Docker simplifies the process of running applications consistently across different environments. It eliminates issues such as “it works on my machine” by ensuring that the application behaves the same way no matter where it runs.</p><h3><strong>2. History of Containerization - The Shift from Virtualization to Containers</strong></h3><p>Before Containerization, virtualization with hypervisors was the standard for isolating applications. Virtual machines (VMs) rely on hypervisors to run multiple operating systems on a single physical machine. While <strong>VMs are powerful, they are heavy, resource-intensive, and slow to start.</strong></p><p>Containerization, on the other hand, leverages operating system-level virtualization. Instead of running multiple OS instances, containers share the host OS kernel while remaining isolated from one another. This makes <strong>containers more lightweight, faster, and resource-efficient compared to VMs.</strong></p><ul><li><em>Hypervisor and Containerization Architecture</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhRxu-YWkGAmZ8kOrHvm0Q.png" /></figure><h3><strong><em>3. Containers:</em></strong></h3><p>They are similar to VMs, we can create isolated systems, but they all share the host OS. They <strong>share the host operating system’s kernel</strong>, while each container includes its <strong>own filesystem, libraries, dependencies, and runtime</strong> packaged inside the image.</p><blockquote><strong>Note:</strong> Containers share the host kernel, but use a <strong>layered filesystem</strong>. Image layers are <strong>read-only</strong>, while each running container has its own <strong>read-write layer</strong> on top.</blockquote><ul><li>The architecture of a container:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*2hr-EB1Yyv5jZ2QjyGKmUg.png" /><figcaption>Container Architecture</figcaption></figure><p>For running these containers we need an engine, there comes Docker Engine or we can say the software ‘Docker’.</p><h3><strong>3. What is Docker? Breaking Down Its Structure and Architecture</strong></h3><p>Docker is an open-source platform for developing, shipping, and running containers. It includes a set of tools and components that allow you to develop, package, and run applications in containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4UDbQKul1wFSMgbsNJKWg.jpeg" /><figcaption>Docker Architecture</figcaption></figure><p><em>Here’s a quick look at the key parts of Docker’s architecture:</em></p><ol><li><strong>Docker Engine</strong>: The runtime that runs and manages containers. It consists of:</li></ol><ul><li><strong>Docker Daemon</strong>: The background service that manages containers.</li><li><strong>Docker CLI</strong>: The command-line interface that allows you to interact with the Docker daemon and manage containers.</li></ul><p><strong>2. Docker Images</strong>: Read-only templates used to create containers. Images contain everything needed to run an application: the code, libraries, dependencies, and runtime. <em>(They are in the inactive state.)</em></p><p><strong>3. Docker Containers</strong>: Instances of Docker images that can be run, stopped, and modified. <em>(They are in the active state.)</em></p><p><strong>4. Docker Hub</strong>: A public repository of Docker images that you can use to build your containers. Docker Hub also offers private repositories.</p><p><strong>5. Docker Compose</strong>: A tool for defining and running multi-container Docker applications.</p><h3><strong>4. Docker Images</strong></h3><p>Docker images are the blueprints from which containers are created. They are stored in registries, such as Docker Hub, and can be versioned and shared across different systems.</p><p><em>Every Image has two properties:</em></p><ol><li><strong>Docker Image ID</strong>:</li></ol><ul><li>Each Docker image is uniquely identified by an <strong>Image ID</strong>.</li><li>The Image ID is a string of 12 characters that cannot be redefined or modified once assigned.</li><li>It serves as a unique fingerprint for the image, ensuring its distinct identity across systems.</li></ul><blockquote>Note: Docker displays a shortened <strong>12-character Image ID</strong>, while internally images are identified using a <strong>SHA256 hash</strong>.</blockquote><p>2. <strong>Virtual Size</strong>:</p><ul><li>The <strong>virtual size</strong> of a Docker image represents the total size of the image.</li><li>It includes the size of all the layers that make up the image.</li><li>Layers accumulate during the image creation process, each contributing to the overall virtual size.</li><li>Understanding virtual size helps in optimizing storage and improving resource management, especially when dealing with large images.</li></ul><p><strong>Basic Commands:</strong></p><pre>-&gt; Download an image from a registry.<br>    docker pull &lt;image_name&gt;<br><br>-&gt; Build an image from a Dockerfile.<br>    docker build -t &lt;image_name&gt; &lt;path&gt;<br><br>-&gt; List all the images available on your machine.<br>    docker images<br><br>-&gt; Remove an image from your system.<br>    docker rmi &lt;image_name&gt;</pre><h3><strong>5. Docker Containers</strong></h3><p>Containers are the runtime instances of Docker images. A container is a lightweight, standalone, executable package of software that includes everything needed to run the application.</p><p><strong>Basic Commands:</strong></p><pre>-&gt; Create and start a container from an image.<br>    docker run &lt;image_name&gt;<br><br>-&gt; List running containers.<br>    docker ps<br><br>-&gt; Stop a running container.<br>    docker stop &lt;container_id&gt;<br><br>-&gt; Start a stopped container.<br>    docker start &lt;container_id&gt;<br><br>-&gt; Remove a container from your system.<br>    docker rm &lt;container_id&gt;</pre><h3><strong>6. Docker Hub and Docker Trusted Registry</strong></h3><p>Docker Hub is the default public registry where Docker images are stored and shared. It allows you to pull popular images or push your own custom-built images to share with others.</p><p>For private image storage, Docker also offers Docker Trusted Registry, which allows organizations to host and manage their own private image repositories with added security features.</p><p><strong>Key Features:</strong></p><p>• <strong>Search and pull images</strong> from the Docker Hub.</p><p>• <strong>Create and push custom images</strong> for sharing or use in your applications.</p><p>• <strong>Access control</strong> for private images and repositories.</p><h3><strong>7. Dockerfile</strong></h3><p>A <strong>Dockerfile</strong> is a text document that contains all the commands to assemble an image. It defines the environment, dependencies, and commands to run in the container.</p><p><strong>Basic Structure of a Dockerfile:</strong></p><pre>FROM node:24<br>WORKDIR /app<br>COPY . .<br>RUN npm install<br>EXPOSE 3000<br>CMD [&quot;node&quot;, &quot;app.js&quot;]</pre><p><strong><em>Key Instructions:</em></strong></p><ul><li><strong>FROM:</strong> Specifies the base image to use.</li><li><strong>WORKDIR:</strong> Sets the working directory inside the container.</li><li><strong>COPY: </strong>Copies files from your local machine into the container.</li><li><strong>RUN:</strong> Executes commands during image build (e.g., installing dependencies).</li><li><strong>EXPOSE:</strong> Exposes a port to allow communication with the container.</li><li><strong>CMD: </strong>Specifies the command to run when the container starts.</li></ul><blockquote>Note: Save this file in the same folder of the application and then run the build command to build the image of the application.<br>Assuming here we have taken a node server for containerization.</blockquote><ul><li><em>Other Additional instructions you can add to your dockerfile are:</em></li></ul><ol><li><strong>MAINTAINER &lt;name&gt; &lt;email&gt;</strong>: to specify an author.</li><li><strong>VOLUME &lt;path&gt;: </strong>to mount persistent volume.</li><li><strong>ENTRYPOINT [“executable”, “param1”]:</strong> the first command that runs after the container starts.</li><li><strong>ENV &lt;key&gt; &lt;value&gt;: </strong>environment variables</li></ol><p><strong>Conclusion</strong></p><p>Docker has reshaped the way we approach application development, deployment, and scalability. By understanding Docker’s architecture, core components, and essential commands, you can leverage its power to streamline your development workflow and simplify application management. Docker’s ability to create isolated, reproducible environments is crucial for both developers and DevOps engineers, and its role in cloud-native application development continues to grow.</p><p>As you gain expertise in Docker, you’ll be able to replicate production environments, optimize resource usage, and scale applications effortlessly. By the end of this article, with the working example provided, you’ll be equipped with practical knowledge to start using Docker in your own projects, making it an essential tool in your software development toolkit.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=460135014dc1" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/from-code-to-container-the-architecture-of-modern-apps-part-1-460135014dc1">From Code to Container: The Architecture of Modern Apps[Part-1]</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the Scenes of the Web: [Part 3] — Powering Your Backend with Express.js and Middleware]]></title>
            <link>https://towardsdev.com/behind-the-scenes-of-the-web-part-3-powering-your-backend-with-express-js-and-middleware-2bb59c566ff0?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bb59c566ff0</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Wed, 25 Dec 2024 06:08:40 GMT</pubDate>
            <atom:updated>2024-12-25T17:32:42.857Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Behind the Scenes of the Web: [Part 3] — Powering Your Backend with Express.js and Middleware</strong></h3><p>Welcome to the third part of our 4-part series on backend development! <br>Till now we have covered all the basics from creating a <a href="https://medium.com/@vivek_shaurya/behind-the-scenes-of-the-web-part-1-a-beginners-guide-to-backend-development-57574cc3f33c"><strong>Basic Server</strong></a> to a <a href="https://medium.com/towardsdev/behind-the-scenes-of-the-web-part-2-mvc-architecture-and-crud-applications-bc79f68c9ce7"><strong>CRUD application with MVC architecture</strong></a>. In this guide, we’ll explore <strong>Express.js</strong>, a powerful and lightweight web application framework for Node.js, which simplifies server-side development. We’ll also dive into the world of <strong>middleware</strong> and learn how to use <strong>environment variables</strong> to keep your application secure and configurable. By the end of this article, you’ll be able to build an efficient Express.js application, integrate middleware effectively, and use .env files to manage sensitive data. Let’s get started!</p><figure><img alt="Backend Server" src="https://cdn-images-1.medium.com/max/1024/0*5Dz0KcCF93HmDxaC" /><figcaption>Photo by <a href="https://unsplash.com/@cmzw?utm_source=medium&amp;utm_medium=referral">MW</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>1. Why Use Express with Node.js?</strong></h3><p>While Node.js provides the core functionality for server creation, Express.js streamlines the development process by offering a minimalist framework that makes it easier to manage routes, request handling, middleware, and server configurations. Using Express with Node.js accelerates backend development by providing structure and useful features out of the box, making it a popular choice for building scalable, production-ready applications.</p><h3><strong>2. Setting Up Your Backend Environment</strong></h3><blockquote>Note: Initialize a basic server using ‘npm init -y’. if you need detailed explanation please follow the <a href="https://medium.com/@vivek_shaurya/behind-the-scenes-of-the-web-part-1-a-beginners-guide-to-backend-development-57574cc3f33c">part-1</a> and <a href="https://medium.com/towardsdev/behind-the-scenes-of-the-web-part-2-mvc-architecture-and-crud-applications-bc79f68c9ce7">part-2</a> of this series.</blockquote><p><strong><em>Step 1: Install Express.js</em></strong></p><pre>npm install express</pre><h3><strong>3. Creating Your First Express Server</strong></h3><pre><br>const express = require(&quot;express&quot;); <br>const routes = require(&quot;./Routes&quot;);<br>const app = express(); <br>const PORT = 8000; <br><br><br>app.use(&quot;/api&quot;, routes ); <br><br><br>app.listen(PORT, () =&gt; {<br>    console.log(`Server is running on port ${PORT}`);<br>});</pre><blockquote>Note: Routes, Controller and all the basic Server Concepts are discussed in part 1&amp;2 of this series.</blockquote><p><em>Routes.js</em></p><pre>const express = require(&quot;express&quot;);<br>const router = express.Router();<br>const {login, logout, register}= require(&quot;./controllers&quot;);<br><br>router.get(&quot;/login&quot;, login);<br>router.post(&quot;/register&quot;, register);<br>router.post(&quot;/logout&quot;, logout);<br><br>module.exports = router;</pre><p><em>Explanation:</em></p><ul><li>“express.Router()”: Creates a modular router object to organize routes into separate files.</li><li>“router.get<strong>, </strong>router.post”: Define routes for different HTTP methods (GET, POST, etc.).</li></ul><pre>    <br>router.&lt;method&gt;(path, handler)<br><br>// path: URL endpoint (e.g., /login).<br><br>/* handler: A function (from the controller) that executes when the <br>   endpoint is called. */</pre><p><em>Controller.js</em></p><pre>const login = (req, res) =&gt; {<br>    res.send(&quot;Welcome to the Login Route!&quot;);<br>};<br><br>const register = (req, res) =&gt; {<br>    res.send(&quot;User registered successfully!&quot;);<br>};<br><br>const logout = (req, res) =&gt; {<br>    res.send(&quot;User logged out successfully!&quot;);<br>};<br><br>module.exports = { login , register , logout };</pre><p><em>Explanation:</em></p><ul><li>Handles the business logic and sends the response back to the client.</li></ul><h3><strong>4. Middleware</strong></h3><p><strong>What is Middleware?<br></strong>Middleware functions are executed in the middle of request-response cycles. They process incoming requests before the server sends back a response.</p><p><em>Usages:</em></p><p>1. <strong>Modify Requests/Responses</strong>: Alter request/response data (e.g., add headers or parse request bodies).</p><p>2. <strong>Process Requests</strong>: Authenticate users, log requests, or handle custom logic.</p><p>3. <strong>End the Cycle</strong>: Send a response if no further processing is needed.</p><p>4. <strong>Handle Errors</strong>: Capture and process errors globally.</p><pre>// SYNTAX OF A MIDDELWARE<br>app.use((req, res, next) =&gt; {<br>    console.log(&quot;Middleware executed!&quot;);<br>    next(); // Pass control to the next middleware<br>});</pre><h3><strong>5. Types Of MiddleWare:</strong></h3><ul><li><strong>Application-Level Middleware<br></strong><em>Applied globally to all routes or specific HTTP methods.</em></li></ul><pre>app.use((req, res, next) =&gt; {<br>    console.log(&quot;Global middleware executed!&quot;);<br>    next();<br>});</pre><ul><li><strong>Router-Level Middleware<br></strong><em>Applied to specific routes using express.Router().</em></li></ul><pre>const router = express.Router();<br>router.use((req, res, next) =&gt; {<br>    console.log(&quot;Router-level middleware executed!&quot;);<br>    next();<br>});</pre><ul><li><strong>Error-Handling Middleware<br></strong><em>Used to catch errors in the application.</em></li></ul><pre>//Note: Error-handling middleware has four arguments: (err, req, res, next).<br>app.use((err, req, res, next) =&gt; {<br>    console.error(err.stack);<br>    res.status(500).send(&quot;Something went wrong!&quot;);<br>});</pre><ul><li><strong>Built-In Middleware<br></strong><em>Express comes with some middleware like “express.json()” and “express.static()”.</em></li></ul><ol><li><strong>express.json():</strong> <em>Parses JSON payloads from the request body.</em></li></ol><pre>app.use(express.json());</pre><p>2.<strong> express.urlencoded(): </strong><em>Parses URL-encoded form data.</em></p><pre>app.use(express.urlencoded({ extended: true }));</pre><p><strong>3. express.static():</strong> <em>Serves static files like images, CSS, and JavaScript.</em></p><pre>app.use(express.static(&quot;public&quot;));</pre><ul><li><strong>Third-Party Middleware<br></strong><em>We can also use third-party libraries like cookie-parser, cors, and helmet for additional functionality.</em></li></ul><ol><li><strong>cors:</strong> <em>Enables Cross-Origin Resource Sharing (CORS).</em></li></ol><pre>const cors = require(&quot;cors&quot;);<br>app.use(cors());</pre><p>2. <strong>cookie-parser:</strong> <em>Parses cookies in incoming requests.</em></p><pre>const cookieParser = require(&quot;cookie-parser&quot;);<br>app.use(cookieParser());</pre><h3><strong>6. Using Environment Variables</strong></h3><p>Environment variables are crucial for keeping sensitive data, like API keys or database credentials, secure. We’ll use the dotenv package to manage these variables.</p><p><em>Step 1: Install dotenv</em></p><pre>npm install dotenv  </pre><p><em>Step 2: Create a .env File</em></p><p>In the root of your project, create a .env file:</p><pre># Add this in your.env file<br>PORT=8000  <br>API_KEY=my-secret-key  </pre><p><em>Step 3: Configure Your App</em></p><p>Update app.js:</p><pre>require(&#39;dotenv&#39;).config(); // Load .env variables  <br>const PORT = process.env.PORT;  <br><br>app.listen(PORT, () =&gt; {  <br>  console.log(`Server is running on http://localhost:${PORT}`);  <br>});  </pre><p>Now your app uses the port number from the .env file.</p><h3><strong>6. Complete Example</strong></h3><p>Here’s a complete example of integrating everything:</p><pre>const express = require(&#39;express&#39;);  <br>const bodyParser = require(&#39;body-parser&#39;); <br>require(&#39;dotenv&#39;).config(); <br>app.use(&quot;/api&quot;, routes );<br>  <br><br>const app = express();  <br>const PORT = process.env.PORT || 8000;  <br><br>// Middleware for logging  <br>app.use((req, res, next) =&gt; {  <br>  console.log(`${req.method} request for ${req.url}`);  <br>  next();  <br>});  <br><br>// Middleware for parsing JSON  <br>app.use(bodyParser.json());  <br><br>app.use(&quot;/api&quot;, routes );<br><br>// Start the server  <br>app.listen(PORT, () =&gt; {  <br>  console.log(`Server is running on http://localhost:${PORT}`);  <br>});  </pre><h3><strong>7. Conclusion</strong></h3><p>In this third part of our 4-part series on backend development, we’ve unlocked the power of <strong>Express.js</strong> to streamline backend development. We’ve also seen how middleware simplifies handling tasks like logging and parsing requests, making your application more robust. Finally, we used environment variables to keep sensitive information secure and make our app configurable.</p><p>Express.js, with its simplicity and flexibility, makes backend development more intuitive and enjoyable. As we continue this journey, we’ll dive deeper into advanced concepts like API versioning and error handling.</p><p>Thank you for joining me on this learning adventure! Stay tuned for the next part, where we’ll explore more tools to enhance your backend development skills.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bb59c566ff0" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/behind-the-scenes-of-the-web-part-3-powering-your-backend-with-express-js-and-middleware-2bb59c566ff0">Behind the Scenes of the Web: [Part 3] — Powering Your Backend with Express.js and Middleware</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the Scenes of the Web: [Part 2] — MVC Architecture and CRUD Applications]]></title>
            <link>https://towardsdev.com/behind-the-scenes-of-the-web-part-2-mvc-architecture-and-crud-applications-bc79f68c9ce7?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc79f68c9ce7</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[api-development]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 04:01:48 GMT</pubDate>
            <atom:updated>2024-12-20T11:30:27.999Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Behind the Scenes of the Web: [Part 2] — MVC Architecture and CRUD Applications</strong></h3><p>Welcome back to Part 2 of our series on backend development! In <a href="https://medium.com/@vivek_shaurya/behind-the-scenes-of-the-web-part-1-a-beginners-guide-to-backend-development-57574cc3f33c"><strong>[PART 1]</strong></a>, we laid the groundwork for building a backend server. Now, we’ll dive deeper into organizing our application with the <strong>MVC (Model-View-Controller)</strong> architecture, which is a popular design pattern that helps structure our code into manageable components.</p><p>In this part, we’ll also walk through implementing a simple <strong>CRUD (Create, Read, Update, Delete)</strong> application that manages user data, all while leveraging MongoDB for data storage. By the end of this guide, you’ll have a solid understanding of how to organize your backend code and perform basic database operations in a Node.js environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*28aqffPWFWKFTL-3" /><figcaption>Photo by <a href="https://unsplash.com/@cmzw?utm_source=medium&amp;utm_medium=referral">MW</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>1. Introduction to MVC Architecture</strong></h3><p>The <strong>MVC pattern</strong> is a popular way to organize code in web applications, separating the logic into three main components:</p><p><strong><em>1</em></strong><em>. </em><strong><em>Model</em></strong></p><p>The <strong>Model</strong> represents the application’s data and business logic, serving as the layer that defines how data is structured and interacts with the database. It handles tasks like database operations, validations, and managing the rules that govern the data.</p><ul><li>For example, in an e-commerce application, the Product model would define the attributes of a product (such as name, price, and stock) and include methods to retrieve, update, or delete product data from the database. This ensures that all logic related to the application’s data is centralized and consistent.</li></ul><p><strong><em>2. View</em></strong></p><p>The <strong>View</strong> represents the user interface or what the user interacts with. In backend applications, the “view” is often the JSON response sent to the client rather than a visual interface.</p><ul><li>For example, in an e-commerce app, the view could be the JSON response containing product details sent to the frontend or the rendered product listing page that users see. It focuses on presenting data in a user-friendly format.</li></ul><p><strong><em>3. Controller</em></strong></p><p>The <strong>Controller</strong> serves as the intermediary between the Model and the View. It handles user input, such as API requests, processes the data, and communicates with the Model to fetch or update information.</p><ul><li>For example, when a user requests details about a product, the controller processes the request, retrieves the data from the Model, and sends it as a JSON response back to the client.</li></ul><h3><strong>2. Setting Up Your Folder Structure</strong></h3><pre>backend-app/<br>├── controllers/        // Controller files (business logic)<br>│   └── userController.js<br>├── models/             // Model files (database logic)<br>│   └── userModel.js<br>├── routes/             // Routes to handle incoming requests<br>│   └── userRoutes.js<br>└── server.js           // Entry point for your app</pre><h3><strong>3. What is CRUD?</strong></h3><p>CRUD stands for <strong>Create</strong>, <strong>Read</strong>, <strong>Update</strong>, and <strong>Delete</strong> — the fundamental persistent storage operations in most applications. These operations allow us to manipulate and interact with data effectively:</p><p>• <strong>Create</strong>: Add new data</p><p>• <strong>Read</strong>: Retrieve existing data</p><p>• <strong>Update</strong>: Modify existing data</p><p>• <strong>Delete</strong>: Remove data</p><p>These operations form the backbone of almost every backend application and allow us to build powerful systems to manage data efficiently. Let’s dive into building our CRUD application!</p><h3>4. Setting Up Database</h3><p>In this article, I will be using MongoDB Atlas to set up and manage the database for my project. We will then integrate this database with our Node.js application to handle data storage and management.</p><blockquote><strong>Note: </strong>MongoDB is a NoSQL database that stores data in flexible, JSON-like documents instead of traditional relational tables. This schema-less nature makes it easier to work with unstructured or semi-structured data and scale horizontally across multiple servers.</blockquote><ol><li><strong>What is MongoDB Atlas?</strong></li></ol><p><strong>MongoDB Atlas</strong> is a cloud service provided by MongoDB to manage MongoDB databases. It is fully managed and takes care of scaling, security, backups, and maintenance.</p><p><strong>2. Steps to setup the database:</strong></p><p><em>Step 1: Create a MongoDB Atlas Account</em></p><ol><li>Go to the <a href="https://www.mongodb.com/cloud/atlas">MongoDB Atlas website</a>.</li><li>Click on the <strong>Sign in </strong>button and login. If you don’t have an account, simply Sign Up.</li><li>After logging in, you’ll be directed to the <strong>MongoDB Atlas Dashboard</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yb-ex7CdhTttsyT90QpPuw.png" /></figure><p><em>Step 2: Create a New Cluster</em></p><ol><li>On the MongoDB Atlas Dashboard, click <strong>Create a New Cluster</strong>.</li><li>Choose your cloud provider (AWS, Google Cloud, or Azure) and select a region closest to you for the cluster location.</li><li>You can select a <strong>Free Tier</strong> (M0) for the database if you’re just testing or developing.</li><li>After selecting the region and other settings, click <strong>Create Deployment</strong>. <em>This will take you to the Connect to Cluster page to create a User.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gjFQxQODdHynk-mnm9YwLg.png" /></figure><p><em>Step 3: Create a Database User</em></p><ol><li>Create your Username and Password.</li><li>Click <strong>Create Database User</strong>. (Make sure to save the password securely.)</li></ol><p><em>Step 4: Whitelist Your IP Address</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lHY8Xi2iaa4GK7cp34uWig.png" /></figure><p>1. In the <strong>Network Access</strong> section of the MongoDB Atlas Dashboard, click <strong>Add IP Address</strong>.</p><p>2. Click <strong>Allow Access from Anywhere</strong> to allow connections from any IP address (or you can whitelist a specific IP address for security).</p><p>3. Click <strong>Confirm</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZpafsIDaCd3v41JIQZxYsQ.png" /></figure><p><em>Step 5: Get Your MongoDB Connection URI</em></p><p>1. Go to the <strong>Clusters</strong> section and click <strong>Connect</strong> for your cluster.</p><p>2. Select <strong>Connect your application</strong>.</p><p>3. Choose your version of <strong>Node.js</strong>.</p><p>4. Copy the provided connection string, which looks like this:</p><pre>mongodb+srv://&lt;username&gt;:&lt;password&gt;@cluster0.mongodb.net/DatabaseName?retryWrites=true&amp;w=majority</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EL_FAaU8PTD1T3HkP1ojpg.png" /></figure><h3>5. Setting up Mongoose and Node.JS Server</h3><ol><li><strong><em>Install Mongoose</em></strong></li></ol><pre>npm install mongoose</pre><p><strong><em>2. Create the MongoDB Connection File</em></strong></p><p>To set up the MongoDB connection, we’ll create a separate configuration file to handle all database-related logic. This will allow us to easily manage the database connection and use it throughout the application.</p><pre>//File: config/db.js<br><br>const mongoose = require(&#39;mongoose&#39;);<br><br>const uri = &quot;your-mongodb-connection-string&quot;; <br><br>const connectDB = async () =&gt; {<br>  try {<br>    await mongoose.connect(uri, { <br>      useNewUrlParser: true,<br>      useUnifiedTopology: true<br>    });<br>    console.log(&quot;Successfully connected to MongoDB with Mongoose!&quot;);<br>  } catch (error) {<br>    console.error(&quot;Error connecting to MongoDB:&quot;, error);<br>    throw error;<br>  }<br>};<br><br>module.exports = { connectDB };In this file:</pre><ul><li>mongoose.connect(): This function connects your Node.js application to the MongoDB database using the provided connection string (URI).</li><li>useNewUrlParser and useUnifiedTopology: These are options to use the latest connection string parser and the new MongoDB topology engine.</li><li>db.js: This file exports the connectDB function, which you can call to establish the database connection when your application starts.</li></ul><p><strong><em>3. Create a User Model</em></strong></p><p>Now, let’s create a <strong>User model</strong> using Mongoose to interact with the database. Mongoose uses <strong>schemas</strong> to define the structure of your documents in a collection.</p><pre>// File: models/userModel.js<br><br>const mongoose = require(&#39;mongoose&#39;);<br><br>// Define the user schema with fields like name and email<br>const userSchema = new mongoose.Schema({<br>  name: { type: String, required: true },  <br>  email: { type: String, required: true, unique: true }  <br>});<br><br><br>const User = mongoose.model(&#39;User&#39;, userSchema);<br><br>module.exports = User;</pre><ul><li>userSchema: This defines the structure of the User document. In this case, we are saying a user must have a name and email. The email field must be unique, so no two users can have the same email.</li><li>User: This is the Mongoose model that corresponds to the users collection in the database. You use this model to perform operations like creating, reading, updating, and deleting users in the database.</li></ul><blockquote><strong>Note: </strong>Till now we have create a conection with our database and have a userModel for schema for our database and now our folder structure should look like this.</blockquote><pre>backend-app/<br>├── controllers/           // Controller files (business logic)<br>│   ├── userController.js  <br>├── models/                // Model files (database logic)<br>│   ├── userModel.js       <br>├── routes/                // Routes to handle incoming requests<br>│   └── userRoutes.js     <br>├── config/                // Configuration files<br>│   └── db.js              <br>└── server.js              // Entry point for your application (sets up the server)</pre><h3><strong>6: Implementing CRUD Operations in Node.js</strong></h3><p>Now that we have set up our project and connected to MongoDB using Mongoose, let’s implement the CRUD operations for managing user data.</p><p><strong><em>1. Setup the Controller.Js file</em></strong></p><pre>// File: controllers/userController.js<br>const User = require(&#39;../models/userModel&#39;);<br><br>// Create a new user<br>const createUser = async (req, res) =&gt; {<br>  const { name, email } = req.body;<br><br>  try {<br>    // Check if the user already exists<br>    const existingUser = await User.findOne({ email });<br>    if (existingUser) {<br>      return res.status(400).json({ message: &#39;User with this email already exists&#39; });<br>    }<br><br>    const newUser = new User({ name, email });<br>    await newUser.save();<br><br>    res.status(201).json({ message: &#39;User created successfully&#39;, user: newUser });<br>  } catch (error) {<br>    res.status(400).json({ message: &#39;Error creating user&#39;, error: error.message });<br>  }<br>};<br><br>// Get all users<br>const getAllUsers = async (req, res) =&gt; {<br>  try {<br>    const users = await User.find();<br>    res.status(200).json({ users });<br>  } catch (error) {<br>    res.status(500).json({ message: &#39;Error retrieving users&#39;, error: error.message });<br>  }<br>};<br><br>// Get a single user by ID<br>const getUserById = async (req, res) =&gt; {<br>  const { userId } = req.params;<br><br>  try {<br>    const user = await User.findById(userId);<br>    if (!user) {<br>      return res.status(404).json({ message: &#39;User not found&#39; });<br>    }<br><br>    res.status(200).json({ user });<br>  } catch (error) {<br>    res.status(500).json({ message: &#39;Error retrieving user&#39;, error: error.message });<br>  }<br>};<br><br>// Update a user<br>const updateUser = async (req, res) =&gt; {<br>  const { userId } = req.params;<br>  const { name, email } = req.body;<br><br>  try {<br>    const updatedUser = await User.findByIdAndUpdate(<br>      userId,<br>      { name, email },<br>      { new: true } // This option returns the modified document<br>    );<br><br>    if (!updatedUser) {<br>      return res.status(404).json({ message: &#39;User not found&#39; });<br>    }<br><br>    res.status(200).json({ message: &#39;User updated successfully&#39;, user: updatedUser });<br>  } catch (error) {<br>    res.status(400).json({ message: &#39;Error updating user&#39;, error: error.message });<br>  }<br>};<br><br>// Delete a user<br>const deleteUser = async (req, res) =&gt; {<br>  const { userId } = req.params;<br><br>  try {<br>    const deletedUser = await User.findByIdAndDelete(userId);<br>    if (!deletedUser) {<br>      return res.status(404).json({ message: &#39;User not found&#39; });<br>    }<br><br>    res.status(200).json({ message: &#39;User deleted successfully&#39; });<br>  } catch (error) {<br>    res.status(500).json({ message: &#39;Error deleting user&#39;, error: error.message });<br>  }<br>};<br><br>module.exports = {<br>  createUser, getAllUsers, getUserById, updateUser, deleteUser<br>};</pre><p><strong><em>Explanation:</em></strong></p><ol><li><strong>Create User (</strong>createUser<strong>)</strong>:</li></ol><ul><li>Extracts the name and email from the request body.</li><li>Check if a user with the provided email already exists in the database.</li><li>If not, create a new user and save it to the database. If successful, returns a response with the created user.</li></ul><p>2. <strong>Get All Users (</strong>getAllUsers<strong>)</strong>:</p><ul><li>Fetches all users from the database using User.find().</li><li>Returns the list of users in the response.</li></ul><p>3. <strong>Get User by ID (</strong>getUserById<strong>)</strong>:</p><ul><li>Retrieves a user from the database by their unique ID (using req.params.userId).</li><li>If the user exists, return the user. Otherwise, returns a “not found” error.</li></ul><p>4. <strong>Update User (</strong>updateUser<strong>)</strong>:</p><ul><li>Finds a user by their ID and updates their name and email (using req.params.userId for the ID and req.body for the updated data).</li><li>If the user is updated successfully, returns the updated user.</li></ul><p>5. <strong>Delete User (</strong>deleteUser<strong>)</strong>:</p><ul><li>Finds a user by their ID and deletes them from the database.</li><li>If the user is successfully deleted, send a success message; otherwise, an error.</li></ul><p><strong><em>2. Setup the UserRoutes.Js file</em></strong></p><pre>// File: routes/userRoutes.js<br>const http = require(&#39;http&#39;);<br>const userController = require(&#39;../controllers/userController&#39;);<br><br>const userRoutes = (req, res) =&gt; {<br>  const { method, url } = req;<br>  const urlParts = url.split(&#39;/&#39;);<br>  const userId = urlParts[2];<br><br>  if (method === &#39;POST&#39; &amp;&amp; url === &#39;/user&#39;) {<br>    let body = &#39;&#39;;<br>    req.on(&#39;data&#39;, chunk =&gt; {<br>      body += chunk;<br>    });<br>    req.on(&#39;end&#39;, () =&gt; {<br>      req.body = JSON.parse(body);<br>      userController.createUser(req, res);<br>    });<br>  }<br><br>  if (method === &#39;GET&#39; &amp;&amp; url === &#39;/users&#39;) {<br>    userController.getAllUsers(req, res);<br>  }<br><br>  if (method === &#39;GET&#39; &amp;&amp; url.startsWith(&#39;/user/&#39;) &amp;&amp; userId) {<br>    req.params = { userId };<br>    userController.getUserById(req, res);<br>  }<br><br>  if (method === &#39;PUT&#39; &amp;&amp; url.startsWith(&#39;/user/&#39;) &amp;&amp; userId) {<br>    let body = &#39;&#39;;<br>    req.on(&#39;data&#39;, chunk =&gt; {<br>      body += chunk;<br>    });<br>    req.on(&#39;end&#39;, () =&gt; {<br>      req.body = JSON.parse(body);<br>      req.params = { userId };<br>      userController.updateUser(req, res);<br>    });<br>  }<br><br>  if (method === &#39;DELETE&#39; &amp;&amp; url.startsWith(&#39;/user/&#39;) &amp;&amp; userId) {<br>    req.params = { userId };<br>    userController.deleteUser(req, res);<br>  }<br>};<br><br>module.exports = userRoutes;</pre><p><strong><em>Explanation:</em></strong></p><ul><li><strong>POST </strong>/user: The request body is parsed, and createUser is called to create a new user.</li><li><strong>GET </strong>/users: Calls getAllUsers to fetch and return all users.</li><li><strong>GET </strong>/user/:id: Extracts the userId from the URL and calls getUserById to fetch a single user by ID.</li><li><strong>PUT </strong>/user/:id: Extracts the userId and updated data from the request and calls updateUser to modify the user’s details.</li><li><strong>DELETE </strong>/user/:id: Extracts the userId from the URL and calls deleteUser to delete the user by ID.</li></ul><p><strong><em>3. Setup the server.Js file</em></strong></p><pre>// File: server.js<br>const http = require(&#39;http&#39;);<br>const mongoose = require(&#39;mongoose&#39;);<br>const { connectDB } = require(&#39;./config/db&#39;);<br>const userRoutes = require(&#39;./routes/userRoutes&#39;);<br><br>// Connect to MongoDB<br>connectDB();<br><br>// Create the server<br>const server = http.createServer(userRoutes);<br><br>// Start the server on port 5000<br>server.listen(5000, () =&gt; {<br>  console.log(&#39;Server is running on http://localhost:5000&#39;);<br>});</pre><p><strong><em>Explanation:</em></strong></p><ul><li><strong>Database Connection</strong>: The connectDB function from the config/db.js file is called to establish a connection with MongoDB.</li><li><strong>HTTP Server</strong>: The server listens on port 5000 and uses userRoutes to handle the routes.</li></ul><h3>Conclusion</h3><p>In this part, we’ve taken a solid step toward building a backend from scratch with Node.js. By setting up a simple server, managing different routes, and structuring our project using the MVC pattern, you’ve gained hands-on experience in backend development.</p><p>Creating a backend server from the ground up with Node.js not only strengthens your understanding of server-side programming but also prepares you to build lightweight and efficient applications. With each line of code, you get to see the flexibility and power of Node.js, which empowers developers to create robust backend systems.</p><p>Thank you for joining me on this journey! In the next part, we’ll take things further by introducing <strong>Express.js</strong>, an essential framework that simplifies routing and enhances the power of our server. We’ll also dive into <strong>middleware</strong>, which allows us to add custom functionality between the request and response cycle.</p><p>Stay tuned for the next chapter as we continue to build on this foundation and level up your backend development skills.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc79f68c9ce7" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/behind-the-scenes-of-the-web-part-2-mvc-architecture-and-crud-applications-bc79f68c9ce7">Behind the Scenes of the Web: [Part 2] — MVC Architecture and CRUD Applications</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the Scenes of the Web: [Part 1] — A Beginner’s Guide to Backend Development]]></title>
            <link>https://towardsdev.com/behind-the-scenes-of-the-web-part-1-a-beginners-guide-to-backend-development-57574cc3f33c?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/57574cc3f33c</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Mon, 09 Dec 2024 03:30:05 GMT</pubDate>
            <atom:updated>2024-12-23T17:08:49.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>Behind the Scenes of the Web: [Part 1] — <strong>A Beginner’s Guide to Backend Development</strong></h3><p>Welcome to the world of backend development! In this first part of my 4-part series, we’ll dive into building a backend server from scratch using Node.js and Express.js. By the end of this guide, you’ll have a solid understanding of how to set up a basic server, handle routes, and organize your project structure effectively. Stay tuned for the following parts, where we’ll expand on this foundation and cover more advanced topics like Express, middleware, and API versioning. Let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RXpzPMFAwwil12-8" /><figcaption>Photo by <a href="https://unsplash.com/@cmzw?utm_source=medium&amp;utm_medium=referral">MW</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>1. What is Backend Development?</strong></h3><p>Backend development refers to the server-side logic that powers an application. It handles tasks like managing databases, processing APIs, and ensuring smooth communication between the frontend and backend.</p><h3><strong><em>2. Setting Up Your Backend Environment</em></strong></h3><p><strong><em>Step 1: Install Node.js</em></strong></p><ol><li>Download and install the latest version of Node.js from the <a href="https://nodejs.org/">official Node.js website</a>.</li></ol><blockquote><strong>Note:</strong> Node.js comes with a tool named “npm” (Node Package Manager), which is used to install, manage, and share JavaScript packages or libraries.</blockquote><p><strong><em>Step 2: Create a New Project</em></strong></p><pre>mkdir backend-app<br>cd backend-app<br><br>#Intialise the server<br>npm init -y </pre><h3><strong>3. Creating Your First Node.js Server</strong></h3><p>A Node.js server can handle HTTP requests and send responses. Let’s create a simple server.</p><p><strong><em>Step 1: Create a Server File</em></strong></p><p>Create a file named server.js in your project folder and add the following code:</p><pre>const http = require(&#39;http&#39;);<br><br>const PORT = 8000;<br><br>// Create the server<br>const server = http.createServer((req, res) =&gt; {<br>  // Define a simple route<br>  if (req.url === &#39;/&#39; &amp;&amp; req.method === &#39;GET&#39;) {<br>    res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>    res.end(&#39;Welcome to the world of Backend Development!&#39;);<br>  } else {<br>    res.writeHead(404, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>    res.end(&#39;Route not found&#39;);<br>  }<br>});<br><br>// Start the server to listen on specific port<br>server.listen(PORT, () =&gt; {<br>  console.log(`Server is running on http://localhost:${PORT}`);<br>});</pre><p><strong><em>Step 2: Run Your Server</em></strong></p><pre>#Run this in terminal to start the server<br>node server.js</pre><blockquote>Open your browser and navigate to <strong>http://localhost:8000</strong>. You should see <strong>“Welcome to the world of Backend Development!”</strong></blockquote><p><strong><em>Detailed Code Explanation:</em></strong></p><pre>if (req.url === &#39;/&#39; &amp;&amp; req.method === &#39;GET&#39;) {</pre><p>This checks whether the incoming request is to the root URL (/) and the request method is ‘GET ’. The root URL refers to the server&#39;s home page, and GET is the method used to request data (like loading a webpage).</p><pre>res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/plain&#39; });</pre><p>This sends an HTTP response header to the client. The 200 indicates that the request was successful (status code for “OK”). The Content-Type: ‘text/plain’ tells the client that the response will be plain text.</p><pre>res.end(&#39;Welcome to the world of Backend Development!&#39;);</pre><p>This sends the actual response body to the client, which is the string “Welcome to the world of Backend Development!”. The res.end() method also signals the end of the response, meaning no more data will be sent.</p><p><strong><em>In simple terms:</em></strong></p><p>When a user visits the home page (/) of the website and makes a GET request (like typing the URL in their browser), the server responds by sending a success message, “Welcome to the world of Backend Development!”, back to the user.</p><h3><strong>4. Handling Routes</strong></h3><p><strong>Routes</strong> are the defined paths or endpoints that a server responds to when it receives an HTTP request. A route typically consists of:</p><p>1. <strong>Path</strong>: The specific URL (e.g., /about, /api/data) the server listens for.</p><p>2. <strong>HTTP Method</strong>: The type of request, such as GET, POST, PUT, or DELETE.</p><p>Routes determine how a server handles different requests based on the path and method combination. Each route is mapped to a specific function or logic that defines what the server should do in response to that request.</p><p>Let’s expand our server to handle multiple routes. Update your server.js file:</p><pre>const http = require(&#39;http&#39;);<br><br>const PORT = 8000;<br><br>const server = http.createServer((req, res) =&gt; {<br>  if (req.url === &#39;/&#39; &amp;&amp; req.method === &#39;GET&#39;) {<br>    res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>    res.end(&#39;Welcome to the Home Page!&#39;);<br>  } else if (req.url === &#39;/about&#39; &amp;&amp; req.method === &#39;GET&#39;) {<br>    res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>    res.end(&#39;This is the About Page.&#39;);<br>  } else {<br>    res.writeHead(404, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>    res.end(&#39;Route not found&#39;);<br>  }<br>});<br><br>server.listen(PORT, () =&gt; {<br>  console.log(`Server is running on http://localhost:${PORT}`);<br>});</pre><blockquote>Open your browser and navigate to <strong>http://localhost:8000</strong>. You will see the message: <strong>“Welcome to the Home Page!”</strong>. Now, if you go to <strong>http://localhost:8000/about</strong>, you will be greeted with: <strong>“This is the About Page.”</strong> If you navigate to any other route, such as <strong>http://localhost:8000/someotherpath</strong>, you will see a <strong>404 error</strong> message: <strong>“Route not found.”</strong></blockquote><h3><strong>5. Folder Structure for Your Project</strong></h3><p>As your application grows, it’s important to keep your code modular and organized. Here’s a simple structure you can follow:</p><pre>backend-app/ <br>├── server.js // Entry point for your app <br>├── routes/ // Define your app&#39;s routes <br>├── controllers/ // Handle logic for your routes</pre><p><strong><em>Step 1: Create Functions in a separate Controller.js file in the controllers folder</em></strong></p><pre>const getHomePage = (res) =&gt; {<br>  res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>  res.end(&#39;Welcome to the Home Page!&#39;);<br>};<br><br>const getAboutPage = (res) =&gt; {<br>  res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>  res.end(&#39;This is the About Page.&#39;);<br>};<br><br>const handleNotFound = (res) =&gt; {<br>  res.writeHead(404, { &#39;Content-Type&#39;: &#39;text/plain&#39; });<br>  res.end(&#39;Route not found&#39;);<br>};<br><br>module.exports = { getHomePage, getAboutPage, handleNotFound };<br>/* Export the functions to be accessed by other files */</pre><p><strong><em>Step 2: Create a Route.js file to handle incoming Requests in the routes folder</em></strong></p><pre>const { getHomePage, getAboutPage, handleNotFound } = require(&#39;../PathToYour/Controller.js&#39;); // Import controller functions<br><br>const handleRoutes = (req, res) =&gt; {<br>  if (req.url === &#39;/&#39; &amp;&amp; req.method === &#39;GET&#39;) {<br>    getHomePage(res); // Call the controller function for the Home Page<br>  } else if (req.url === &#39;/about&#39; &amp;&amp; req.method === &#39;GET&#39;) {<br>    getAboutPage(res); // Call the controller function for the About Page<br>  }else {<br>    handleNotFound(res); // Handle unknown routes<br>  }<br>};<br><br>module.exports = handleRoutes; // Export the route handler</pre><p><strong><em>Step 3: Update the Server to export the handleRoutes</em></strong></p><pre>const http = require(&#39;http&#39;);<br>const handleRoutes = require(&#39;../PathToYour/Routes.js&#39;); // Import routes<br><br>const PORT = 8000;<br><br>const server = http.createServer((req, res) =&gt; {<br>  handleRoutes(req, res); // Delegate request handling to routes<br>});<br><br>server.listen(PORT, () =&gt; {<br>  console.log(`Server is running on http://localhost:${PORT}`);<br>});</pre><blockquote>Start the Server again and you will get the same messages as the previous one.</blockquote><h3>Conclusion</h3><p>In this part, we’ve covered the essential steps of setting up a basic server, handling routes, and organizing your project for better scalability. By following this guide, you’ve learned how to build a simple server, manage different endpoints, and structure your code effectively using controllers and routes.</p><p>Building a backend from the ground up with Node.js gives you a deeper understanding of server-side programming and prepares you to create lightweight, efficient applications. As you continue exploring and experimenting, you’ll see the true power and flexibility that Node.js offers for backend development.</p><p>Thank you for joining me on this journey! Stay tuned for the next part, where we’ll expand on this foundation and dive deeper into CRUD and the MVC pattern.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57574cc3f33c" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/behind-the-scenes-of-the-web-part-1-a-beginners-guide-to-backend-development-57574cc3f33c">Behind the Scenes of the Web: [Part 1] — A Beginner’s Guide to Backend Development</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Branching Out: The Essential Beginner’s Guide to Git and GitHub (Part 2)]]></title>
            <link>https://towardsdev.com/branching-out-the-essential-beginners-guide-to-git-and-github-part-2-48a3c3e8bb82?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/48a3c3e8bb82</guid>
            <category><![CDATA[git-branching-strategy]]></category>
            <category><![CDATA[git-branching]]></category>
            <category><![CDATA[git-merge-vs-rebase]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Sat, 30 Nov 2024 15:01:07 GMT</pubDate>
            <atom:updated>2024-12-23T17:08:55.472Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back to the second part of our Git and GitHub journey! In the first part, <a href="https://medium.com/@vivek_shaurya/branching-out-the-essential-beginners-guide-to-git-and-github-part-1-9ed5c988db0b">[Part 1]</a> we laid the groundwork by covering the basics of creating repositories and mastering push and pull commands. Now, we’re going to take a deeper dive into the powerful features of Git: branching and merging. Understanding these concepts is crucial for managing your projects efficiently and collaborating effectively with others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Hjd4KaKOUB0QKmT" /><figcaption>Photo by <a href="https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral">Roman Synkevych</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>1. Understanding Branching</strong></h3><blockquote><strong>What is Branching?</strong></blockquote><p>Branching allows you to create a separate line of development within your repository. This is particularly useful when you want to work on new features or experiments without affecting the main codebase.</p><p><strong><em>Types of Branches: Prod, Stage, and Dev</em></strong></p><p>Modern software development often organizes branches into three main environments to manage code at different stages of the development and deployment lifecycle. Here’s how branching typically works in <strong>Prod</strong>, <strong>Stage</strong>, and <strong>Dev</strong> environments:</p><ol><li><strong>Production Branch (main or master)</strong></li></ol><ul><li><strong>Environment</strong>: <strong>Prod</strong> (Production).</li><li><strong>Purpose</strong>: Contains the stable and tested code ready for deployment to end-users.</li><li><strong>Usage</strong>: <br>Only critical hotfixes or tested code from release branches are merged here.<br>The code is thoroughly reviewed and tested before merging.</li></ul><p><strong>2. Staging Branch (stage or staging)</strong></p><ul><li><strong>Environment</strong>: <strong>Stage</strong> (Pre-Production).</li><li><strong>Purpose</strong>: Serves as a replica of the production environment for final testing and verification.</li><li><strong>Usage</strong>: <br>Code from the develop branch (or feature/release branches) is merged here after being tested.<br>Used for Quality Assurance (QA) and User Acceptance Testing (UAT).</li></ul><p><strong>3. Development Branch (develop)</strong></p><ul><li><strong>Environment</strong>: <strong>Dev</strong> (Development).</li><li><strong>Purpose</strong>: The main working branch for ongoing development.</li><li><strong>Usage</strong>:<br>Serves as the integration point for all feature branches.<br>Developers regularly merge their work (e.g., feature or bugfix branches) here for collaboration.</li></ul><blockquote><strong>Supporting Branches Across Environments: </strong>To support these main branches, the following types are commonly used:</blockquote><blockquote>1. <strong>Feature Branches</strong>: Created from develop.<br>Merged into develop once the feature is complete and reviewed.</blockquote><blockquote>2. <strong>Bugfix Branches</strong>: Created from develop or stage.<br>Merged into develop or stage after fixing and testing.</blockquote><blockquote>3. <strong>Hotfix Branches</strong>: Created from main for urgent production issues.<br>Merged into both main and develop (or stage).</blockquote><blockquote>4. <strong>Release Branches</strong>: Created from develop.<br>Finalized in stage before merging into main.</blockquote><p><strong><em>Step 1: Creating a New Branch</em></strong></p><p>1. Open your terminal and navigate to your repository.</p><p>2. Use the following command to create a new branch:</p><pre>git checkout -b feature/feature-branch-name<br>#Replace feature-branch-name with a descriptive name for your branch.</pre><p><strong><em>Step 2: Switching Between Branches</em></strong></p><p>• To switch back to the main branch:</p><pre>git checkout main<br>#git checkout &lt;branch_name&gt;</pre><h3><strong>2. Making Changes in Your Branch</strong></h3><p><strong><em>Step 1: Work on Your Changes</em></strong></p><ul><li>Create or edit files in your branch as needed.</li></ul><p><strong><em>Step 2: Stage and Commit Your Changes</em></strong></p><p>1. Stage the changes:</p><pre>git add .</pre><p>2. Commit the changes:</p><pre>git commit -m &quot;Add new feature or update existing code&quot;</pre><h3><strong>3. Merging Branches</strong></h3><p><strong><em>Step 1: Switching to the Main Branch</em></strong></p><p>• Make sure you’re on the main branch:</p><pre>git checkout main</pre><p><strong><em>Step 2: Merging Your Feature Branch</em></strong></p><p>• Merge the feature branch into the main branch:</p><pre>git merge feature-branch-name</pre><blockquote><strong><em>Using Merge, Rebase, and Fast-Forward Merging</em></strong></blockquote><p>When merging branches, you have different options depending on how you want to manage your project history:</p><p>1. <strong>Merge</strong>: This creates a merge commit in the main branch that ties together the histories of both branches. It’s simple and maintains the history of your project.</p><pre>git merge feature-branch-name</pre><p>2. <strong>Rebase</strong>: This rewrites the commit history of your feature branch so that it appears as if you made your changes on top of the current main branch. This can lead to a <em>cleaner project history.</em></p><pre>git checkout feature-branch-name<br>git rebase main</pre><p>3. <strong>Fast-Forward Merge</strong>: If the main branch hasn’t diverged since you created your feature branch, you can perform a fast-forward merge. This moves the main branch pointer forward to your latest commit on the feature branch without creating a new merge commit.</p><pre># Example after rebasing:<br>git checkout main<br><br>git merge feature-branch-name<br># If the feature branch is ahead of the main branch without any new commits on the main, this will fast-forward.</pre><h3><strong>4. Resolving Merge Conflicts</strong></h3><blockquote><strong>What is a Merge Conflict?</strong></blockquote><p>A merge conflict occurs when two branches have changes to the same line of a file or when one branch deletes a file that another branch is trying to modify.</p><p><strong><em>Step 1: Detecting a Merge Conflict</em></strong></p><p>• If there are conflicts during the merge or rebase, Git will indicate which files are affected.</p><p><strong><em>Step 2: Resolving the Conflict</em></strong></p><p>1. Open the conflicted files in your text editor.</p><p>2. Look for conflict markers (&lt;&lt;&lt;&lt;&lt;&lt;&lt;, =======, &gt;&gt;&gt;&gt;&gt;&gt;&gt;) to see the conflicting changes.</p><p>3. Manually edit the file to resolve the conflicts, then save it.</p><p><strong><em>Step 3: Staging and Committing the Resolved Changes</em></strong></p><p>1. Stage the resolved files:</p><pre>git add resolved-file-name</pre><p>2. Commit the merge resolution:</p><pre>git commit -m &quot;Resolve merge conflict&quot;</pre><h3><strong>Conclusion</strong></h3><p>In this second part of our exploration of Git and GitHub, we’ve covered essential concepts of branching and merging, including the differences between merging, rebasing, and fast-forwarding. We’ve also discussed how to handle merge conflicts. By mastering these skills, you can manage your projects more effectively and collaborate seamlessly with others.</p><p>Git and GitHub empower you to control your code’s evolution, enabling you to work in parallel on different features without disrupting the main codebase. As you continue to explore the capabilities of these tools, remember that practice is key to becoming proficient.</p><p>Thank you for joining me on this journey.</p><p>Love 💙 &amp; Peace ☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48a3c3e8bb82" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/branching-out-the-essential-beginners-guide-to-git-and-github-part-2-48a3c3e8bb82">Branching Out: The Essential Beginner’s Guide to Git and GitHub (Part 2)</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Branching Out: The Essential Beginner’s Guide to Git and GitHub (Part 1)]]></title>
            <link>https://towardsdev.com/branching-out-the-essential-beginners-guide-to-git-and-github-part-1-9ed5c988db0b?source=rss-7c3489346ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ed5c988db0b</guid>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[code-management]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Vivek Shaurya]]></dc:creator>
            <pubDate>Sat, 23 Nov 2024 17:25:53 GMT</pubDate>
            <atom:updated>2024-12-23T17:08:58.636Z</atom:updated>
            <content:encoded><![CDATA[<p>In this two-part series, I’m excited to guide you through the essentials of using Git and GitHub. This first part will focus on the foundational aspects, from creating your first repository to mastering the push and pull commands. Whether you’re a complete beginner or someone looking to refine your skills, this guide aims to equip you with the knowledge to navigate version control confidently and effectively.</p><p>In the second part, we’ll take a deeper dive into branching, merging, and resolving merge conflicts, further enhancing your ability to manage projects efficiently. Let’s embark on this journey together and unlock the power of Git and GitHub!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_sImiVBmkFA068kg" /><figcaption>Photo by <a href="https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral">Roman Synkevych</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>1. Creating a GitHub Repository</strong></h3><p><strong><em>Step 1: Sign In to GitHub</em></strong></p><ul><li>Go to <a href="https://github.com/">GitHub</a> and sign in or create an account if you don’t have one.</li></ul><p><strong><em>Step 2: Create a New Repository</em></strong></p><ol><li>Click the “+” icon in the upper right corner and select “New repository.”</li></ol><p>2. Give your repository a name (e.g., my-awesome-project).</p><p>3. Optionally, add a description.</p><p>4. Choose visibility (public or private) and select “Initialize this repository with a README.”</p><p>5. Click “Create repository.”</p><h3><strong>2. Connecting Your Local Device</strong></h3><p><strong><em>Step 1: Install Git</em></strong></p><ul><li>For Windows, download from <a href="https://gitforwindows.org/">Git for Windows</a>.</li><li>For macOS, use Homebrew:</li></ul><pre>brew install git</pre><ul><li>For Linux, use your package manager.</li></ul><pre>sudo apt install git</pre><p><strong><em>Step 2: Clone Your Repository</em></strong></p><p>1. Open your terminal (or command prompt).</p><p>2. Navigate to the directory where you want to clone the repository.</p><p>3. Use the command:</p><pre>git clone https://github.com/username/my-awesome-project.git<br><br>#Replace “username” with your GitHub username.</pre><h3><strong>3. Configuring Git with Your Username and Password</strong></h3><p>To ensure that your commits are correctly attributed and you can seamlessly push to GitHub, you’ll need to set your Git username and configure your credentials.</p><p><strong><em>Step 1: Setting or Changing Your Git Username</em></strong></p><p>To set or change your Git username for all repositories, open your terminal and enter:</p><pre>git config -global user.name &quot;Your Name&quot;<br># Replace &quot;Your Name&quot; with your GitHub username. <br># This command sets your username for all repositories on your device.</pre><p>To set the username for a specific repository only, navigate to that repository’s directory and run:</p><pre>git config user.name &quot;Your Name&quot;</pre><p><strong><em>Step 2: Configuring Password Access</em></strong></p><p>GitHub now recommends using a <strong>personal access token</strong> instead of your GitHub password when pushing changes. Here’s how to configure this:</p><p><em>Step 2.1: Generate a Personal Access Token:</em></p><ul><li>Go to <a href="https://github.com/settings/tokens">GitHub’s token settings</a>.</li><li>Click “Generate new token” and select the appropriate permissions for your needs.</li><li>Copy the token as it will be required for authentication.</li></ul><p><em>Step 2.2: Save Your Token in Git:</em></p><ul><li>When you first push to GitHub, Git will prompt you for a username and password.</li><li>Enter your GitHub username, and for the password, paste it into your personal access token.</li></ul><p><em>Step2.3: Optional: Caching Your Credentials</em></p><p>To avoid entering your credentials repeatedly, you can enable credential caching:</p><pre>git config -global credential.helper cache</pre><blockquote>Note: This command will cache your credentials for a default time period, typically 15 minutes. Alternatively, to store credentials securely, you can use:</blockquote><pre>git config -global credential.helper store</pre><p>This will store the credentials in plain text in your .git-credentials file.</p><h3><strong><em>4. Using Git with Your Repository</em></strong></h3><p><strong><em>Step 1: Navigating to Your Local Repository</em></strong></p><ul><li>Change to your repository directory:</li></ul><pre>cd my-awesome-project</pre><p><strong><em>Step 2: Making Changes</em></strong></p><ul><li>Create a new file or edit an existing one.</li></ul><p><strong><em>Step 3: Checking the Status</em></strong></p><pre>git status<br># This command shows you the changes made.</pre><h3><strong>5. Staging and Committing Changes</strong></h3><p><strong><em>Step 1: Staging Your Changes</em></strong></p><ul><li>To stage changes, use:</li></ul><pre>git add .<br>#This stages all modified files.</pre><p><strong><em>Step 2: Committing Your Changes</em></strong></p><pre>git commit -m &quot;Add new feature or fix issue&quot;<br>#Commit the changes with a message</pre><h3><strong>6. Pushing and Pulling Changes</strong></h3><p><strong><em>Step 1: Pushing Changes to GitHub</em></strong></p><ul><li>To send your local changes to GitHub, use:</li></ul><pre>git push origin main</pre><p><strong><em>Step 2: Pulling Changes from GitHub</em></strong></p><p>• To update your local repository with changes from GitHub, use:</p><pre>git pull origin main</pre><blockquote><strong>Note</strong>: Before pushing your changes to GitHub, it’s crucial to perform a pull first to ensure that both your local and remote repositories are synchronized.</blockquote><h3>7. <strong>Understanding Pull vs F</strong>etch</h3><p>While both pull and fetch are used to retrieve changes from a remote repository, they serve different purposes and are used in different scenarios:</p><p><strong><em>Fetch</em></strong></p><p>• This command downloads changes from the remote repository but does <strong>not</strong> automatically <strong>merge</strong> them into your local branch. It allows you to review the changes first.</p><pre>git fetch origin<br>#This fetches all changes from the remote origin, including branches and tags.</pre><p><strong><em>Pull</em></strong></p><p>• Combines git fetch and git merge in a single step. It retrieves changes from the remote repository and <strong>merges</strong> them into your current branch.</p><pre>git pull origin main<br>#This fetches changes from the main branch in the remote repository and <br>#merges them into your current branch.</pre><blockquote><strong>When to Use Which</strong></blockquote><p>• <strong>Use git fetch</strong> if you’re working on a large project and want to preview changes before merging.</p><p>• <strong>Use git pull</strong> if you’re confident that the remote changes can be merged into your branch without conflicts.</p><h3>Conclusion</h3><p>In this first part of our journey through Git and GitHub, we’ve covered the essential steps to get you started with version control. By learning how to create a repository, connect it to your local device, and effectively use the push and pull commands, you’re now equipped to manage your projects with greater confidence.</p><p>Git and GitHub are invaluable tools for collaboration and version management, and as you continue to practice and explore their features, you’ll find even more ways to enhance your workflow. In the second part <a href="https://medium.com/@vivek_shaurya/branching-out-the-essential-beginners-guide-to-git-and-github-part-2-48a3c3e8bb82">[Part 2]</a> of this series, we’ll delve into branching and merging, including how to handle merge conflicts, which are key skills for any developer.</p><p>Stay tuned!</p><p>Love💙 &amp; Peace☮️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ed5c988db0b" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/branching-out-the-essential-beginners-guide-to-git-and-github-part-1-9ed5c988db0b">Branching Out: The Essential Beginner’s Guide to Git and GitHub (Part 1)</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>