<?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 Harshana on Medium]]></title>
        <description><![CDATA[Stories by Harshana on Medium]]></description>
        <link>https://medium.com/@harshanacz?source=rss-c8a39a6ed0c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XdVBAFMK1Z0O_7LNYjUdMg.png</url>
            <title>Stories by Harshana on Medium</title>
            <link>https://medium.com/@harshanacz?source=rss-c8a39a6ed0c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 08:52:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshanacz/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[What 16 Papers Say About Language Server Performance (And What They Don’t)]]></title>
            <link>https://medium.com/@harshanacz/what-16-papers-say-about-language-server-performance-and-what-they-dont-e464f9539dde?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e464f9539dde</guid>
            <category><![CDATA[language-server-protocol]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Fri, 09 Oct 2026 16:08:42 GMT</pubDate>
            <atom:updated>2026-10-09T16:08:42.518Z</atom:updated>
            <content:encoded><![CDATA[<p>A quick note first: this is not a peer-reviewed paper. It’s a literature review I wrote for my independent study at the University of Moratuwa. I was the only reviewer, I didn’t re-run anyone’s experiments, and I took the numbers as the authors reported them. Treat it as a well-organized reading list with opinions, not a verdict.</p><p>I’ve been working on a language server rewrite during my WSO2 internship, so one question kept nagging me: <strong>how fast is a language server supposed to be, and what does that speed cost?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LslOXVnAdsOc3n2gx47sYA.png" /></figure><p>LSP is great for the L×I problem. Instead of every language needing a plugin for every editor, you get L + I. But the protocol was designed for local, interactive editing, where users expect a reply within a few hundred milliseconds. On big projects, that budget gets hard to hit.</p><p>So I reviewed 16 studies across four areas, i<strong>ncremental parsing, memory and caching, client-server communication, and response latency. </strong>Here’s what I found.</p><h3>1. Speedups are real, but they come with a bill</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7hsk5E_JSV7t4k2r9WG8g.png" /></figure><p>The headline numbers look amazing. Adapton, a demand-driven incremental computation library, reports roughly 7x to 2000x speedups when only a small part of the output is needed. A scope-graph-based incremental type checker reports up to 147x on synthetic cases and 21x on real projects.</p><p>But the costs are reported in completely different forms:</p><ul><li>Adapton pays in memory, with max heap 2.7 to 14 times the lazy baseline.</li><li>The scope-graph checker pays in initial runtime, at most 10% overhead, and doesn’t report memory.</li><li>Merlin (the OCaml language server) says its memory stays close to non-incremental parsing thanks to structural sharing, but that’s a qualitative claim.</li></ul><p>Different baselines, different workloads, different costs. You can’t line these numbers up on one scale without re-running everything.</p><h3>2. How much you demand matters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h41fjDaSfiRFZ7HB6vRIVw.png" /></figure><p>Demand-driven incrementality shines when you only look at a small slice of the output. In the one benchmark that varied demand (quicksort), the advantage shrank as more output was requested. And in LSP, requests vary wildly: one study measured completion at around 5 ms while rename took about 7 seconds and a full compile took almost 15 minutes on the same server. One incrementality strategy probably doesn’t fit every request.</p><h3>3. Granularity caps the benefit</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*njKRr7muAmvQagsyTdxZhw.png" /></figure><p>The type checker works at compilation-unit granularity. Small projects barely benefit, and commits touching many units recover much less, because every edited unit gets reanalyzed in full.</p><h3>4. Parser design matters, not just diffing</h3><p>Wagner’s classic principles (balanced sequences, reusing the nodes on the path from the root to the edit) still hold up. And in a study on lossless syntax trees, tree construction, not diffing, dominated latency on large files. Merlin also showed a nice engineering idea: treat the cache as performance-only, so a stale cache gives you a slowdown, never a wrong answer.</p><h3>5. The surprise: state beats messages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_2aolJ6jkioLwXqNGPfKQ.png" /></figure><p>I expected JSON-RPC serialization to be the villain. The only direct measurement I found (splitting Xtext language services into microservices) showed protocol overhead of roughly 9 to 58 ms. The real latency, up to about 2 seconds in the worst cases, came from stateless services reloading the program model on every request.</p><p>Where state lives mattered more than how messages travel. That’s a strong argument for keeping structurally shared state around.</p><p>One more thing: LSP returns source locations, not symbol identifiers. One study doing dependency analysis had to match locations back to graph nodes, and doing that naively made the whole analysis 2.35x slower on average.</p><h3>What nobody has measured</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eXJP79w5NbZ-9ilWNpwLlw.png" /></figure><p>This was the most interesting part for me:</p><ol><li><strong>No shared benchmark.</strong> Nobody compares language servers under one methodology.</li><li><strong>Memory footprint of real language servers is basically unmeasured.</strong> Everyone talks about it, nobody reports it.</li><li><strong>LSP’s own JSON-RPC cost is not isolated.</strong> The one measurement used HTTP between microservices, not LSP messages.</li><li><strong>Transfer from adjacent fields is assumed.</strong> Adapton and the scope-graph work aren’t language servers, and nobody has shown they carry over to production ones.</li><li><strong>Stateful vs stateless</strong> is still unresolved per service.</li><li><strong>Granularity is coarse.</strong> Nobody has tried finer-than-unit incrementality.</li></ol><h3>Caveats</h3><p>Single reviewer, English-only, five databases plus snowballing, and I excluded industry blog posts, which means a lot of real-world performance engineering from production language servers isn’t in here. Several included studies come from adjacent fields, so how relevant they are is partly my interpretation.</p><h3>Takeaway</h3><p>If you’re building a language server: keep state, share structure, don’t treat all requests the same, and measure memory, because the literature mostly doesn’t.</p><p>If you’re a researcher, there’s a gap waiting: a fair, shared benchmark that reports speedup and overhead together.</p><p><em>Full review is available if anyone wants it. Happy to hear where I got things wrong.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e464f9539dde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your WASM Function Call Isn’t Async. It’s a Full Stop.]]></title>
            <link>https://medium.com/@harshanacz/your-wasm-function-call-isnt-async-it-s-a-full-stop-71fd9762e332?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/71fd9762e332</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[language-server-protocol]]></category>
            <category><![CDATA[webassembly]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 07:26:41 GMT</pubDate>
            <atom:updated>2026-09-28T07:26:41.998Z</atom:updated>
            <content:encoded><![CDATA[<p>While rebuilding WSO2’s Micro Integrator language server in TypeScript, I compiled Apache Xerces-C++ to WebAssembly so we could do real XSD validation in JavaScript (I wrote about that part <a href="https://medium.com/@harshanacz/ultra-fast-xml-schema-xsd-validation-in-javascript-with-webassembly-and-grammar-caching-9edb2b67bcdd">here</a>).</p><p>Once the Xerces build was compiling, I thought the hard part was over. It wasn’t. I just hit a different kind of confusion. My TypeScript code calls validator.validate(xmlString) and gets an answer back, and for a while I genuinely didn&#39;t understand what was happening between those two lines. JavaScript and this compiled C++ blob don&#39;t share a garbage collector, and they don&#39;t even agree on what a string is. So how does any of it actually work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UIuJgu_J23xdRKeT_gmBiA.png" /></figure><h3>Two memories, not one</h3><p>The first thing that took a while to sink in: JS and WASM don’t share one memory. They sit in the same process, but each has its own separate space.</p><p>JavaScript keeps all its data (objects, arrays, strings) in one storage area, and it cleans up after itself automatically. You never have to manually free anything.</p><p>WebAssembly’s storage works completely differently. It’s just one long strip of raw bytes, with no structure to it, and nothing gets cleaned up automatically. If C++ code creates something there, that same code has to manually delete it later, or it just sits there forever, wasting space.</p><p>And the two sides don’t see each other the same way. WASM can’t see anything in JavaScript’s memory. JavaScript can see WASM’s memory, but only as a raw array of bytes. So to hand WebAssembly a string, JavaScript can’t just point at it. It has to encode the string and physically copy it in, byte by byte.</p><p>That single fact explains a lot of the weirdness in how you write code against a WASM module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dmVfsIoFeAIEsH_SQc8eAA.png" /></figure><h3>Async loading doesn’t mean async calls</h3><p>Loading the module is asynchronous. You read the .wasm file, hand the bytes to WebAssembly.instantiate(), and you get a Promise back.</p><p>I assumed that since loading was async, calling it would be too. That’s the mistake. The async part is just compiling the module, which takes real time, so the API returns a Promise instead of freezing your program while it happens. Once the module is loaded, every call is synchronous.</p><h3>The call itself is not async, and that matters</h3><p>Here’s the part that actually bit me. Calling a WASM function from JS works like calling any regular function. You call it, JS pauses, the WASM code runs, and control comes back when it’s done.</p><p>Which means if that function takes 400 milliseconds to run, your Node process is frozen for 400 milliseconds. Nothing else happens. No other requests get handled, and nothing else in your event loop moves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfcHUwztrqdJyCZntZtBMQ.png" /></figure><p>This is exactly why grammar pool caching mattered so much for the language server. A validation call that takes a few milliseconds is invisible. A validation call that takes hundreds of milliseconds, running every time someone types, would stall the whole server again and again while they’re just trying to write XML.</p><h3>Passing a string across isn’t really ‘passing a string’</h3><p>WASM doesn’t know what a string is. It only understands numbers. So handing an XML document to the validator, at the lowest level, looks nothing like a normal function call:</p><ol><li>Ask the WASM side to allocate some memory for you</li><li>Encode your JS string into bytes and write them into that memory</li><li>Call the actual function, passing a memory offset and a length instead of the string</li><li>Free that memory afterward, because nothing on the WASM side will do it for you</li></ol><p>In code, the raw version looks roughly like this:</p><pre>const bytes = new TextEncoder().encode(xml);<br>const ptr = wasm._malloc(bytes.length);<br>wasm.HEAPU8.set(bytes, ptr);<br>const result = wasm._validate(ptr, bytes.length);<br>wasm._free(ptr);</pre><p><em>Simplified for illustration. The real function names in the build are different.</em></p><p>That’s the bare-metal mechanism, and writing the bridge by hand at that level would have been miserable. A bug in step 4 alone is a slow memory leak you won’t notice until memory usage climbs over hours of use.</p><p>I didn’t have to write any of that by hand, though. The bridge uses Embind, which generates all of that marshaling code at compile time. From the TypeScript side, the call is just:</p><pre>const result = validator.validate(xmlText);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Krp5FGeCaIJqqwp8MLYZtQ.png" /></figure><p>Underneath, Embind is doing the allocate, encode, write, free dance on every call. I just never had to think about it, until I went looking for why a raw WASM tutorial online looked nothing like the code I was writing.</p><h3>Where this actually mattered</h3><p>Two things came out of understanding this properly.</p><p>First, the blocking behavior is the whole reason the grammar pool has to be fast. There’s no way to move a WASM call away from the rest of the server without deliberately putting it on a worker thread, and we didn’t need to once validation dropped to a few milliseconds.</p><p>Second, knowing that Embind was quietly handling the memory boundary meant I stopped worrying about manual cleanup in our own code and started paying attention to it in the one place it actually lived: inside destroy(), where the grammar pool itself gets released.</p><p>It’s a small enough piece of the whole project that it’s easy to skip past. But once I understood where the memory boundary was and why the function call blocked the way it did, a bunch of earlier decisions in the language server (why we cache the pool, why destroy() matters, why a slow validator would have been a real problem and not a minor inconvenience) stopped being things I&#39;d been told and started being things I actually understood.</p><p>You can try the validator in your browser at <a href="https://xerces-wasm.harshanacz.com/">xerces-wasm.harshanacz.com</a>, or grab it from npm as <a href="https://www.npmjs.com/package/xerces-wasm">xerces-wasm</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71fd9762e332" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ultra-Fast XML Schema (XSD) Validation in JavaScript with WebAssembly and Grammar Caching]]></title>
            <link>https://medium.com/@harshanacz/ultra-fast-xml-schema-xsd-validation-in-javascript-with-webassembly-and-grammar-caching-9edb2b67bcdd?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9edb2b67bcdd</guid>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[xerces]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[dx]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Thu, 06 Aug 2026 04:22:01 GMT</pubDate>
            <atom:updated>2026-08-06T04:22:01.198Z</atom:updated>
            <content:encoded><![CDATA[<p>Validating XML against XML Schema Definitions (XSD) in JavaScript has always been a painful experience.</p><p>For years, Node.js developers had to choose between clunky native bindings like libxmljs (which often break during node-gyp builds) or shelling out to external system binaries like Java or xmllint. While WebAssembly ports like xmllint-wasm solved the binary dependency problem, high-throughput applications still hit a major performance bottleneck: <strong>re-parsing the same XSD schema over and over again on every single validation run.</strong></p><p>That’s why we built <a href="https://www.npmjs.com/package/xerces-wasm"><strong>xerces-wasm</strong></a> , a pure WebAssembly port of the battle-tested Xerces-C++ engine, bringing pre-compiled <strong>Grammar Caching</strong> and project-based multi-schema support directly to Node.js and the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLstHyCfVkCWpeL805dIjw.png" /><figcaption>xerces-playground-screenshot</figcaption></figure><h3>The Bottleneck in Existing WASM Validators</h3><p>Most JS-based XML validators re-parse and re-compile the XSD schema every time you validate an XML payload. If your microservice handles thousands of API requests per minute using the same standard schema, you are wasting massive CPU cycles re-interpreting the same XML schema rules.</p><p>xerces-wasm changes this paradigm by allowing you to pre-compile and cache the parsed schema (Grammar Pool) in memory once, and reuse it instantly across thousands of validation runs.</p><h3>Performance Benchmarks</h3><p>Here is how xerces-wasm performs against xmllint-wasm when validating XML payloads using a cached schema over 1,000 iterations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*qAKPNUASkFdyBsfuivs_SQ.png" /></figure><blockquote><strong><em>Key Takeaway:</em></strong><em> For high-volume microservices, small-to-medium API payloads, and repeated validations, grammar caching delivers up to a </em><strong><em>400x speedup</em></strong><em>.</em></blockquote><p>(Note: For massive multi-megabyte XML files, performance naturally scales with stream/string parsing overhead, but for high-frequency request handling, grammar caching is an absolute game-changer).</p><p>Full<a href="https://github.com/harshanacz/xml-val-benchmark"> Benchmark results</a></p><h3>Key Features</h3><ul><li><strong>Pre-Compiled Grammar Caching:</strong> Parse your XSD once, validate millions of XMLs at microsecond speeds.</li><li><strong>Zero Native Dependencies:</strong> Pure WASM — no node-gyp, no Java runtime, and no system-installed xmllint required.</li><li><strong>Project-Based Multi-Schema Support:</strong> Easily manage complex schema structures with multiple xs:include and xs:import relative dependencies in a single project scope.</li><li><strong>Strict XSD 1.0 Spec Conformance:</strong> Powered by the enterprise-grade Apache Xerces-C++ core engine.</li></ul><h3>Quick Start Guide</h3><p>1. Installation</p><pre>npm install xerces-wasm</pre><p>2. Basic Usage with Grammar Caching</p><pre>import { Xerces } from &#39;xerces-wasm&#39;;<br><br>const main = async () =&gt; {<br>  // Initialize the WASM module<br>  const xerces = await Xerces.init();<br><br>  const xsdSchema = `<br>    &lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;<br>      &lt;xs:element name=&quot;note&quot;&gt;<br>        &lt;xs:complexType&gt;<br>          &lt;xs:sequence&gt;<br>            &lt;xs:element name=&quot;to&quot; type=&quot;xs:string&quot;/&gt;<br>            &lt;xs:element name=&quot;body&quot; type=&quot;xs:string&quot;/&gt;<br>          &lt;/xs:sequence&gt;<br>        &lt;/xs:complexType&gt;<br>      &lt;/xs:element&gt;<br>    &lt;/xs:schema&gt;<br>  `;<br><br>  // Pre-compile and Cache the Schema<br>  const cachedGrammar = xerces.loadSchema(xsdSchema);<br><br>  const xmlData = `<br>    &lt;note&gt;<br>      &lt;to&gt;Harshana&lt;/to&gt;<br>      &lt;body&gt;Hello from xerces-wasm!&lt;/body&gt;<br>    &lt;/note&gt;<br>  `;<br><br>  // High-speed validation using cached grammar<br>  const result = cachedGrammar.validate(xmlData);<br><br>  if (result.isValid) {<br>    console.log(&#39;XML is valid!&#39;);<br>  } else {<br>    console.error(&#39;Validation errors:&#39;, result.errors);<br>  }<br>};<br><br>main();</pre><h3>Try It Live</h3><p>We’ve built an interactive playground where you can test schema imports, multi-file projects, and grammar caching directly in your browser:</p><p><strong>Live Playground:</strong> <a href="https://www.google.com/search?q=https://xerces-wasm.harshanacz.com">https://xerces-wasm.harshanacz.com</a></p><p><strong>npm Package</strong>:<a href="https://www.google.com/search?q=https://www.npmjs.com/package/xerces-wasm"> https://www.npmjs.com/package/xerces-was</a>m</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9edb2b67bcdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Language Servers Actually Work Under the Hood]]></title>
            <link>https://medium.com/@harshanacz/everyone-thinks-vs-code-is-smart-its-actually-just-listening-1cce3b6e7f06?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cce3b6e7f06</guid>
            <category><![CDATA[cursor]]></category>
            <category><![CDATA[language-server-protocol]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[language-server]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Tue, 04 Aug 2026 05:12:51 GMT</pubDate>
            <atom:updated>2026-09-28T06:21:44.042Z</atom:updated>
            <content:encoded><![CDATA[<p>Before this year, I used language servers every single day without knowing they existed. Red squiggles under broken code, autocomplete popping up when I type &lt;, hover tooltips explaining what an element does. I just assumed that was &quot;VS Code being smart.&quot;</p><p>Then WSO2 handed me a project: rebuild the language server we use for Micro Integrator, in TypeScript. Part of the reason was practical the existing one is Java-based, which means it can’t run directly in a browser environment. You need a JVM, which usually means Docker or something similar sitting behind it, and that adds cost and real limitations.</p><p>And suddenly I had to learn what that magic actually was. This is what I wish someone had told me on day one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BPjKZRK3wHBQqylpp40wg.png" /></figure><h3>The problem LSP solves</h3><p>Here’s a fun bit of history I only learned after starting. Before 2016, every editor implemented language intelligence separately. VS Code had its own TypeScript smarts, Vim had its own, Sublime had its own. If you built a new language, you had to integrate with every editor one by one. N editors times M languages. A mess.</p><p>Microsoft’s answer was the <a href="https://microsoft.github.io/language-server-protocol/">Language Server Protocol</a>. Instead of putting the intelligence inside the editor, you put it in a separate program, the language server and the editor just talks to it over a standard protocol. Build the server once, and any editor that speaks LSP can use it. VS Code, Neovim, whatever comes next.</p><p>Even Claude Code speaks LSP now..</p><h3>It’s just two programs talking through pipes</h3><p>This was the thing that demystified everything for me. A language server is not some deeply integrated editor plugin. It’s a completely separate process, and the editor talks to it by writing JSON to its stdin and reading JSON from its stdout. That’s it. Pipes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08lXEKk7jcKNnz6caX-Prw.png" /></figure><p>What actually flows through those pipes turned out to be almost boringly simple. Every message starts with a header telling the other side how many bytes are coming, then a blank line, then plain JSON:</p><pre>Content-Length: 107<br><br>{&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;id&quot;:1,&quot;method&quot;:&quot;initialize&quot;,&quot;params&quot;:{...}}</pre><p>No sockets, no binary encoding, no custom framing you have to reverse engineer. Every question the editor asks : what can I complete here, what does this element mean, is this line broken, travels across in that exact shape, and every answer comes back the same way.</p><p>That’s the whole trick behind red squiggles and autocomplete. Not intelligence baked into the editor. Just a separate program, listening on stdin, replying on stdout, one JSON message at a time.</p><h3>The conversation, start to finish</h3><p>The lifecycle goes roughly like this:</p><p>1. Editor starts your server as a child process<br>2. Editor sends `initialize` - here’s who I am, here’s what I support<br>3. Server replies with its capabilities- I can do completion, hover, diagnostics, folding…<br>4. Editor sends `initialized`, and from that point it streams events<br>5. User opens a file → `textDocument/didOpen` with the full text<br>6. User types → `textDocument/didChange` with the changes<br>7. Server validates and pushes `textDocument/publishDiagnostics` back<br>8. User hovers → `textDocument/hover` request → server responds with content</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sam85Z0g33y5lbMQZzUgbQ.png" /></figure><p>In TypeScript, the `vscode-languageserver` package handles all the protocol plumbing for us. Our actual server code ends up looking like a set of event handlers:</p><pre>connection.onHover((params) =&gt; {<br> const document = documents.get(params.textDocument.uri);<br> if (!document) return null;<br> const xmlDoc = service.parseXMLDocument(document.uri, document.getText());<br> return service.doHover(xmlDoc, params.position);<br>});</pre><p>Which is honestly pretty pleasant. The hard parts are not the protocol. The hard parts are everything behind these handlers.</p><h3>Hard part one: users never write valid code</h3><p>This one changed how I think about parsers permanently.</p><p>Every XML parser I’d used before assumed the input was, you know, XML. But in an editor, the document is broken almost all of the time, because the user is in the middle of typing it:</p><p>&lt;proxy|<br>&lt;proxy name|<br>&lt;proxy name=”|<br>&lt;proxy name=”Test”|</p><p>Every single one of those is invalid XML. And your server has to keep answering hover and completion requests through all of them. A parser that throws on the first error is useless here.</p><p>So we built on top of a fault-tolerant parser that produces a tree even from garbage input, and wrapped our own clean AST around it. When the user types `&lt;proxy name=”` and hovers over `proxy`, the server can still find that node in the tree and answer. (like below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3aj40uaC_vn9TTHftrJytA.png" /></figure><h3>Hard part two: the module system fight</h3><p>I’m including this because nobody warns you, and it cost me days.</p><p>VS Code extensions must be CommonJS. My server had to be ESM, because a WebAssembly dependency deep in the stack uses top-level await, which only exists in ESM. So the extension physically could not `require()` the server.</p><p>The way out: the extension doesn’t import the server at all. It spawns it as a separate process and talks over stdio.which is what LSP wants anyway. Then esbuild bundles the whole ESM server into a single CommonJS file for distribution. One `dist/server.js`, about a megabyte, everything inlined.</p><blockquote>There was also a full day lost to the server silently doing nothing because the client never passed the ` — stdio` flag, so the server didn’t know which transport to listen on. It just sat there. No error, no output, nothing. If your language server “hangs” check the transport flag first. You’re welcome.</blockquote><h3>Hard part three: making validation cheap enough to never think about</h3><p>Schema validation was the piece I spent the most time on,</p><p>Every keystroke fires a `didChange` message, and every `didChange` triggers a full validation. That’s a lot of validation calls one per character typed. Most systems handle this by cutting the number of calls down, waiting a bit before validating instead of doing it on every character.</p><p>The slow part of XSD validation was never checking the actual XML, it’s parsing the schema files first and building a grammar from them. WSO2 MI’s schemas are dozens of XSD files, and rebuilding that grammar on every keystroke would’ve made this pointless. So we don’t rebuild it. Apache Xerces, compiled to WebAssembly, parses all the schema files once when a project opens and keeps that compiled grammar locked in memory.</p><p>Every validation after that just runs the XML against what’s already there. No re-parsing, nothing rebuilt, just checking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0W10VzewnrRUOL6-yZb4GA.png" /></figure><p>Somewhere in the middle of building this, it hit me that the WASM build could probably be useful to people who had nothing to do with WSO2 or XML language servers at all . anyone on Node.js who just needs real XSD validation. actually publish it instead of letting it sit buried inside our repo, so I finally split it out onto npm on its own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjZ4BAMwsno3veRdONlj3A.png" /></figure><pre>npm i xerces-wasm</pre><p>Later I threw together a small unrelated side project, <a href="https://github.com/harshanacz/xml-review-bot-demo">xml-review-bot</a></p><h3>The unexpected ending</h3><p>Near the end of this, my mentor pointed out that Claude Code has a plugin system with built-in LSP support. I pointed it at my server with a small config file,</p><p><a href="https://github.com/harshanacz/xml-lsp-marketplace">GitHub - harshanacz/xml-lsp-marketplace: XML language intelligence plugin for Claude Code with diagnostics, schema-aware completion, hover, and XSD validation.</a></p><p>and suddenly an AI coding agent had semantic understanding of XML files real diagnostics after every edit it makes, real hover info, real schema knowledge. I hadn’t planned for that when I started. It fell out for free, because LSP is a standard and the server doesn’t care who’s on the other end of the pipe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6gClARPaq9cSAoXsQ2Ryw.png" /></figure><p>That’s the actual lesson. A language server is a program that answers questions about a file over stdin and stdout. Build it once, and it doesn’t matter which editor is on the other end. VS Code, Claude Code, whatever shows up next year. It just works, because none of it was ever tied to VS Code in the first place.</p><p>Three months ago I thought red squiggles were editor magic. Turns out the editor was never smart. It was just listening.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cce3b6e7f06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WSO2 Micro Integrator / Universal Translator, Connecting the Unconnected.]]></title>
            <link>https://medium.com/@harshanacz/wso2-micro-integrator-universal-translator-connecting-the-unconnected-d789122be0c2?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d789122be0c2</guid>
            <category><![CDATA[wso2-micro-integrator]]></category>
            <category><![CDATA[universal-design]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[esb]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 18:03:28 GMT</pubDate>
            <atom:updated>2026-02-12T18:03:28.441Z</atom:updated>
            <content:encoded><![CDATA[<p>You know, in the world of enterprise software, getting all your different systems to actually talk to each other is one of the biggest challenges out there. It’s like a constant, complicated puzzle of connecting apps, data, and services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8RGqU-FmB1TlXYb4AhXGQ.png" /></figure><p>If you are a developer or an architect, you know this struggle. You have critical business logic locked inside totally different apps. Bridging those gaps is complex, takes forever, and honestly? It’s incredibly frustrating.</p><p>Think about it this way. You might have one modern app that speaks fluent JSON, but another old one that only understands legacy XML. One uses shiny new REST APIs, while the other uses an old-school queue system. They are trying to work together, but they are speaking completely different languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xxPd30qYeyBm17d9MrYb7g.png" /><figcaption>Are your applications speaking different languages?</figcaption></figure><p>This creates real architectural chaos. On one hand, you have the new world of decentralized microservices, where small services do one thing really well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMz0JeRxgaiIwk0ykn-chg.png" /><figcaption>WSO2 Micro Integrator (MI) works in Microservices Architecture.</figcaption></figure><p>But on the other hand, you still have the traditional centralized Enterprise Service Bus (ESB) that acts as a massive hub for everything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VKlOv0GtqRsnrTgFD91Ng.png" /></figure><p>The reality is that most companies today are living in a messy “hybrid” world with a bit of both. That makes the integration challenge even tougher to solve.</p><p>— — — — — — — — — — -</p><h3>The Solution</h3><p>But what if you could teach all these systems to speak the exact same language? What if there was a way to navigate all this complexity?</p><p>Let’s introduce the hero of our story: <a href="https://wso2.com/integrator/mi"><strong>WSO2 Micro Integrator</strong>.</a></p><p>At its core, it is a lightweight, open-source integration engine. What makes it great is its flexibility. It doesn’t force you into one style. It handles both the new microservices world and the old centralized world perfectly.</p><p>Think of it as the <strong>universal translator</strong> for your entire ecosystem. It listens, understands, and lets your apps talk to each other effortlessly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2MVYoc1s4xbeHXKr3scD8Q.png" /><figcaption>WSO2 Micro Integrator (MI)</figcaption></figure><h4>The AI Advantage</h4><p>This is where things get really exciting. It combines a battle-tested engine with a modern <strong>AI-powered development experience</strong>. We aren’t talking about writing boring boilerplate code anymore. It is faster, smarter, and more intuitive.</p><p>Check this out. There is an <a href="https://mi.docs.wso2.com/en/latest/develop/mi-for-vscode/mi-copilot/"><strong>AI Co-pilot</strong></a> living right inside VS Code. Instead of struggling with complex syntax, you just describe what you want in plain English.</p><p>ref- <a href="https://mi.docs.wso2.com/en/latest/develop/mi-for-vscode/mi-copilot/">https://mi.docs.wso2.com/en/latest/develop/mi-for-vscode/mi-copilot/</a></p><p>You literally type: <em>“When a request comes in, send an email.”</em> The Co-pilot then generates the configuration for you.</p><h4>Visual Data Mapping</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLUbYzfyQlCPJYFEXaaRbg.png" /><figcaption>visual data mapping</figcaption></figure><p>One of the biggest headaches is data mapping. taking a field from one system and fitting it into another.</p><p>Micro Integrator fixes this with an <strong>AI-powered Visual Data Mapper</strong>. You get an awesome drag-and-drop interface to map fields between formats like JSON and XML. As you draw the diagram, the actual code is generated side-by-side. It’s the perfect balance of simplicity and power.</p><p>ref- <a href="https://wso2.com/library/blogs/introducing-the-new-visual-data-mapper-for-wso2-micro-integrator">https://wso2.com/library/blogs/introducing-the-new-visual-data-mapper-for-wso2-micro-integrator</a></p><p>— — — — — — — — — -</p><h3>How It Actually Works</h3><p>So you have this slick developer experience, but underneath it all is an engine that is rock solid. It’s built on proven enterprise patterns, so it’s not just easy to use . it’s incredibly robust.</p><p><strong>Let’s look at three key ways it works:</strong></p><p><strong>1. Content-Based Routing:</strong> It can peek inside a message and decide where it goes.</p><ul><li><em>Example:</em> If an order is over $1,000, send it to fraud detection. If not, send it straight to fulfillment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIg2ZPW4v37Y0Wr_HfRd-Q.png" /><figcaption><strong>Content-Based Routing with WSO2 Micro Integrator</strong></figcaption></figure><p><strong>2. Message Transformation:</strong> This is that “universal translator” power. It grabs a message, changes the format, removes fields, or adds info to match exactly what the receiving system needs.</p><p><strong>3. Service Orchestration:</strong> You get to be the conductor. You can take multiple small services and combine them into one powerful business process.</p><p>(Other key features -</p><ul><li><strong>Cloud-Native &amp; K8s Ready:</strong> It’s built for the cloud from day one. Whether you are running on Docker or Kubernetes, it fits right into your modern DevOps pipeline without any hassle.</li><li><strong>200+ Ready-Made Connectors:</strong> You don’t need to code everything from scratch. It comes with connectors for all the big players like Salesforce, SAP, Jira, and Amazon S3. You just plug and play.</li><li><strong>Protocol Powerhouse:</strong> It’s not just about HTTP. It speaks almost any protocol you throw at it — gRPC, GraphQL, WebSocket, TCP, and even Kafka for real-time streaming.</li><li><strong>Deep Observability:</strong> You are never flying blind. It integrates easily with monitoring tools like Grafana, Prometheus, and Jaeger, so you can always see exactly what’s happening inside your integrations.</li><li><strong>Enterprise-Grade Security:</strong> Security isn’t an afterthought. It has built-in support for major standards like OAuth2 and OpenID Connect to keep your data safe.</li></ul><p>)</p><p>— —</p><h3>Real-World Example: Healthcare</h3><p>Let’s bring this down to earth. Imagine a patient just wants to find a doctor. Simple, right?</p><p>But behind the scenes, that doctor data is hidden in two completely different hospital systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lGImcJBSlkuMfiORc_4l9Q.png" /><figcaption>WSO2 Intergrator for Healthcare</figcaption></figure><p>Micro Integrator acts as the single front door.</p><ol><li>It receives the patient’s request.</li><li>It uses a <strong>Clone Mediator</strong> to copy the request and ask both hospitals at the same time.</li><li>It gets the answers, merges them into one simple list, and sends it back to the patient.</li></ol><p>All that complexity is completely hidden from the user.</p><p>— — -</p><h3>The Big Picture</h3><p>Connecting systems isn’t just a technical exercise. It has a real impact on your business.</p><p>We aren’t talking about experimental tech here. WSO2’s software handles over <strong>60 trillion transactions a year</strong> globally. That is the level of trust we are talking about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5P0EOwzDkZ3iwn9KOSHoA.png" /><figcaption>WSO2 Integrator architecture</figcaption></figure><h3>References &amp; Further Reading</h3><p>Want to dive deeper? Check out the official resources below:</p><ul><li><strong>Official Product Page:</strong> <a href="https://wso2.com/micro-integrator/">WSO2 Micro Integrator</a></li><li><strong>Documentation:</strong> <a href="https://mi.docs.wso2.com/">WSO2 MI Official Docs</a></li><li><strong>GitHub Repository:</strong> <a href="https://github.com/wso2/micro-integrator">WSO2 Micro Integrator on GitHub</a></li><li><strong>VS Code Extension:</strong> <a href="https://marketplace.visualstudio.com/items?itemName=WSO2.micro-integrator">MI for VS Code (AI Copilot)</a></li><li><strong>Customer Success Stories:</strong> <a href="https://wso2.com/customers/">WSO2 Case Studies</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d789122be0c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best AWS Services for Your Docker Container? (beginner friendly)]]></title>
            <link>https://medium.com/@harshanacz/best-aws-services-for-your-docker-container-beginner-friendly-c152aedf4bc9?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c152aedf4bc9</guid>
            <category><![CDATA[aws-docker]]></category>
            <category><![CDATA[aws-app-runner]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containerization]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Thu, 14 Aug 2025 08:46:46 GMT</pubDate>
            <atom:updated>2025-08-14T08:46:46.413Z</atom:updated>
            <content:encoded><![CDATA[<p>You know how to use Docker to package your app. That’s great! Now, you want to put your app on the internet using Amazon Web Services (AWS).</p><p>But when you look at AWS, you see many tools. It can be confusing. Don’t worry. This guide will help you pick the right tool for your needs, in simple words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGBpnYSTqn1CxgqNFWbmOw.png" /><figcaption>Best AWS Services for Your Docker Container</figcaption></figure><h4><strong>The Easiest Way: AWS App Runner.</strong></h4><p>If you are new to AWS or just want a quick and easy way to get your app online, use <strong>App Runner</strong>.</p><p>Think of it as an “easy button.” You give App Runner your Docker app, and it does all the hard work for you. You don’t have to set up any servers or networks.</p><p><strong>Use this if:</strong> You want to focus on your code and not worry about servers.</p><h4>A Mix of Easy and Control: Amazon Fargate</h4><p>This tool gives you more control than App Runner, but it’s still simple. With <strong>Amazon ECS and Fargate</strong>, you can set up your own network rules and have more say in how your app runs.</p><p>The best part? You still don’t have to manage any servers yourself.</p><p><strong>Use this if:</strong> You want more options but don’t want the job of managing servers.</p><h4>For Full Control: EKS and EC2</h4><p>If you are an expert building a very big app, use <strong>Amazon EKS</strong>. It’s a powerful tool that works with another popular tool called Kubernetes.</p><p>If you want to build everything from the ground up, use <strong>Amazon EC2</strong>. This is like renting a basic computer from AWS. You have total control, but you also have to manage everything.</p><p><strong>Use these if:</strong> You are an expert who needs a lot of power and control.</p><h4>A Place to Store Your Apps: Amazon ECR</h4><p>No matter which tool you choose, you need a place to keep your Docker apps. <strong>Amazon ECR</strong> is the tool for that. It’s a safe place to store your apps, and it works well with all the other AWS tools.</p><p>Now you can pick the right tool for your needs and get back to building your great app.</p><p><strong>in this article, i will guide you and share my experince how to deploy to AWS App runner</strong></p><p><strong>There Are Two Ways to Deploy to App Runner</strong><br>Method 1: Direct from GitHub (Easiest — No Docker needed!)<br>Method 2: Upload Docker Container (What we’re doing)</p><p><strong>Let me teach you Method 2 step by step</strong>, then show you Method 1.</p><p><strong>(Step01) First of all, lets Understanding the Big Picture</strong></p><pre>Your Computer → AWS Storage (ECR) → App Runner → Live API<br>     🏠              📦                🚀         🌐</pre><ul><li><strong>Your Computer:</strong> Has your Docker image</li><li><strong>AWS ECR: </strong>Cloud storage for Docker images (like Google Drive for containers)</li><li><strong>App Runner:</strong> AWS service that runs your container</li><li><strong>Live API:</strong> Your API accessible on the internet</li></ul><p><strong>(Step02) Next, Manual Commands (No Script Needed) (We can do this using shell scripts, i will say how to do it later. now for easy understand lets go with manual commands)</strong></p><p><strong>2.1: Get Your AWS Account Info</strong></p><pre># Find out your AWS account number<br>aws sts get-caller-identity</pre><p>You’ll see something like:</p><pre>{<br>    &quot;UserId&quot;: &quot;AIDACKCEVSQ6C2EXAMPLE&quot;,<br>    &quot;Account&quot;: &quot;123456789012&quot;,  ← This is your account ID<br>    &quot;Arn&quot;: &quot;arn:aws:iam::123456789012:user/your-name&quot;<br>}</pre><p>Write down your Account ID: 123456789012 (yours will be different)</p><p><strong>2.2: Create Storage Space in AWS</strong></p><pre># Create a &quot;folder&quot; in AWS to store your container<br>aws ecr create-repository --repository-name &lt;namehere&gt; --region us-east-1</pre><p><strong>2.3: Login to AWS Storage</strong></p><pre># Get permission to upload to AWS<br>aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com</pre><p>Replace 123456789012 with YOUR account ID</p><p><strong>2.4: Prepare Your Container for AWS (</strong>Tag Your Image)</p><pre># Give your container an AWS-compatible name<br>docker tag &lt;name&gt;:latest 123456789012.dkr.ecr.us-east-1.amazonaws.com/&lt;name&gt;:latest</pre><p>🏷️ What is Docker Tagging? (why this step?)</p><p>Think of Docker tags like address labels on packages:</p><p>Before Tagging (Local Package):</p><pre>📦 Package: &quot;content-moderation-api:latest&quot; #ur package name<br>🏠 Address: &quot;My House&quot; (your computer)</pre><p>After Tagging (Shipping Package):</p><pre>📦 Same Package: &quot;content-moderation-api:latest&quot; <br>🏠 New Address: &quot;123##.dkr.ecr.us-east-1.amazonaws.com/content-moderation-api:latest&quot;<br>                 (AWS warehouse address)</pre><p>I think you got it, but, again i want confirm,</p><p>Why Do We Need Tagging?<br>Problem Without Tagging:</p><pre># This won&#39;t work - Docker doesn&#39;t know where to send it<br>docker push content-moderation-api:latest<br># Error: &quot;Where should I send this? What&#39;s the address?&quot;</pre><p>Solution With Tagging:</p><pre># This works - Docker knows the full AWS address</pre><p>Breaking Down the Tag Components:</p><pre>012345396589.dkr.ecr.us-east-1.amazonaws.com/content-moderation-api:latest<br>│            │   │   │          │              │                      │<br>│            │   │   │          │              │                      └── Version (latest)<br>│            │   │   │          │              └── Repository name<br>│            │   │   │          └── AWS domain<br>│            │   │   └── Region (Mumbai)<br>│            │   └── ECR service<br>│            └── Docker registry<br>└── Your AWS Account ID </pre><p>Ok, now next,</p><p><strong>2.5: Upload to AWS</strong></p><pre># Upload your container to AWS storage<br>docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/content-moderation-api:latest</pre><h3>Step 3: Create App Runner Service</h3><p>Now go to AWS Console:</p><p><strong>3.1: Open AWS Console</strong><br>Go to <a href="https://aws.amazon.com/console/">https://aws.amazon.com/console/</a><br>Sign in<br>Search for “App Runner”<br>Click “App Runner”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVhIiZdnwya9mS0hyBGT0g.png" /><figcaption>app runner aws</figcaption></figure><p><strong>3.2: Create Service</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvdFRVN-a78o9LpPyhWIig.png" /></figure><p>Click “Create service”<br>Choose “Container registry”<br>Choose “Amazon ECR”<br>Click “Browse”<br>Select your repository: “ur repo name”<br>Select image tag: “latest”<br>Click “Continue”</p><p><strong>3.3: Configure Service</strong><br>Service settings:</p><p>Service name: content-moderation-api<br>Port: 8000<br>Start command: uvicorn app.main:app — host 0.0.0.0 — port 8000</p><p><strong>3.4: Deploy</strong><br>Click “Create &amp; Deploy”<br>Wait 5–10 minutes<br>Get your URL: <a href="https://abc123.us-east-1.awsapprunner.com/">https://abc123.us-east-1.awsapprunner.com</a></p><h3>Method 1: GitHub Deployment (Much Easier!) (Not docker)</h3><p>This method skips Docker entirely:</p><p><strong>Step 1: Push Code to GitHub</strong></p><pre># In your project folder<br>git init<br>git add .<br>git commit -m &quot;Initial commit&quot;<br>git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git<br>git push -u origin main</pre><p><strong>Step 2: Create App Runner from GitHub</strong><br>AWS Console → App Runner → Create service<br>Choose “Source code repository”<br>Connect to GitHub<br>Select your repository<br>Build settings:<br>Runtime: Python 3<br>Build command: pip install -r requirements.txt<br>Start command: uvicorn app.main:app — host 0.0.0.0 — port 8000<br>Add same environment variables<br>Deploy!</p><p><strong>Which Method Should You Use?</strong><br>For Learning Docker: Use Method 2 (Container)<br>For Speed: Use Method 1 (GitHub)</p><h3>Why Do We Have Scripts?</h3><p>The .sh and .ps1 files I created just automate the manual commands:</p><p>Without script: Type 5–6 commands manually With script: Type 1 command, script does the rest</p><p>Scripts are optional — they just save time and reduce errors.</p><p><strong>Let’s Practice: Which Method Do You Want?</strong></p><p>Option A: “I want to learn Docker properly” → Use Method 2 (manual commands)</p><p>Option B: “I just want my API online fast” → Use Method 1 (GitHub)</p><p>Bye. i will bring how to use “sh” — Scripts later.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c152aedf4bc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Complete Docker Lifecycle Example]]></title>
            <link>https://medium.com/@harshanacz/complete-docker-lifecycle-example-76b732b8d762?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/76b732b8d762</guid>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Thu, 14 Aug 2025 07:11:51 GMT</pubDate>
            <atom:updated>2025-08-14T07:11:51.547Z</atom:updated>
            <content:encoded><![CDATA[<h3>Complete Docker Lifecycle Example (Flow)</h3><p>This guide walks you through creating, running, and cleaning up a Docker application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*239jur4bwgqmuYAfmYVMzQ.png" /><figcaption>modern software development lifecycle using Docker</figcaption></figure><h3>analogy-list The Kitchen Analogy: Docker Explained</h3><p>Think of Docker as a restaurant kitchen:</p><ul><li><strong>Image</strong>: A <strong>recipe</strong> in a book. It contains all the instructions but isn’t a dish itself.</li><li><strong>Running Container</strong>: A <strong>chef actively cooking </strong>🍳 that recipe. The dish is being prepared and can be served.</li><li><strong>Stopped Container</strong>: A <strong>prepared dish that’s gone cold</strong>. It exists but isn’t being served. You can quickly “reheat” (start) it.</li><li><strong>Removed Container</strong>: The <strong>dish has been thrown away</strong>. It’s gone forever.</li></ul><p>— — — — — — —</p><p><strong>Step 1: Build the Image (Create the Recipe)</strong> <br>An image is the blueprint for your application.</p><pre>docker build -t my-app .<br># Result: An image named &#39;my-app&#39; is created, but nothing is running yet.</pre><p><strong>Step 2: Run the Container (Bake the Cake)</strong> <br>A container is a running instance of your image.</p><pre>docker run -p 8000:8000 my-app<br># Result: A container is created and starts running.<br># Your app is now live at http://localhost:8000</pre><p><strong>Step 3: Check Running Containers</strong> <br>See what’s currently active.</p><pre>docker ps<br># Shows your &#39;my-app&#39; container running.</pre><p><strong>Step 4: Stop the Container (Turn Off the Oven)</strong> <br>This stops the running process but doesn’t delete anything.</p><pre>docker stop &lt;container-id&gt;<br># Result: The container stops, and the app goes offline.</pre><p><strong>Step 5: Check All Containers</strong> <br>See both running and stopped containers.</p><pre>docker ps -a<br># Shows the stopped &#39;my-app&#39; container.</pre><p><strong>Step 6: Remove the Container (Throw Away the Cake)</strong> <br>This permanently deletes the container.</p><pre>docker rm &lt;container-id&gt;<br># Result: The stopped container is deleted.</pre><p><strong>Step 7: Remove the Image (Throw Away the Recipe)</strong> <br>This permanently deletes the image blueprint.</p><pre>docker rmi my-app<br># Result: The &#39;my-app&#39; image is deleted. You must rebuild it to use it again.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76b732b8d762" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thinking Serverless? Your Guide to AWS Lambda Starts Here.]]></title>
            <link>https://medium.com/@harshanacz/thinking-serverless-your-guide-to-aws-lambda-starts-here-0397fd6cbe88?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/0397fd6cbe88</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[project-ideas]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[awsserverless]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 19:11:46 GMT</pubDate>
            <atom:updated>2025-08-12T19:11:46.026Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how to run your code without the headache of managing servers? Welcome to the world of serverless computing, with AWS Lambda leading the charge. This guide will break down exactly what Lambda is, explore why it has become so popular, and show you what you can build with it, complete with project ideas to get you started. Let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjvbFzAjrDqzs22hS32Hjg.png" /><figcaption>aws lambda</figcaption></figure><h3>What is AWS Lambda?</h3><p>Think of AWS Lambda as a “magic” box for your code.</p><p>Normally, to run code for a website or an app, you need a computer that’s always on (a server). You have to manage this server, make sure it’s working, and pay for it even when no one is using your app.</p><p>With AWS Lambda, you don’t need to worry about servers at all. You just give your code to AWS, and they run it for you whenever it’s needed. This is called <strong>serverless</strong> computing.</p><p>With a <strong>traditional server</strong>, you’re right; it’s like a computer that is <strong>always on</strong> and waiting to serve users.</p><p>With <strong>AWS Lambda</strong>, there isn’t a dedicated server that is always running just for you. Instead, it works on demand:</p><ol><li>A user makes a request to your website.</li><li>AWS instantly finds an available execution environment, loads your code into it, and runs it.</li><li>Your code processes the request and returns a response.</li><li>Afterward, the environment is shut down.</li></ol><h3>Why is it so popular?</h3><p>Lambda is a big deal for a few key reasons:</p><ul><li><strong>Pay Only for What You Use:</strong> You’re only charged for the milliseconds your code is actually running. If nobody is using your app, you pay nothing. It’s like only paying for electricity when the light is switched on.</li><li><strong>No Need to Manage Servers:</strong> AWS handles all the hard work of keeping the servers running, updated, and secure. This frees you up to focus on writing good code.</li><li><strong>Scales Automatically:</strong> If one person uses your app, Lambda runs your code once. If a thousand people use it at the same time, Lambda automatically runs your code a thousand times. You don’t have to do anything to handle the extra traffic.</li><li><strong>Event-Driven:</strong> Lambda functions run in response to “events.” An event could be someone visiting your website, uploading a file, or a specific time of day.</li></ul><h3>What can you do with it?</h3><p>You can use AWS Lambda for a huge variety of tasks. It’s like a Swiss Army knife for developers. (Like our cover photo)</p><p>Here are some common uses:</p><ul><li><strong>Powering Websites and Apps:</strong> It can run the backend logic for your applications. For example, when a user fills out a contact form, a Lambda function can process that information and send you an email.</li><li><strong>Processing Data:</strong> You can use it to automatically resize images when they are uploaded, convert files from one format to another, or analyze data as it comes in.</li><li><strong>Automating Tasks:</strong> You can schedule Lambda functions to run at specific times to perform routine tasks, like backing up data or generating daily reports.</li><li><strong>Building Chatbots and Voice Assistants:</strong> Lambda can provide the “brains” for a chatbot or an Alexa skill, processing what the user says and figuring out how to respond.</li></ul><h3>Excellent Fit For:</h3><p>AWS Lambda is very flexible, but it’s a perfect match for certain kinds of web applications and less ideal for others.</p><p>Here’s a simple breakdown:</p><ul><li><strong>APIs and Microservices:</strong> This is the most common use case. Instead of one giant application, you build many small, independent functions (e.g., userLogin, getProducts, processPayment). It&#39;s clean, scalable, and easy to manage.</li><li><strong>Websites with Unpredictable Traffic:</strong> Think of a blog that suddenly goes viral, a voting website, or a ticketing site. Lambda automatically scales to handle huge spikes in traffic without you doing anything, and you don’t pay for servers sitting idle during quiet times.</li><li><strong>Backend Tasks (Data Processing):</strong> Perfect for things that happen in the background. For example, when a user uploads an image to your site, a Lambda function can automatically trigger to resize it, run it through analysis, or add a watermark.</li><li><strong>Websites with Simple Dynamic Content:</strong> Great for powering contact forms, surveys, or pages that pull data from a database like Amazon DynamoDB.</li></ul><h3>Maybe Not The Best Fit For:🤔</h3><ul><li><strong>Long-Running Processes:</strong> Lambda functions have a maximum runtime limit (<strong>currently 15 minutes — </strong><a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-timeout.html">https://docs.aws.amazon.com/lambda/latest/dg/configuration-timeout.html</a> ). They are not suitable for tasks that take hours to complete, like transcoding a full movie or running a large scientific simulation in a single go.</li><li><strong>Stateful Applications:</strong> Applications that need to “remember” information in memory from one user request to the next (like a live chat room’s connection data) are difficult to build on Lambda, as each invocation is independent. State must be stored externally in a database or cache.</li><li><strong>Apps Needing Consistent, Ultra-Low Latency:</strong> For applications like high-frequency stock trading or real-time multiplayer game servers, the potential delay from a “cold start” might be unacceptable. A dedicated, always-on server (like AWS EC2) is often better for these cases.</li></ul><h3>What are some project ideas for a beginner? (using lambda)</h3><p>Getting your hands dirty is the best way to learn! there are a few simple project ideas:</p><ul><li><strong>Serverless Contact Form:</strong> Create a simple HTML form on a webpage. When a user submits it, have a Lambda function take the data and email it to you using another AWS service called Simple Email Service (SES).</li><li><strong>Image Thumbnail Generator:</strong> Set up a Lambda function that automatically creates a small thumbnail version of any image you upload to an AWS storage bucket (called S3).</li><li><strong>Scheduled Daily Quote:</strong> Write a Lambda function that runs once a day, fetches a random inspirational quote from an API on the internet, and sends it to you via email or a messaging app.</li><li><strong>Basic URL Shortener:</strong> Build a simple service where you can enter a long URL and have a Lambda function generate a short, unique link for it, storing the mapping in a simple database like Amazon DynamoDB.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0397fd6cbe88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The MERN Stack Developer’s Cheatsheet]]></title>
            <link>https://medium.com/@harshanacz/the-mern-stack-developers-cheatsheet-80284a05ddbd?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/80284a05ddbd</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Thu, 07 Aug 2025 13:49:35 GMT</pubDate>
            <atom:updated>2025-08-07T13:49:35.741Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*I21u65vvX66b9MCnIB8JOQ.jpeg" /></figure><h3>#1 JavaScript Array Methods 🧺</h3><p>Think of these as tools to work with lists (arrays) of things.</p><ol><li><strong>map()</strong></li></ol><p>Creates a <strong>new</strong> array by doing something to <strong>each</strong> item in an old array.</p><p>Example- You have a list of prices in dollars. map can create a new list with all those prices converted to Sri Lankan Rupees.</p><pre>const dollarPrices = [10, 25, 50]; // Example list of prices in USD<br>const exchangeRate = 300; // 1 USD = 300 LKR<br><br>const lkrPrices = dollarPrices.map(priceInDollars =&gt; priceInDollars * exchangeRate);<br><br>console.log(lkrPrices); // Output: [3000, 7500, 15000]</pre><p>Here are some key use cases:</p><ul><li>Data Transformation and Reformatting</li><li>Rendering Lists</li></ul><pre>const products = [&#39;Laptop&#39;, &#39;Mouse&#39;, &#39;Keyboard&#39;];<br><br>const htmlListItems = products.map(product =&gt; `&lt;li&gt;${product}&lt;/li&gt;`);<br><br>console.log(htmlListItems); <br>// Output: [&#39;&lt;li&gt;Laptop&lt;/li&gt;&#39;, &#39;&lt;li&gt;Mouse&lt;/li&gt;&#39;, &#39;&lt;li&gt;Keyboard&lt;/li&gt;&#39;]</pre><ul><li>Chain with Other Methods</li></ul><p>2.<strong> forEach()</strong></p><p>Executes a function once for each array element. It <strong>doesn’t</strong> create a new array; it’s just for running a loop.</p><p>3. <strong>reduce()</strong></p><p>The <strong>reduce()</strong> method is used to turn an array of many values into a <strong>single value</strong>.</p><p>Here are some use cases:</p><ul><li>Calculating a Total</li></ul><pre>const sales = [100, 250, 75, 500];<br>const totalSales = sales.reduce((sum, item) =&gt; sum + item, 0); // starts with 0<br><br>console.log(totalSales); // Output: 925</pre><ul><li>Counting Items in an Array</li></ul><p>You can count how many times each item appears in an array.</p><pre>const fruits = [&#39;apple&#39;, &#39;orange&#39;, &#39;apple&#39;, &#39;banana&#39;, &#39;orange&#39;, &#39;apple&#39;];<br><br>const fruitCounts = fruits.reduce((counts, fruit) =&gt; {<br>  counts[fruit] = (counts[fruit] || 0) + 1;<br>  return counts;<br>}, {}); // starts with an empty object {}<br><br>console.log(fruitCounts); <br>// Output: { apple: 3, orange: 2, banana: 1 }</pre><p>4. <strong>find()</strong></p><p>Returns the <strong>first element</strong> in the array that satisfies the provided testing function. If no values satisfy the function, undefined is returned.</p><pre>const users = [<br>  { id: 10, name: &#39;Ravi&#39; },<br>  { id: 21, name: &#39;Saman&#39; },<br>  { id: 35, name: &#39;Kasun&#39; },<br>];<br><br>// Find the user with the id of 21<br>const userSaman = users.find(user =&gt; user.id === 21);<br><br>console.log(userSaman); // Output: { id: 21, name: &#39;Saman&#39; }</pre><p>5. <strong>findIndex()</strong></p><p>Returns the <strong>index</strong> of the first element in the array that satisfies the testing function. Otherwise, it returns -1.</p><pre>const users = [<br>  { id: 10, name: &#39;Ravi&#39; },<br>  { id: 21, name: &#39;Saman&#39; },<br>  { id: 35, name: &#39;Kasun&#39; },<br>];<br><br>// Find the index of the user named &#39;Saman&#39;<br>const samanIndex = users.findIndex(user =&gt; user.name === &#39;Saman&#39;);<br><br>console.log(samanIndex); // Output: 1</pre><p>6.<strong> includes()</strong></p><p>Checks if an array contains a certain value among its entries, returning true or false.</p><pre>const cities = [&#39;Colombo&#39;, &#39;Kandy&#39;, &#39;Galle&#39;];<br><br>const hasKandy = cities.includes(&#39;Kandy&#39;);<br>console.log(hasKandy); // Output: true<br><br>const hasJaffna = cities.includes(&#39;Jaffna&#39;);<br>console.log(hasJaffna); // Output: false</pre><p>7. <strong>push() / </strong><strong>pop()</strong></p><p>push() adds one or more elements to the <strong>end</strong> of an array. pop() removes the <strong>last</strong> element.</p><pre>let shoppingList = [&#39;Rice&#39;, &#39;Dhal&#39;];<br><br>// Add an item to the end<br>shoppingList.push(&#39;Coconut&#39;);<br>console.log(shoppingList); // Output: [&#39;Rice&#39;, &#39;Dhal&#39;, &#39;Coconut&#39;]<br><br>// Remove the last item<br>const removedItem = shoppingList.pop();<br>console.log(removedItem);   // Output: &#39;Coconut&#39;<br>console.log(shoppingList); // Output: [&#39;Rice&#39;, &#39;Dhal&#39;]</pre><p>8. <strong>shift()</strong></p><p>Removes the <strong>first</strong> element from an array and returns that removed element.</p><pre>let queue = [&#39;Kamal&#39;, &#39;Nimal&#39;, &#39;Sunil&#39;];<br><br>// The first person leaves the queue<br>const firstPerson = queue.shift();<br><br>console.log(firstPerson); // Output: &#39;Kamal&#39;<br>console.log(queue);     // Output: [&#39;Nimal&#39;, &#39;Sunil&#39;]</pre><p>9. <strong>slice()</strong></p><p>Returns a <strong>shallow copy</strong> of a portion of an array into a new array. The original array is <strong>not</strong> modified.</p><pre>const numbers = [10, 20, 30, 40, 50];<br><br>// Get a copy of elements from index 1 up to (but not including) index 4<br>const middleNumbers = numbers.slice(1, 4);<br><br>console.log(middleNumbers); // Output: [20, 30, 40]<br>console.log(numbers); // Original is unchanged: [10, 20, 30, 40, 50]</pre><p>10.<strong> splice()</strong></p><p><strong>Changes</strong> the contents of an array by removing or replacing existing elements and/or adding new elements. It modifies the original array.</p><pre>let months = [&#39;Jan&#39;, &#39;March&#39;, &#39;April&#39;, &#39;June&#39;];<br><br>// Add &#39;Feb&#39; at index 1<br>// The parameters are: (start index, how many to delete, item to add)<br>months.splice(1, 0, &#39;Feb&#39;);<br>console.log(months); // Output: [&#39;Jan&#39;, &#39;Feb&#39;, &#39;March&#39;, &#39;April&#39;, &#39;June&#39;]<br><br>// Now, remove &#39;June&#39; (at index 4)<br>months.splice(4, 1);<br>console.log(months); // Output: [&#39;Jan&#39;, &#39;Feb&#39;, &#39;March&#39;, &#39;April&#39;]</pre><h3>#2 JavaScript Object/General</h3><p>These are general tools for working with data.</p><p><strong>Object.keys() / </strong><strong>Object.values() / </strong><strong>Object.entries()</strong>: Ways to get information from an object (e.g., let user = {name: &#39;John&#39;, age: 30}).</p><ul><li>Object.keys(user) gives you [&#39;name&#39;, &#39;age&#39;].</li><li>Object.values(user) gives you [&#39;John&#39;, 30].</li><li>Object.entries(user) gives you [[&#39;name&#39;, &#39;John&#39;], [&#39;age&#39;, 30]].</li></ul><p><strong>Destructuring</strong>: A shortcut to pull values from objects or arrays into variables.</p><ul><li>Instead of let name = user.name;, you can write let { name } = user;.</li></ul><p><strong>Spread operator (</strong><strong>...)</strong>: &quot;Spreads out&quot; the elements of an array or object. Great for copying or merging.</p><ul><li>let combined = [...array1, ...array2];</li><li>let updatedUser = {...user, location: &#39;Wattala&#39;};</li></ul><p><strong>Rest parameters (</strong><strong>...)</strong>: Looks the same but used in functions. It collects all remaining arguments into a single array.</p><ul><li>function sum(...numbers) { ... } // numbers will be an array</li></ul><h3>#3 JavaScript Language Features</h3><p>Core features of the JS language itself.</p><ul><li><strong>async / </strong><strong>await</strong>: The modern way to handle code that takes time (like database calls). It makes asynchronous code look and behave a little more like normal, synchronous code.</li><li>async: Put this before a function to tell it you&#39;ll be using await inside.</li><li>await: Put this before a Promise (like a database query). It pauses the function until the promise is settled.</li><li><strong>Promise</strong>: An object representing a future result of an asynchronous operation. It&#39;s a &quot;promise&quot; that you&#39;ll get a value back eventually, either a success value or a failure reason.</li><li><strong>try...catch</strong>: Handles errors. You put risky code in the try block. If an error happens, the catch block runs, preventing your app from crashing.</li><li><strong>class / </strong><strong>constructor</strong>: class is a blueprint for creating objects. The constructor is a special method inside the class that sets up the object when it&#39;s created.</li><li><strong>export / </strong><strong>import</strong>: How you share code between different files in modern JavaScript. <strong>export</strong> makes variables/functions available, and <strong>import</strong> brings them into another file.</li></ul><h3>#4 JavaScript Language Features</h3><p>These are specific to your backend environment.</p><ul><li><strong>require / </strong><strong>module.exports</strong>: The older, traditional Node.js way of importing and exporting code between files. You&#39;ll see it a lot.</li><li><strong>res.json() / </strong><strong>res.send() / </strong><strong>res.status()</strong>: Used in Express to send a response back to the browser.</li><li>res.status(200): Sets the HTTP status code (200 = OK).</li><li>res.json({ data: &#39;...&#39; }): Sends a JSON response (most common for APIs).</li><li>res.send(&#39;Hello&#39;): Sends a plain text or HTML response.</li><li><strong>next()</strong>: In middleware, next() passes control to the next middleware function in the stack.</li><li><strong>Middleware</strong>: Functions that run in the middle, between a request being received and a response being sent. Think of them as checkpoints.</li></ul><h3>#5 JavaScript Language Features</h3><p>hese are commands for interacting with your MongoDB database using the Mongoose library.</p><ul><li><strong>Model.find() / </strong><strong>findById() / </strong><strong>findOne()</strong>: To read data. find() gets many documents, findById() gets one by its ID, and findOne() gets the first one that matches a query.</li><li><strong>Model.save()</strong>: Saves a new document (or updates an existing one) to the database.</li><li><strong>Model.updateOne() / </strong><strong>updateMany()</strong>: Updates documents in the database without fetching them first.</li><li><strong>Model.deleteOne() / </strong><strong>deleteMany()</strong>: Deletes documents.</li><li><strong>populate()</strong>: A powerful feature. If a Post has an author field with a user&#39;s ID, populate(&#39;author&#39;) will fetch the post and automatically replace the ID with the full author&#39;s information (name, email, etc.).</li></ul><h3>#6 JavaScript Language Features</h3><p>These are important patterns and ideas in backend development.</p><p><strong>JWT (JSON Web Token)</strong>: A compact and secure way to represent a user’s identity. After a user logs in, the server gives them a JWT. The user includes this token with every future request to prove who they are. It’s like a digital ID card.</p><p><strong>Middleware (Use Cases)</strong>: Perfect for tasks that need to happen on many requests, like:</p><ul><li><strong>Authentication</strong>: Checking if the user’s JWT is valid.</li><li><strong>Validation</strong>: Checking if the incoming data is correct.</li><li><strong>Logging</strong>: Recording details about each request.</li></ul><p><strong>Validation</strong>: The process of making sure user input is correct and safe before you use it (e.g., is the email in a valid format? Is the password strong enough?).</p><p><strong>Error Handling</strong>: A strategy for catching errors and sending back clean, predictable error messages to the user instead of crashing the server.</p><p>Hope this helps you get a clearer picture! Let me know if you want to dive deeper into any of these.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80284a05ddbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What You Should Know When Sending Data from Next.js to MongoDB]]></title>
            <link>https://medium.com/@harshanacz/what-you-should-know-when-sending-data-from-next-js-to-mongodb-95589e1bb4b0?source=rss-c8a39a6ed0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/95589e1bb4b0</guid>
            <category><![CDATA[mongodb-atlas]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Harshana]]></dc:creator>
            <pubDate>Tue, 29 Apr 2025 17:27:06 GMT</pubDate>
            <atom:updated>2025-04-29T17:27:06.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vmv0wfb3TDVpovBAYxsinw.png" /><figcaption>nextjs with mongodb</figcaption></figure><h3>1. Overview of Next.js and MongoDB Integration</h3><ul><li><strong>Next.js</strong>: A React-based framework for building server-side rendered (SSR), static, or API-driven web applications.</li><li><strong>MongoDB</strong>: A NoSQL database that stores data in flexible, JSON-like documents.</li><li><strong>Integration</strong>: Typically, you connect Next.js to MongoDB using server-side logic (e.g., API routes or server components) to perform CRUD operations (Create, Read, Update, Delete).</li></ul><p>Key steps:</p><ul><li>Set up a MongoDB database (local or cloud, e.g., MongoDB Atlas).</li><li>Use a library like mongoose or the MongoDB Node.js driver to interact with MongoDB.</li><li>Create API routes or server-side logic in Next.js to handle data operations.</li></ul><h3>2. Key Concepts</h3><h4>-&gt; Schema</h4><ul><li>A <strong>schema</strong> defines the structure of your data in MongoDB. It specifies the fields, data types, and constraints for documents in a collection.</li><li>MongoDB is <strong>schema-less</strong> by default, meaning you can store documents with different structures in the same collection. However, using a schema (via libraries like Mongoose) enforces consistency and validation.</li><li>Example (using Mongoose):</li></ul><pre>const mongoose = require(&#39;mongoose&#39;);<br>const userSchema = new mongoose.Schema({<br>  name: { type: String, required: true },<br>  email: { type: String, required: true, unique: true },<br>  age: { type: Number, min: 18 },<br>  createdAt: { type: Date, default: Date.now }<br>});</pre><ul><li><strong>Purpose</strong>: Ensures data consistency, validates input, and simplifies querying.</li><li><strong>Fields</strong>: Define properties like type (String, Number, Date, etc.), required, default, unique, min, max, etc.</li></ul><h4>-&gt; Data Models</h4><ul><li>A <strong>data model</strong> is a compiled version of a schema that provides an interface to interact with a MongoDB collection.</li><li>In Mongoose, a model is created from a schema and represents a collection in the database. It allows you to perform CRUD operations.</li><li>Example:</li></ul><pre>const User = mongoose.model(&#39;User&#39;, userSchema);</pre><p><strong>Usage</strong>:</p><ul><li>Create a document: const newUser = new User({ name: ‘John’, email: ‘john@example.com’, age: 25 });</li><li>Save to database: await newUser.save();</li><li>Query: const users = await User.find({ age: { $gte: 18 } });</li></ul><p><strong>Purpose</strong>: Models abstract database operations, making it easier to create, read, update, and delete data.</p><h4>-&gt; Collections</h4><ul><li>MongoDB organizes data into <strong>collections</strong>, which are analogous to tables in relational databases.</li><li>Each collection contains <strong>documents</strong> (JSON-like objects).</li><li>Example: A users collection might contain documents like</li></ul><pre>{ &quot;_id&quot;: &quot;123&quot;, &quot;name&quot;: &quot;John&quot;, &quot;email&quot;: &quot;john@example.com&quot;, &quot;age&quot;: 25 }<br>{ &quot;_id&quot;: &quot;124&quot;, &quot;name&quot;: &quot;Jane&quot;, &quot;email&quot;: &quot;jane@example.com&quot;, &quot;age&quot;: 30 }</pre><h3>3. Setting Up MongoDB with Next.js</h3><p>In this article, I’ll give you quick guide what u should do, therefore, im not going to do the technical part. you can easily do it — can get clear idea from Chatgpt or Gemini</p><h4>Step 1: Install Dependencies</h4><h4><strong>Step 2: Connect to MongoDB</strong></h4><h4>Step 3: Define Schemas and Models</h4><h4>Step 4: Create API Routes</h4><h4>Step 5: Call API from Frontend</h4><h3>4. <strong>Best Practices</strong></h3><h4>1. Environment Variables</h4><ul><li>Store sensitive data (e.g., MONGODB_URI) in .env.local.</li><li>Ensure .env.local is added to .gitignore to avoid exposing secrets.</li></ul><h4>2. Error Handling</h4><ul><li>Always handle errors in API routes and database operations.</li><li>Example</li></ul><pre>try {<br>  await user.save();<br>} catch (error) {<br>  res.status(400).json({ success: false, error: error.message });<br>}</pre><h4>3. Connection Management</h4><ul><li>Reuse MongoDB connections to avoid performance issues.</li><li>Check connection state before connecting (as shown in connectDB example).</li></ul><h4>4. Validation</h4><ul><li>Use Mongoose schema validation (required, unique, min, max, etc.).</li><li>Add custom validation if needed:</li></ul><pre>userSchema.path(&#39;email&#39;).validate((email) =&gt; {<br>  return /\S+@\S+\.\S+/.test(email);<br>}, &#39;Invalid email&#39;);</pre><h4>5. Security</h4><ul><li>Sanitize user input to prevent injection attacks (Mongoose handles most MongoDB injection concerns).</li><li>Use HTTPS for API requests.</li><li>Implement authentication/authorization (e.g., NextAuth.js, JWT) to secure API routes.</li></ul><h4>6. Performance</h4><ul><li>Use indexes on frequently queried fields</li></ul><pre>userSchema.index({ email: 1 });</pre><ul><li>Paginate large datasets:</li></ul><pre>const users = await User.find().skip(10).limit(10);</pre><h4>7. API Route Structure</h4><ul><li>Organize API routes logically (e.g., /api/users, /api/posts).</li><li>Use HTTP methods appropriately (GET, POST, PUT, DELETE).</li></ul><h3>5. Example Project Structure</h3><pre>my-nextjs-app/<br>├── models/<br>│   └── User.ts<br>├── lib/<br>│   └── mongodb.ts<br>├── app/<br>│   ├── api/<br>│   │   └── users.ts<br>│   └── page.tsx<br>├── .env.local<br>├── package.json</pre><h3>Resources</h3><ul><li><a href="https://mongoosejs.com/docs/">Mongoose Documentation</a></li><li><a href="https://mongodb.github.io/node-mongodb-native/">MongoDB Node.js Driver</a></li><li><a href="https://nextjs.org/docs/api-routes/introduction">Next.js API Routes</a></li><li><a href="https://www.mongodb.com/cloud/atlas">MongoDB Atlas</a></li><li><a href="https://vercel.com/guides/nextjs-mongodb">Next.js with MongoDB Tutorial</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95589e1bb4b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>