<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Debug School: rakesh kumar</title>
    <description>The latest articles on Debug School by rakesh kumar (@rakeshdevcotocus_468).</description>
    <link>https://www.debug.school/rakeshdevcotocus_468</link>
    <image>
      <url>https://www.debug.school/images/WnjM0tj_qJIv1YRaHUFCcWCxLQyroc-__BJWYYD46DE/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvdXNl/ci9wcm9maWxlX2lt/YWdlLzkvMzhjZTM3/NDAtZDA2NC00MmVh/LTk1MmMtODg2MGQ2/MGNhZGU1LmpwZWc</url>
      <title>Debug School: rakesh kumar</title>
      <link>https://www.debug.school/rakeshdevcotocus_468</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://www.debug.school/feed/rakeshdevcotocus_468"/>
    <language>en</language>
    <item>
      <title>Website performance improvement</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 29 May 2026 11:14:40 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/website-performance-improvement-1el5</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/website-performance-improvement-1el5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Large css dumped inline in listing pages&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Use debounce to avoid unnecessary Api call&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Large css dumped inline in listing pages
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Why it is a problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When CSS is written directly inside the Blade page, the browser has to download that CSS again and again on every page load.&lt;/p&gt;

&lt;p&gt;The browser cannot cache it separately.&lt;/p&gt;

&lt;p&gt;So every time user opens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/bike-listing
/car-listing
/search-vehicle
/booking
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the same CSS may be sent again with the HTML response.&lt;/p&gt;

&lt;p&gt;This makes the page heavier and slower.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meaning of “not cacheable”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If CSS is in a separate file like:&lt;/p&gt;

&lt;p&gt;resources/css/bike-listing.css&lt;/p&gt;

&lt;p&gt;then Vite can generate a versioned file like:&lt;/p&gt;

&lt;p&gt;bike-listing-abc123.css&lt;/p&gt;

&lt;p&gt;The browser can cache this file.&lt;/p&gt;

&lt;p&gt;So next time user visits the page, browser does not need to download CSS again.&lt;/p&gt;

&lt;p&gt;But if CSS is inside Blade:&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;then it is part of the HTML. Browser cannot reuse it separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The screenshot says:&lt;/p&gt;

&lt;p&gt;+200–500ms LCP on slow connections&lt;/p&gt;

&lt;p&gt;LCP means Largest Contentful Paint.&lt;/p&gt;

&lt;p&gt;Simple meaning:&lt;br&gt;
how much time the main visible content takes to load on screen.&lt;/p&gt;

&lt;p&gt;If inline CSS is large, it can delay page rendering, especially on mobile or slow internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommended fix&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Move the inline CSS from Blade files into a separate CSS file.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources/css/bike-listing.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then load it using Vite:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@vite(['resources/css/bike-listing.css'])

Or if you already have one main CSS file:

