<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dinith Pamunuwatte on Medium]]></title>
        <description><![CDATA[Stories by Dinith Pamunuwatte on Medium]]></description>
        <link>https://medium.com/@dinithchamo?source=rss-b5901b61ef6a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mn-jJeS8Yp2QrdcfFT95iA.jpeg</url>
            <title>Stories by Dinith Pamunuwatte on Medium</title>
            <link>https://medium.com/@dinithchamo?source=rss-b5901b61ef6a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:07:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dinithchamo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Strengthening Web Application Security with OIDC and OWASP Top 10]]></title>
            <link>https://medium.com/@dinithchamo/strengthening-web-application-security-with-oidc-and-owasp-top-10-6789c2b346c0?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6789c2b346c0</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 09:04:13 GMT</pubDate>
            <atom:updated>2026-08-30T09:04:13.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QxOjtTNDf0Evimb3" /><figcaption>Photo by <a href="https://unsplash.com/@flyd2069?utm_source=medium&amp;utm_medium=referral">FlyD</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Building a web application is not only about making features work. It is also about ensuring that users, data, and application resources are protected against security threats.</p><p>As part of my <strong>Secure Web Application Development</strong> assessment, I worked on <strong>UniShowcase</strong>, a MERN-based web application developed using <strong>React, Node.js, Express, MongoDB, and Socket.io</strong>. The application provides Google-based authentication and functionality for managing and showcasing student projects.</p><p>For this assessment, I reviewed the existing application from a security perspective, identified vulnerabilities, implemented security improvements, and tested the fixes against relevant <strong>OWASP Top 10 risks</strong>.</p><h3>🔗 Project Links</h3><p><strong>Original Project — Main Branch</strong></p><p><a href="https://github.com/dinithanki/Uni-ShowCase/tree/main">UniShowcase — Main Branch</a></p><p><strong>Security Implementation — Assessment Branch</strong></p><p><a href="https://github.com/dinithanki/Uni-ShowCase/tree/assessment-2-security">UniShowcase — Assessment 2 Security Branch</a></p><p>The <strong>main branch</strong> represents the original application, while the <strong>assessment-2-security branch</strong> contains the security improvements implemented for this assessment.</p><h3>🔐 Google OIDC Authentication</h3><p>Authentication is an important part of the application’s security. UniShowcase uses <strong>Google OpenID Connect (OIDC)</strong> to authenticate users.</p><p>The simplified authentication flow is:</p><p><strong>Google Login → OIDC ID Token → Backend Validation → Application JWT → Protected APIs</strong></p><p>Google acts as the external Identity Provider. The backend validates the Google ID token before identifying the user. After successful authentication, the application generates its own JWT for protected API and Socket.io communication.</p><p>This ensures that the backend does not simply trust identity information provided by the frontend.</p><h3>🛡️ From Vulnerabilities to a More Secure Application</h3><p>Once authentication was in place, I looked at the application from a different perspective — <strong>not only as a developer using the system normally, but also as someone trying to misuse it.</strong></p><p>The security review uncovered weaknesses across authentication, authorization, configuration, APIs, input handling, and file uploads. The following improvements were implemented.</p><h3>🔐 Protecting Application Secrets</h3><p>Sensitive credentials related to <strong>MongoDB, JWT, Google, SMTP, and Cloudinary</strong> were found in local environment files.</p><p>The environment files were removed from the workspace and excluded from Git. Sensitive configuration is now supplied through environment variables, and the insecure hard-coded JWT fallback was removed.</p><p><strong>Result:</strong> Sensitive credentials are no longer stored directly in the application configuration.</p><h3>🔑 Strengthening JWT Authentication</h3><p>The application previously used a predictable fallback JWT secret when the real JWT_SECRET was unavailable.</p><p>The fallback was removed, and the backend now fails securely when the required secret is not configured.</p><p><strong>Result:</strong> Authentication no longer depends on an insecure default secret.</p><h3>👤 Preventing User Impersonation</h3><p>A significant issue was found in <strong>Socket.io</strong>. The frontend could provide a user ID when registering a socket connection, meaning the server was trusting the client to identify itself.</p><p>The socket authentication flow was changed so that the backend verifies the JWT and derives the user’s identity from the verified authentication information.</p><p><strong>Result:</strong> A client can no longer simply claim another user’s identity.</p><h3>🚫 Fixing Broken Access Control and IDOR</h3><p>The review found that unauthorized users could potentially attempt to modify projects they did not own.</p><p>Backend ownership and role checks were added to ensure that users can only perform actions they are authorized to perform.</p><p><strong>Result:</strong> Knowing a project ID is no longer enough to modify it.</p><h3>🔒 Protecting Private Projects</h3><p>Private projects could previously be accessed by unauthorized users who knew the project ID.</p><p>Access was restricted so that private projects can only be accessed by the <strong>project owner or an Admin</strong>.</p><p><strong>Result:</strong> Private project information is now protected by backend authorization.</p><h3>🎟️ Securing Invitation Tokens</h3><p>Invitation tokens were not sufficiently tied to the Google account completing the registration and could potentially be reused.</p><p>The system was updated to match invitations with the <strong>verified Google email</strong>, allow only pending invitations, and prevent completed invitations from being reused.</p><p><strong>Result:</strong> Invalid, mismatched, and reused invitations are rejected.</p><h3>🌐 Restricting CORS</h3><p>The original CORS configuration accepted broad *.vercel.app origins.</p><p>This was replaced with an explicit allowlist of trusted frontend origins, applied to both HTTP and Socket.io connections.</p><p><strong>Result:</strong> Only approved application origins can communicate with the backend.</p><h3>⚠️ Reducing Information Disclosure</h3><p>Internal server errors could previously expose implementation details to clients.</p><p>Centralized error handling was introduced so detailed errors are logged on the server while clients receive safe and controlled responses.</p><p><strong>Result:</strong> Internal application and database information is no longer unnecessarily exposed.</p><h3>📝 Strengthening Input Validation</h3><p>Search values were being used directly in MongoDB regular expressions, pagination was unbounded, and some ObjectIds were not validated.</p><p>The application was improved with:</p><ul><li>Regex escaping</li><li>Search-length limits</li><li>Pagination limits</li><li>ObjectId validation</li><li>Role validation</li></ul><p><strong>Result:</strong> Unexpected and potentially malicious input is rejected or safely processed.</p><h3>🛡️ Adding Security Headers and Rate Limiting</h3><p>The backend initially lacked security headers and request-rate controls.</p><p><strong>Helmet</strong> was added for security headers, together with rate limits for general API and authentication requests.</p><p><strong>Result:</strong> The application now has an additional layer of protection against automated abuse and common web threats.</p><h3>📁 Making File Uploads Safer</h3><p>An image extension does not necessarily mean a file is really an image.</p><p>Instead of trusting only client-provided MIME types, the application now checks <strong>file signatures</strong>, restricts supported image formats, sanitizes filenames, and forces Cloudinary to process uploads as images.</p><p><strong>Result:</strong> Simply renaming an unsafe file as .jpg is no longer sufficient to bypass validation.</p><h3>📦 Updating Vulnerable Dependencies</h3><p>Security problems do not always come from our own code. Third-party packages can introduce vulnerabilities too.</p><p>The frontend and backend dependencies were audited and updated.</p><p><strong>Final result:</strong></p><p><strong>Frontend — 0 vulnerabilities</strong><br><strong>Backend — 0 vulnerabilities</strong></p><h3>🧪 Security Testing</h3><p>Fixing the code was only part of the process. I also tested the implemented security controls.</p><p>Testing covered:</p><ul><li>JWT authentication and validation</li><li>Socket.io authentication</li><li>Access control and IDOR protection</li><li>CORS restrictions</li><li>Input validation</li><li>Security headers</li><li>Rate limiting</li><li>File upload validation</li><li>Error handling</li><li>Dependency vulnerabilities</li><li>Frontend production build</li><li>Backend validation</li></ul><p>For example, unauthorized project actions are rejected with <strong>403 Forbidden</strong>, excessive authentication requests reach <strong>429 Too Many Requests</strong>, and untrusted CORS origins are rejected.</p><p>SQL Injection, XSS, and CSRF were also reviewed. No confirmed SQL Injection or direct cookie-based CSRF vulnerability was identified. No confirmed React XSS sink was found, although HTML email content remains an area for additional hardening.</p><h3>💡 What I Learned</h3><p>The biggest lesson from this assessment was that <strong>security is not a single feature behind the login button</strong>.</p><p>It is a chain.</p><p>Google OIDC helps establish identity. JWTs protect authenticated communication. Authorization determines what users can access. Input validation protects application logic, while secure configuration and dependency management protect the application itself.</p><p>A weakness in any one of these areas can affect the security of the entire application.</p><blockquote><strong><em>Never trust the client. Authenticate the user, authorize the action, validate the input, and verify the result.</em></strong></blockquote><h3>🚀 Conclusion</h3><p>Securing UniShowcase gave me practical experience applying <strong>Google OIDC, JWT security, OWASP Top 10 principles, access control, secure API development, and security testing</strong> to a real MERN application.</p><p>The assessment demonstrated that secure development is not simply about preventing users from logging in incorrectly. It is about making sure that <strong>every request, identity, input, and action is properly verified</strong>.</p><p>Most importantly, I learned that security should be considered throughout the development lifecycle — from authentication and authorization to testing and deployment — rather than being treated as a final step.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6789c2b346c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Logging and Monitoring Matter in Cloud Deployments]]></title>
            <link>https://medium.com/@dinithchamo/why-logging-and-monitoring-matter-in-cloud-deployments-0dae3e17eafc?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0dae3e17eafc</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[logging-and-monitoring]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Sat, 18 Jul 2026 06:41:01 GMT</pubDate>
            <atom:updated>2026-07-18T06:41:01.476Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtOOZ_7pkRi95UpQJr_5JA.png" /></figure><p>Deploying an application to the cloud is an important milestone, but maintaining its reliability is just as important. Logging and monitoring help you detect issues early, track application performance, and ensure a smooth experience for your users.</p><h3>What is Logging?</h3><p>Logging is the process of recording events that happen inside an application or server. These records, called <strong>logs</strong>, help developers understand what the application is doing.</p><p>For example, logs can show:</p><ul><li>User login attempts</li><li>API requests and responses</li><li>Error messages</li><li>Database queries</li><li>System events</li></ul><p>If an application crashes or a user reports an issue, logs provide the information needed to investigate and find the root cause.</p><h3>What is Monitoring?</h3><p>Monitoring is the process of continuously checking the health and performance of an application or infrastructure.</p><p>Instead of recording events, monitoring collects metrics such as:</p><ul><li>CPU usage</li><li>Memory usage</li><li>Disk space</li><li>Response time</li><li>Error rate</li><li>Network traffic</li></ul><p>These metrics help teams understand whether the application is healthy and performing as expected.</p><h3>Why Are They Important?</h3><p><strong>Logging</strong> and <strong>monitoring</strong> work together to keep cloud applications reliable. <strong>Monitoring</strong> alerts you when something goes wrong, while <strong>logging</strong> provides the details needed to identify and fix the root cause. Together, they help ensure better performance, faster troubleshooting, and a more stable application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*hFgtzg9ll4mt-kUGfKKIUw.png" /></figure><p>Some key benefits include:</p><ul><li><strong>Faster troubleshooting</strong> by identifying errors quickly.</li><li><strong>Better performance</strong> by tracking resource usage.</li><li><strong>Early issue detection</strong> through alerts before users are affected.</li><li><strong>Improved reliability</strong> by continuously monitoring application health.</li><li><strong>Enhanced security</strong> by recording login attempts and suspicious activities.</li></ul><h3>Common Tools</h3><p>Many organizations use popular tools to collect logs and monitor applications, including:</p><ul><li>Prometheus</li><li>Grafana</li><li>Elasticsearch</li><li>Kibana</li><li>Grafana Loki</li><li>AWS CloudWatch</li></ul><p>These tools help visualize system performance, search logs, and send alerts when problems occur.</p><h3>Conclusion</h3><blockquote>Logging and monitoring are essential for every cloud application. They help detect issues early, troubleshoot problems faster, and keep applications reliable. Whether you’re managing a small web app or a large microservices platform, using logging and monitoring is a best practice that improves performance and delivers a better user experience.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0dae3e17eafc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple Real-Time Chat Application Using Socket.IO]]></title>
            <link>https://medium.com/@dinithchamo/building-a-simple-real-time-chat-application-using-socket-io-bb67c5829738?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb67c5829738</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Fri, 05 Jun 2026 09:26:00 GMT</pubDate>
            <atom:updated>2026-06-05T09:26:00.745Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VxppyRxAmR8lNdsW" /><figcaption>Photo by <a href="https://unsplash.com/@akurakuu?utm_source=medium&amp;utm_medium=referral">kuu akura</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>In this article, we will build a simple real-time chat application using Socket.IO.</p><p>The application will allow users to:</p><ul><li>Send messages</li><li>Receive messages instantly</li><li>See updates without refreshing the page</li></ul><h4>Step 1: Install Dependencies</h4><p>Initialize the project and install required packages:</p><pre>npm init -y<br>npm install express socket.io</pre><h4>Step 2 Project Structure</h4><pre>project-folder/<br>│<br>├── server.js<br>└── public/<br>    └── index.html</pre><h3><strong>Backend (Server Side)</strong></h3><h4>Step 3 Create server.js</h4><p>This server handles real-time communication.</p><pre>const express = require(&quot;express&quot;);<br>const http = require(&quot;http&quot;);<br>const { Server } = require(&quot;socket.io&quot;);<br><br>const app = express();<br>const server = http.createServer(app);<br>const io = new Server(server);<br><br>// Serve frontend files<br>app.use(express.static(&quot;public&quot;));<br><br>// When a user connects<br>io.on(&quot;connection&quot;, (socket) =&gt; {<br>    console.log(&quot;User connected&quot;);<br><br>    // Receive message from client<br>    socket.on(&quot;msg&quot;, (data) =&gt; {<br>        console.log(&quot;Message received:&quot;, data);<br><br>        // Send message to all users<br>        io.emit(&quot;msg&quot;, data);<br>    });<br><br>    // When user disconnects<br>    socket.on(&quot;disconnect&quot;, () =&gt; {<br>        console.log(&quot;User disconnected&quot;);<br>    });<br>});<br><br>// Start server<br>server.listen(3000, () =&gt; {<br>    console.log(&quot;Server running on http://localhost:3000&quot;);<br>});</pre><h3>Frontend (Client Side)</h3><h4>Step 4 Create public/index.html</h4><p>This is the user interface.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Socket.IO Chat App&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br><br>&lt;h2&gt;Real Time Chat Application&lt;/h2&gt;<br><br>&lt;input id=&quot;text&quot; placeholder=&quot;Enter message&quot; /&gt;<br>&lt;button onclick=&quot;send()&quot;&gt;Send&lt;/button&gt;<br><br>&lt;ul id=&quot;list&quot;&gt;&lt;/ul&gt;<br><br>&lt;!-- Socket.IO client --&gt;<br>&lt;script src=&quot;/socket.io/socket.io.js&quot;&gt;&lt;/script&gt;<br><br>&lt;script&gt;<br>    // Connect to server<br>    const socket = io();<br><br>    // Receive messages from server<br>    socket.on(&quot;msg&quot;, (data) =&gt; {<br>        const li = document.createElement(&quot;li&quot;);<br>        li.innerText = data;<br>        document.getElementById(&quot;list&quot;).appendChild(li);<br>    });<br><br>    // Send message to server<br>    function send() {<br>        const value = document.getElementById(&quot;text&quot;).value;<br>        socket.emit(&quot;msg&quot;, value);<br>    }<br>&lt;/script&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Run the Project</h3><h3>Step 5 Start Server</h3><pre>node server.js</pre><p>Open in browser:</p><pre>http://localhost:3000</pre><h3>What Happens Behind the Scenes</h3><p>Here is what is actually happening:</p><h4>1. Connection is created</h4><p>When you open the page:</p><ul><li>Socket.IO creates a live connection between browser and server</li></ul><h4>2. Sending a message</h4><p>When you type and send a message:</p><ul><li>Browser sends data to server using Socket.IO</li></ul><h4>3. Server receives it</h4><p>Server listens for messages:</p><ul><li>It catches the message instantly</li></ul><h4>4. Server broadcasts it</h4><p>Server sends the message to all connected users:</p><ul><li>This is called broadcasting</li></ul><h4>5. Everyone sees it instantly</h4><p>All clients receive the message without refreshing the page</p><h3>Key Socket.IO Concepts</h3><h4>emit (Send data)</h4><p>Used to send data from client or server.</p><pre>socket.emit(&quot;msg&quot;, data);</pre><h4>on (Receive data)</h4><p>Used to listen for incoming data.</p><pre>socket.on(&quot;msg&quot;, (data) =&gt; {<br>    console.log(data);<br>});</pre><h4>io.emit (Broadcast)</h4><p>Send data to all connected users.</p><pre>io.emit(&quot;msg&quot;, data);</pre><h3>Why This is Powerful</h3><p>Socket.IO is powerful because it:</p><ul><li>Removes page refresh</li><li>Enables instant communication</li><li>Works across all users in real-time</li><li>Makes web apps interactive</li></ul><p>This is the foundation of modern applications like:</p><ul><li>Chat apps</li><li>Gaming systems</li><li>Live dashboards</li><li>Collaboration tools</li></ul><blockquote><strong>Conclusion</strong></blockquote><blockquote>You have now built a working real-time chat application and also understood how it works internally. Socket.IO transforms normal web applications into live systems where data flows instantly between users. Once you understand this concept, you can extend it to build advanced applications such as WhatsApp-style chat systems, multiplayer games, and live tracking systems.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb67c5829738" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Socket.IO A Simple Guide to Real Time Web Applications]]></title>
            <link>https://medium.com/@dinithchamo/learn-socket-io-a-simple-guide-to-real-time-web-applications-4368d607814b?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4368d607814b</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Tue, 02 Jun 2026 19:36:01 GMT</pubDate>
            <atom:updated>2026-06-02T19:36:01.363Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8k8T2chDm1m5TqUYZO20wQ.png" /></figure><blockquote><strong>What is Socket.IO?</strong></blockquote><blockquote>Socket.IO is a JavaScript library that enables real-time, bidirectional communication between a client (browser) and a server.</blockquote><blockquote>In simple terms, it allows data to be sent and received instantly without refreshing the page.</blockquote><p><strong>This makes it ideal for applications such as:</strong></p><ul><li>Chat applications</li><li>Live notifications</li><li>Multiplayer games</li><li>Real-time dashboards</li></ul><h3>Traditional Web vs Real-Time Web</h3><h4>Traditional Web (HTTP Model)</h4><p>In a traditional web application:</p><ul><li>The client sends a request to the server</li><li>The server responds</li><li>The connection closes</li></ul><p>This model is not suitable for real-time updates because the client must continuously refresh or request new data.</p><h4>Real-Time Web (Socket.IO Model)</h4><p>With Socket.IO:</p><ul><li>A persistent connection is established between client and server</li><li>Both sides can send data at any time</li></ul><p>This enables instant updates without refreshing the page.</p><h3>How Socket.IO Works</h3><p>Socket.IO maintains a continuous connection between:</p><ul><li>Client (browser)</li><li>Server (Node.js backend)</li></ul><p>Once connected, both sides can exchange messages instantly.</p><h3>Core Concepts</h3><h4>Socket</h4><p>A socket is a persistent connection between client and server.</p><h4>Emit (Sending Data)</h4><p>Used to send data from one side to another.</p><pre>socket.emit(&quot;message&quot;, &quot;Hello&quot;);</pre><h4>On (Receiving Data)</h4><p>Used to listen and receive data.</p><pre>socket.on(&quot;message&quot;, (data) =&gt; {<br>  console.log(data);<br>});</pre><h3>Why Socket.IO is Used</h3><p>Socket.IO is widely used because it provides:</p><ul><li>Real-time communication</li><li>Persistent connections</li><li>Simple event-based structure</li><li>Cross-platform support</li></ul><h3>Common Use Cases</h3><ul><li>Real-time chat systems</li><li>Live sports updates</li><li>Collaborative tools</li><li>Online multiplayer games</li><li>Real-time tracking systems</li></ul><blockquote>Summary</blockquote><blockquote>Socket.IO allows developers to build real-time applications by enabling continuous communication between client and server.</blockquote><blockquote>It transforms traditional request-response applications into interactive, live systems.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4368d607814b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Chose Zustand Instead of Redux for My E-Commerce Application]]></title>
            <link>https://medium.com/@dinithchamo/why-i-chose-zustand-instead-of-redux-for-my-e-commerce-application-d58a44e06f6a?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d58a44e06f6a</guid>
            <category><![CDATA[redux-vs-zustand]]></category>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Fri, 08 May 2026 23:36:00 GMT</pubDate>
            <atom:updated>2026-05-08T23:36:00.427Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5SIk0fot6vlqmQBI" /><figcaption>Photo by <a href="https://unsplash.com/@lautaroandreani?utm_source=medium&amp;utm_medium=referral">Lautaro Andreani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When building my e-commerce application, one of the biggest decisions was choosing a state management library. At first, I considered Redux because it is one of the most popular solutions in the React ecosystem. However, after researching and experimenting with both libraries, I decided to use Zustand instead.</p><h3>1. Simpler Setup</h3><p>Redux requires a lot of setup:</p><ul><li>Actions</li><li>Reducers</li><li>Dispatch functions</li><li>Store configuration</li></ul><p>For a beginner-friendly and fast-moving project like my e-commerce application, this felt too complex.</p><p>Zustand, on the other hand, allows me to create a global store with just a few lines of code. The learning curve is much smaller, and development becomes faster.</p><h3>2. Less Boilerplate Code</h3><p>One thing I really disliked about Redux was the amount of repetitive code.</p><p>With Zustand:</p><ul><li>No reducers</li><li>No action types</li><li>No dispatching</li></ul><p>This keeps my project cleaner and easier to maintain.</p><p>Example:</p><pre>const useCartStore = create((set) =&gt; ({<br>  cart: [],<br>  addToCart: (product) =&gt;<br>    set((state) =&gt; ({<br>      cart: [...state.cart, product],<br>    })),<br>}))</pre><p>This simple structure was enough for managing my cart system.</p><h3>3. Better Developer Experience</h3><p>As a software engineering student, I prefer tools that help me focus more on building features instead of writing configuration files.</p><p>Zustand feels very natural because it works like a React hook. I can access global state anywhere in my application without complicated patterns.</p><p>This improved my productivity during development.</p><h3>4. Perfect for Small and Medium Projects</h3><p>Redux is powerful, especially for very large enterprise applications. But my e-commerce project does not require extremely complex state management.</p><p>Zustand provides everything I need:</p><ul><li>Cart management</li><li>Authentication state</li><li>Product filtering</li><li>Wishlist handling</li><li>User data management</li></ul><p>Without unnecessary complexity.</p><h3>5. Better Performance</h3><p>Zustand is lightweight and optimized. Components only re-render when the specific state they use changes.</p><p>This helps improve performance in an e-commerce application where many components update frequently.</p><h3>6. Easier to Learn and Maintain</h3><p>If another developer joins my project later, understanding Zustand will be much easier compared to Redux.</p><p>The codebase stays cleaner, smaller, and more readable.</p><blockquote><strong>Final Thoughts</strong></blockquote><blockquote>Redux is still an excellent library and widely used in large-scale applications. However, for my e-commerce project, Zustand was the better choice because it is:</blockquote><blockquote>Simple</blockquote><blockquote>Lightweight</blockquote><blockquote>Fast</blockquote><blockquote>Easy to maintain</blockquote><blockquote>Beginner friendly</blockquote><blockquote>Choosing the right tool depends on the project requirements. For my case, Zustand allowed me to focus more on building the application instead of managing complex state architecture.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d58a44e06f6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is JWT? A Beginner-Friendly Explanation]]></title>
            <link>https://medium.com/@dinithchamo/what-is-jwt-a-beginner-friendly-explanation-ae5613ca2d37?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae5613ca2d37</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Thu, 07 May 2026 22:26:28 GMT</pubDate>
            <atom:updated>2026-05-07T22:26:28.297Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>If you are learning web development, backend development, or authentication systems, you have probably heard the term <strong>JWT</strong> many times.</blockquote><blockquote>At first, JWT can sound confusing and complicated. But the idea behind it is actually very simple.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f7HpZWlQ48fheAJr" /><figcaption>Photo by <a href="https://unsplash.com/@flyd2069?utm_source=medium&amp;utm_medium=referral">FlyD</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>In this article, I’ll explain:</strong></h3><blockquote>What JWT is</blockquote><blockquote>Why we use it</blockquote><blockquote>How it works</blockquote><blockquote>Where we store it</blockquote><blockquote>Why it’s important in modern web applications</blockquote><h3>What is JWT?</h3><p>JWT stands for <strong>JSON Web Token</strong>.</p><p>It is a secure way to identify users between the frontend and backend after login.</p><p>Think of JWT like a digital identity card.</p><p>When a user logs in successfully:</p><ol><li>The server checks the username and password</li><li>The server creates a JWT token</li><li>The token is sent to the user</li><li>The user sends that token with future requests</li></ol><p>Instead of logging in again and again, the token proves the user’s identity.</p><h3>Simple Real-World Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fM-tqFwu42gGUWtS" /><figcaption>Photo by <a href="https://unsplash.com/@lifesimplyrocks?utm_source=medium&amp;utm_medium=referral">lifesimply.rocks</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine going to a concert.</p><p>At the entrance:</p><ul><li>You buy a ticket</li><li>They give you a wristband</li></ul><p>Now, every time you enter a section, security checks your wristband instead of asking for your payment receipt again.</p><p>JWT works the same way.</p><p>The wristband = JWT token.</p><h3>Why Do We Use JWT?</h3><p>Without JWT:</p><ul><li>Users would need to send username and password for every request</li><li>The server would constantly check the database</li><li>Authentication becomes slower</li></ul><p>With JWT:</p><ul><li>User logs in once</li><li>Server gives a token</li><li>User sends the token in future requests</li><li>Server verifies the token instantly</li></ul><p>This makes applications:</p><ul><li>Faster</li><li>More scalable</li><li>Better for APIs</li><li>Perfect for React, mobile apps, and modern web applications</li></ul><h3>Structure of a JWT</h3><p>A JWT has 3 parts:</p><pre>HEADER.PAYLOAD.SIGNATURE</pre><p>Example:</p><pre>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...</pre><h3>1. Header</h3><p>The header contains information about the token type and encryption algorithm.</p><p>Example:</p><pre>{<br>  &quot;alg&quot;: &quot;HS256&quot;,<br>  &quot;typ&quot;: &quot;JWT&quot;<br>}</pre><h3>2. Payload</h3><p>The payload contains user information.</p><p>Example:</p><pre>{<br>  &quot;id&quot;: &quot;123&quot;,<br>  &quot;name&quot;: &quot;Dinith&quot;,<br>  &quot;role&quot;: &quot;admin&quot;<br>}</pre><p>Important:<br>Never store passwords inside a JWT payload.</p><h3>3. Signature</h3><p>The signature is used to verify that the token was not modified.</p><p>The backend creates the signature using a secret key.</p><p>If someone changes the payload manually, the signature becomes invalid.</p><p>This helps protect the token from tampering.</p><h3>How JWT Authentication Works</h3><p>Here is the basic flow:</p><pre>User Login<br>    ↓<br>Backend Verifies Credentials<br>    ↓<br>JWT Token Generated<br>    ↓<br>Frontend Stores Token<br>    ↓<br>Frontend Sends Token in Requests<br>    ↓<br>Backend Verifies Token<br>    ↓<br>Access Granted</pre><h3>Where Can We Store JWT?</h3><p>There are several common ways to store JWT tokens.</p><h3>1. HttpOnly Cookies (Most Secure)</h3><p>The backend stores the token inside a secure cookie.</p><p>Advantages:</p><ul><li>Better security</li><li>Protected from JavaScript attacks</li><li>Common in production applications</li></ul><h3>2. Local Storage</h3><p>Frontend stores the token manually.</p><p>Example:</p><pre>localStorage.setItem(&quot;token&quot;, token);</pre><p>Advantages:</p><ul><li>Easy to implement</li><li>Popular for beginner projects</li></ul><p>Disadvantages:</p><ul><li>Vulnerable to XSS attacks</li></ul><h3>3. Session Storage</h3><p>Similar to localStorage, but the token disappears when the browser tab closes.</p><h3>JWT in React and Node.js</h3><p>Frontend sends the token:</p><pre>fetch(&quot;/profile&quot;, {<br>  headers: {<br>    Authorization: `Bearer ${token}`<br>  }<br>});</pre><p>Backend verifies the token:</p><pre>jwt.verify(token, SECRET_KEY);</pre><h3>Why JWT is Popular</h3><p>JWT is widely used because:</p><ul><li>It works well with REST APIs</li><li>It supports frontend-backend separation</li><li>It’s scalable</li><li>It’s lightweight</li><li>It’s perfect for MERN stack applications</li></ul><p>Today, JWT is commonly used in:</p><ul><li>React applications</li><li>Mobile apps</li><li>Multiplayer games</li><li>SaaS platforms</li><li>Modern backend APIs</li></ul><h3>Security Tips</h3><p>Always remember:</p><ul><li>Never store passwords inside JWT</li><li>Always verify JWT on the backend</li><li>Use strong secret keys</li><li>Set expiration times</li><li>Use HTTPS in production</li></ul><p>Example:</p><pre>jwt.sign(data, secret, {<br>  expiresIn: &quot;7d&quot;<br>});</pre><blockquote><strong>Final Thoughts</strong></blockquote><blockquote>JWT is one of the most important concepts in modern web development.</blockquote><blockquote>At first it may seem complicated, but the core idea is simple:</blockquote><blockquote>User logs in</blockquote><blockquote>Server creates a token</blockquote><blockquote>Token proves the user’s identity</blockquote><blockquote>Once you understand JWT, authentication systems become much easier to build.</blockquote><blockquote>If you are learning React, Node.js, APIs, or the MERN stack, JWT is definitely a technology you should understand well.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae5613ca2d37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supercapacitor–Battery Hybrid PV System for Off-Grid Applications]]></title>
            <link>https://medium.com/@dinithchamo/supercapacitor-battery-hybrid-pv-system-for-off-grid-applications-45b45c57ccbe?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/45b45c57ccbe</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 13:10:04 GMT</pubDate>
            <atom:updated>2025-12-26T13:10:04.155Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Paper ID:</strong> 16</p><h3>Authors</h3><p>Amaraweera T.F.P.<br>Premasiri R.M.H.D.<br>Piyumal P.L.K.<br>Ranaveera A.A.K.</p><p><em>Department of Physics and Electronics, University of Kelaniya</em></p><h3>Introduction</h3><p>Off-grid photovoltaic (PV) systems play an important role in providing sustainable electricity to rural and remote areas where grid access is limited. However, one major drawback of PV systems is their dependence on sunlight, which causes power fluctuations due to changing weather conditions. These fluctuations reduce system reliability and efficiency.</p><p>To overcome this issue, the researchers propose a <strong>hybrid energy storage system</strong> that combines <strong>supercapacitors (SCs)</strong>with <strong>lithium-ion batteries</strong>. This hybrid approach aims to improve energy stability by integrating the fast response of supercapacitors with the long-term storage capability of batteries.</p><h3>Research Objective</h3><p>The main objective of this research is to <strong>design, implement, and evaluate a hybrid PV system</strong> that uses both supercapacitors and batteries to enhance:</p><ul><li>Power stability</li><li>System reliability</li><li>Overall efficiency</li></ul><p>This evaluation is carried out under different operating conditions commonly found in off-grid environments.</p><h3>Methodology</h3><p>A <strong>laboratory-scale hybrid photovoltaic prototype</strong> was developed to test system performance. The system was operated using <strong>six manually switchable modes</strong>, depending on the availability of solar power and load demand.</p><h3>Operating Modes:</h3><blockquote>Mode 1: PV array powers the load</blockquote><blockquote>Mode 2: PV array powers the load and charges the supercapacitor bank</blockquote><blockquote>Mode 3: PV array powers the load and charges the battery</blockquote><blockquote>Mode 4: Both PV array and supercapacitor bank power the load</blockquote><blockquote>Mode 5: Both PV array and battery power the load</blockquote><blockquote>Mode 6: Load is powered only by the battery</blockquote><p>A block diagram was used to illustrate how energy flows between the PV array, supercapacitors, battery, and load.</p><h3>Results</h3><p>The results obtained from different operating modes clearly show performance variations. Graphical analysis indicates that:</p><ul><li>Modes using <strong>supercapacitors</strong> responded quickly to sudden power changes</li><li>Battery-only operation provided steady but slower energy delivery</li></ul><p>The hybrid configuration effectively handled both <strong>short-term power fluctuations</strong> and <strong>long-term energy needs</strong>.</p><h3>Discussion and Conclusion</h3><p>The hybrid PV system demonstrated improved efficiency by combining the strengths of supercapacitors and lithium-ion batteries. Key findings include:</p><ul><li>Supercapacitors provided rapid charge–discharge support during transient conditions</li><li>Batteries ensured continuous and stable power delivery</li><li>The hybrid system reduced stress on individual storage units</li><li>Load stability and overall system reliability were significantly improved compared to single-storage systems</li></ul><p>This research confirms that hybrid energy storage systems are well-suited for off-grid solar applications.</p><h3>Future Work</h3><p>The authors suggest several improvements for future research:</p><ul><li>Implement <strong>automated switching</strong> and <strong>MPPT (Maximum Power Point Tracking)</strong> control</li><li>Conduct long-term field testing under real environmental conditions</li><li>Perform scalability studies for larger load capacities</li></ul><h3>Acknowledgement</h3><p>The authors acknowledge the support of the <strong>Department of Physics and Electronics, University of Kelaniya</strong>, and express gratitude to project supervisors and laboratory staff for their guidance and assistance.</p><h3>Images from the Exhibition</h3><p><em>(Poster image captured at URSIE 2025 — Faculty of Science, University of Kelaniya)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*FI-igkE3uT_KKHXPvcAnyg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45b45c57ccbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ I Built a Simple OS in Assembly:]]></title>
            <link>https://medium.com/@dinithchamo/i-built-a-simple-os-in-assembly-29e8362faceb?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/29e8362faceb</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Wed, 25 Jun 2025 12:02:10 GMT</pubDate>
            <atom:updated>2025-06-25T12:02:10.717Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j08pM6OkBUhZljlp" /><figcaption>Photo by <a href="https://unsplash.com/@6heinz3r?utm_source=medium&amp;utm_medium=referral">Gabriel Heinzer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>Have you ever wanted to build your own operating system?</em></blockquote><blockquote><em>I did — and I created Dinith_OS, a lightweight 16-bit real-mode OS written entirely in Assembly language.</em></blockquote><blockquote><em>This is my first OS project, and it boots straight from a floppy image, showing a basic command-line interface with a few built-in commands.</em></blockquote><h3>⚙️ What Can Dinith_OS Do?</h3><p>Dinith_OS includes a basic set of features:</p><ul><li>help – Shows available commands</li><li>info – Displays OS version and description</li><li>clear – Clears the screen</li><li>time – Shows the current system time</li><li>date – Shows the current system date</li></ul><p>Everything runs on BIOS interrupts, making it super close to the hardware.</p><h3>📂 Project Files</h3><ul><li>boot.asm – Bootloader (loads the kernel from disk)</li><li>kernel.asm – Main OS with command processing</li><li>Makefile – To build the image easily</li><li>AOS.img – Bootable floppy image</li></ul><h3>You can run it using QEMU:</h3><blockquote>qemu-system-i386 -fda AOS.img</blockquote><h3>🔗 Get the OS from GitHub</h3><p>👉 <a href="https://github.com/dinithanki/Dinith_OS">Download Dinith_OS on GitHub</a></p><p>Feel free to fork it, test it, or use it as a base for your own OS experiments.</p><h3>🧭 What I Learned</h3><p>Building Dinith_OS taught me:</p><ul><li>How bootloaders work</li><li>How to write in x86 Assembly</li><li>How to interact with BIOS via interrupts</li><li>How operating systems manage input/output at a low level</li></ul><p>This was a fun and educational project that helped me dive deeper into systems programming.</p><blockquote><strong>Created with ❤️ by Dinith </strong><br> <em>Follow me for more low-level programming experiments and OS dev projects!</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29e8362faceb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Software Licenses: Why They’re a Big Deal]]></title>
            <link>https://medium.com/@dinithchamo/understanding-software-licenses-why-theyre-a-big-deal-34e625527396?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/34e625527396</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Tue, 27 May 2025 13:24:47 GMT</pubDate>
            <atom:updated>2025-05-27T13:24:47.446Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What’s a Software License Anyway?</strong></h3><blockquote>A software license is basically a legal contract that explains how you can use, share, tweak, or distribute a software program. It’s the rulebook made by the creators or companies for everyone who wants to use their software.</blockquote><blockquote>Let’s break down the main types of software licenses you should know about.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EwmTslgNN2lwZPoszBr2vg.jpeg" /></figure><h4><strong>🔓 Open Source Licenses: Freedom to Innovate</strong></h4><p>Open source licenses give you the freedom to see the software’s source code, change it, and share it with others. These licenses promote teamwork and open innovation. But heads up not all open source licenses work the same way. Some require any changes you make to also be shared under the same license (called “copyleft”).</p><p>Here are some popular open source licenses:</p><ul><li><strong>MIT License</strong> — super permissive and simple</li><li><strong>Apache License 2.0</strong> — allows patents and contributions</li><li><strong>GNU GPL (General Public License)</strong> — strong copyleft, keeps software free</li><li><strong>GNU LGPL (Lesser GPL)</strong> — more flexible for libraries</li><li><strong>Mozilla Public License (MPL)</strong> — middle ground between permissive and copyleft</li></ul><h4>🔐 Proprietary Licenses: Keeping Control</h4><p>Proprietary licenses lock down the software’s code and limit how you can use or share it. Usually, you pay to use the software, and you must follow strict rules from the owner.</p><p>Types include:</p><ul><li><strong>Commercial Licenses</strong> — paid licenses for full features</li><li><strong>Freemium Licenses</strong> — free basic features with paid upgrades</li><li><strong>Shareware</strong> — try-before-you-buy software</li></ul><h4>🎨 Creative Commons: Sharing Non-Code Content</h4><p>Creative Commons (CC) licenses aren’t meant for software code but are popular for related materials like documentation, graphics, or tutorials. These licenses let creators decide how their work can be shared or adapted by others.</p><p>Use cases:</p><ul><li>Manuals and guides</li><li>Design assets</li><li>Educational resources</li></ul><h4><strong>🔄 Dual Licensing: Best of Both Worlds</strong></h4><p>Dual licensing means the same software is available under two licenses: an open source license and a commercial license. This way, developers and communities can use it freely, while businesses can pay for extra perks like support or fewer restrictions.</p><p><strong>Example:</strong> MySQL offers both GPL (open source) and commercial licenses.</p><h4><strong>💡 Why Should You Care?</strong></h4><p>Software licenses might seem like a snooze, but they’re crucial. They tell you exactly what you’re allowed to do with software whether you can use it for a project, tweak it, share it, or sell it.</p><ul><li><strong>For developers:</strong> Picking the right license protects your work and controls how others use it.</li><li><strong>For users/businesses:</strong> Licenses tell you the legal boundaries, so you don’t end up in trouble or lose rights.</li></ul><p>Messing up licensing can cause big legal headaches or accidentally give away your hard work. Knowing your licenses means you’re covered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*8F9zYZzRwkHQ6weZbSFTqw.jpeg" /></figure><h3>✅ Wrapping Up</h3><blockquote>Software licenses are the secret sauce behind how software is built, shared, and protected. Whether you’re into the open-source freedom, the locked-down proprietary world, creative commons for content, or dual licensing that balances both, understanding them is key.</blockquote><p>Always check the license details before using or releasing software it saves you from drama and helps your project thrive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34e625527396" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stored Procedures in MySQL]]></title>
            <link>https://medium.com/@dinithchamo/stored-procedures-in-mysql-1c148bf135fe?source=rss-b5901b61ef6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c148bf135fe</guid>
            <dc:creator><![CDATA[Dinith Pamunuwatte]]></dc:creator>
            <pubDate>Tue, 28 Jan 2025 15:20:19 GMT</pubDate>
            <atom:updated>2025-01-28T15:41:14.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yCnsCpcCqyzxvWX3" /><figcaption>Photo by <a href="https://unsplash.com/@rubaitulazad?utm_source=medium&amp;utm_medium=referral">Rubaitul Azad</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What Are Stored Procedures?</h3><blockquote>A stored procedure represents database protocols that compile SQL commands to perform at the database host. Application clients can trigger these procedures which minimize the requirement to send different SQL queries between application and database server. A database maintains stored procedures while developers can execute them through unique names. The storage of business logic at the database layer becomes possible through this mechanism.</blockquote><h3>Advantages of Stored Procedures</h3><ol><li>Improved Performance</li><li>Reduced Network Traffic</li><li>Reusability and Modularity</li><li>Enhanced Security</li><li>Easier Maintenance</li></ol><h3>Disadvantages of Stored Procedures</h3><ol><li>Complex Debugging</li><li>Database Portability</li><li>Increased Load on the Database Server</li><li>Version Control Challenges</li></ol><h3>How to Write and Execute Stored Procedures in MySQL</h3><h3>Writing a Stored Procedure</h3><p>The MySQL system uses CREATE PROCEDURE to develop stored procedures. Here is the basic syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*nI0DXjIjFbcQXmt_dQHtRA.png" /></figure><p><strong>DELIMITER</strong>: Changes the default delimiter (;) to avoid conflicts with the statement terminator within the procedure.</p><p><strong>procedure_name</strong>: The name of the stored procedure.</p><p><strong>parameters</strong>: Input, output, or input/output parameters for the procedure.</p><p><strong>BEGIN ... END</strong>: Encloses the SQL statements that make up the procedure.</p><h4>Executing a Stored Procedure</h4><p>A stored procedure is executed using the CALL statement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*5bQhcJ9P5NUxsNFtn0gNuA.png" /></figure><h4>Example Use Case: Calculating Total Sales</h4><p><strong>Problem: </strong>Suppose we have an e-commerce database with a table called orders that stores order details. We want to calculate the total sales for a given customer ID.</p><p><strong>Solution: We</strong> can create a stored procedure to perform this calculation.</p><p><strong>Steps</strong></p><p>01.Create the orders table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*FE0FNpUOqit61GjNEux94w.png" /></figure><p>02.Create the stored procedure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*AU-fFXO3Rk1A7uqr4eyjMQ.png" /></figure><p>03.Execute the stored procedure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*rU4nE-jygH1Q9vpdpJT6NQ.png" /></figure><p><strong>Output</strong></p><p>The result of the query will display the total sales for customer ID 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*h7sI8GdiSXTBZ3NMPWV70w.png" /></figure><h3>Conclusion</h3><blockquote>Many businesses utilize stored procedures in MySQL to manage system logic directly through their database. The substantial performance and security strengths of stored procedures compel development teams to assess them against debugging intricacy along with database compatibility implications. Through stored procedures mastery you can use their power to enhance both the operation efficiency of databases and overall system performance.</blockquote><h4>References:</h4><p>01. DigitalOcean. (n.d.). <em>How to use stored procedures in MySQL</em>. Retrieved January 29, 2025, from <a href="https://www.digitalocean.com/community/tutorials/how-to-use-stored-procedures-in-mysql">https://www.digitalocean.com/community/tutorials/how-to-use-stored-procedures-in-mysql</a></p><p>02. W3Schools. (n.d.). <em>SQL stored procedures</em>. Retrieved January 29, 2025, from <a href="https://www.w3schools.com/sql/sql_stored_procedures.asp">https://www.w3schools.com/sql/sql_stored_procedures.asp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c148bf135fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>