@vite(['resources/css/app.css'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.debug.school/images/Zt6NlebPOpIwvhMiznoXJZKGE53s_Gafrl62xWoOlwk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcjczdjYx/ZmpraWI0bDl0dTE1/bHYucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/Zt6NlebPOpIwvhMiznoXJZKGE53s_Gafrl62xWoOlwk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcjczdjYx/ZmpraWI0bDl0dTE1/bHYucG5n" alt=" " width="612" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/qPiInfNdhas9tpBynQ01pDtOiB-u49TXaE75iCMOWV4/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvNTh4cmNx/dHAzdWZoZjN1Z3hy/cDQucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/qPiInfNdhas9tpBynQ01pDtOiB-u49TXaE75iCMOWV4/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvNTh4cmNx/dHAzdWZoZjN1Z3hy/cDQucG5n" alt=" " width="582" height="631"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/AbSk3O7Ipv8JKHsm6SYnfE5uqRpLxFHkOxzmO_YIbfc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvN21iN2w0/MmNscHBxbDMwY20z/MngucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/AbSk3O7Ipv8JKHsm6SYnfE5uqRpLxFHkOxzmO_YIbfc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvN21iN2w0/MmNscHBxbDMwY20z/MngucG5n" alt=" " width="625" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/d3k1nxDEXJVM1QlC7XAieRC6lkd43ENDeP8zyd5EDcE/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcmZ1bW1h/cjA1ZnVyeXN0NHg4/YWYucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/d3k1nxDEXJVM1QlC7XAieRC6lkd43ENDeP8zyd5EDcE/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcmZ1bW1h/cjA1ZnVyeXN0NHg4/YWYucG5n" alt=" " width="605" height="617"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/jIwMgP_1RWT1DVMLDpbnGFNU6KCuEX6PDNvb-DRFbkI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvMzlzNmI1/NmNiNTVsZXRxeTNu/bmkucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/jIwMgP_1RWT1DVMLDpbnGFNU6KCuEX6PDNvb-DRFbkI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvMzlzNmI1/NmNiNTVsZXRxeTNu/bmkucG5n" alt=" " width="571" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/siY59h7cvsTgqbCdlbnsOyCp3XrtvxvMuf8v8iDn9h8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbnd5MTE1/bGR2enY1MHVzang4/NzgucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/siY59h7cvsTgqbCdlbnsOyCp3XrtvxvMuf8v8iDn9h8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbnd5MTE1/bGR2enY1MHVzang4/NzgucG5n" alt=" " width="613" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use debounce to avoid unnecessary Api call
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install lodash.debounce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Debounce is used to improve performance by reducing unnecessary function calls, API calls, database queries, and browser work.&lt;/p&gt;

&lt;p&gt;Debounce is a programming technique used to delay the execution of a function until the user stops triggering the same event for a specific time.&lt;/p&gt;

&lt;p&gt;In simple words:&lt;/p&gt;

&lt;p&gt;Debounce means: “Wait for some time. If the user does not repeat the action again, then run the function.”&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;When user types in a search box, instead of calling API on every letter, debounce waits until the user stops typing for 400ms or 500ms, then calls the API once.&lt;/p&gt;

&lt;p&gt;Without debounce:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;m → API call
mo → API call
mob → API call
mobi → API call
mobile → API call
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With debounce:&lt;br&gt;
mobile → API call only once after user stops typing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before Debounce&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this code, API/function runs on every key press.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const searchBox = document.getElementById('searchBox');

searchBox.addEventListener('input', function () {
    const keyword = searchBox.value;

    searchProduct(keyword);
});

function searchProduct(keyword) {
    console.log('API called for:', keyword);

    // Example API call
    fetch(`/api/search?keyword=${keyword}`)
        .then(response =&amp;gt; response.json())
        .then(data =&amp;gt; {
            document.getElementById('result').innerHTML = JSON.stringify(data);
        });
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens here?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User types:&lt;/p&gt;

&lt;p&gt;mobile&lt;/p&gt;

&lt;p&gt;API calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API called for: m
API called for: mo
API called for: mob
API called for: mobi
API called for: mobil
API called for: mobile

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So API is called 6 times.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Problem&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This creates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Too many API calls
Slow performance
More server load
Bad user experience
Unnecessary database queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After Debounce&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install lodash.debounce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, API runs only when user stops typing for 500ms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const searchBox = document.getElementById('searchBox');

let searchTimer = null;

searchBox.addEventListener('input', function () {
    const keyword = searchBox.value;

    clearTimeout(searchTimer);

    searchTimer = setTimeout(function () {
        searchProduct(keyword);
    }, 500);
});

function searchProduct(keyword) {
    console.log('API called for:', keyword);

    // Example API call
    fetch(`/api/search?keyword=${keyword}`)
        .then(response =&amp;gt; response.json())
        .then(data =&amp;gt; {
            document.getElementById('result').innerHTML = JSON.stringify(data);
        });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens now?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User types quickly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mobile

API call:

API called for: mobile

Only 1 API call happens after user stops typing.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Another code example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Before debounce&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const handlePinCodeChange = (e) =&amp;gt; {
    const pinCode = e.target.value.replaceAll(/\D/g, '').slice(0, 6);
    setFormData((prev) =&amp;gt; ({ ...prev, pinCode }));
    setFieldErrors((prev) =&amp;gt; { const { pinCode: _, ...rest } = prev; return rest; });
    if (pinCode.length === 6) fetchStateAndCity(pinCode);
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;After Debounce&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install lodash.debounce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { debounce } from "lodash";
import { useMemo } from "react";

// inside the component:
const debouncedFetch = useMemo(
  () =&amp;gt; debounce(fetchStateAndCity, 400),
  []
);

const handlePinCodeChange = (e) =&amp;gt; {
  const pinCode = e.target.value.replaceAll(/\D/g, '').slice(0, 6);
  setFormData((prev) =&amp;gt; ({ ...prev, pinCode }));
  setFieldErrors((prev) =&amp;gt; { const { pinCode: _, ...rest } = prev; return rest; });
  if (pinCode.length === 6) debouncedFetch(pinCode);
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Where We Can Use Debounce&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Why Debounce Helps&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Search box&lt;/td&gt;
&lt;td&gt;Avoid API call on every letter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pincode city/state fetch&lt;/td&gt;
&lt;td&gt;Call API only after full pincode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Username availability check&lt;/td&gt;
&lt;td&gt;Check only after user stops typing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Email validation API&lt;/td&gt;
&lt;td&gt;Avoid repeated validation calls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto-save form&lt;/td&gt;
&lt;td&gt;Save after user stops typing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filter products&lt;/td&gt;
&lt;td&gt;Avoid reloading results again and again&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
    </item>
    <item>
      <title>What is CLAUDE.md and Why Every Software Project Needs It</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 29 May 2026 03:06:19 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/what-is-claudemd-and-why-every-software-project-needs-it-4dcl</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/what-is-claudemd-and-why-every-software-project-needs-it-4dcl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Meta Title&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Meta Description&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What is CLAUDE.md?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;CLAUDE.md in Simple Language&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Why Was CLAUDE.md Needed?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;The Main Purpose of CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;WH Form Explanation of CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Key Advantages of CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What Should Be Included in CLAUDE.md?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Root CLAUDE.md vs Folder-Level CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Best Practices for Writing CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Common Mistakes While Creating CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Recommended Workflow&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Example Prompt Using CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Why Every Software Project Needs CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Meta Title
&lt;/h2&gt;

&lt;p&gt;What is CLAUDE.md and Why Every Software Project Needs It&lt;/p&gt;
&lt;h2&gt;
  
  
  Meta Description
&lt;/h2&gt;

&lt;p&gt;Learn what CLAUDE.md is, why it matters in software projects, how it helps Claude understand your codebase, and how teams can use it to reduce mistakes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Modern software development is no longer limited to only developers writing code manually. Today, AI coding assistants like Claude Code are becoming part of real development workflows. They help developers understand code, create features, fix bugs, improve UI, write tests, refactor logic, and document systems.&lt;/p&gt;

&lt;p&gt;But there is one common problem.&lt;/p&gt;

&lt;p&gt;Every time you start a new AI session, you often need to explain the same project again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is this project?
Which framework is used?
Which folder contains what?
What coding standards should be followed?
Which commands should be run?
Which files should not be touched?
What existing logic must not be broken?
How should UI, performance, security, and maintainability be handled?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This repeated explanation wastes time and increases the chance of mistakes. This is where CLAUDE.md becomes extremely useful.&lt;/p&gt;

&lt;p&gt;CLAUDE.md is like a project memory file for Claude. It gives Claude clear, reusable, and project-specific instructions so that it can work more consistently inside your software project.&lt;/p&gt;

&lt;p&gt;In simple words, CLAUDE.md helps Claude understand your project before it starts working.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is CLAUDE.md?
&lt;/h2&gt;

&lt;p&gt;CLAUDE.md is a markdown file placed inside your software project to guide Claude Code. It contains important information about your project, development rules, architecture, commands, coding standards, folder structure, and safety instructions.&lt;/p&gt;

&lt;p&gt;It works like a permanent instruction file for Claude.&lt;/p&gt;

&lt;p&gt;Instead of explaining your project again and again in every prompt, you write the important project details once inside CLAUDE.md. Then, whenever Claude works inside that project, it can use those instructions as context.&lt;/p&gt;

&lt;h2&gt;
  
  
  CLAUDE.md in Simple Language
&lt;/h2&gt;

&lt;p&gt;Think of CLAUDE.md as a senior developer’s note for an AI assistant.&lt;/p&gt;

&lt;p&gt;When a new developer joins a project, they usually need onboarding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;They need to know the folder structure.
They need to understand the business logic.
They need to know which commands to run.
They need to know coding rules.
They need to know what should not be changed.
They need to know how deployment or testing works.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claude also needs the same kind of onboarding. CLAUDE.md provides that onboarding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Was CLAUDE.md Needed?
&lt;/h2&gt;

&lt;p&gt;AI tools are powerful, but they can make mistakes when they do not understand the project properly.&lt;/p&gt;

&lt;p&gt;Without clear project instructions, Claude may:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Change working logic unnecessarily.
Modify files that should not be touched.
Use the wrong coding pattern.
Ignore existing architecture.
Create duplicate code.
Break old features while adding new ones.
Miss project-specific commands.
Use inconsistent naming conventions.
Create UI that does not match the existing design.
Forget previous decisions after the session ends.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CLAUDE.md reduces these problems by giving Claude a stable source of project truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Main Purpose of CLAUDE.md
&lt;/h2&gt;

&lt;p&gt;The main purpose of CLAUDE.md is to make Claude work like a project-aware assistant instead of a random code generator.&lt;/p&gt;

&lt;p&gt;It helps Claude understand:&lt;/p&gt;

&lt;p&gt;What the project is about.&lt;br&gt;
How the project is structured.&lt;br&gt;
Which technologies are used.&lt;br&gt;
How code should be written.&lt;br&gt;
How features should be modified.&lt;br&gt;
What rules must be followed.&lt;br&gt;
What existing functionality must be protected.&lt;br&gt;
How to test and verify changes.&lt;br&gt;
How to report work after completion.&lt;/p&gt;
&lt;h2&gt;
  
  
  WH Form Explanation of CLAUDE.md
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is CLAUDE.md?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CLAUDE.md is a markdown instruction file used to guide Claude Code inside a software project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is CLAUDE.md Important?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is important because it saves time, reduces mistakes, keeps Claude consistent, and helps protect existing project logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who Should Use CLAUDE.md?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Developers, team leads, DevOps engineers, QA teams, product managers, technical writers, and anyone using Claude for project-based work can use CLAUDE.md.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where Should CLAUDE.md Be Placed?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It can be placed in the root of the project. For larger projects, separate CLAUDE.md files can also be placed inside important folders such as lib, backend, frontend, android, web, api, or each microservice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When Should CLAUDE.md Be Created?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It should be created at the beginning of the project or before using Claude Code seriously for development work. It should also be updated whenever project rules, architecture, commands, or workflows change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Does CLAUDE.md Help?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It gives Claude reusable project context so the developer does not need to repeat the same instructions in every prompt.&lt;/p&gt;
&lt;h2&gt;
  
  
  Key Advantages of CLAUDE.md
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Saves Developer Time&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without CLAUDE.md, developers repeatedly explain the same things to Claude:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project structure.
Framework details.
Coding rules.
Testing commands.
Business logic.
Files to avoid.
UI expectations.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With CLAUDE.md, these details are already documented. The developer can give a shorter prompt because Claude already has the project background.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Instead of writing a long prompt every time, you can say:&lt;/p&gt;

&lt;p&gt;“Fix the booking status issue according to CLAUDE.md rules. Do not break existing functionality.”&lt;/p&gt;

&lt;p&gt;This saves time and makes the workflow faster.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Reduces Mistakes&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AI tools can generate code quickly, but speed can become risky when the tool does not understand the project. CLAUDE.md reduces mistakes by clearly defining boundaries.&lt;/p&gt;

&lt;p&gt;For example, you can mention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not remove existing validation.
Do not change database columns without asking.
Do not break old APIs.
Do not remove backward compatibility.
Do not modify production .env files.
Do not overwrite existing UI logic.
Do not introduce duplicate code.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These rules help Claude work safely.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Protects Existing Features&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Many software projects already have working functionality. The biggest risk in AI-assisted development is that while adding a new feature, Claude may accidentally break an old feature.&lt;/p&gt;

&lt;p&gt;A good CLAUDE.md should clearly say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Preserve existing functionality.
Do not rewrite working modules unnecessarily.
Make minimum required changes.
Before changing logic, understand the current flow.
Keep old fallback behavior unless explicitly told to remove it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is especially useful for old Laravel, Flutter, React, WordPress, or microservice-based projects where many features are already connected.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Keeps Claude Consistent Across Sessions&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Claude sessions can change. One day you may ask Claude to fix a UI issue. Another day you may ask it to improve performance. Without shared memory, Claude may follow different styles in different sessions.&lt;/p&gt;

&lt;p&gt;CLAUDE.md keeps the rules consistent.&lt;/p&gt;

&lt;p&gt;It tells Claude:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use the same coding style.
Use the same folder structure.
Use the same naming convention.
Use the same response format.
Use the same testing checklist.
Use the same UI standards.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates more predictable and professional output.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Improves Code Quality&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A strong CLAUDE.md can include quality rules such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use clean architecture principles.
Keep business logic separate from controllers.
Avoid duplicate code.
Create reusable services.
Follow existing design patterns.
Keep functions small and readable.
Use proper validation.
Use meaningful variable names.
Avoid hardcoded values.
Improve maintainability.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Claude has these rules, the generated code becomes cleaner and easier to maintain.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Helps with Large and Old Projects&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Large projects are difficult for AI tools because they contain many folders, old logic, hidden dependencies, and business rules.&lt;/p&gt;

&lt;p&gt;In such projects, CLAUDE.md becomes even more valuable.&lt;/p&gt;

&lt;p&gt;It can explain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Which folder contains controllers.
Which folder contains services.
Which folder contains views.
Which modules are sensitive.
Which files are legacy.
Which APIs are public.
Which APIs require authentication.
Which database tables are important.
Which areas should not be touched without approval.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helps Claude navigate the project with better understanding.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Useful for Multi-Repo and Microservice Projects&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Many modern projects are not single applications. They may contain multiple services:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frontend application.
Backend API.
Admin panel.
Mobile app.
Notification service.
Authentication service.
Payment service.
File management service.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, one CLAUDE.md is not always enough. You can create multiple files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Root CLAUDE.md for common project rules.
Backend CLAUDE.md for API rules.
Frontend CLAUDE.md for UI rules.
Mobile CLAUDE.md for Flutter or Android rules.
Microservice-level CLAUDE.md for service-specific logic.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helps Claude understand both the full project and the specific area where it is working.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Helps Claude Follow Project Architecture&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every project has its own architecture. Some projects use MVC. Some use clean architecture. Some use service classes. Some use repositories. Some use microservices.&lt;/p&gt;

&lt;p&gt;If Claude does not know the architecture, it may write code in the wrong place.&lt;/p&gt;

&lt;p&gt;CLAUDE.md can define:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Controllers should stay thin.
Business logic should go into services.
Database queries should not be scattered everywhere.
Blade views should not contain heavy business logic.
API response format should remain consistent.
Frontend components should be reusable.
Shared utilities should be used instead of duplicate functions.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This improves structure and reduces technical debt.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Improves UI/UX Consistency&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For frontend and full-stack projects, CLAUDE.md can define UI rules.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use a professional enterprise-level design.
Keep mobile responsiveness in mind.
Use consistent font size and spacing.
Follow the existing color theme.
Do not use random colors.
Keep forms clean and user-friendly.
Use proper loading and error states.
Keep accessibility in mind.
Do not break existing layout.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is very useful when using Claude for UI enhancement work.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Supports Performance Optimization&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;CLAUDE.md can also guide Claude to care about performance.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not load unnecessary scripts.
Avoid duplicate API calls.
Optimize large images.
Use pagination for large lists.
Avoid heavy logic inside frontend build/render methods.
Use caching where appropriate.
Keep database queries optimized.
Avoid N+1 query problems.
Do not parse very large JSON directly on the UI thread in mobile apps.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These rules help Claude build faster and more efficient applications.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Supports Security and Maintainability&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A project-level CLAUDE.md can include safety rules such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not expose secrets.
Do not print sensitive tokens in logs.
Do not modify production credentials.
Do not disable authentication.
Do not bypass authorization checks.
Validate all user input.
Use centralized authentication where required.
Preserve ownership checks.
Follow existing role and permission logic.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can also mention maintainability rules:&lt;/p&gt;

&lt;p&gt;Avoid duplicate code.&lt;br&gt;
Do not create unnecessary files.&lt;br&gt;
Keep code readable.&lt;br&gt;
Follow existing conventions.&lt;br&gt;
Document important decisions.&lt;br&gt;
Add comments only where useful.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Helps with Testing and Verification&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Claude should not only write code. It should also verify the work.&lt;/p&gt;

&lt;p&gt;CLAUDE.md can tell Claude which commands to run after changes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;For Laravel projects, it may include:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Run PHP syntax checks.
Run route list if routes changed.
Run config clear and cache clear when needed.
Check migration impact.
Review git diff before final response.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;For Flutter projects, it may include:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Run flutter analyze.
Check build errors.
Keep mobile responsiveness.
Avoid UI thread blocking.
Test important screens.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For frontend projects, it may include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Run lint command.
Run build command.
Check responsive layout.
Verify browser console errors.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes Claude’s output more reliable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Makes Team Collaboration Easier&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When CLAUDE.md is committed to Git, the whole team gets the same AI working rules.&lt;/p&gt;

&lt;p&gt;This is important because different developers may use Claude differently. Without shared instructions, one developer may ask Claude to follow one style, while another may follow another style.&lt;/p&gt;

&lt;p&gt;A shared CLAUDE.md creates a common standard.&lt;/p&gt;

&lt;p&gt;It helps teams maintain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Same coding style.
Same branch rules.
Same testing checklist.
Same architecture approach.
Same quality expectations.
Same reporting format.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Helps Non-Developers Too&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;CLAUDE.md is not only useful for software developers. It can also help people working on documentation, reports, HR tasks, Excel work, content writing, QA testing, and project management.&lt;/p&gt;

&lt;p&gt;For example, a content team can create a CLAUDE.md that defines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Writing tone.
SEO rules.
Heading structure.
Brand voice.
Formatting rules.
Target audience.
Words to avoid.
Internal linking rules.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An HR team can define:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Report format.
Employee data rules.
Confidentiality guidelines.
Email writing style.
Excel formatting standards.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A QA team can define:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Test case format.
Bug report format.
Severity rules.
Regression checklist.
Acceptance criteria.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means CLAUDE.md is basically reusable work memory, not only coding memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Should Be Included in CLAUDE.md?
&lt;/h2&gt;

&lt;p&gt;A good CLAUDE.md should be simple, clear, and practical. It should not be a long essay. It should contain the rules Claude really needs while working.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recommended CLAUDE.md Sections
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Project Overview&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Explain what the project does in simple language.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;This project is a vehicle rental platform where owners can list vehicles and renters can book them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Technology Stack&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention the tools and frameworks used.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Backend: Laravel
Frontend: Blade or React
Mobile: Flutter
Database: MySQL
Authentication: Keycloak
Server: Apache or Nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Folder Structure&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Explain important folders.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/Http/Controllers contains controllers.
app/Services contains business logic.
resources/views contains Blade templates.
routes/web.php contains web routes.
routes/api.php contains API routes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Development Rules&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention project-specific coding rules.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not break existing functionality.
Follow current architecture.
Do not create duplicate logic.
Use services for business logic.
Keep controllers clean.
Do not make unrelated changes.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;UI/UX Rules&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention design expectations.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Make UI professional and responsive.
Use consistent spacing and typography.
Do not use random colors.
Keep forms simple and readable.
Maintain existing theme.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Security Rules&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention security-related restrictions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not expose secrets.
Do not modify production .env.
Do not bypass login or authorization.
Do not remove validation.
Do not log sensitive information.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Testing Commands&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention common commands.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php -l file.php
php artisan route:list
php artisan config:clear
php artisan cache:clear
npm run build
flutter analyze
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Git and Reporting Rules&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention how Claude should report work.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Show files changed.
Explain logic updated.
Mention commands run.
Mention pending issues.
Give rollback steps.
Give testing checklist.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Do Not Touch Section&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention sensitive files or folders.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not edit production .env.
Do not delete migrations.
Do not remove legacy fallback logic.
Do not modify payment logic without approval.
Do not rewrite authentication flow unless asked.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Prompting Rules&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mention how Claude should behave.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First analyze, then plan, then implement.
For major changes, provide a plan before coding.
Ask only necessary questions.
Prefer small safe changes.
Do not over-engineer.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Root CLAUDE.md vs Folder-Level CLAUDE.md
&lt;/h2&gt;

&lt;p&gt;For small projects, one root CLAUDE.md may be enough.&lt;/p&gt;

&lt;p&gt;For large projects, multiple CLAUDE.md files are better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Root CLAUDE.md&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This file should contain global rules.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Example content:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Project overview.
Common architecture.
Common coding standards.
Git rules.
Security rules.
Testing checklist.
Reporting format.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Folder-Level CLAUDE.md&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Folder-level files should contain local rules.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lib/CLAUDE.md for Flutter app logic.
android/CLAUDE.md for Android build rules.
web/CLAUDE.md for web-specific rules.
backend/CLAUDE.md for Laravel API rules.
frontend/CLAUDE.md for UI rules.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This separation keeps instructions clean and avoids one very large file.&lt;/p&gt;

&lt;p&gt;Example Folder Structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-root/
├── CLAUDE.md
├── backend/
│   └── CLAUDE.md
├── frontend/
│   └── CLAUDE.md
├── mobile/
│   └── CLAUDE.md
└── docs/
    └── features/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example CLAUDE.md Template&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CLAUDE.md

## Project Overview

This project is a software platform used for managing users, bookings, payments, admin workflows, and customer-facing features.

## Technology Stack

- Backend: Laravel
- Frontend: Blade / React
- Mobile: Flutter
- Database: MySQL
- Authentication: Keycloak
- Server: Apache / Nginx

## Core Rules

- Do not break existing functionality.
- Do not remove old working logic unless clearly asked.
- Do not make unrelated changes.
- Follow existing folder structure and coding style.
- Prefer small, safe, reviewable changes.
- Avoid duplicate code.
- Keep business logic out of views.
- Keep controllers clean and move complex logic to services.

## UI/UX Rules

- Maintain a professional and enterprise-level UI.
- Keep all pages mobile responsive.
- Use consistent font size, spacing, and color theme.
- Do not use random design patterns.
- Preserve existing user flow.
- Improve readability without changing business logic unnecessarily.

## Security Rules

- Do not expose secrets, tokens, or passwords.
- Do not edit production `.env` files.
- Do not bypass authentication or authorization.
- Validate user input properly.
- Do not log sensitive data.
- Preserve ownership checks.

## Performance Rules

- Avoid duplicate database queries.
- Use pagination for large lists.
- Avoid unnecessary API calls.
- Optimize images and assets where possible.
- Do not add heavy frontend logic that slows mobile view.

## Testing Rules

After changes, suggest or run relevant checks:

- PHP syntax check
- Laravel route check
- Cache clear if needed
- Build or lint command if frontend changes are made
- Manual testing checklist

## Final Response Format

When work is completed, provide:

1. Summary of changes
2. Files changed
3. Commands run
4. Testing checklist
5. Risks or pending issues
6. Rollback steps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best Practices for Writing CLAUDE.md
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Keep It Practical&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do not write too much theory. Claude needs actionable rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep It Updated&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If project structure changes, update CLAUDE.md.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep It Short Enough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A very long file can become confusing. Keep it clear and organized.&lt;/p&gt;

&lt;p&gt;Use Strong Instructions for Critical Rules&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not break existing functionality.
Do not edit production .env.
Do not remove authentication checks.
Do not change database schema without approval.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add Examples&lt;/p&gt;

&lt;p&gt;Examples help Claude understand your expectations better.&lt;/p&gt;

&lt;p&gt;Commit It to Git&lt;/p&gt;

&lt;p&gt;If the instructions are useful for the whole team, commit CLAUDE.md to the repository.&lt;/p&gt;

&lt;p&gt;Use Local Files for Private Notes&lt;/p&gt;

&lt;p&gt;Sensitive or personal instructions should not be committed. Use local ignored files for private notes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes While Creating CLAUDE.md
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Making It Too Long&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the file becomes too large, Claude may not focus on the most important rules. Keep it clean.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Adding Generic Advice Only&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do not write only generic rules like “write good code.” Be specific.&lt;/p&gt;

&lt;p&gt;Better:&lt;/p&gt;

&lt;p&gt;Use Laravel service classes for business logic.&lt;br&gt;
Do not put database queries inside Blade views.&lt;br&gt;
Use existing CSS classes where possible.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Not Updating It&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Outdated instructions can create confusion. Update the file whenever the project changes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Mixing Global and Local Rules&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do not put every small folder-specific detail in the root file. Use folder-level files when needed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Not Mentioning What Claude Should Avoid&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A good CLAUDE.md should clearly mention what not to do.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Using CLAUDE.md as a Replacement for Thinking&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;CLAUDE.md helps Claude, but it does not replace proper planning, code review, testing, and developer judgment.&lt;/p&gt;

&lt;p&gt;CLAUDE.md and Spec Files&lt;/p&gt;

&lt;p&gt;CLAUDE.md is for long-term project memory.&lt;/p&gt;

&lt;p&gt;A spec file is for one specific feature.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;CLAUDE.md says how the project works.&lt;br&gt;
spec.md says what feature needs to be built.&lt;br&gt;
design.md says how the feature should be implemented.&lt;br&gt;
decisions.md says why certain choices were made.&lt;/p&gt;

&lt;p&gt;This combination creates a strong AI-assisted development workflow.&lt;/p&gt;
&lt;h2&gt;
  
  
  Recommended Workflow
&lt;/h2&gt;

&lt;p&gt;Use this workflow for better results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First, create or update CLAUDE.md.
Second, write a feature spec.md.
Third, ask Claude to read the spec and create a plan.
Fourth, review the plan before allowing code changes.
Fifth, let Claude implement step by step.
Sixth, run tests and review the diff.
Seventh, update decisions or notes if something important changed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example Prompt Using CLAUDE.md
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read the project CLAUDE.md first.

I want to improve the booking page UI.

Rules:
- Do not break existing functionality.
- Do not change backend logic unless required.
- Keep the page mobile responsive.
- Follow the existing theme.
- Avoid duplicate CSS.
- First analyze the current files and give me a plan.
- Do not write code until the plan is approved.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why Every Software Project Needs CLAUDE.md
&lt;/h2&gt;

&lt;p&gt;Every software project has hidden knowledge. Some of it is in code. Some of it is in developers’ minds. Some of it is in old discussions. Some of it is in repeated mistakes.&lt;/p&gt;

&lt;p&gt;CLAUDE.md brings this knowledge into one clear place.&lt;/p&gt;

&lt;p&gt;It makes Claude more useful because Claude no longer works blindly. It works with project context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For small projects, it saves time.
For large projects, it prevents confusion.
For teams, it creates consistency.
For old projects, it protects existing functionality.
For AI-assisted development, it becomes a foundation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;CLAUDE.md is not just another markdown file. It is a project memory system for AI-assisted development.&lt;/p&gt;

&lt;p&gt;It helps Claude understand your software project, follow your rules, protect existing logic, and produce more consistent output. It also saves developers from repeating the same instructions again and again.&lt;/p&gt;

&lt;p&gt;As AI coding tools become a normal part of software development, project-level instruction files like CLAUDE.md will become increasingly important.&lt;/p&gt;

&lt;p&gt;A good CLAUDE.md makes Claude faster, safer, and more reliable.&lt;/p&gt;

&lt;p&gt;That is why every serious software project should have one.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mobile app performance improvement</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Thu, 28 May 2026 09:46:25 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/mobile-app-performance-improvement-phi</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/mobile-app-performance-improvement-phi</guid>
      <description>&lt;p&gt;&lt;strong&gt;Avoids repeated SharedPreferences initialization&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Improve Flutter App Performance Using compute() for Large JSON Responses&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;High-Impact Flutter Refactoring Plan&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Inside build unnecessary ternary operator&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Avoids repeated SharedPreferences initialization
&lt;/h2&gt;

&lt;p&gt;Without cache, you may write this many times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final prefs = await SharedPreferences.getInstance();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If many API methods call it, then every method will try to get the instance again.&lt;/p&gt;

&lt;p&gt;With your _prefs() method, the first call loads SharedPreferences, and after that it reuses the same object.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;So this is better:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final prefs = await _prefs();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Coding example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MotoshareAPI {
  String baseUrl;

  // Cached SharedPreferences instance, lazily initialized on first access so
  // we don't pay the plugin async hop for every API call. The plugin caches
  // internally too, but the round-trip still costs frames on cold path.
  SharedPreferences? _cachedPrefs;

  MotoshareAPI({required this.baseUrl});

  Future&amp;lt;SharedPreferences&amp;gt; _prefs() async {
    return _cachedPrefs ??= await SharedPreferences.getInstance();
  }

  Future&amp;lt;void&amp;gt; init() async {
    final prefs = await _prefs();
    baseUrl = prefs.getString("baseUrl") ?? "https://global.motoshare.com";
    print("Loaded baseUrl from SharedPreferences: $baseUrl");
  }



  Future&amp;lt;bool&amp;gt; registerPartner(
      String phone,
      String name,
      String email,
      String pincode,
      String address,
      String state,
      String city,
      String aadhar) async {
    var url = "$baseUrl/api/registervendor";
    final prefs = await _prefs();
    String? dialCode = prefs.getString("dial_code");

    if (dialCode == null || dialCode.isEmpty) {
      print("Dial code is missing in SharedPreferences");
      return false; // Handle case where dial code is not set
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Avoids repeated SharedPreferences initialization&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without cache, you may write this many times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final prefs = await SharedPreferences.getInstance();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If many API methods call it, then every method will try to get the instance again.&lt;/p&gt;

&lt;p&gt;With your _prefs() method, the first call loads SharedPreferences, and after that it reuses the same object.&lt;/p&gt;

&lt;p&gt;So this is better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final prefs = await _prefs();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Improves performance slightly&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;SharedPreferences.getInstance() is async. It may read stored data from local storage during initialization.&lt;/p&gt;

&lt;p&gt;By caching it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_cachedPrefs ??=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you reduce unnecessary async initialization calls.&lt;/p&gt;

&lt;p&gt;This is useful in service files like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MotoshareAPI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because methods like login, booking, profile, city list, token check, and API calls may frequently need stored values.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Cleaner code&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of writing this everywhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final prefs = await SharedPreferences.getInstance();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can simply write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final prefs = await _prefs();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes your service file cleaner and easier to maintain.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Centralized preference access&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All SharedPreferences access goes through one method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;SharedPreferences&amp;gt; _prefs() async
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in the future, if you want to add logging, error handling, or migration logic, you can do it in one place.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;SharedPreferences&amp;gt; _prefs() async {
  try {
    return _cachedPrefs ??= await SharedPreferences.getInstance();
  } catch (e) {
    throw Exception("Failed to load app preferences");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Helpful for loading dynamic base URL&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your init() method loads baseUrl from local storage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;void&amp;gt; init() async {
  final prefs = await _prefs();
  baseUrl = prefs.getString("baseUrl") ?? "https://global.motoshare.com";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful when your app supports:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Different API base URLs
Environment switching
Country/city based server
Testing/staging/production URLs
Saved user preference
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if baseUrl was already saved earlier, the app will use that. Otherwise, it will use the default URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"https://global.motoshare.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Reduces duplicate code in API methods&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In your login method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Future&amp;lt;bool&amp;gt; login_phone(String phone, String otpMethod) async {
  final prefs = await _prefs();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can easily access saved values like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final dialCode = prefs.getString("dial_code");
final baseUrl = prefs.getString("baseUrl");
final token = prefs.getString("token");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful for API requests.&lt;/p&gt;

&lt;p&gt;Important improvement&lt;/p&gt;

&lt;p&gt;Avoid using print() in production:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Loaded baseUrl from SharedPreferences: $baseUrl");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Better use debug-only logging:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;debugPrint("Loaded baseUrl from SharedPreferences: $baseUrl");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Improve Flutter App Performance Using compute() for Large JSON Responses
&lt;/h2&gt;

&lt;p&gt;Current problem example&lt;/p&gt;

&lt;p&gt;Your current code may look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;AddVehicle&amp;gt;&amp;gt; getMyVehicle() async {
  final response = await http.post(
    Uri.parse("$baseUrl/api/get-my-vehicle"),
    body: {
      "user_id": "123",
    },
  );

  if (response.statusCode == 200) {
    final responseData = jsonDecode(response.body);

    final vehicleData = responseData["data"] as List;

    return vehicleData
        .map((data) =&amp;gt; AddVehicle.fromJson(data))
        .toList();
  } else {
    throw Exception("Failed to load vehicles");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final responseData = jsonDecode(response.body);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For small responses, this is okay.&lt;/p&gt;

&lt;p&gt;But for large responses like 100+ vehicles or bookings, the UI may freeze because Flutter is busy parsing the JSON.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Better solution using compute()&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Flutter provides compute() to move heavy work into a background isolate.&lt;/p&gt;

&lt;p&gt;First import this:&lt;/p&gt;

&lt;p&gt;import 'dart:convert';&lt;br&gt;
import 'package:flutter/foundation.dart';&lt;/p&gt;

&lt;p&gt;Then create a top-level parser function.&lt;/p&gt;

&lt;p&gt;Important: this function should be outside the class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dynamic parseJsonInBackground(String responseBody) {
  return jsonDecode(responseBody);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now use it in your API method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;AddVehicle&amp;gt;&amp;gt; getMyVehicle() async {
  final response = await http.post(
    Uri.parse("$baseUrl/api/get-my-vehicle"),
    body: {
      "user_id": "123",
    },
  );

  if (response.statusCode == 200) {
    final responseData = await compute(
      parseJsonInBackground,
      response.body,
    ) as Map&amp;lt;String, dynamic&amp;gt;;

    final vehicleData = responseData["data"] as List;

    return vehicleData
        .map((data) =&amp;gt; AddVehicle.fromJson(data))
        .toList();
  } else {
    throw Exception("Failed to load vehicles");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now JSON decoding happens in the background, not on the UI thread.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Best practical approach: only use compute() for big responses&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Using compute() also has some cost. So do not use it for every small API response like login, OTP, profile check, etc.&lt;/p&gt;

&lt;p&gt;Use it only when response is large, for example above 20 KB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;Map&amp;lt;String, dynamic&amp;gt;&amp;gt; decodeResponse(String body) async {
  final int sizeInBytes = utf8.encode(body).length;

  if (sizeInBytes &amp;gt; 20 * 1024) {
    return await compute(parseJsonInBackground, body)
        as Map&amp;lt;String, dynamic&amp;gt;;
  }

  return jsonDecode(body) as Map&amp;lt;String, dynamic&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your API method becomes cleaner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;AddVehicle&amp;gt;&amp;gt; getMyVehicle() async {
  final response = await http.post(
    Uri.parse("$baseUrl/api/get-my-vehicle"),
    body: {
      "user_id": "123",
    },
  );

  if (response.statusCode == 200) {
    final responseData = await decodeResponse(response.body);

    final vehicleData = responseData["data"] as List;

    return vehicleData
        .map((data) =&amp;gt; AddVehicle.fromJson(data))
        .toList();
  } else {
    throw Exception("Failed to load vehicles");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is better because:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Small response = normal jsonDecode()
Large response = compute() background parsing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;More complete reusable helper&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can create a reusable helper for your service file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'dart:convert';
import 'package:flutter/foundation.dart';

const int jsonComputeThreshold = 20 * 1024;

dynamic parseJsonInBackground(String body) {
  return jsonDecode(body);
}

Future&amp;lt;dynamic&amp;gt; smartJsonDecode(String body) async {
  final int bodySize = utf8.encode(body).length;

  if (bodySize &amp;gt; jsonComputeThreshold) {
    return await compute(parseJsonInBackground, body);
  }

  return jsonDecode(body);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use this everywhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final responseData = await smartJsonDecode(response.body)
    as Map&amp;lt;String, dynamic&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Example for vehicle brand/model API&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;Before:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;VehicleBrandModel&amp;gt;&amp;gt; getVehicletypeBrandModel() async {
  final response = await http.get(
    Uri.parse("$baseUrl/api/vehicle-type-brand-model"),
  );

  if (response.statusCode == 200) {
    final responseData = jsonDecode(response.body);

    final list = responseData["data"] as List;

    return list
        .map((item) =&amp;gt; VehicleBrandModel.fromJson(item))
        .toList();
  }

  throw Exception("Failed to load vehicle brand model");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;After:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;VehicleBrandModel&amp;gt;&amp;gt; getVehicletypeBrandModel() async {
  final response = await http.get(
    Uri.parse("$baseUrl/api/vehicle-type-brand-model"),
  );

  if (response.statusCode == 200) {
    final responseData = await smartJsonDecode(response.body)
        as Map&amp;lt;String, dynamic&amp;gt;;

    final list = responseData["data"] as List;

    return list
        .map((item) =&amp;gt; VehicleBrandModel.fromJson(item))
        .toList();
  }

  throw Exception("Failed to load vehicle brand model");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Example for booking list API&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;Booking&amp;gt;&amp;gt; getBookings() async {
  final response = await http.post(
    Uri.parse("$baseUrl/api/bookings"),
  );

  if (response.statusCode == 200) {
    final responseData = jsonDecode(response.body);

    final bookingList = responseData["data"] as List;

    return bookingList
        .map((item) =&amp;gt; Booking.fromJson(item))
        .toList();
  }

  throw Exception("Failed to load bookings");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;After:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;Booking&amp;gt;&amp;gt; getBookings() async {
  final response = await http.post(
    Uri.parse("$baseUrl/api/bookings"),
  );

  if (response.statusCode == 200) {
    final responseData = await smartJsonDecode(response.body)
        as Map&amp;lt;String, dynamic&amp;gt;;

    final bookingList = responseData["data"] as List;

    return bookingList
        .map((item) =&amp;gt; Booking.fromJson(item))
        .toList();
  }

  throw Exception("Failed to load bookings");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Even better: move model conversion also to background&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Only moving jsonDecode() helps, but this part can also be heavy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return vehicleData
    .map((data) =&amp;gt; AddVehicle.fromJson(data))
    .toList();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For very large lists, fromJson() also runs on the UI thread.&lt;/p&gt;

&lt;p&gt;Better approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;AddVehicle&amp;gt; parseVehiclesInBackground(String body) {
  final responseData = jsonDecode(body) as Map&amp;lt;String, dynamic&amp;gt;;
  final vehicleData = responseData["data"] as List;

  return vehicleData
      .map((item) =&amp;gt; AddVehicle.fromJson(item))
      .toList();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;List&amp;lt;AddVehicle&amp;gt;&amp;gt; getMyVehicle() async {
  final response = await http.post(
    Uri.parse("$baseUrl/api/get-my-vehicle"),
  );

  if (response.statusCode == 200) {
    final int bodySize = utf8.encode(response.body).length;

    if (bodySize &amp;gt; 20 * 1024) {
      return await compute(parseVehiclesInBackground, response.body);
    }

    final responseData = jsonDecode(response.body) as Map&amp;lt;String, dynamic&amp;gt;;
    final vehicleData = responseData["data"] as List;

    return vehicleData
        .map((item) =&amp;gt; AddVehicle.fromJson(item))
        .toList();
  }

  throw Exception("Failed to load vehicles");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is stronger because both operations happen in the background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JSON decoding
Model mapping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Where to apply in your project&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Apply this mainly in large list APIs inside:&lt;/p&gt;

&lt;p&gt;lib/services/motoshare_service.dart&lt;/p&gt;

&lt;p&gt;Especially methods like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getVehicletype_brand_model
getmyvehicle
booking list APIs
notification list APIs
vehicle listing APIs
partner vehicle APIs
city or location list APIs if response is large
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not apply it blindly to small APIs like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;login
OTP verify
logout
single profile detail
small settings API
token validation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For those, normal jsonDecode() is fine.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Final recommended code for your service file&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Add this near the top-level of motoshare_service.dart, outside the class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'dart:convert';
import 'package:flutter/foundation.dart';

const int jsonDecodeComputeThreshold = 20 * 1024;

dynamic _parseJson(String body) {
  return jsonDecode(body);
}

Future&amp;lt;Map&amp;lt;String, dynamic&amp;gt;&amp;gt; decodeJsonResponse(String body) async {
  final int bodySize = utf8.encode(body).length;

  if (bodySize &amp;gt; jsonDecodeComputeThreshold) {
    return await compute(_parseJson, body) as Map&amp;lt;String, dynamic&amp;gt;;
  }

  return jsonDecode(body) as Map&amp;lt;String, dynamic&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Then replace this:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final responseData = jsonDecode(response.body);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;with this:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final responseData = await decodeJsonResponse(response.body);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a safe, small, and professional performance improvement.&lt;/p&gt;

&lt;p&gt;Main benefit: large API responses will not freeze the Flutter UI while JSON is being parsed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coding Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/foundation.dart';   // for compute()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  static const int _largePayloadBytes = 20 * 1024;

  Future&amp;lt;dynamic&amp;gt; _decodeJson(String body) async {
    if (body.length &amp;gt; _largePayloadBytes) {
      return compute(jsonDecode, body);
    }
    return jsonDecode(body);
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (response.statusCode == 200) {
      // Parse the response body to a Map&amp;lt;String, dynamic&amp;gt;
      final responseData = await _decodeJson(response.body) as Map&amp;lt;String, dynamic&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;===============================================&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public function getmyvehicle(Request $request)
                {
                    $input = $request-&amp;gt;all();
                      $selectedCountry = strtolower(config('app.selected_country', 'india'));
            Log::info("Selected country", ['country' =&amp;gt; $selectedCountry]);
            $locationHelper = new LocationHelper();
            $cityCountryCodeLookup = $locationHelper-&amp;gt;handleExcludedRegions($selectedCountry) ?? [];
            Log::info("Selected cityCountryCodeLookup", $cityCountryCodeLookup);
                    $getshop_data =  DB::table('addvechicles')
                    -&amp;gt;leftJoin('users', 'addvechicles.vendor_email', '=', 'users.email')
                    -&amp;gt;leftJoin('shops', 'addvechicles.shop_id', '=', 'shops.id')
                    -&amp;gt;leftJoin('bookings', 'addvechicles.id', '=', 'bookings.vechicle_id')
                    -&amp;gt;leftJoin('addvehical_byadmins', 'addvechicles.vehical_id', '=', 'addvehical_byadmins.id')
                    -&amp;gt;select(
                        'addvechicles.id',
                        DB::raw('MAX(addvechicles.vender_ID) as vender_ID'),
                        DB::raw('MAX(addvechicles.shop_id) as shop_id'),
                        DB::raw('MAX(addvechicles.price) as price'),
                        DB::raw('MAX(addvechicles.id) as vehical_id'),
                        DB::raw('MAX(addvechicles.numbers_of_vechile) as numbers_of_vechile'),
                        DB::raw('MAX(addvechicles.vendor_email) as vendor_email'),
                        DB::raw('MAX(addvechicles.rc_number_of_vechile) as rc_number_of_vechile'),
                        DB::raw('MAX(addvechicles.insurence) as insurence'),
                        DB::raw('MAX(addvechicles.pollution) as pollution'),
                        DB::raw('MAX(addvechicles.rc_ducoment) as rc_ducoment'),
                        DB::raw('MAX(addvechicles.vechicle_image) as vechicle_image'),
                        DB::raw('MAX(addvechicles.status) as status'),
                        DB::raw('MAX(users.profile_img) as profile_img'),
                        DB::raw('MAX(addvechicles.publish) as publish'),
                        DB::raw('MAX(addvechicles.info_field) as info_field'),
                        DB::raw('MAX(addvechicles.created_at) as created_at'),
                        DB::raw('MAX(addvechicles.updated_at) as updated_at'),
                        DB::raw('MAX(addvehical_byadmins.vehical) as vehical'),
                        DB::raw('MAX(addvehical_byadmins.brand) as brand'),
                        DB::raw('MAX(addvechicles.payment_type) as payment_type'),
                        DB::raw('MAX(addvehical_byadmins.model) as model'),
                        DB::raw('MAX(shops.location) as location'),
                        DB::raw('MAX(shops.longitude) as longitude'),
                        DB::raw('MAX(shops.latitude) as latitude'),
                          DB::raw('MAX(shops.shop_hours) as shop_hours'),
                        DB::raw('MAX(shops.partner_name) as PartnerName'),
                        DB::raw('MAX(shops.city) as shopcity'),
                        DB::raw('MAX(users.state) as state'),
                        DB::raw('MAX(users.address) as address'),
                        DB::raw('MAX(users.city) as city'),
                        DB::raw('MAX(users.name) as username'),
                        DB::raw('MAX(users.number) as number'),
                        DB::raw('MAX(bookings.id) as booking_id'),
                        DB::raw('MAX(bookings.start_date) as start_date'),
                        DB::raw('MAX(bookings.end_date) as end_date'),
                        DB::raw('MAX(bookings.price) as booking_price')
                    )
                    -&amp;gt;where('addvechicles.dummy_data', '0')
                     -&amp;gt;where('addvechicles.publish', '1')
                      -&amp;gt;where('addvechicles.status', 'active')
                    -&amp;gt;groupBy('addvechicles.id')
                    -&amp;gt;orderBy('addvechicles.id', 'desc') // Change 'id' to the column you want to order by
                    -&amp;gt;get()
                    -&amp;gt;map(function ($vehicle) use ($cityCountryCodeLookup) {
            $vehicle-&amp;gt;currency_code = $cityCountryCodeLookup[$vehicle-&amp;gt;shop_id] ?? null;
            return $vehicle;
        });


            $vehicleIds = $getshop_data-&amp;gt;pluck('id')-&amp;gt;toArray();

                       $bookings_all = Booking::whereIn('vechicle_id', $vehicleIds)
    -&amp;gt;whereIn('status', [0, 1, 2, 3, 4]) // Add this line
    -&amp;gt;get(['vechicle_id', 'start_date', 'end_date'])
    -&amp;gt;groupBy('vechicle_id')
    -&amp;gt;map(function ($vehicleBookings) {
        return $vehicleBookings-&amp;gt;map(function ($booking) {
            return [
                'start' =&amp;gt; \Carbon\Carbon::parse($booking-&amp;gt;start_date)-&amp;gt;toDateString(),
                'end' =&amp;gt; \Carbon\Carbon::parse($booking-&amp;gt;end_date)-&amp;gt;toDateString()
            ];
        });
    });


                log::info("bookings_all");
                log::info($bookings_all);
                        $getshop_data = $getshop_data-&amp;gt;map(function ($vehicle) use ($bookings_all) {
                            // Convert vehicle ID to string to match the bookings_all keys
                            $vehicleIdStr = (string) $vehicle-&amp;gt;id;
                            // Add empty bookings array by default
                            $vehicle-&amp;gt;bookings = [];
                            // If this vehicle has bookings, add them
                            if ($bookings_all-&amp;gt;has($vehicleIdStr)) {
                                $vehicle-&amp;gt;bookings = $bookings_all-&amp;gt;get($vehicleIdStr);
                            }
                            return $vehicle;
                        });
                    log::info($getshop_data);

                    $response = [
                        'success' =&amp;gt; true,
                        'data' =&amp;gt; addvechiclesResource::collection($getshop_data),
                        'message' =&amp;gt; 'get_shop_type retrieved successfully.',
                    ];
                    return response()-&amp;gt;json($response, 200);
                }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function getmyvehicle(Request $request)
{
    $user = auth()-&amp;gt;user();
    $selectedCountry = strtolower(config('app.selected_country', 'india'));

    // Cache the country/region lookup — same per country, no need to recompute
    $cityCountryCodeLookup = Cache::remember(
        "excluded_regions_{$selectedCountry}",
        3600,
        fn() =&amp;gt; (new LocationHelper())-&amp;gt;handleExcludedRegions($selectedCountry) ?? []
    );

    // Main query: no booking join (was causing cartesian explosion),
    // no MAX/GROUP BY (not needed once bookings join is gone),
    // filtered to authenticated partner, paginated
    $paginator = DB::table('addvechicles')
        -&amp;gt;leftJoin('users', 'addvechicles.vendor_email', '=', 'users.email')
        -&amp;gt;leftJoin('shops', 'addvechicles.shop_id', '=', 'shops.id')
        -&amp;gt;leftJoin('addvehical_byadmins', 'addvechicles.vehical_id', '=', 'addvehical_byadmins.id')
        -&amp;gt;select(
            'addvechicles.id',
            'addvechicles.vender_ID',
            'addvechicles.shop_id',
            'addvechicles.price',
            'addvechicles.id as vehical_id',
            'addvechicles.numbers_of_vechile',
            'addvechicles.vendor_email',
            'addvechicles.rc_number_of_vechile',
            'addvechicles.insurence',
            'addvechicles.pollution',
            'addvechicles.rc_ducoment',
            'addvechicles.vechicle_image',
            'addvechicles.status',
            'addvechicles.publish',
            'addvechicles.info_field',
            'addvechicles.payment_type',
            'addvechicles.created_at',
            'addvechicles.updated_at',
            'users.profile_img',
            'users.state',
            'users.address',
            'users.city',
            'users.name as username',
            'users.number',
            'shops.location',
            'shops.longitude',
            'shops.latitude',
            'shops.shop_hours',
            'shops.partner_name as PartnerName',
            'shops.city as shopcity',
            'addvehical_byadmins.vehical',
            'addvehical_byadmins.brand',
            'addvehical_byadmins.model'
        )
        -&amp;gt;where('addvechicles.dummy_data', '0')
        -&amp;gt;where('addvechicles.publish', '1')
        -&amp;gt;where('addvechicles.status', 'active')
        -&amp;gt;where('addvechicles.vendor_email', $user-&amp;gt;email)
        -&amp;gt;orderByDesc('addvechicles.id')
        -&amp;gt;paginate($request-&amp;gt;input('per_page', 20));

    $vehicles    = collect($paginator-&amp;gt;items());
    $vehicleIds  = $vehicles-&amp;gt;pluck('id')-&amp;gt;all();

    // Fetch bookings in ONE separate query, group by vehicle
    $bookingsByVehicle = Booking::whereIn('vechicle_id', $vehicleIds)
        -&amp;gt;whereIn('status', [0, 1, 2, 3, 4])
        -&amp;gt;get(['vechicle_id', 'start_date', 'end_date'])
        -&amp;gt;groupBy('vechicle_id')
        -&amp;gt;map(fn ($group) =&amp;gt; $group-&amp;gt;map(fn ($b) =&amp;gt; [
            'start' =&amp;gt; Carbon::parse($b-&amp;gt;start_date)-&amp;gt;toDateString(),
            'end'   =&amp;gt; Carbon::parse($b-&amp;gt;end_date)-&amp;gt;toDateString(),
        ])-&amp;gt;values());

    // Attach currency + bookings to each vehicle
    foreach ($vehicles as $v) {
        $v-&amp;gt;currency_code = $cityCountryCodeLookup[$v-&amp;gt;shop_id] ?? null;
        $v-&amp;gt;bookings      = $bookingsByVehicle-&amp;gt;get((string) $v-&amp;gt;id, collect())-&amp;gt;values();
    }

    return response()-&amp;gt;json([
        'success'    =&amp;gt; true,
        'data'       =&amp;gt; addvechiclesResource::collection($vehicles),
        'pagination' =&amp;gt; [
            'current_page' =&amp;gt; $paginator-&amp;gt;currentPage(),
            'last_page'    =&amp;gt; $paginator-&amp;gt;lastPage(),
            'per_page'     =&amp;gt; $paginator-&amp;gt;perPage(),
            'total'        =&amp;gt; $paginator-&amp;gt;total(),
        ],
        'message'    =&amp;gt; 'get_shop_type retrieved successfully.',
    ], 200);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  High-Impact Flutter Refactoring Plan
&lt;/h2&gt;

&lt;p&gt;Split profiledialog.dart into smaller files&lt;/p&gt;

&lt;p&gt;Current problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;profiledialog.dart
- Dialog header
- Address section
- Google Places field
- Manual address field
- Pin/state/city fields
- Document upload section
- File picker card
- Submit button/footer
- API/geocode logic
- Validation logic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Better structure:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lib/screens/drawer_widget/profile_dialog/profile_dialog.dart
lib/screens/drawer_widget/profile_dialog/widgets/profile_dialog_header.dart
lib/screens/drawer_widget/profile_dialog/widgets/profile_form_fields.dart
lib/screens/drawer_widget/profile_dialog/widgets/profile_address_section.dart
lib/screens/drawer_widget/profile_dialog/widgets/profile_document_section.dart
lib/screens/drawer_widget/profile_dialog/widgets/profile_footer_actions.dart
lib/screens/drawer_widget/profile_dialog/helpers/profile_form_validators.dart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Main file should only control state and compose widgets.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Keep build() lightweight&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your build() should not contain the full UI tree. It should look more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@override
Widget build(BuildContext context) {
  return Dialog(
    insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
    backgroundColor: Colors.white,
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        ProfileDialogHeader(
          onClose: () =&amp;gt; Navigator.of(context).pop(),
        ),
        Flexible(
          child: ProfileDialogFormBody(
            formKey: _formKey,
            nameController: _nameController,
            emailController: _emailController,
            phoneController: _phoneController,
            pinCodeController: pinCodeController,
            adharController: _adharController,
            cityController: _cityController,
            stateController: _stateController,
            locationController: _locationController,
            locationFocusNode: _locationFocusNode,
            useManualAddress: _useManualAddress,
            addressError: addressError,
            profileImage: _profileImage,
            qrImage: _qrImage,
            onAddressModeChanged: _changeAddressMode,
            onPinCodeChanged: fetchStateAndCity,
            onProfileImagePicked: (file) =&amp;gt; setState(() =&amp;gt; _profileImage = file),
            onQrImagePicked: (file) =&amp;gt; setState(() =&amp;gt; _qrImage = file),
          ),
        ),
        ProfileFooterActions(
          isLoading: _isLoading,
          onCancel: () =&amp;gt; Navigator.of(context).pop(),
          onSubmit: _submitProfileData,
        ),
      ],
    ),
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the file readable and reduces rebuild complexity.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Convert helper methods into widgets&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of keeping these inside the same file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_buildAddressSection()
_buildAddressModeOption()
_buildField()
_buildBadgedField()
_buildFilePickerCard()
_sectionLabel()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Move them into separate reusable widgets.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ProfileDialogHeader extends StatelessWidget {
  final VoidCallback onClose;

  const ProfileDialogHeader({
    super.key,
    required this.onClose,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.fromLTRB(20, 16, 16, 16),
      decoration: const BoxDecoration(
        color: Color(0xFFFFFAF8),
        borderRadius: BorderRadius.vertical(top: Radius.circular(17)),
        border: Border(
          bottom: BorderSide(color: Color(0xFFEEE0D8)),
        ),
      ),
      child: Row(
        children: [
          const Expanded(
            child: Text(
              'Edit Profile',
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w700,
              ),
            ),
          ),
          InkWell(
            onTap: onClose,
            child: const Icon(Icons.close_rounded),
          ),
        ],
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Move jsonDecode() and API logic away from widget&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This method is inside UI file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final data = jsonDecode(response.body);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For small Google geocode response it may be okay, but better structure is to move it into a service:&lt;/p&gt;

&lt;p&gt;lib/services/location_service.dart&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class LocationService {
  Future&amp;lt;LocationResult?&amp;gt; getCityAndStateFromLatLng(
    double latitude,
    double longitude,
  ) async {
    final response = await http.get(Uri.parse(
      'https://maps.googleapis.com/maps/api/geocode/json?latlng=$latitude,$longitude&amp;amp;key=YOUR_KEY',
    ));

    if (response.statusCode != 200) return null;

    final data = jsonDecode(response.body);

    if (data['status'] != 'OK') return null;

    String? city;
    String? state;

    for (final result in data['results']) {
      for (final component in result['address_components']) {
        if (component['types'].contains('locality')) {
          city = component['long_name'];
        }

        if (component['types'].contains('administrative_area_level_1')) {
          state = component['long_name'];
        }
      }
    }

    return LocationResult(city: city, state: state);
  }
}

class LocationResult {
  final String? city;
  final String? state;

  LocationResult({
    this.city,
    this.state,
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then your UI only calls:&lt;/p&gt;

&lt;p&gt;final result = await LocationService().getCityAndStateFromLatLng(lat!, lng!);&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Do not hardcode API keys in Dart files&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your uploaded file contains Google API key directly inside the Dart file. This is risky because Flutter app code can be reverse-engineered. Move it to backend/config or use restricted API key settings.&lt;/p&gt;

&lt;p&gt;Better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const googleMapsApiKey = String.fromEnvironment('GOOGLE_MAPS_API_KEY');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then build with:&lt;/p&gt;

&lt;p&gt;flutter build apk --dart-define=GOOGLE_MAPS_API_KEY=your_key_here&lt;/p&gt;

&lt;h2&gt;
  
  
  Inside build unnecessary ternary operator
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;code&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;child: _isLoading
    ? const Center(
        child: CircularProgressIndicator(color: _kPrimary))
    : userProfile == null
        ? _buildEmptyState()
        : _buildProfileContent(),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How this creates problems (the "pron"/cons)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Readability — the eye has to parse ? : chains&lt;/strong&gt;
A reader must mentally translate:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A ? X : (B ? Y : Z)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;into "if loading → spinner, else if no profile → empty, else → content".&lt;br&gt;
With one more state (e.g. _hasError), it becomes a 4-branch nested ternary that is almost unreadable in code review.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build() does branching work every frame&lt;/strong&gt;
build() runs on every setState, every parent rebuild, every keyboard open, every orientation change. Each rebuild:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;re-evaluates _isLoading&lt;br&gt;
re-evaluates userProfile == null&lt;br&gt;
calls _buildEmptyState() or _buildProfileContent() — these are methods, not widgets, so Flutter cannot cache or const-optimize them.&lt;br&gt;
A method returning a Widget rebuilds the entire subtree from scratch every time. A StatelessWidget with a const constructor would let Flutter skip the rebuild when inputs don't change.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No const optimization possible&lt;/strong&gt;&lt;br&gt;
Only the spinner line is const. _buildEmptyState() and _buildProfileContent() cannot be const because they are function calls. Extracting them as StatelessWidget classes with const constructors lets Flutter reuse the same element tree.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hard to add a new state safely&lt;/strong&gt;&lt;br&gt;
Tomorrow you need an "error" state. You must either:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Add another nested ternary (4 levels deep — unreadable), or&lt;br&gt;
Refactor under pressure (risky — violates the Core Safety Rule in CLAUDE.md).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging / breakpoints are awkward&lt;/strong&gt;&lt;br&gt;
You can't put a breakpoint on "the empty-state branch" cleanly — it's an expression, not a statement. Stack traces also point at build, not at a named widget like ProfileEmptyState, so Flutter DevTools' widget inspector is less useful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixes decision logic with UI construction&lt;/strong&gt;&lt;br&gt;
build() should describe what to render, not run multi-step decisions about which screen state we're in. The decision belongs in a small helper or a switch on an enum (ProfileViewState.loading | empty | ready).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;SOLUTION&lt;/strong&gt;:&lt;br&gt;
&lt;code&gt;using switch opertor&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;child: switch ((_isLoading, userProfile)) {
  (true, _) =&amp;gt; const Center(
      child: CircularProgressIndicator(color: _kPrimary)),
  (_, null) =&amp;gt; _buildEmptyState(),
  _ =&amp;gt; _buildProfileContent(),
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.debug.school/images/hZY07RG76AzH7pXvkuloqDJRVS_BnTB7JNCKaUuiw50/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbm1menVv/MnhpeGhpNXg4ZWlq/NGoucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/hZY07RG76AzH7pXvkuloqDJRVS_BnTB7JNCKaUuiw50/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbm1menVv/MnhpeGhpNXg4ZWlq/NGoucG5n" alt=" " width="693" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Another example&lt;/code&gt;&lt;br&gt;
&lt;code&gt;The triple branch is local to the build() method&lt;/code&gt;&lt;br&gt;
The triple branch is local to the build() method. I have enough context — applying the same safe switch-expression pattern as before, plus adding a one-line comment explaining the previously-hidden "empty state wrapped in ListView" workaround&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Two whole ListView widget trees inlined in a ternary&lt;/code&gt;&lt;br&gt;
Unlike partner_profile.dart where each branch was _buildSomething(), here each branch is a full multi-line widget constructor with parameters. The eye has to parse:&lt;/p&gt;

&lt;p&gt;"OK, _isLoading? No. Then isEmpty? Yes → this ListView constructor with physics: ..., padding: ..., children: [...] — wait, is that part of the empty branch or the data branch? Let me count parens..."&lt;/p&gt;

&lt;p&gt;Reviewers literally count ?, :, and ) to find which arm they're in.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Duplicated physics config in both branches&lt;/code&gt;
Both ListViews share:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;physics: const BouncingScrollPhysics(
  parent: AlwaysScrollableScrollPhysics(),
),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you change scroll behavior (e.g. switch to ClampingScrollPhysics), you must remember to update both places. Easy to miss → inconsistent scroll feel between empty and populated screens.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;itemBuilder closure is recreated every rebuild&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
itemBuilder: (context, index) =&amp;gt; _notificationCard(item: _notifications[index]),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A fresh function object on every build(). Even when _notifications hasn't changed, Flutter can't identity-compare the builder, so ListView.builder can't safely skip element rebuilds. With 50 notifications and a parent rebuild (keyboard, theme change, orientation), all visible cards rebuild from scratch.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;The empty state is hidden behind a ListView hack (no comment)&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ListView(
  physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
  padding: const EdgeInsets.fromLTRB(20, 48, 20, 120),
  children: [_buildEmptyState()],
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Why is a single empty-state widget wrapped in a ListView? Because RefreshIndicator needs a scrollable child to trigger pull-to-refresh — a Center would break refresh on the empty screen. This is a real, important workaround, but a new reader has no idea why; there's no comment, and the hack is buried inside a nested ternary.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;_buildEmptyState() and _notificationCard() are methods&lt;/code&gt;, not widgets
They cannot have const constructors.
Flutter rebuilds the entire subtree on every parent rebuild.
The widget inspector shows them as anonymous tree fragments, not named widgets like NotificationEmptyState / NotificationCard
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;child: _isLoading
    ? const Center(
        child: CircularProgressIndicator(color: _kPrimary),
      )
    : _notifications.isEmpty
        ? ListView(
            physics: const BouncingScrollPhysics(
              parent: AlwaysScrollableScrollPhysics(),
            ),
            padding: const EdgeInsets.fromLTRB(20, 48, 20, 120),
            children: [
              _buildEmptyState(),
            ],
          )
        : ListView.builder(
            physics: const BouncingScrollPhysics(
              parent: AlwaysScrollableScrollPhysics(),
            ),
            padding: const EdgeInsets.fromLTRB(16, 10, 16, 96),
            itemCount: _notifications.length,
            itemBuilder: (context, index) =&amp;gt;
                _notificationCard(item: _notifications[index]),
          ),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;*&lt;em&gt;after applying switch *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     child: RefreshIndicator(
            color: _kPrimary,
            onRefresh: _fetchData,
            child: switch ((_isLoading, _notifications.isEmpty)) {
              (true, _) =&amp;gt; const Center(
                  child: CircularProgressIndicator(color: _kPrimary),
                ),
              // Empty state is wrapped in a ListView (not Center) so that
              // RefreshIndicator's pull-to-refresh still works when the list
              // has no items.
              (_, true) =&amp;gt; ListView(
                  physics: const BouncingScrollPhysics(
                    parent: AlwaysScrollableScrollPhysics(),
                  ),
                  padding: const EdgeInsets.fromLTRB(20, 48, 20, 120),
                  children: [
                    _buildEmptyState(),
                  ],
                ),
              _ =&amp;gt; ListView.builder(
                  physics: const BouncingScrollPhysics(
                    parent: AlwaysScrollableScrollPhysics(),
                  ),
                  padding: const EdgeInsets.fromLTRB(16, 10, 16, 96),
                  itemCount: _notifications.length,
                  itemBuilder: (context, index) =&amp;gt;
                      _notificationCard(item: _notifications[index]),
                ),
            },
          ),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>“What is CLAUDE.md? A Complete Guide to Using Claude AI for Software Development”</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Wed, 27 May 2026 08:31:09 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/what-is-claudemd-a-complete-guide-to-using-claude-ai-for-software-development-2m03</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/what-is-claudemd-a-complete-guide-to-using-claude-ai-for-software-development-2m03</guid>
      <description>&lt;p&gt;What is CLAUDE.md and Why Every Software Project Needs It&lt;br&gt;
How CLAUDE.md Helps Developers Save Time and Reduce Coding Mistakes&lt;br&gt;
CLAUDE.md vs Normal Prompt: What is the Difference?&lt;br&gt;
How to Use Claude Code for Large Software Product Development&lt;br&gt;
Best Folder Structure for Claude AI in Multi-Repo Projects&lt;br&gt;
How to Create a Perfect CLAUDE.md File for Laravel Projects&lt;br&gt;
Using Claude AI as a Coding Assistant for Old Legacy Projects&lt;br&gt;
How Claude Code Helps in Microservices Development&lt;br&gt;
How to Write Better Prompts for Claude Code&lt;br&gt;
CLAUDE.md for Product Development: A Complete Beginner’s Guide&lt;br&gt;
How to Use Claude AI for Keycloak Integration in Laravel Projects&lt;br&gt;
Claude Code Best Practices for Safe Software Development&lt;br&gt;
How to Build Project Documentation for Claude AI&lt;br&gt;
Why AI Coding Tools Need Project Memory&lt;br&gt;
Claude AI for Developers: How to Use It Without Breaking Existing Code&lt;br&gt;
How to Use Claude Code with GitHub, Laravel, and Microservices&lt;br&gt;
Common Mistakes Developers Make While Using Claude Code&lt;br&gt;
How CLAUDE.md Improves Team Collaboration in Software Projects&lt;br&gt;
Claude Code Workflow: Analyze, Plan, Implement, Test, and Report&lt;br&gt;
How to Use Claude AI for Product Planning, Architecture, and Development&lt;/p&gt;
&lt;h2&gt;
  
  
  Best prompt for Claude
&lt;/h2&gt;

&lt;p&gt;You are working on the HolidayLandmark project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First read the project documentation before doing anything:
1. CLAUDE.md
2. docs/PRODUCT_REQUIREMENTS.md
3. docs/FEATURES.md
4. docs/AI_FEATURES.md
5. docs/ADMIN_PANEL.md
6. docs/ARCHITECTURE.md
7. docs/DATABASE_SCHEMA.md
8. docs/TESTING_CHECKLIST.md

Rules:
- Do not start coding immediately.
- First summarize the product, modules, current architecture, and development rules.
- Identify which files/modules are related to my task.
- Prepare a safe implementation plan.
- Mention risks before coding.
- Wait for my approval before making changes.
- Do not edit .env.
- Do not remove existing code without explaining why.
- Do not run migrations without asking.
- Keep existing functionality safe.

My task is:
[WRITE YOUR TASK HERE]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Another&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are working in my Motoshare Flutter project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Before making any change, please read and follow:
1. /CLAUDE.md for global project safety rules
2. /lib/CLAUDE.md because this task is inside Flutter app code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best workflow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 1: Read docs
Step 2: Understand existing project
Step 3: Summarize what you understood
Step 4: Create plan
Step 5: Ask approval
Step 6: Implement
Step 7: Test
Step 8: Final report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use of CLAUDE.md while developing a software product
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Gives Claude project context&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It explains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is this product?
Which technology is used?
Which folders are important?
Which APIs, services, and modules exist?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;This is a Laravel-based travel booking platform.&lt;br&gt;
Users can browse trips, organizers can create packages, and admins manage bookings.&lt;/p&gt;

&lt;p&gt;This helps Claude understand the product before changing code.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Prevents Claude from breaking existing logic&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can write rules like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do not remove existing routes.
Do not change database columns without migration.
Do not modify production .env files.
Do not break old login flow while adding Keycloak SSO.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is very useful in old projects where existing functionality must stay safe.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Defines coding standards&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can tell Claude:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use Laravel best practices.
Follow existing controller-service-repository pattern.
Keep Blade UI responsive.
Use proper validation.
Do not duplicate code.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the output becomes more consistent and professional.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Helps in large product development&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For products like Motoshare, MyHospitalNow, HolidayLandmark, DevOpsSchool, one codebase may have many modules.&lt;/p&gt;

&lt;p&gt;CLAUDE.md can explain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Admin module
User module
Booking module
Payment module
Notification module
SEO module
API module
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then Claude can understand where to work instead of randomly editing files.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Improves AI-generated prompts and implementation&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without CLAUDE.md, Claude needs full explanation every time.&lt;/p&gt;

&lt;p&gt;With CLAUDE.md, you can simply say:&lt;/p&gt;

&lt;p&gt;Fix the booking status issue as per project rules.&lt;/p&gt;

&lt;p&gt;Claude will already know the architecture, rules, commands, testing steps, and safety limits.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Useful for team development&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you commit CLAUDE.md in GitHub, every developer using Claude gets the same project instructions. Anthropic’s docs also mention that project Claude files can be committed to Git so the team can share them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best use in software product development
&lt;/h2&gt;

&lt;p&gt;You should create CLAUDE.md in your project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/opt/lampp/htdocs/your-project/CLAUDE.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example sections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Product Overview
# Tech Stack
# Folder Structure
# Database Rules
# Authentication Rules
# API Rules
# UI/UX Rules
# SEO Rules
# Testing Commands
# Deployment Safety Rules
# Do Not Touch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Simple meaning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CLAUDE.md works like a developer guide for Claude.&lt;/p&gt;

&lt;h2&gt;
  
  
  Levels of claude.md file
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/jri1wnMfTHooL0EpEPBOibyBoot2HGeKjNDcsFswNNA/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMveDNoYnli/bDhsaXd1cHR5dG93/b2gucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/jri1wnMfTHooL0EpEPBOibyBoot2HGeKjNDcsFswNNA/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMveDNoYnli/bDhsaXd1cHR5dG93/b2gucG5n" alt=" " width="800" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Root CLAUDE.md&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use this when you have multiple related repositories/microservices.&lt;/p&gt;

&lt;p&gt;Example path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/opt/lampp/htdocs/myhospitalnow/CLAUDE.md
/opt/lampp/htdocs/motoshare/CLAUDE.md
/opt/lampp/htdocs/devopsschool/CLAUDE.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Content of root CLAUDE.md&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This file should contain information that is common for the full product.

# Product Overview

This product is a multi-service Laravel-based platform.
It contains multiple microservices that work together for user, admin, booking, notification, payment, and authentication flows.

# System Architecture

Explain how all repositories are connected.

Example:
- main-web handles public website and customer-facing pages.
- admin-ms handles admin management.
- user-ms handles user profile and login-related data.
- notification-ms handles email, SMS, and WhatsApp notifications.
- file-management-ms handles uploaded documents and images.
- Keycloak is used as centralized identity provider.

# Cross-Repo Workflow

When a feature affects more than one repo, first analyze all impacted services before coding.

Example:
- Login issue may affect frontend, backend API, Keycloak, and user database.
- Booking issue may affect web, admin, payment, and notification services.

# Shared Coding Rules

- Do not break existing functionality.
- Do not remove old fields unless explicitly asked.
- Do not modify production `.env`.
- Do not run database migrations without confirmation.
- Keep backward compatibility.
- Use safe migrations only.
- Always check existing routes, controllers, models, and database columns before changing logic.

# Shared Git Rules

- Create small, meaningful commits.
- Do not push directly to production branch unless instructed.
- Show changed files before final response.
- Mention testing commands performed.

# Shared Tech Stack

- Laravel
- MySQL / MariaDB
- Blade
- REST APIs
- Keycloak SSO
- Apache / LAMPP
- GitHub
- Flutter app if applicable

# Shared Security Rules

- Never expose secrets.
- Never print client secrets, database passwords, or API keys.
- Do not commit `.env`.
- Validate all user input.
- Protect admin routes.
- Maintain authentication and authorization checks.

# Shared Testing Commands

Before final report, run when applicable:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
php -l path/to/changed/file.php&lt;br&gt;
php artisan route:list&lt;br&gt;
php artisan config:clear&lt;br&gt;
php artisan cache:clear&lt;br&gt;
composer dump-autoload&lt;br&gt;
git diff --stat&lt;br&gt;
git diff&lt;br&gt;
Final Response Format&lt;/p&gt;

&lt;p&gt;After every implementation, provide:&lt;/p&gt;

&lt;p&gt;Files changed&lt;br&gt;
Logic changed&lt;br&gt;
Commands run&lt;br&gt;
Testing checklist&lt;br&gt;
Rollback steps&lt;br&gt;
Pending issues&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# 2. Per-repo `CLAUDE.md`

Use this inside each specific repository.

Example:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
/opt/lampp/htdocs/myhospitalnow/doc-core-ma/CLAUDE.md&lt;br&gt;
/opt/lampp/htdocs/myhospitalnow/mydoc-doctors-ms/CLAUDE.md&lt;br&gt;
/opt/lampp/htdocs/motoshare.in/motoshare-web/CLAUDE.md&lt;br&gt;
/opt/lampp/htdocs/devopsschool/ds-student-ms/CLAUDE.md&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content of per-repo CLAUDE.md&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This file should explain only that repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Repository Overview

This repository is responsible for [specific module name].

Example:
This repo handles doctor listing, doctor profile, doctor login, doctor dashboard, and doctor-related APIs.

# Folder Structure

Important folders:

- app/Http/Controllers
- app/Models
- app/Services
- routes/web.php
- routes/api.php
- resources/views
- database/migrations
- public
- config

# Main Entry Points

Mention important files:

- routes/web.php contains web routes.
- routes/api.php contains API routes.
- DoctorController handles doctor profile logic.
- AuthController handles login and callback logic.
- resources/views/pages contains frontend Blade pages.

# Repo-Specific Rules

- Do not change unrelated modules.
- Follow existing controller and service pattern.
- Keep old login working while improving SSO.
- Do not remove legacy columns.
- Add migration only if column is missing.
- Check existing database structure before writing new query.

# Authentication Rules

Example:
- Public listing pages should remain open.
- Dashboard pages require authentication.
- Keycloak user ID should be preferred where available.
- Legacy email/user_id fallback should remain for old data.

# Database Rules

- Do not rename existing columns directly.
- Use nullable columns for safe backward compatibility.
- Always check `Schema::hasColumn()` in safe migrations.
- Never run migration without user approval.

# API Rules

- Keep existing API response format.
- Do not break mobile app compatibility.
- Add new fields without removing old fields.
- Validate request parameters.

# UI/UX Rules

- Keep existing layout functional.
- Improve design without breaking Blade variables.
- Mobile responsive design is mandatory.
- Do not remove existing form fields unless instructed.

# Performance Rules

- Avoid duplicate queries.
- Use eager loading where needed.
- Cache only safe public data.
- Do not cache user-specific sensitive data incorrectly.

# Local Commands



bash
php artisan route:list
php artisan config:clear
php artisan cache:clear
php artisan view:clear
composer dump-autoload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Known Gotchas&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Storage permission issues may cause view/log errors.
.env should not be edited directly.
Some old users may not have keycloak_user_id.
Some APIs are used by mobile app, so response format must remain stable.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final Report Required&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/CM_Ii93ZueZLPHNrdo6LPTX16peZq3cjeGHmGRPrNH0/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOHY4YXU2/cGcydnBhZmRld29z/a2MucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/CM_Ii93ZueZLPHNrdo6LPTX16peZq3cjeGHmGRPrNH0/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOHY4YXU2/cGcydnBhZmRld29z/a2MucG5n" alt=" " width="510" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Claude must always provide:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary of changes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Files changed
Commands run
Testing result
Risk areas
Rollback steps

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;prompt&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;first read this blog https://aiopsschool.com/blog/category/claude/ and also read  parntthread https://chatgpt.com/c/6a168024-2a58-83a2-8518-00c2c330482d then this blogWhat is CLAUDE.md and Why Every Software Project Needs It this is my blog topic iwant full heading point wise  advantage wh form what one blog content should be
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CLAUDE.md file for writing any blog topic
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CLAUDE.md

## Purpose of This File

This CLAUDE.md file is created to guide Claude while writing professional, SEO-friendly, humanized, and well-structured blog content on any topic.

Claude must follow this file whenever creating, rewriting, improving, or expanding blog content.

The goal is to produce blog content that is:

- Easy to understand
- Humanized and professional
- SEO-friendly
- Well-structured
- Informative and detailed
- Useful for readers
- Suitable for publishing on websites
- Written in simple language
- Free from unnecessary complexity
- Original and plagiarism-free

---

# General Blog Writing Rules

## 1. Writing Tone

Claude must write in a simple, professional, humanized, and reader-friendly tone.

The blog should feel natural, not robotic.

Avoid overly complex words unless the topic requires them. If technical words are used, explain them in simple language.

The content should be suitable for beginners, students, professionals, business owners, and general readers depending on the blog topic.

## 2. Content Quality

Every blog must provide real value to the reader.

Claude should not write thin, generic, or repetitive content.

Each section should explain the topic clearly with practical details, examples, benefits, use cases, and important points.

## 3. SEO Guidelines

Every blog must include:

- Meta Title
- Meta Description
- SEO-friendly Introduction
- Proper heading structure
- Clear subheadings
- Naturally placed keywords
- Helpful explanation
- FAQs if required
- Final conclusion

Do not overuse keywords.

Use keywords naturally inside the content.

## 4. Formatting Rules

Use clean markdown formatting.

Use:

- H1 for the main title
- H2 for major sections
- H3 for sub-sections
- Bullet points only where useful
- Tables where comparison or structured explanation is needed
- Bold text for important highlights

Do not use icons or emojis.

Do not add unnecessary decorative symbols.

## 5. Originality Rules

The blog must be unique and original.

Do not copy content from other websites.

Do not repeat the same paragraph idea again and again.

If multiple blogs are requested on the same topic, each blog must have a unique title, different structure, different examples, and different wording.

---

# Mandatory Blog Structure

Claude should follow this structure for most blog topics unless the user gives a different format.

---

## Meta Title

Create a short, SEO-friendly meta title.

Rules:

- Keep it clear and attractive
- Include the main keyword
- Avoid clickbait
- Prefer 50–60 characters if possible

Example:

What is CLAUDE.md and Why Every Software Project Needs It

---

## Meta Description

Create a short meta description.

Rules:

- 150–160 characters preferred
- Include the main keyword naturally
- Explain what the reader will learn
- Make it useful and clear

Example:

Learn what CLAUDE.md is, why it matters, how it helps Claude understand projects, and why every software team should use it.

---

## Introduction

Write a strong introduction.

The introduction should:

- Start with the reader’s problem or curiosity
- Explain why the topic matters
- Give a simple overview of what the blog will cover
- Be engaging and easy to understand
- Avoid unnecessary long background

The introduction should make the reader feel that the blog will answer their question properly.

---

## What is [Topic]?

Explain the main topic clearly.

Rules:

- Give a simple definition
- Avoid too much technical language
- Explain the meaning in a practical way
- Mention where it is used
- Mention why people should know about it

Example for CLAUDE.md:

CLAUDE.md is a markdown file used to give Claude project-specific instructions, rules, context, and workflow guidance.

---

## [Topic] in Simple Language

Explain the topic in very simple words.

This section should be useful for beginners.

Use real-life comparisons if helpful.

Example:

Think of CLAUDE.md as a project instruction notebook for Claude. Just like a new developer needs onboarding, Claude also needs project guidance before working properly.

---

## Why Was [Topic] Needed?

Explain the problem that created the need for this topic.

Cover:

- What problem existed before
- Why the topic became important
- What issues it solves
- What happens if people ignore it

Example points:

- Repeated explanation
- Lack of consistency
- More mistakes
- Poor documentation
- Confusion in large projects

---

## The Main Purpose of [Topic]

Explain the core objective of the topic.

This section should answer:

- What is the main goal?
- Who benefits from it?
- What does it improve?
- Why should someone care?

Keep this section clear and direct.

---

## WH Form Explanation of [Topic]

Explain the topic using WH questions.

Include:

### What is [Topic]?

Explain the basic meaning.

### Why is [Topic] Important?

Explain its value.

### Who Should Use [Topic]?

Mention the target users.

### Where is [Topic] Used?

Explain common use cases or environments.

### When Should You Use [Topic]?

Explain the right time or situation.

### How Does [Topic] Work?

Explain the working process simply.

---

## Key Advantages of [Topic]

Create a detailed advantages section.

Each advantage should have:

- A clear heading
- Simple explanation
- Practical value
- Example if useful

Possible advantage sections:

### 1. Saves Time

Explain how the topic reduces repeated work.

### 2. Reduces Mistakes

Explain how it improves accuracy.

### 3. Improves Consistency

Explain how it keeps output or process stable.

### 4. Helps Beginners

Explain how it makes the topic easier to understand or use.

### 5. Improves Productivity

Explain how users can work faster.

### 6. Supports Team Collaboration

Explain how it helps teams follow the same process.

### 7. Improves Quality

Explain how it improves final output.

### 8. Makes Work More Organized

Explain how it creates better structure.

Add more advantages based on the topic.

---

## What Should Be Included in [Topic]?

Explain the important components.

For example, if the topic is CLAUDE.md, include:

- Project Overview
- Technology Stack
- Folder Structure
- Development Rules
- UI/UX Rules
- Security Rules
- Testing Commands
- Git Rules
- Reporting Format
- Do Not Touch Section

For other topics, customize this section according to the subject.

---

## Types, Levels, or Structure of [Topic]

Use this section when the topic has multiple types or levels.

For CLAUDE.md, explain:

### Root CLAUDE.md

Used for global project rules.

### Folder-Level CLAUDE.md

Used for specific module or folder rules.

For other topics, explain the relevant types, categories, or levels.

---

## Best Practices for [Topic]

Write practical best practices.

Rules:

- Make each point useful
- Avoid generic advice
- Explain why each best practice matters
- Keep language simple

Example:

### Keep It Clear

A clear instruction file is easier for Claude to follow.

### Keep It Updated

Outdated instructions can confuse the AI and create wrong output.

### Avoid Unnecessary Complexity

The file should guide Claude, not confuse it.

---

## Common Mistakes While Using or Creating [Topic]

Explain mistakes users should avoid.

Each mistake should include:

- What the mistake is
- Why it is a problem
- How to avoid it

Example mistakes:

### Making It Too Long

Too much unnecessary content can reduce clarity.

### Not Updating It

Old instructions can cause wrong implementation.

### Giving Generic Instructions

Instructions like “write good code” are not enough. Specific rules work better.

---

## Recommended Workflow

Give a step-by-step workflow.

The workflow should explain how to use the topic practically.

Example for CLAUDE.md:

1. Create the root CLAUDE.md file.
2. Add project overview and rules.
3. Add folder-level CLAUDE.md files if needed.
4. Ask Claude to read the file before working.
5. Start with analysis before implementation.
6. Review the plan.
7. Allow implementation.
8. Test the changes.
9. Update CLAUDE.md when project rules change.

For other topics, customize the workflow.

---

## Example Prompt Using [Topic]

Provide a practical prompt that users can copy and use.

Rules:

- Make the prompt clear
- Include role, task, rules, and output expectation
- Mention safety rules if relevant
- Keep it useful for real work

Example:

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
text&lt;br&gt;
Read the CLAUDE.md file first.&lt;/p&gt;

&lt;p&gt;I want you to write a complete blog on the topic: "[Blog Topic]".&lt;/p&gt;

&lt;p&gt;Follow the blog structure, SEO rules, tone, formatting, and quality guidelines from CLAUDE.md.&lt;/p&gt;

&lt;p&gt;The blog should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Meta Title&lt;/li&gt;
&lt;li&gt;Meta Description&lt;/li&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is the topic?&lt;/li&gt;
&lt;li&gt;Simple explanation&lt;/li&gt;
&lt;li&gt;Why it is needed&lt;/li&gt;
&lt;li&gt;Advantages&lt;/li&gt;
&lt;li&gt;Best practices&lt;/li&gt;
&lt;li&gt;Common mistakes&lt;/li&gt;
&lt;li&gt;Recommended workflow&lt;/li&gt;
&lt;li&gt;Final thoughts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Write in simple, humanized, professional language.&lt;br&gt;
Do not use icons or emojis.&lt;br&gt;
Do not copy content from other websites.&lt;br&gt;
Make the content detailed and publish-ready.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


[chatgpt](https://chatgpt.com/c/6a168024-2a58-83a2-8518-00c2c330482d)
[claude](https://aiopsschool.com/blog/category/claude/)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Clean Architecture in Laravel + React: Separating Business Logic, Database, and Presentation"</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Tue, 26 May 2026 02:21:53 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/clean-architecture-in-laravel-react-separating-business-logic-database-and-presentation-7pf</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/clean-architecture-in-laravel-react-separating-business-logic-database-and-presentation-7pf</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hybrid SSR + SPA, single bundle&lt;/strong&gt;. &lt;br&gt;
resources/js/appss.jsx mounts  on #motoshare-app (SPA shell) and / on chrome nodes — same JS file, mode chosen by which DOM IDs the page contains. Auth state, API base, and current path flow from PHP → data-* attributes → window._&lt;em&gt;MOTOSHARE&lt;/em&gt;* globals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/dwLBV5Bfcq82pZX42d4q_V_HGWoDDC4-XCluxKeh9Uk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOHQ0aXZq/bTlmcmt1ZGM0dXIz/bTMucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/dwLBV5Bfcq82pZX42d4q_V_HGWoDDC4-XCluxKeh9Uk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOHQ0aXZq/bTlmcmt1ZGM0dXIz/bTMucG5n" alt=" " width="630" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/JY-8YeVfowmy7TvKtBkVWzr3YEMmWeg79YRrUY5TCjc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvc3M2dHJu/cnRrdnI4aWhsbm9p/YTIucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/JY-8YeVfowmy7TvKtBkVWzr3YEMmWeg79YRrUY5TCjc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvc3M2dHJu/cnRrdnI4aWhsbm9p/YTIucG5n" alt=" " width="626" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/kZXgyiqYYWzCrXZj2CkYHGzLnM09kBAyA8pmCD3x7G4/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcGZxdXlu/c2xra3pkazhrYmVt/N2cucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/kZXgyiqYYWzCrXZj2CkYHGzLnM09kBAyA8pmCD3x7G4/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcGZxdXlu/c2xra3pkazhrYmVt/N2cucG5n" alt=" " width="651" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repository pattern is strictly enforced&lt;/strong&gt;.&lt;br&gt;
 I grepped — zero DB:: calls in any controller. Discipline that most Laravel projects don't keep.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/9WhWEwK9qZYLKjzDpSzBupzTvvEY9FIv1zFTBeoyI74/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMva2lpOGZy/amYzcDFzejZpcnpy/MmoucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/9WhWEwK9qZYLKjzDpSzBupzTvvEY9FIv1zFTBeoyI74/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMva2lpOGZy/amYzcDFzejZpcnpy/MmoucG5n" alt=" " width="655" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/15v1hNb8ly8A6u0qprBuZnUI38nV_MEWCCqJrHeuakk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvZzZ2cGFx/b3p4djBjMzh0czBv/czcucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/15v1hNb8ly8A6u0qprBuZnUI38nV_MEWCCqJrHeuakk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvZzZ2cGFx/b3p4djBjMzh0czBv/czcucG5n" alt=" " width="625" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database power features are leveraged&lt;/strong&gt;.&lt;br&gt;
 Complex reads go through MySQL views (vw_vehicle_catalog, vw_booking_details) and stored procs (sp_list_booking_details_by_actor) — significantly faster than equivalent Eloquent + N+1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/Q1enPjX2sMguVTxEphCltNHn4FRsG-Xizox1wwLmx7Y/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbHd5Z2U3/NjU3YnlvZGhoZHB2/NWkucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/Q1enPjX2sMguVTxEphCltNHn4FRsG-Xizox1wwLmx7Y/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbHd5Z2U3/NjU3YnlvZGhoZHB2/NWkucG5n" alt=" " width="645" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/GvNkInrkLD_Edv5HDySR8kl6zHASog3Jv2RNeHHJapw/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvNWdqanJ6/cXRzY2Y2dW1pM213/bnYucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/GvNkInrkLD_Edv5HDySR8kl6zHASog3Jv2RNeHHJapw/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvNWdqanJ6/cXRzY2Y2dW1pM213/bnYucG5n" alt=" " width="667" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/QAzDLMiMZHhMprX0Be0gimJUEoZwSnJ5uv1A9hcSxVc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvc2Rtem1k/OWh2b3B1azA5aGUz/eG8ucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/QAzDLMiMZHhMprX0Be0gimJUEoZwSnJ5uv1A9hcSxVc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvc2Rtem1k/OWh2b3B1azA5aGUz/eG8ucG5n" alt=" " width="640" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unified API surface&lt;/strong&gt;. &lt;br&gt;
routes/api_shared.php is loaded under both /api (token / mobile-future) and /web-api (session-cookie auth for the React SPA). Add an endpoint once, both clients get it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/GxbkbuefxDasn5pw1WMW4baci7odd1JpV6msaRv1IdM/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvdWxmc2J6/NjVlM3RpZHE3OWJ3/bHkucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/GxbkbuefxDasn5pw1WMW4baci7odd1JpV6msaRv1IdM/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvdWxmc2J6/NjVlM3RpZHE3OWJ3/bHkucG5n" alt=" " width="630" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/JYIlCDzgu9WevO2IMOmm7jF1cNPZrUK5qLaJubycxwo/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMveWc5eWRw/dzE4anNhMWI4aWEx/dnoucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/JYIlCDzgu9WevO2IMOmm7jF1cNPZrUK5qLaJubycxwo/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMveWc5eWRw/dzE4anNhMWI4aWEx/dnoucG5n" alt=" " width="642" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clean centralized exception&lt;/strong&gt; → &lt;br&gt;
JSON conversion for api/* and web-api/* in bootstrap/app.php. HTTP exceptions, validation errors, and unexpected throwables all return consistent { message } shape.&lt;br&gt;
&lt;a href="https://www.debug.school/images/zHitryofTu6mCJ5jC1Bwv2UFhrgCU-xdxRplD-8dOpI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYWl5dGJ5/cmxxeWE1N2g2eHh3/aG8ucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/zHitryofTu6mCJ5jC1Bwv2UFhrgCU-xdxRplD-8dOpI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYWl5dGJ5/cmxxeWE1N2g2eHh3/aG8ucG5n" alt=" " width="657" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/vuSUYF1JyksgckYSvRYw9TydsTbv0kNFWRSMb4H8dWI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvdzRqN2p2/Mnp0cWU5bTA1NXpx/eGYucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/vuSUYF1JyksgckYSvRYw9TydsTbv0kNFWRSMb4H8dWI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvdzRqN2p2/Mnp0cWU5bTA1NXpx/eGYucG5n" alt=" " width="641" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/gIYV3GTkfJbQo8Om4jYsa12Kx2jrCT_Qzkm09ER_Okk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvd2ZkNHBp/djJsYnB1YmcxN2lj/bHkucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/gIYV3GTkfJbQo8Om4jYsa12Kx2jrCT_Qzkm09ER_Okk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvd2ZkNHBp/djJsYnB1YmcxN2lj/bHkucG5n" alt=" " width="617" height="112"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Minimal, focused middleware&lt;/strong&gt;.&lt;br&gt;
 Just EnsureSessionUser.php — one job, 15 lines, no surprises.&lt;br&gt;
&lt;a href="https://www.debug.school/images/TkDfLTZqBd19mf8iZDJne5QHZvFlIuvxPj_YnEAvxXo/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbWpvMzhu/bG1iMm83YmJvemx3/dnoucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/TkDfLTZqBd19mf8iZDJne5QHZvFlIuvxPj_YnEAvxXo/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbWpvMzhu/bG1iMm83YmJvemx3/dnoucG5n" alt=" " width="610" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/p3GUb9wzzbKUOkCdqwhKhNq1WYY_LUm644AYH-c2p6k/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvajRqZTE5/MGxsMGZqYnd6NXJt/MmgucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/p3GUb9wzzbKUOkCdqwhKhNq1WYY_LUm644AYH-c2p6k/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvajRqZTE5/MGxsMGZqYnd6NXJt/MmgucG5n" alt=" " width="630" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Standardized response envelope via ApiResponder.php&lt;/strong&gt; — { message, data } everywhere, so the React api.js client has one parse path.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/yjmTxu0c-qp_TT-YOBaSG0mEPMnmbu9Vk_tFi6xIHz8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMveHZjcTR5/YjVnNTlyeHR4MXgw/eGIucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/yjmTxu0c-qp_TT-YOBaSG0mEPMnmbu9Vk_tFi6xIHz8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMveHZjcTR5/YjVnNTlyeHR4MXgw/eGIucG5n" alt=" " width="657" height="596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/s_0f6x1Dl052mlcSAzG8mgakzp36UtXe-0qfwvMb9Y8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYjZnem5s/ZzIxenRremhhYTEz/aXEucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/s_0f6x1Dl052mlcSAzG8mgakzp36UtXe-0qfwvMb9Y8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYjZnem5s/ZzIxenRremhhYTEz/aXEucG5n" alt=" " width="658" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern that ties them together
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/zF3gYtEEAzySo9HNvdgNYCONPf2zhE2psnz84lwuBZM/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYXc1bGt0/cXdzY3EzZHR4NXB6/dTkucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/zF3gYtEEAzySo9HNvdgNYCONPf2zhE2psnz84lwuBZM/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYXc1bGt0/cXdzY3EzZHR4NXB6/dTkucG5n" alt=" " width="655" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of this architecture (general)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;SEO + speed of SSR with the interactivity of SPA&lt;/strong&gt;, without paying the cost of Next.js / Inertia / Vue SSR runtimes.&lt;br&gt;
&lt;strong&gt;Performance ceiling is high&lt;/strong&gt; — hand-tuned SQL plus DB-side views/SPs.&lt;br&gt;
&lt;strong&gt;Mobile-future ready&lt;/strong&gt; — api_shared.php already serves token-style auth and JSON; you can add a React Native client without controller rewrites.&lt;br&gt;
&lt;strong&gt;Repository pattern → testability&lt;/strong&gt; — services can mock repos in PHPUnit without DB roundtrips.&lt;br&gt;
&lt;strong&gt;Single deploy artifact&lt;/strong&gt; — one Laravel app + one Vite bundle. No Node server, no separate SSR worker process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/J_V-wkZPg6iR-IE0EA9xCQvCi0yMZ9jk1vJYp-8dSZY/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOGw3MWxt/ajI4NXNuenNrdzEw/eGsucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/J_V-wkZPg6iR-IE0EA9xCQvCi0yMZ9jk1vJYp-8dSZY/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOGw3MWxt/ajI4NXNuenNrdzEw/eGsucG5n" alt=" " width="457" height="563"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/XM-_J_wIvejn4bhU6qxIpxgr9kQdrPJ2mjp7NqKS_pc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvdWl0b2Jp/NjQ0Z242bWdmMjJk/YncucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/XM-_J_wIvejn4bhU6qxIpxgr9kQdrPJ2mjp7NqKS_pc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvdWl0b2Jp/NjQ0Z242bWdmMjJk/YncucG5n" alt=" " width="746" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/e-PoEjszSYLHSI-exLEfrStsXaZK6u3dkk5PFdfBm4U/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvM2w1Zm0y/anQyMWNodG4xZjg4/MzIucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/e-PoEjszSYLHSI-exLEfrStsXaZK6u3dkk5PFdfBm4U/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvM2w1Zm0y/anQyMWNodG4xZjg4/MzIucG5n" alt=" " width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aiopsschool.com/blog/category/claude/" rel="noopener noreferrer"&gt;blog-claude.md&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=TAKDIvvUdc4" rel="noopener noreferrer"&gt;claude tutorial&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Fix MySQL Error 2002: Connection Timed Out While Connecting Laravel to traccar MariaDB</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Sat, 23 May 2026 07:01:09 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/how-to-fix-mysql-error-2002-connection-timed-out-while-connecting-laravel-to-traccar-mariadb-1kja</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/how-to-fix-mysql-error-2002-connection-timed-out-while-connecting-laravel-to-traccar-mariadb-1kja</guid>
      <description>&lt;p&gt;Traccar MariaDB Connection Timeout Troubleshooting Summary&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Commands to check connection timeout from Laravel server&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run these commands on your Laravel server.&lt;/p&gt;

&lt;p&gt;Check ping&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ping 13.126.68.234
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Stop ping using:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CTRL + C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Ping can fail if ICMP is blocked. So ping is not the final test.&lt;/p&gt;

&lt;p&gt;Check MySQL port 3306 on public IP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nc -vz 13.126.68.234 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check MySQL port 3306 on private IP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nc -vz 172.31.34.212 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If nc command is missing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install netcat-openbsd -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Test MySQL login from Laravel server&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -h 172.31.34.212 -P 3306 -u traccar -p traccar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or public IP test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -h 13.126.68.234 -P 3306 -u traccar -p traccar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After login:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SHOW TABLES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Meaning of timeout&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You received:&lt;/p&gt;

&lt;p&gt;nc: connect to 172.31.34.212 port 3306 (tcp) failed: Connection timed out&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;p&gt;Laravel server cannot reach Traccar DB server on port 3306.&lt;/p&gt;

&lt;p&gt;Since MariaDB is already listening on:&lt;/p&gt;

&lt;p&gt;0.0.0.0:3306&lt;/p&gt;

&lt;p&gt;the problem is mostly:&lt;/p&gt;

&lt;p&gt;AWS Security Group&lt;br&gt;
UFW firewall&lt;br&gt;
iptables firewall&lt;br&gt;
Network ACL&lt;br&gt;
Different VPC/routing issue&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Commands to check MariaDB on Traccar server&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run these commands on the Traccar DB server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Check MariaDB is listening on 3306&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ss -tulnp | grep 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0.0.0.0:3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your output is already correct.&lt;/p&gt;

&lt;p&gt;Check MariaDB service status&lt;br&gt;
sudo systemctl status mariadb&lt;/p&gt;

&lt;p&gt;or:&lt;/p&gt;

&lt;p&gt;sudo systemctl status mysql&lt;br&gt;
Restart MariaDB if needed&lt;br&gt;
sudo systemctl restart mariadb&lt;/p&gt;

&lt;p&gt;or:&lt;/p&gt;

&lt;p&gt;sudo systemctl restart mysql&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Commands to resolve firewall issue on Traccar server&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run on Traccar DB server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Check UFW status&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Allow Laravel server private IP&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow from 172.31.6.53 to any port 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check UFW again&lt;br&gt;
sudo ufw status numbered&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Commands to check iptables on Traccar server&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo iptables -L -n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Check only MySQL related rules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo iptables -L -n | grep 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check if any DROP rule exists:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo iptables -L -n | grep DROP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Temporary allow rule for testing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo iptables -I INPUT -p tcp -s 172.31.6.53 --dport 3306 -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then test again from Laravel server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nc -vz 172.31.34.212 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;AWS Security Group rule to add&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In AWS Console, go to:&lt;/p&gt;

&lt;p&gt;EC2 &amp;gt; Traccar Server &amp;gt; Security &amp;gt; Security Group &amp;gt; Inbound Rules&lt;/p&gt;

&lt;p&gt;Add this inbound rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Type: MySQL/Aurora
Protocol: TCP
Port: 3306
Source: 172.31.6.53/32
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Better option:&lt;/p&gt;

&lt;p&gt;Source: Laravel server Security Group ID&lt;/p&gt;

&lt;p&gt;Do not open MySQL to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0.0.0.0/0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;DB user permission commands&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run on Traccar DB server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -u root -p

Check existing Traccar user:

SELECT user, host FROM mysql.user WHERE user='traccar';

Create user for Laravel private IP:

CREATE USER 'traccar'@'172.31.6.53' IDENTIFIED BY 'NEW_STRONG_PASSWORD';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read-only permission:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GRANT SELECT ON traccar.* TO 'traccar'@'172.31.6.53';
FLUSH PRIVILEGES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read/write permission if needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GRANT SELECT, INSERT, UPDATE, DELETE ON traccar.* TO 'traccar'@'172.31.6.53';
FLUSH PRIVILEGES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check grants:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SHOW GRANTS FOR 'traccar'@'172.31.6.53';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Final testing commands&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run on Laravel server after firewall/AWS fix.&lt;/p&gt;

&lt;p&gt;Test port&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nc -vz 172.31.34.212 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Connection to 172.31.34.212 3306 port [tcp/mysql] succeeded
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test MySQL login&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -h 172.31.34.212 -P 3306 -u traccar -p traccar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside MySQL:&lt;/p&gt;

&lt;p&gt;SHOW TABLES;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Laravel .env update&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use private IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRACCAR_DB_HOST=172.31.34.212
TRACCAR_DB_PORT=3306
TRACCAR_DB_DATABASE=traccar
TRACCAR_DB_USERNAME=traccar
TRACCAR_DB_PASSWORD=NEW_STRONG_PASSWORD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then clear Laravel cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan config:clear
php artisan cache:clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test in Laravel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan tinker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside tinker:&lt;/p&gt;

&lt;p&gt;DB::connection('mysqlTraccar')-&amp;gt;select('SHOW TABLES');&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Best final setup&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Laravel Server Private IP: 172.31.6.53
Traccar DB Server Private IP: 172.31.34.212
MariaDB Port: 3306
Connection: Private AWS network
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Most important fix&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Allow inbound MySQL/Aurora port 3306 in Traccar server AWS Security Group from 172.31.6.53/32.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chatgpt.com/c/6a1147c0-428c-83a7-b39b-2efd2e876376" rel="noopener noreferrer"&gt;chatgptlink&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Different kind of prompt used by Spring AI</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 27 Mar 2026 06:17:45 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/different-kind-of-prompt-used-by-spring-ai-1o3j</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/different-kind-of-prompt-used-by-spring-ai-1o3j</guid>
      <description>&lt;p&gt;Main kinds of prompts Spring AI helps you make&lt;br&gt;
A. &lt;strong&gt;System prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This tells the model how to behave.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“You are a helpful banking assistant.”
“Answer in simple English.”
“Do not return unsafe medical advice.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Role: controls tone, style, rules, and boundaries. Spring AI docs say system messages are generated by the system to guide the conversation.&lt;/p&gt;

&lt;p&gt;B. &lt;strong&gt;User prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the actual question or request from the user.&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“What is compound interest?”
“Summarize this document.”
“Translate this to Hindi.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Role: carries the direct input to the model. Spring AI identifies user messages as the direct inputs from the user.&lt;/p&gt;

&lt;p&gt;C. &lt;strong&gt;Multi-message chat prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This combines multiple messages together, usually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;one or more system messages
one user message
sometimes previous conversation messages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Role: gives the model better context than a single plain text prompt. Spring AI’s prompt model is message-based, not just one raw string.&lt;/p&gt;

&lt;p&gt;D. &lt;strong&gt;Template prompt / parameterized prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a prompt with placeholders like {name}, {topic}, {question}.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;p&gt;“Explain {topic} to a beginner.”&lt;br&gt;
“Write an email to {customerName} about {issue}.”&lt;/p&gt;

&lt;p&gt;Role: makes prompts reusable and dynamic. The docs note that prompts often contain placeholders substituted at runtime. The prompt docs also compare this to a view template or SQL with placeholders.&lt;/p&gt;

&lt;p&gt;E. &lt;strong&gt;External file prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can keep prompts outside Java code in template files instead of hardcoding them. That makes them reusable and easier to version and maintain. Your screenshot mentions .st, .mustache, and .ftl, and Spring AI’s docs show PromptTemplate rendering support, including the default StPromptTemplate based on StringTemplate.&lt;/p&gt;

&lt;p&gt;F. &lt;strong&gt;RAG prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is used when you want the model to answer using retrieved context from documents or a vector database. Spring AI’s RAG support lets you customize a PromptTemplate that merges the user query with retrieved context, and the docs specify placeholders such as query and question_answer_context.&lt;/p&gt;

&lt;p&gt;G. &lt;strong&gt;Memory-aware prompt&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LLMs are stateless by default, so Spring AI adds chat memory features to carry useful prior context into later interactions. This helps create prompts that include conversation context without you manually rebuilding it each time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Why these prompt types matter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Different prompt types solve different problems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System prompt → behavior and rules
User prompt → actual request
Template prompt → reuse and dynamic input
RAG prompt → answer from documents/context
Memory-aware prompt → continue a conversation naturally
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is why Spring AI is useful: it gives structure around prompt creation instead of making you manually assemble raw HTTP JSON every time. ChatClient builds prompt parts fluently, and Advisors can add memory, retrieved documents, and more advanced behavior.&lt;/p&gt;

&lt;p&gt;3) Coding examples&lt;/p&gt;

&lt;p&gt;These examples are written in the normal Spring AI style and may need small adjustment depending on your exact Spring AI version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1: Simple system prompt + user prompt&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RestController
@RequestMapping("/ai")
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/explain")
    public String explain(@RequestParam String topic) {
        return chatClient.prompt()
                .system("You are a Java teacher. Explain in simple English.")
                .user("Explain this topic for a beginner: {topic}")
                .param("topic", topic)
                .call()
                .content();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens here&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.system(...) creates a system prompt
.user(...) creates a user prompt
.param(...) fills the template placeholder dynamically
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This matches the docs’ message-based prompt model and runtime placeholder substitution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2: Reusable template prompt&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Service
public class EmailPromptService {

    private final ChatClient chatClient;

    public EmailPromptService(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    public String generateEmail(String customerName, String issue) {
        return chatClient.prompt()
                .system("You are a professional customer support writer.")
                .user("""
                      Write a polite support email to {customerName}.
                      The issue is: {issue}
                      Keep the tone professional and short.
                      """)
                .param("customerName", customerName)
                .param("issue", issue)
                .call()
                .content();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this is useful&lt;/p&gt;

&lt;p&gt;Same prompt structure, different values. That is the main idea of template prompts. Spring AI docs explicitly describe placeholders being replaced based on user requests or application code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3: Prompt from external template file idea&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose you keep a prompt file like:&lt;/p&gt;

&lt;p&gt;src/main/resources/prompts/greeting.st&lt;/p&gt;

&lt;p&gt;Hello, my name is {name}. Can you greet me back nicely?&lt;/p&gt;

&lt;p&gt;Then your code can render and send it through Spring AI. A simplified example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Service
public class GreetingService {

    private final ChatClient chatClient;

    public GreetingService(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    public String greet(String name) {
        String template = "Hello, my name is {name}. Can you greet me back nicely?";

        return chatClient.prompt()
                .user(template)
                .param("name", name)
                .call()
                .content();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI supports prompt templating and documents PromptTemplate; for RAG templates it uses StPromptTemplate by default, based on StringTemplate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 4: RAG-style prompt&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String answer = chatClient.prompt()
        .system("Answer only from the provided context. If unsure, say you do not know.")
        .user("""
              Question: {question}

              Context:
              {context}
              """)
        .param("question", "What is the refund policy?")
        .param("context", """
                Refunds are allowed within 7 days of purchase
                if the product has not been activated.
                """)
        .call()
        .content();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the basic idea behind a RAG prompt: merge the user query with retrieved context. Spring AI’s RAG docs describe custom templates that combine query and retrieved context for answering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 5: Memory-aware chat idea&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String response = chatClient.prompt()
        .system("You are a helpful assistant that remembers prior discussion context.")
        .user("Continue our last discussion and summarize the final decision.")
        .call()
        .content();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In real apps, chat memory is usually backed by Spring AI chat memory support, because LLMs are stateless by default and Spring AI adds memory abstractions to maintain useful context.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/ICe4A002KxlSMhQ7niFzTjYFqMi_0lTB3IjFZt6SMdk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvajFzeGUy/NmNqeG93NTkwNHl0/a2wucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/ICe4A002KxlSMhQ7niFzTjYFqMi_0lTB3IjFZt6SMdk/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvajFzeGUy/NmNqeG93NTkwNHl0/a2wucG5n" alt=" " width="632" height="703"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Very simple summary
&lt;/h2&gt;

&lt;p&gt;Spring AI mainly helps you create these prompt types:&lt;/p&gt;

&lt;p&gt;System prompts&lt;br&gt;
User prompts&lt;br&gt;
Multi-message prompts&lt;br&gt;
Template prompts&lt;br&gt;
External-file prompts&lt;br&gt;
RAG prompts&lt;br&gt;
Memory-aware prompts&lt;/p&gt;

&lt;p&gt;So the big benefit is not just “send text to GPT.”&lt;br&gt;
The real benefit is: Spring AI gives prompt structure, reuse, context, and maintainability inside a Spring Boot application&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How Spring AI Simplifies REST API Integration in Modern Applications</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 27 Mar 2026 05:30:34 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/how-spring-ai-simplifies-rest-api-integration-in-modern-applications-2l5c</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/how-spring-ai-simplifies-rest-api-integration-in-modern-applications-2l5c</guid>
      <description>&lt;p&gt;&lt;strong&gt;Theory explanation&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Why not call REST API directly from controller?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Main purpose of Spring AI interface&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Why this helps in modern applications&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Simple flow&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Coding example&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Theory explanation
&lt;/h2&gt;

&lt;p&gt;In a normal Spring Boot project, you can call an AI provider directly with REST APIs.&lt;br&gt;
That means your code builds HTTP requests, adds headers, sends JSON, handles authentication, parses responses, and manages retries by itself.&lt;/p&gt;

&lt;p&gt;That works for small demos, but in modern applications it becomes repetitive and hard to maintain.&lt;/p&gt;

&lt;p&gt;Spring AI simplifies this by putting a Spring-style abstraction layer between your application and the AI provider. Instead of writing low-level HTTP code everywhere, you work with higher-level APIs such as ChatClient, ChatModel, Prompt, and advisors. The Spring AI reference describes ChatClient as a fluent API for communicating with an AI model, where prompts are built from messages like user and system messages.&lt;/p&gt;

&lt;p&gt;So the difference is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REST API only = low-level transport and manual integration
Spring AI = structured, reusable, Spring-friendly AI integration built on top of provider APIs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why not call REST API directly from controller?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Because controller should mainly handle:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;incoming request
validation
response

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;If controller also manages:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AI API payloads
prompt structure
JSON parsing
retries
embeddings
vector DB lookup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.debug.school/images/9hbPDkP6r2Gl5J8i7l9u6_i1Dxb-LPpYTDmd--0F2uI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvY3h3d2t2/YmV1cDZrMXUxcHg1/NGIucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/9hbPDkP6r2Gl5J8i7l9u6_i1Dxb-LPpYTDmd--0F2uI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvY3h3d2t2/YmV1cDZrMXUxcHg1/NGIucG5n" alt=" " width="453" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;then controller becomes overloaded.&lt;/p&gt;

&lt;p&gt;Spring AI keeps the design cleaner.&lt;br&gt;
&lt;a href="https://www.debug.school/images/ojHOMRmwwKQKQczz2ElO1MPlZiLxFg9nYrHaURwUetg/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbDVjM2ht/bzV5eWEyNGRlaHln/dmIucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/ojHOMRmwwKQKQczz2ElO1MPlZiLxFg9nYrHaURwUetg/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbDVjM2ht/bzV5eWEyNGRlaHln/dmIucG5n" alt=" " width="715" height="277"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Main purpose of Spring AI interface
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;It hides low-level HTTP complexity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You do not need to manually build every REST request.&lt;/p&gt;

&lt;p&gt;Instead of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create URL
create headers
add API key
build JSON
send request
parse result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use a cleaner Spring-style approach.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;It gives a Spring-friendly programming model&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Spring Boot, developers like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependency injection
beans
service classes
reusable configuration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI fits that style.&lt;/p&gt;

&lt;p&gt;So AI feels like a normal Spring service, not like raw external API handling.&lt;/p&gt;

&lt;p&gt;Example idea:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ChatClient
EmbeddingModel
PromptTemplate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are easier to use in service classes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;It reduces vendor lock-in&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Different providers have different request and response formats.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Without Spring AI:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OpenAI code looks one way
another provider looks different
switching providers means code change in many places
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;With Spring AI&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;you work through a common abstraction
changing provider becomes easier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;It supports AI-specific features, not just REST calling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI integration is not just sending text over HTTP.&lt;/p&gt;

&lt;p&gt;It often includes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompt templating
chat memory
embeddings
vector search
RAG flow
structured output
model options
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;REST API does not give these patterns automatically.&lt;/p&gt;

&lt;p&gt;Spring AI provides structure for them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It makes enterprise code cleaner&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In small demo projects, direct REST calls are okay.&lt;/p&gt;

&lt;p&gt;But in real applications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chatbot
recommendation engine
support assistant
document Q&amp;amp;A
healthcare AI assistant
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you need better architecture.&lt;/p&gt;

&lt;p&gt;Spring AI helps separate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;controller
business logic
AI interaction
prompt layer
retrieval layer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That makes the project easier to scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this helps in modern applications
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Cleaner code&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without Spring AI, you often repeat:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API URL handling
auth token or API key setup
request body creation
response parsing
provider-specific JSON mapping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI centralizes that interaction. Its model API is designed as a portable interface across providers, which makes the code cleaner and more maintainable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Easier provider switching&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you call one provider directly using raw REST, your code usually becomes tightly coupled to that provider’s request and response format.&lt;/p&gt;

&lt;p&gt;Spring AI’s Chat Model API is designed to be portable, so moving across supported providers requires fewer code changes than rewriting raw REST integration everywhere.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Prompt handling becomes structured&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Modern AI apps need more than one plain input string. They need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;system instructions
user prompts
templates
placeholders
context injection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI supports prompts as structured message collections and supports prompt templating, which is much better than building JSON strings manually for each REST call.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Better support for advanced AI patterns&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Modern applications often need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chat memory
embeddings
RAG
tool calling
streaming responses
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI supports these patterns directly through its APIs and advisors, which is far beyond “just send a REST request.”&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Better fit with Spring Boot architecture&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spring developers prefer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependency injection
beans
service classes
configuration properties
starter-based setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI fits naturally into that model. For example, the official docs provide Spring Boot starter-based configuration such as spring-ai-starter-model-openai, and the getting-started docs state support for Spring Boot 3.4.x and 3.5.x.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple flow
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Direct REST approach&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Controller → Service → Manual HTTP Client → AI Provider API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Spring AI approach&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Controller → Service → ChatClient / ChatModel → AI Provider API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI still uses provider APIs underneath, but your application code stays much simpler.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding example
&lt;/h2&gt;

&lt;p&gt;Below is a simple Spring Boot example using Spring AI with OpenAI-style integration.&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Maven dependencies&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependencyManagement&amp;gt;
    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework.ai&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-ai-bom&amp;lt;/artifactId&amp;gt;
            &amp;lt;version&amp;gt;YOUR_VERSION&amp;lt;/version&amp;gt;
            &amp;lt;type&amp;gt;pom&amp;lt;/type&amp;gt;
            &amp;lt;scope&amp;gt;import&amp;lt;/scope&amp;gt;
        &amp;lt;/dependency&amp;gt;
    &amp;lt;/dependencies&amp;gt;
&amp;lt;/dependencyManagement&amp;gt;

&amp;lt;dependencies&amp;gt;
    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework.ai&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-ai-starter-model-openai&amp;lt;/artifactId&amp;gt;
    &amp;lt;/dependency&amp;gt;

    &amp;lt;dependency&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;/artifactId&amp;gt;
    &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The official Spring AI OpenAI chat docs show spring-ai-starter-model-openai as the starter artifact.&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;application.properties&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring.ai.openai.api-key=YOUR_API_KEY
spring.ai.openai.chat.options.model=gpt-4o-mini
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring AI provides Spring Boot auto-configuration for the OpenAI chat client through properties under the Spring AI namespace.&lt;/p&gt;

&lt;p&gt;3) &lt;strong&gt;Service class&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.demo.service;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Service;

@Service
public class AiService {

    private final ChatClient chatClient;

    public AiService(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    public String explainTopic(String topic) {
        return chatClient.prompt()
                .system("You are a helpful Java and Spring expert. Explain in simple English.")
                .user("Explain this topic in a modern application context: {topic}")
                .param("topic", topic)
                .call()
                .content();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses ChatClient’s fluent API to build a prompt from system and user messages, with runtime parameters. That is exactly the sort of prompt-building model described in the official docs.&lt;/p&gt;

&lt;p&gt;4) &lt;strong&gt;REST controller&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.demo.controller;

import com.example.demo.service.AiService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiController {

    private final AiService aiService;

    public AiController(AiService aiService) {
        this.aiService = aiService;
    }

    @GetMapping("/api/explain")
    public String explain(@RequestParam String topic) {
        return aiService.explainTopic(topic);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your application exposes a normal REST endpoint, but internally it uses Spring AI rather than a manually coded HTTP call to the model provider.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/9dZjWh6b4U7oicTYDGqu_GFiJ_q7TSaptCcfJoLOKpc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvamhsMHBr/MTk1OXNpcWwxMDZ6/eTQucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/9dZjWh6b4U7oicTYDGqu_GFiJ_q7TSaptCcfJoLOKpc/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvamhsMHBr/MTk1OXNpcWwxMDZ6/eTQucG5n" alt=" " width="342" height="697"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to integrate AI models into Spring Boot applications using Spring AI</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 27 Mar 2026 03:39:18 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/how-to-integrate-ai-models-into-spring-boot-applications-using-spring-ai-amp</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/how-to-integrate-ai-models-into-spring-boot-applications-using-spring-ai-amp</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Spring AI?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Spring AI Architecture&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Purpose of Spring AI&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Role of Spring AI&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;How Flow Works&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Common Questions (with Answers)&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Spring AI?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/_-xR9Nw_BnWWUecHPUpfYtdUlRLgeTEu2NlClfK0dzs/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvNGl6Y25i/aWVmbDJwcjl4bWFt/N3EucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/_-xR9Nw_BnWWUecHPUpfYtdUlRLgeTEu2NlClfK0dzs/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvNGl6Y25i/aWVmbDJwcjl4bWFt/N3EucG5n" alt=" " width="688" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Spring AI is a framework that helps developers integrate AI models (like GPT, LLMs, embeddings, etc.) into Spring Boot applications easily.&lt;/p&gt;

&lt;p&gt;Instead of manually calling AI APIs and handling complexity, Spring AI provides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Clean Java-based abstraction
Easy integration with AI providers (OpenAI, Azure, etc.)
Support for chat, embeddings, vector DB, prompt templates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 In simple words:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Spring AI = Bridge between Spring Boot apps and AI models
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎯 &lt;/p&gt;

&lt;h2&gt;
  
  
  Spring AI Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/Xs3VJf5GJv7PQ0BX1A9MHBi3eOcTOLWs-NC4iw70vU8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYjUxMGtw/cXpvNWcwNHl5emE0/aDEucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/Xs3VJf5GJv7PQ0BX1A9MHBi3eOcTOLWs-NC4iw70vU8/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvYjUxMGtw/cXpvNWcwNHl5emE0/aDEucG5n" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Spring AI Works&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Users give input to Spring Boot REST controller.&lt;/li&gt;
&lt;li&gt;Spring AI  processes the user input using Prompt Templates or ChatClient (to call LLM)&lt;/li&gt;
&lt;li&gt;ChatClient connects to external AI providers (OpenAI, Ollama, etc.)&lt;/li&gt;
&lt;li&gt;And response is returned to the Spring Boot app and sent back to the user
. 
&lt;strong&gt;Multi-Provider Support&lt;/strong&gt;: Spring AI framework supports connecting to multiple LLM providers like
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OpenAI (ChatGPT)
Azure OpenAI
Hugging Face (Transformers)
Ollama (for local models)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Chat Client API&lt;/strong&gt;: Standardizes communication with LLMs using a fluent API, regardless of provider differences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt Templates&lt;/strong&gt;: Developers can define dynamic prompts with variables using Spring Expression Language (SpEL).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embedding and Vector Store Integration&lt;/strong&gt;: Spring AI supports converting text into embeddings like numeric vector and storing them in vector databases like PostgreSQL with pgvector.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structured Outputs ( Like POJO Mapping)&lt;/strong&gt;: Spring AI model output (like JSON) directly to the Java POJOs class using annotations and converters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features of Spring AI&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Purpose of Spring AI
&lt;/h2&gt;

&lt;p&gt;The main purpose is to simplify AI integration in enterprise Java applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Goals:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reduce boilerplate code for AI API calls
Provide standardized APIs (like Spring Data, Spring MVC)
Enable production-ready AI apps
Support scalable and maintainable architecture
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧩 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/FY8Np1unpTsJoihNjo8zyy6EaqZaRgkMqIHWU7sZSYI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOWJrc3U4/bG5mZ3FrbzEwOWN0/MTMucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/FY8Np1unpTsJoihNjo8zyy6EaqZaRgkMqIHWU7sZSYI/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvOWJrc3U4/bG5mZ3FrbzEwOWN0/MTMucG5n" alt=" " width="800" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Role of Spring AI
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;AI Integration Layer&lt;/strong&gt;
Connects your Spring Boot app with AI models
Handles API calls, authentication, retries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstraction Provider&lt;/strong&gt;
You don’t write raw HTTP calls
Use simple Java interfaces&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt Management&lt;/strong&gt;
Helps structure prompts cleanly
Supports templates&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Handling (Vector + Embeddings)&lt;/strong&gt;
Store &amp;amp; search semantic data
Used in RAG (Retrieval-Augmented Generation)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enterprise Enablement&lt;/strong&gt;
Works with microservices
Secure, scalable, production-ready
🏗️ Architecture (Colorful + Labeled Representation)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://www.debug.school/images/zNBH2tvUSYxle2_iBZkJi20nljpVu8jSIOd2_LMFm1c/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbXF5N2Vq/amFoc3UwdDJiZnFz/MjEucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/zNBH2tvUSYxle2_iBZkJi20nljpVu8jSIOd2_LMFm1c/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvbXF5N2Vq/amFoc3UwdDJiZnFz/MjEucG5n" alt=" " width="387" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How Flow Works
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User sends request → Frontend
Request hits → Spring Boot Controller
Service calls → Spring AI layer
Spring AI sends request → AI Model (GPT)
AI response → back to Spring Boot → UI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❓ &lt;/p&gt;

&lt;h2&gt;
  
  
  Common Questions (with Answers)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why use Spring AI instead of direct API calls?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 Because it reduces complexity, gives structure, and is production-ready.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Can Spring AI work with Laravel backend?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 No directly. Spring AI is for Java ecosystem.&lt;br&gt;
For Laravel, you use OpenAI SDK or HTTP APIs manually.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Is Spring AI suitable for microservices?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 Yes, very suitable. You can create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AI microservice
Chat service
Recommendation engine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What features does Spring AI provide?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chat completion
Embeddings
Prompt templates
Vector DB integration
RAG support
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;When should you choose Spring AI?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 Choose it when:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your backend is Spring Boot
You need enterprise AI integration
You want clean, scalable architecture
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;When NOT to use Spring AI?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 Avoid if:&lt;/p&gt;

&lt;p&gt;Your backend is Laravel/PHP&lt;br&gt;
Small project (simple API call enough)&lt;br&gt;
🔥 &lt;strong&gt;Final Simple Summary&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Purpose: Simplify AI integration
Role: Bridge Spring Boot ↔ AI Models
Benefit: Clean, scalable, enterprise-ready AI apps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://medium.com/@0_bibhuti/spring-ai-build-intelligent-applications-with-ease-c3c28c7bb15d" rel="noopener noreferrer"&gt;Reference&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=BFk_nAJapYc&amp;amp;list=PL0zysOflRCen1TeDUm-ebl9T-WbJygCGE&amp;amp;index=5" rel="noopener noreferrer"&gt;utube&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Build a Simple AI Question Answer App with LangChain</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Tue, 17 Mar 2026 10:35:28 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/how-to-build-a-simple-ai-question-answer-app-with-langchain-4cc9</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/how-to-build-a-simple-ai-question-answer-app-with-langchain-4cc9</guid>
      <description>&lt;p&gt;&lt;strong&gt;Direct LLM call&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = llm.invoke("What is generative AI?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Chain call&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chain = prompt | llm
response = chain.invoke({"input":"Can you tell me about Langsmith?"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Chain with output parser&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chain = prompt | llm | output_parser
response = chain.invoke({"input":"Can you tell me about Langsmith?"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why use chain?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use a chain to connect multiple steps in one flow.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;first step = format the prompt

second step = send it to LLM

third step = parse the output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So instead of writing everything separately, chain makes it clean, reusable, and easy to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple sentence:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Chain is used to join prompt + model + parser into one pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use StrOutputParser?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you call:&lt;/p&gt;

&lt;p&gt;response = chain.invoke(...)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;without parser, the output is usually an AIMessage object.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That means response contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;content

metadata

extra model information
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But many times we only need the final text.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;So StrOutputParser() converts the output into a plain string.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Simple sentence:&lt;/p&gt;

&lt;p&gt;StrOutputParser is used to extract only text from the model response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Difference between both chains&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chain 1
chain = prompt | llm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output type:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;AIMessage&lt;br&gt;
Chain 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chain = prompt | llm | output_parser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output type:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;str&lt;br&gt;
&lt;strong&gt;Why use second chain?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because it gives clean text output, which is easier to:&lt;/p&gt;

&lt;p&gt;print&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;store in database

show in UI

pass to next function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;20 Important Questions Based on Your Screenshot&lt;/p&gt;

&lt;h2&gt;
  
  
  Subjective Questions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is the purpose of load_dotenv() in this code?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
load_dotenv() loads environment variables from the .env file into Python, so secrets like API keys can be used safely.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why do we store OPENAI_API_KEY in environment variables?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
Because API keys are sensitive data. Keeping them in environment variables is safer than writing them directly in code.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is the use of ChatOpenAI(model="gpt-4o")?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
It creates an LLM object that allows us to communicate with the OpenAI chat model.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What does llm.invoke("What is generative AI?") do?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
It sends the input question to the model and gets a response back.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is ChatPromptTemplate?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
ChatPromptTemplate helps us create structured prompts using system messages and user messages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why do we use a system message in prompt template?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
A system message sets the behavior of the model, like telling it to act as an AI engineer or teacher.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why do we use {input} inside the prompt template?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
{input} is a variable placeholder. It lets us send different user questions dynamically.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why do we use prompt | llm?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
It creates a chain where the prompt is first prepared and then sent to the language model automatically.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why do we use StrOutputParser()?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
Because the LLM normally returns an AIMessage object, and StrOutputParser() converts that into plain text.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is the main benefit of using chains in LangChain?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer:&lt;br&gt;
Chains reduce manual coding and make the workflow modular, readable, and reusable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objective Questions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;load_dotenv() is used to&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: Load variables from .env file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;os.getenv("OPENAI_API_KEY") is used to:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: Read the API key from environment variables.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The output type of prompt | llm is generally&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: AIMessage&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The output type of prompt | llm | StrOutputParser() is generally&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: string&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ChatPromptTemplate.from_messages() is used to&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: Create prompt structure using system and human messages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;LANGCHAIN_TRACING_V2="true" is used for&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: Tracking and monitoring LangChain execution.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The symbol | in LangChain is used to&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer: Combine components into a chain.&lt;/p&gt;

&lt;h2&gt;
  
  
  MCQ Questions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Which function loads environment variables from a .env file&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. getenv()&lt;br&gt;
B. load_dotenv()&lt;br&gt;
C. setenv()&lt;br&gt;
D. read_env()&lt;/p&gt;

&lt;p&gt;Answer: B. load_dotenv()&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What does StrOutputParser() return?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. JSON object&lt;br&gt;
B. Dictionary&lt;br&gt;
C. Plain text string&lt;br&gt;
D. AIMessage object&lt;/p&gt;

&lt;p&gt;Answer: C. Plain text string&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why is prompt | llm | output_parser better than only prompt | llm in many cases?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. It increases API speed&lt;br&gt;
B. It converts response into plain text&lt;br&gt;
C. It removes API key&lt;br&gt;
D. It changes model version&lt;/p&gt;

&lt;p&gt;Answer: B. It converts response into plain text&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is the role of PromptTemplate in this code?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. To create database models&lt;br&gt;
B. To define structured prompt text for the LLM&lt;br&gt;
C. To validate JSON request&lt;br&gt;
D. To start Flask server&lt;/p&gt;

&lt;p&gt;Answer: B. To define structured prompt text for the LLM&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which of the following is one of the prompt keys in the prompts dictionary?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. student_details&lt;br&gt;
B. recommendation&lt;br&gt;
C. save_recipe&lt;br&gt;
D. database_query&lt;/p&gt;

&lt;p&gt;Answer: B. recommendation&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What is checked in this block?&lt;/strong&gt;
if llm is None:
return jsonify({"error": "LLM is not available"}), 500&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Whether query is empty&lt;br&gt;
B. Whether prompt is missing&lt;br&gt;
C. Whether language model instance is available&lt;br&gt;
D. Whether JSON is valid&lt;/p&gt;

&lt;p&gt;Answer: C. Whether language model instance is available&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What does status code 500 mean here?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Data created successfully&lt;br&gt;
B. Redirect response&lt;br&gt;
C. Internal server error&lt;br&gt;
D. Unauthorized user&lt;/p&gt;

&lt;p&gt;Answer: C. Internal server error&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What is created by this line?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chains = {key: prompts[key] | llm for key in selected_chains}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A. A database connection&lt;br&gt;
B. A dictionary of runnable chains for selected prompts&lt;br&gt;
C. A list of user queries&lt;br&gt;
D. A JSON response&lt;/p&gt;

&lt;p&gt;Answer: B. A dictionary of runnable chains for selected prompts&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What does the | operator do in this line?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompts[key] | llm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A. Performs bitwise OR&lt;br&gt;
B. Joins prompt template with LLM into a pipeline/chain&lt;br&gt;
C. Compares two values&lt;br&gt;
D. Converts string to JSON&lt;/p&gt;

&lt;p&gt;Answer: B. Joins prompt template with LLM into a pipeline/chain&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Why is RunnableParallel(&lt;/strong&gt;chains) used?**&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. To execute all selected chains one after another very slowly&lt;br&gt;
B. To run multiple selected chains in parallel&lt;br&gt;
C. To save results in database&lt;br&gt;
D. To validate prompt variables&lt;/p&gt;

&lt;p&gt;Answer: B. To run multiple selected chains in parallel&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What does this line do?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;results = parallel_chain.invoke({"query": query})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A. Deletes the query&lt;br&gt;
B. Executes the chains using the given query input&lt;br&gt;
C. Stops the LLM&lt;br&gt;
D. Creates a new route&lt;/p&gt;

&lt;p&gt;Answer: B. Executes the chains using the given query input&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What is the main purpose of this loop?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for key, value in results.items():
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A. To create database tables&lt;br&gt;
B. To process each chain output one by one&lt;br&gt;
C. To remove invalid prompts&lt;br&gt;
D. To sort the JSON request&lt;/p&gt;

&lt;p&gt;Answer: B. To process each chain output one by one&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Why is this line used?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;content = value.content if hasattr(value, "content") else str(value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A. To check whether output has a content attribute and extract text safely&lt;br&gt;
B. To delete content from result&lt;br&gt;
C. To convert list into dictionary&lt;br&gt;
D. To validate selected chains&lt;/p&gt;

&lt;p&gt;Answer: A. To check whether output has a content attribute and extract text safely&lt;/p&gt;

&lt;p&gt;Extra Important Interview Questions From This Screenshot&lt;/p&gt;

&lt;p&gt;Here are some more commonly asked short questions you can revise:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why not call the model directly every time?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because direct model calls are fine for simple tasks, but chains are better for structured and reusable workflows.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Why use prompt templates instead of raw strings&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because prompt templates are dynamic, cleaner, and easier to reuse.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What happens if we do not use output parser?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We get a model response object like AIMessage, not just plain text.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;When is StrOutputParser very useful?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is useful when you want only final text for display, saving, or passing to another function.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why is chain more scalable?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because later you can add memory, retrievers, tools, parsers, and multiple steps easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  One-line easy revision
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LLM gives response

Prompt template formats input

Chain connects steps

StrOutputParser extracts plain text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>How to apply Persistent Login to Secure Sessions in Rust</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 06 Mar 2026 10:35:17 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/how-to-apply-persistent-login-to-secure-sessions-in-rust-32ga</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/how-to-apply-persistent-login-to-secure-sessions-in-rust-32ga</guid>
      <description>&lt;p&gt;Normally in web applications there are two types of login systems.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Session Login (Normal Login)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;User logs in → session cookie created → session stored in server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Problem&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If browser closes → session expires

If server restarts → session lost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User must login again&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Persistent Login (Remember Me)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Persistent login allows:&lt;/p&gt;

&lt;p&gt;User logs in → system stores secure token in database + cookie&lt;/p&gt;

&lt;p&gt;Even if:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;browser closes

session expires

server restarts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User can still be automatically logged in.&lt;/p&gt;

&lt;p&gt;So the purpose of persistent login is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Improve user experience

Reduce repeated login

Maintain security

Allow long-term authentication safely
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add security env vars&lt;/strong&gt;&lt;br&gt;
Add security env vars: SESSION_KEY, SESSION_TTL_HOURS, SESSION_SECURE_COOKIE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SESSION_KEY=replace-with-32-byte-random-secret
SESSION_TTL_HOURS=24
# In production behind HTTPS set true. Local HTTP dev can stay false.
SESSION_SECURE_COOKIE=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Read and validate those env vars into AppConfig fields:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;src/config.rs&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Read and validate those env vars into AppConfig fields:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;session_ttl_hours&lt;br&gt;
session_secure_cookie&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub session_ttl_hours: i64,
pub session_secure_cookie: bool,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let session_ttl_hours = env::var("SESSION_TTL_HOURS")
            .ok()
            .and_then(|v| v.parse::&amp;lt;i64&amp;gt;().ok())
            .filter(|v| *v &amp;gt; 0)
            .unwrap_or(24);

        // Keep local dev usable on HTTP, default secure in non-local environments.
        let inferred_local = bind_addr.contains("127.0.0.1") || bind_addr.contains("localhost");
        let session_secure_cookie = env::var("SESSION_SECURE_COOKIE")
            .ok()
            .map(|v| {
                let lower = v.trim().to_ascii_lowercase();
                lower == "1" || lower == "true" || lower == "yes" || lower == "on"
            })
            .unwrap_or(!inferred_local);

        Self {
            app_name,
            bind_addr,
            database_url,
            session_ttl_hours,
            session_secure_cookie,
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;full code&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use std::env;

#[derive(Clone, Debug)]
pub struct AppConfig {
    pub app_name: String,
    pub bind_addr: String,
    pub database_url: String,
    pub session_ttl_hours: i64,
    pub session_secure_cookie: bool,
}

impl AppConfig {
    pub fn from_env() -&amp;gt; Self {
        let app_name = env::var("APP_NAME").unwrap_or_else(|_| "Rust CRUD Dashboard".to_string());
        let bind_addr = env::var("APP_BIND").unwrap_or_else(|_| "127.0.0.1:8080".to_string());
        let database_url = env::var("DATABASE_URL")
            .unwrap_or_else(|_| "mysql://root:@127.0.0.1:3306/rust_crud".to_string());
        let session_ttl_hours = env::var("SESSION_TTL_HOURS")
            .ok()
            .and_then(|v| v.parse::&amp;lt;i64&amp;gt;().ok())
            .filter(|v| *v &amp;gt; 0)
            .unwrap_or(24);

        // Keep local dev usable on HTTP, default secure in non-local environments.
        let inferred_local = bind_addr.contains("127.0.0.1") || bind_addr.contains("localhost");
        let session_secure_cookie = env::var("SESSION_SECURE_COOKIE")
            .ok()
            .map(|v| {
                let lower = v.trim().to_ascii_lowercase();
                lower == "1" || lower == "true" || lower == "yes" || lower == "on"
            })
            .unwrap_or(!inferred_local);

        Self {
            app_name,
            bind_addr,
            database_url,
            session_ttl_hours,
            session_secure_cookie,
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Apply session middleware hardening:&lt;/strong&gt;&lt;br&gt;
Apply session middleware hardening:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;custom cookie name
cookie_secure(...)
cookie_http_only(true)
session_lifecycle(PersistentSession...session_ttl...)
safer SESSION_KEY handling (no fixed default secret)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;src/main.rs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Apply session middleware hardening:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;custom cookie name
cookie_secure(...)
cookie_http_only(true)
session_lifecycle(PersistentSession...session_ttl...)
safer SESSION_KEY handling (no fixed default secret)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      if valid {
            session.renew();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   if valid {
            session.renew();
            session
                .insert("username", user.username.clone())
                .map_err(error::ErrorInternalServerError)?;
            session
                .insert("user_id", user.id)
                .map_err(error::ErrorInternalServerError)?;
            session
                .insert("role", role.clone())
                .map_err(error::ErrorInternalServerError)?;
            println!("[login] session_set username={}", user.username);
            let response = ApiResponse {
                message: "Login successful".to_string(),
                data: AuthUser {
                    username: user.username,
                    role,
                },
            };
            return Ok(HttpResponse::Ok().json(response));
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;On successful login, call session.renew() before inserting session values to reduce session fixation&lt;/strong&gt; &lt;br&gt;
&lt;code&gt;src/handlers/auth.rs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use actix_session::{
    config::{PersistentSession, TtlExtensionPolicy},
    storage::CookieSessionStore,
    SessionMiddleware,
};
use actix_web::{
    cookie::{time::Duration, Key, SameSite},
    web, App, HttpServer,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    let session_key = std::env::var("SESSION_KEY").unwrap_or_else(|_| {
        eprintln!("[startup] SESSION_KEY is missing; generating ephemeral key for this process.");
        format!("{}{}", uuid::Uuid::new_v4(), uuid::Uuid::new_v4())
    });
    let mut session_key_bytes = session_key.into_bytes();
    if session_key_bytes.len() &amp;lt; 32 {
        session_key_bytes.resize(32, b'0');
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App::new()
            .app_data(state.clone())
            .wrap(cors)
            .wrap(
                SessionMiddleware::builder(CookieSessionStore::default(), key.clone())
                    .cookie_name("rust_crud_session".to_string())
                    .cookie_secure(cfg.session_secure_cookie)
                    .cookie_http_only(true)
                    .cookie_same_site(SameSite::Lax)
                    .session_lifecycle(
                        PersistentSession::default()
                            .session_ttl(Duration::hours(cfg.session_ttl_hours))
                            .session_ttl_extension_policy(TtlExtensionPolicy::OnEveryRequest),
                    )
                    .build(),
            )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;full code&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mod config;
mod db;
mod handlers;
mod layout;
mod middleware;
mod models;

use actix_cors::Cors;
use actix_files::Files;
use actix_session::{
    config::{PersistentSession, TtlExtensionPolicy},
    storage::CookieSessionStore,
    SessionMiddleware,
};
use actix_web::{
    cookie::{time::Duration, Key, SameSite},
    web, App, HttpServer,
};
use config::AppConfig;
use db::{init_pool, normalize_brand_model_rows, normalize_shop_rows, state_data, AppState};
use dotenvy::dotenv;

#[actix_web::main]
async fn main() -&amp;gt; std::io::Result&amp;lt;()&amp;gt; {
    dotenv().ok();
    std::fs::create_dir_all("uploads/brand_models")?;
    std::fs::create_dir_all("uploads/insurance")?;
    std::fs::create_dir_all("uploads/pollution")?;
    std::fs::create_dir_all("uploads/rc_document")?;
    let cfg = AppConfig::from_env();
    let pool = init_pool(&amp;amp;cfg.database_url)
        .await
        .expect("Database connection failed");
    if let Err(err) = normalize_brand_model_rows(&amp;amp;pool).await {
        eprintln!("[startup] normalize_brand_model_rows failed: {err}");
    }
    if let Err(err) = normalize_shop_rows(&amp;amp;pool).await {
        eprintln!("[startup] normalize_shop_rows failed: {err}");
    }

    let state = state_data(AppState {
        pool,
        app_name: cfg.app_name.clone(),
    });

    let session_key = std::env::var("SESSION_KEY").unwrap_or_else(|_| {
        eprintln!("[startup] SESSION_KEY is missing; generating ephemeral key for this process.");
        format!("{}{}", uuid::Uuid::new_v4(), uuid::Uuid::new_v4())
    });
    let mut session_key_bytes = session_key.into_bytes();
    if session_key_bytes.len() &amp;lt; 32 {
        session_key_bytes.resize(32, b'0');
    }
    let key = Key::derive_from(&amp;amp;session_key_bytes);

    HttpServer::new(move || {
        let cors = Cors::default()
            .allowed_origin("http://localhost:5173")
            .allowed_origin("http://127.0.0.1:5173")
            .allowed_origin("http://localhost:5174")
            .allowed_origin("http://127.0.0.1:5174")
            .allowed_origin("http://localhost:8080")
            .allowed_origin("http://127.0.0.1:8080")
            .allowed_origin("http://localhost:8081")
            .allowed_origin("http://127.0.0.1:8081")
            .allow_any_header()
            .allow_any_method()
            .supports_credentials();

        App::new()
            .app_data(state.clone())
            .wrap(cors)
            .wrap(
                SessionMiddleware::builder(CookieSessionStore::default(), key.clone())
                    .cookie_name("rust_crud_session".to_string())
                    .cookie_secure(cfg.session_secure_cookie)
                    .cookie_http_only(true)
                    .cookie_same_site(SameSite::Lax)
                    .session_lifecycle(
                        PersistentSession::default()
                            .session_ttl(Duration::hours(cfg.session_ttl_hours))
                            .session_ttl_extension_policy(TtlExtensionPolicy::OnEveryRequest),
                    )
                    .build(),
            )
            .service(
                web::scope("/api")
                    .route("/login", web::post().to(handlers::login))
                    .route("/logout", web::post().to(handlers::logout))
                    .route("/home/vehicles", web::get().to(handlers::list_home_vehicle_cards_handler))
                    .service(
                        web::scope("")
                            .wrap(middleware::AuthMiddleware)
                            .route("/me", web::get().to(handlers::me))
                            .route("/dashboard", web::get().to(handlers::dashboard))
                            .service(
                                web::scope("")
                                    .wrap(middleware::require_roles(&amp;amp;["user"]))
                                    .route("/shops", web::get().to(handlers::list_shops_handler))
                                    .route("/shops", web::post().to(handlers::create_shop_handler))
                                    .route("/shops/{id}", web::get().to(handlers::get_shop_handler))
                                    .route("/shops/{id}", web::put().to(handlers::update_shop_handler))
                                    .route("/shops/{id}", web::delete().to(handlers::delete_shop_handler))
                                    .route("/vehicles", web::get().to(handlers::list_vehicles_handler))
                                    .route("/vehicles", web::post().to(handlers::create_vehicle_handler))
                                    .route(
                                        "/vehicles/upload-documents",
                                        web::post().to(handlers::upload_vehicle_documents_handler),
                                    )
                                    .route(
                                        "/vehicles/upload-partner-image",
                                        web::post().to(handlers::upload_vehicle_partner_image_handler),
                                    )
                                    .route("/vehicles/{id}", web::get().to(handlers::get_vehicle_handler))
                                    .route("/vehicles/{id}", web::put().to(handlers::update_vehicle_handler))
                                    .route("/vehicles/{id}", web::delete().to(handlers::delete_vehicle_handler))
                                    .route("/bookings/offline", web::post().to(handlers::save_offline_booking_handler))
                                    .route("/brand-models", web::get().to(handlers::list_brand_models_handler))
                                    .route("/brand-models", web::post().to(handlers::create_brand_model_handler))
                                    .route(
                                        "/brand-models/upload-images",
                                        web::post().to(handlers::upload_brand_model_images_handler),
                                    )
                                    .route(
                                        "/brand-models/upload-images/",
                                        web::post().to(handlers::upload_brand_model_images_handler),
                                    )
                                    .route(
                                        "/brand-model/upload-images",
                                        web::post().to(handlers::upload_brand_model_images_handler),
                                    )
                                    .route("/brand-models/{id}", web::get().to(handlers::get_brand_model_handler))
                                    .route("/brand-models/{id}", web::put().to(handlers::update_brand_model_handler))
                                    .route("/brand-models/{id}", web::delete().to(handlers::delete_brand_model_handler)),
                            ),
                    ),
            )
            .service(Files::new("/uploads", "./uploads"))
    })
    .bind(cfg.bind_addr)?
    .run()
    .await
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let session_ttl_hours = env::var("SESSION_TTL_HOURS")
            .ok()
            .and_then(|v| v.parse::&amp;lt;i64&amp;gt;().ok())
            .filter(|v| *v &amp;gt; 0)
            .unwrap_or(24);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.debug.school/images/x9L0DAOTAJFOwYw_rnklOidt-5iiOu2IKAfbQ_2eqS0/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcW5xeTMw/bm10YjBhNDBqZHg5/OTAucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://www.debug.school/images/x9L0DAOTAJFOwYw_rnklOidt-5iiOu2IKAfbQ_2eqS0/rt:fit/w:800/g:sm/q:0/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvYXJ0/aWNsZXMvcW5xeTMw/bm10YjBhNDBqZHg5/OTAucG5n" alt=" " width="462" height="702"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;alternative way&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Same Logic in Beginner Style (Long Version)&lt;/p&gt;

&lt;p&gt;This is the same code written in a more beginner friendly style.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use std::env;

fn main() {

    let value = env::var("SESSION_TTL_HOURS");

    let session_ttl_hours = match value {

        Ok(v) =&amp;gt; {
            match v.parse::&amp;lt;i64&amp;gt;() {
                Ok(num) if num &amp;gt; 0 =&amp;gt; num,
                _ =&amp;gt; 24
            }
        }

        Err(_) =&amp;gt; 24
    };

    println!("Session TTL = {}", session_ttl_hours);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Output is the same.&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding the Two-Layer Architecture of Actix Middleware: Transform vs Service</title>
      <dc:creator>rakesh kumar</dc:creator>
      <pubDate>Fri, 06 Mar 2026 02:57:33 +0000</pubDate>
      <link>https://www.debug.school/rakeshdevcotocus_468/understanding-the-two-layer-architecture-of-actix-middleware-transform-vs-service-3go2</link>
      <guid>https://www.debug.school/rakeshdevcotocus_468/understanding-the-two-layer-architecture-of-actix-middleware-transform-vs-service-3go2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why do we need both Transform and Service?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Why Actix Middleware Has Two Layers&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Simple Real-World Analogy&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What Transform Does&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What Service Does&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Core Difference&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Visual Flow&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Now Actual Actix Middleware Example&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Step-by-Step Theory of the Code&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Simple Understanding of Left and Right Body&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What Happens at Runtime&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Objective and MCQ&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When developers start building custom middleware in Actix-Web, one concept creates the most confusion:&lt;/p&gt;
&lt;h2&gt;
  
  
  Why do we need both Transform and Service?
&lt;/h2&gt;

&lt;p&gt;At first, it feels like both are doing the same job. But in reality, they have different responsibilities.&lt;/p&gt;

&lt;p&gt;This is the core idea:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Transform&lt;/code&gt; creates the middleware&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Service&lt;/code&gt; runs the middleware logic for each request&lt;/p&gt;

&lt;p&gt;Once you understand this two-layer architecture, custom middleware becomes much easier.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Actix Middleware Has Two Layers
&lt;/h2&gt;

&lt;p&gt;Actix middleware is designed in a flexible and reusable way.&lt;/p&gt;

&lt;p&gt;A middleware must do two separate things:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 1: Build the middleware&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This happens when Actix sets up your app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 2: Process every incoming request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This happens every time a user calls an API route.&lt;/p&gt;

&lt;p&gt;Because these are two different jobs, Actix separates them into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transform

Service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Simple Real-World Analogy
&lt;/h2&gt;

&lt;p&gt;Think of a security system in an office.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transform&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is the company that installs the security gate.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Service&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is the security guard who checks every person entering.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;the gate is created once

the checking happens again and again for each visitor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is exactly how middleware works in Actix.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What Transform Does
&lt;/h2&gt;

&lt;p&gt;Transform is the middleware factory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Its job is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
receive the next inner service

wrap it

return a new middleware service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In simple words:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Transform prepares the middleware structure.&lt;/p&gt;

&lt;p&gt;It does not handle every request directly.&lt;/p&gt;

&lt;p&gt;Basic Theory of Transform&lt;/p&gt;

&lt;p&gt;When you use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
.wrap(AuthMiddleware)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actix calls Transform behind the scenes.&lt;/p&gt;

&lt;p&gt;It says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“Here is the inner service. Build a middleware around it.”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So Transform is like a constructor or factory.&lt;/p&gt;

&lt;p&gt;2.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Service Does
&lt;/h2&gt;

&lt;p&gt;Service is the real request processor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Its job is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;receive each request

inspect it

decide whether to block or allow

call the next service if allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In simple words:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Service contains the actual middleware logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is where you write code like:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;check session

check token

check role

log request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;measure response time&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Core Difference
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Transform&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runs when middleware is attached

creates the middleware wrapper

setup layer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Service&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runs on every request

executes middleware logic

runtime layer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Visual Flow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App Startup
   ↓
Transform runs
   ↓
Middleware service created
   ↓
-----------------------------
Each Client Request
   ↓
Service runs
   ↓
Check request
   ↓
Allow or block
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;A Very Simple Rust Example First&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before Actix, let us understand the idea using plain Rust thinking.&lt;/p&gt;

&lt;p&gt;Factory example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct GateFactory;

struct Gate;

impl GateFactory {
    fn build(&amp;amp;self) -&amp;gt; Gate {
        Gate
    }
}

impl Gate {
    fn check(&amp;amp;self, name: &amp;amp;str) {
        println!("Checking entry for {}", name);
    }
}

fn main() {
    let factory = GateFactory;
    let gate = factory.build();

    gate.check("Ashwani");
    gate.check("Ravi");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Checking entry for Ashwani
Checking entry for Ravi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GateFactory = like Transform

Gate = like Service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Factory creates the gate once.&lt;br&gt;
Gate checks people many times.&lt;/p&gt;

&lt;p&gt;That is the same idea as Actix middleware.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Now Actual Actix Middleware Example
&lt;/h2&gt;

&lt;p&gt;Below is a basic custom authentication middleware.&lt;/p&gt;

&lt;p&gt;It checks whether request contains header x-auth-token.&lt;/p&gt;

&lt;p&gt;If header is missing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return 401 Unauthorized
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If present:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;allow request to continue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Full Middleware Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use std::future::{ready, Ready};
use std::rc::Rc;

use actix_web::{
    body::{EitherBody, MessageBody},
    dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
    Error, HttpResponse,
};
use futures_util::future::LocalBoxFuture;

pub struct AuthMiddleware;

impl&amp;lt;S, B&amp;gt; Transform&amp;lt;S, ServiceRequest&amp;gt; for AuthMiddleware
where
    S: Service&amp;lt;ServiceRequest, Response = ServiceResponse&amp;lt;B&amp;gt;, Error = Error&amp;gt; + 'static,
    B: MessageBody + 'static,
{
    type Response = ServiceResponse&amp;lt;EitherBody&amp;lt;B&amp;gt;&amp;gt;;
    type Error = Error;
    type InitError = ();
    type Transform = AuthMiddlewareService&amp;lt;S&amp;gt;;
    type Future = Ready&amp;lt;Result&amp;lt;Self::Transform, Self::InitError&amp;gt;&amp;gt;;

    fn new_transform(&amp;amp;self, service: S) -&amp;gt; Self::Future {
        ready(Ok(AuthMiddlewareService {
            service: Rc::new(service),
        }))
    }
}

pub struct AuthMiddlewareService&amp;lt;S&amp;gt; {
    service: Rc&amp;lt;S&amp;gt;,
}

impl&amp;lt;S, B&amp;gt; Service&amp;lt;ServiceRequest&amp;gt; for AuthMiddlewareService&amp;lt;S&amp;gt;
where
    S: Service&amp;lt;ServiceRequest, Response = ServiceResponse&amp;lt;B&amp;gt;, Error = Error&amp;gt; + 'static,
    B: MessageBody + 'static,
{
    type Response = ServiceResponse&amp;lt;EitherBody&amp;lt;B&amp;gt;&amp;gt;;
    type Error = Error;
    type Future = LocalBoxFuture&amp;lt;'static, Result&amp;lt;Self::Response, Self::Error&amp;gt;&amp;gt;;

    forward_ready!(service);

    fn call(&amp;amp;self, req: ServiceRequest) -&amp;gt; Self::Future {
        let service = self.service.clone();

        Box::pin(async move {
            let has_token = req.headers().contains_key("x-auth-token");

            if !has_token {
                let response = HttpResponse::Unauthorized().body("Missing auth token");
                return Ok(req.into_response(response).map_into_right_body());
            }

            let response = service.call(req).await?;
            Ok(response.map_into_left_body())
        })
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step-by-Step Theory of the Code
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Part 1: Middleware marker struct&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub struct AuthMiddleware;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the middleware type you attach with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.wrap(AuthMiddleware)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This struct does not contain logic itself.&lt;br&gt;
It simply represents the middleware.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 2: Transform implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;impl&amp;lt;S, B&amp;gt; Transform&amp;lt;S, ServiceRequest&amp;gt; for AuthMiddleware
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means:&lt;/p&gt;

&lt;p&gt;AuthMiddleware can transform an inner service into a middleware-wrapped service.&lt;/p&gt;

&lt;p&gt;Here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
S = inner service

B = body type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Part 3: new_transform()&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn new_transform(&amp;amp;self, service: S) -&amp;gt; Self::Future {
    ready(Ok(AuthMiddlewareService {
        service: Rc::new(service),
    }))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the most important Transform function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it does&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;receives the inner service

wraps it inside AuthMiddlewareService

returns it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this is the creation layer.&lt;/p&gt;

&lt;p&gt;This happens when Actix builds the middleware pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 4: middleware service struct&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub struct AuthMiddlewareService&amp;lt;S&amp;gt; {
    service: Rc&amp;lt;S&amp;gt;,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This struct stores the inner service.&lt;/p&gt;

&lt;p&gt;After middleware check passes, request will be forwarded to this inner service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 5: Service implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;impl&amp;lt;S, B&amp;gt; Service&amp;lt;ServiceRequest&amp;gt; for AuthMiddlewareService&amp;lt;S&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means:&lt;/p&gt;

&lt;p&gt;AuthMiddlewareService behaves like a service that can process requests.&lt;/p&gt;

&lt;p&gt;This is the runtime layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 6: call() method&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn call(&amp;amp;self, req: ServiceRequest) -&amp;gt; Self::Future
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method runs on every request.&lt;/p&gt;

&lt;p&gt;This is where the actual middleware logic is written.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 7: request checking logic&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let has_token = req.headers().contains_key("x-auth-token");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Middleware checks whether request has authentication token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 8: block unauthorized request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if !has_token {
    let response = HttpResponse::Unauthorized().body("Missing auth token");
    return Ok(req.into_response(response).map_into_right_body());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;If token missing:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;middleware stops request&lt;/p&gt;

&lt;p&gt;returns 401 Unauthorized&lt;/p&gt;

&lt;p&gt;This is middleware-generated response.&lt;/p&gt;

&lt;p&gt;So it uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map_into_right_body()
Part 9: allow request to continue
let response = service.call(req).await?;
Ok(response.map_into_left_body())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;If token exists:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;middleware forwards request to inner service&lt;/p&gt;

&lt;p&gt;handler runs normally&lt;/p&gt;

&lt;p&gt;This is handler-generated response.&lt;/p&gt;

&lt;p&gt;So it uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map_into_left_body()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Simple Understanding of Left and Right Body
&lt;/h2&gt;

&lt;p&gt;In middleware there can be two response sources:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Left body&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Normal handler response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Right body&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Middleware custom response&lt;/p&gt;

&lt;p&gt;So remember:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map_into_left_body() = request allowed

map_into_right_body() = request blocked by middleware
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How to Use This Middleware in main.rs&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use actix_web::{web, App, HttpResponse, HttpServer, Responder};

mod auth_middleware;
use auth_middleware::AuthMiddleware;

async fn dashboard() -&amp;gt; impl Responder {
    HttpResponse::Ok().body("Welcome to dashboard")
}

#[actix_web::main]
async fn main() -&amp;gt; std::io::Result&amp;lt;()&amp;gt; {
    HttpServer::new(|| {
        App::new()
            .service(
                web::scope("/api")
                    .wrap(AuthMiddleware)
                    .route("/dashboard", web::get().to(dashboard))
            )
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What Happens at Runtime
&lt;/h2&gt;

&lt;p&gt;App startup&lt;/p&gt;

&lt;p&gt;When application starts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.wrap(AuthMiddleware)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actix triggers Transform.&lt;/p&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transform creates AuthMiddlewareService
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;middleware pipeline is prepared&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request 1: No token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User sends request without header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Middleware Service runs:&lt;/p&gt;

&lt;p&gt;checks header&lt;/p&gt;

&lt;p&gt;header missing&lt;/p&gt;

&lt;p&gt;returns 401&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Output&lt;/code&gt;&lt;br&gt;
Missing auth token&lt;br&gt;
&lt;strong&gt;Request 2: With token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User sends request with header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x-auth-token: abc123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Middleware Service runs:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;checks header

token exists

forwards request to handler

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Handler returns:&lt;/p&gt;

&lt;p&gt;Welcome to dashboard&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Output Summary&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Without token
Status: 401 Unauthorized
Body: Missing auth token
With token
Status: 200 OK
Body: Welcome to dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why Beginners Get Confused&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Many beginners think middleware is only one thing.&lt;/p&gt;

&lt;p&gt;They expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;one struct

one trait

one request handler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But Actix separates middleware into two levels:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Level 1: Creation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Handled by Transform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Level 2: Execution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Handled by Service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This design gives Actix great flexibility.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Interview-Style Answer&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If someone asks in interview:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is the difference between Transform and Service in Actix middleware?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can answer like this:&lt;/p&gt;

&lt;p&gt;In Actix custom middleware, Transform acts as a factory that creates the middleware wrapper around the inner service. It runs when the application pipeline is built. Service contains the actual middleware logic and runs on every incoming request. Transform is the setup layer, while Service is the execution layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objective and MCQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is the main purpose of middleware in Actix-web?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A. Handle database queries&lt;br&gt;
B. Intercept requests before they reach handlers&lt;br&gt;
C. Compile Rust code faster&lt;br&gt;
D. Replace HTTP responses&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
Middleware can inspect or reject requests before they reach handlers.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Middleware in Actix-web is typically implemented using which two traits&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Future and Async&lt;br&gt;
B. Transform and Service&lt;br&gt;
C. Handler and Request&lt;br&gt;
D. Router and Scope&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
Middleware is created using Transform (factory) and Service (execution) traits.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which Actix type represents an incoming HTTP request inside middleware?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. HttpRequest&lt;br&gt;
B. ServiceRequest&lt;br&gt;
C. RequestContext&lt;br&gt;
D. RequestBody&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
ServiceRequest contains the request data processed by middleware.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which type represents the response returned from middleware or handlers?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. HttpResponse&lt;br&gt;
B. ServiceResponse&lt;br&gt;
C. ResponseBody&lt;br&gt;
D. HandlerResponse&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
ServiceResponse wraps both request and response objects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What happens if middleware decides to block a request?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Request continues to handler&lt;br&gt;
B. Middleware returns its own HTTP response&lt;br&gt;
C. Server restarts&lt;br&gt;
D. Request is ignored&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
Middleware can stop processing and return an early response.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which HTTP response is commonly returned when authentication fails?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. 200 OK&lt;br&gt;
B. 401 Unauthorized&lt;br&gt;
C. 201 Created&lt;br&gt;
D. 302 Redirect&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which method in middleware processes each incoming request?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. execute()&lt;br&gt;
B. handle()&lt;br&gt;
C. call()&lt;br&gt;
D. run()&lt;/p&gt;

&lt;p&gt;✅ Answer: C&lt;br&gt;
The call() function is where request processing occurs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What does forward_ready! macro do in middleware&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Sends response to client&lt;br&gt;
B. Forwards readiness check to inner service&lt;br&gt;
C. Creates a request object&lt;br&gt;
D. Serializes JSON&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why does middleware often use generics like ?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. To support different services and response body types&lt;br&gt;
B. To reduce code size&lt;br&gt;
C. To store database values&lt;br&gt;
D. To handle logging&lt;/p&gt;

&lt;p&gt;✅ Answer: A&lt;br&gt;
Generics allow middleware to work with any service and body type.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What does S usually represent in middleware generic parameters?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Session object&lt;br&gt;
B. Inner service being wrapped&lt;br&gt;
C. Server configuration&lt;br&gt;
D. Security token&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which trait must response body type implement in Actix middleware?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Clone&lt;br&gt;
B. Serialize&lt;br&gt;
C. MessageBody&lt;br&gt;
D. Future&lt;/p&gt;

&lt;p&gt;✅ Answer: C&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What does the middleware authentication function typically check?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Database schema&lt;br&gt;
B. Request headers or session tokens&lt;br&gt;
C. Compiler version&lt;br&gt;
D. JSON parsing&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What architectural pattern describes middleware execution order?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. MVC pattern&lt;br&gt;
B. Onion / pipeline pattern&lt;br&gt;
C. Observer pattern&lt;br&gt;
D. Singleton pattern&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
Middleware layers wrap around handlers like an onion structure.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;In route protection middleware, what usually happens when the user is authenticated?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Request stops&lt;br&gt;
B. Middleware calls the inner service&lt;br&gt;
C. Server logs out user&lt;br&gt;
D. Database connection closes&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Which Actix function allows attaching middleware to an application&lt;/strong&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. attach()&lt;br&gt;
B. wrap()&lt;br&gt;
C. register()&lt;br&gt;
D. bind()&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
App::wrap() attaches middleware.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which type is commonly used to represent asynchronous middleware results?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Result&lt;br&gt;
B. LocalBoxFuture&lt;br&gt;
C. AsyncResponse&lt;br&gt;
D. FutureResult&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is the role of Transform trait in middleware?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Handle request execution&lt;br&gt;
B. Create middleware service instances&lt;br&gt;
C. Manage database connections&lt;br&gt;
D. Serialize responses&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which scenario is a common use case for route protection middleware?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Image processing&lt;br&gt;
B. Authentication and authorization&lt;br&gt;
C. File compression&lt;br&gt;
D. Code compilation&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which middleware logic is typically executed before the handler?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Response serialization&lt;br&gt;
B. Authentication check&lt;br&gt;
C. Database backup&lt;br&gt;
D. File upload&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What is the main advantage of middleware-based route protection?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A. Reduces database size&lt;br&gt;
B. Centralizes authentication logic&lt;br&gt;
C. Removes need for handlers&lt;br&gt;
D. Increases CPU usage&lt;/p&gt;

&lt;p&gt;✅ Answer: B&lt;br&gt;
Middleware centralizes authentication and security checks for multiple routes.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
