Files
Portfolio_Site/public/posts/demo/index.html
2025-12-29 21:36:37 +05:45

2 lines
17 KiB
HTML

<!doctype html><html lang=en dir=auto data-theme=dark><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=robots content="index, follow"><title>Understanding Separation of Concerns (SoC) in NestJS | Saurav Dhakal</title><meta name=keywords content="nestjs,typescript,architecture"><meta name=description content="A guide to understanding Separation of Concerns in NestJS using modules, services, and controllers."><meta name=author content="Saurav Dhakal"><link rel=canonical href=https://sauravdhakal.com.np/posts/demo/><meta name=google-site-verification content="G-V0CXG8ZEG2"><link crossorigin=anonymous href=/assets/css/stylesheet.1819d1b52fd9f2af4d88316fde3f9b918c48d08dac9a2e1ef0a7ca49d1f18ddb.css integrity="sha256-GBnRtS/Z8q9NiDFv3j+bkYxI0I2smi4e8KfKSdHxjds=" rel="preload stylesheet" as=style><link rel=icon href=https://sauravdhakal.com.np/%3Clink%20/%20abs%20url%3E><link rel=icon type=image/png sizes=16x16 href=https://sauravdhakal.com.np/%3Clink%20/%20abs%20url%3E><link rel=icon type=image/png sizes=32x32 href=https://sauravdhakal.com.np/%3Clink%20/%20abs%20url%3E><link rel=apple-touch-icon href=https://sauravdhakal.com.np/%3Clink%20/%20abs%20url%3E><link rel=mask-icon href=https://sauravdhakal.com.np/%3Clink%20/%20abs%20url%3E><meta name=theme-color content="#2e2e33"><meta name=msapplication-TileColor content="#2e2e33"><link rel=alternate hreflang=en href=https://sauravdhakal.com.np/posts/demo/><noscript><style>#theme-toggle,.top-link{display:none}</style></noscript><meta property="og:url" content="https://sauravdhakal.com.np/posts/demo/"><meta property="og:site_name" content="Saurav Dhakal"><meta property="og:title" content="Understanding Separation of Concerns (SoC) in NestJS"><meta property="og:description" content="A guide to understanding Separation of Concerns in NestJS using modules, services, and controllers."><meta property="og:locale" content="en-us"><meta property="og:type" content="article"><meta property="article:section" content="posts"><meta property="article:published_time" content="2025-08-19T00:00:00+00:00"><meta property="article:modified_time" content="2025-08-19T00:00:00+00:00"><meta property="article:tag" content="Nestjs"><meta property="article:tag" content="Typescript"><meta property="article:tag" content="Architecture"><meta name=twitter:card content="summary"><meta name=twitter:title content="Understanding Separation of Concerns (SoC) in NestJS"><meta name=twitter:description content="A guide to understanding Separation of Concerns in NestJS using modules, services, and controllers."><script type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Posts","item":"https://sauravdhakal.com.np/posts/"},{"@type":"ListItem","position":2,"name":"Understanding Separation of Concerns (SoC) in NestJS","item":"https://sauravdhakal.com.np/posts/demo/"}]}</script><script type=application/ld+json>{"@context":"https://schema.org","@type":"BlogPosting","headline":"Understanding Separation of Concerns (SoC) in NestJS","name":"Understanding Separation of Concerns (SoC) in NestJS","description":"A guide to understanding Separation of Concerns in NestJS using modules, services, and controllers.","keywords":["nestjs","typescript","architecture"],"articleBody":"When building applications, one of the most important design principles to keep in mind is Separation of Concerns (SoC). NestJS, with its modular architecture, makes applying SoC almost effortless — but understanding why it matters and how to use it properly will help you write cleaner, testable, and future-proof code.\nWhat is Separation of Concerns and Why it Matters? The basic idea is:\nA program should be divided into distinct sections, where each section addresses a single responsibility.\n","wordCount":"78","inLanguage":"en","datePublished":"2025-08-19T00:00:00Z","dateModified":"2025-08-19T00:00:00Z","author":[{"@type":"Person","name":"Saurav Dhakal"}],"mainEntityOfPage":{"@type":"WebPage","@id":"https://sauravdhakal.com.np/posts/demo/"},"publisher":{"@type":"Organization","name":"Saurav Dhakal","logo":{"@type":"ImageObject","url":"https://sauravdhakal.com.np/%3Clink%20/%20abs%20url%3E"}}}</script></head><body id=top><header class=header><nav class=nav><div class=logo><a href=https://sauravdhakal.com.np/ accesskey=h title="SauravDhakal (Alt + H)">SauravDhakal</a><div class=logo-switches></div></div><ul id=menu><li><a href=https://sauravdhakal.com.np/posts/ title=posts><span>posts</span></a></li><li><a href=https://sauravdhakal.com.np/tags/ title=tags><span>tags</span></a></li></ul></nav></header><main class=main><article class=post-single><header class=post-header><div class=breadcrumbs><a href=https://sauravdhakal.com.np/>Home</a>&nbsp;»&nbsp;<a href=https://sauravdhakal.com.np/posts/>Posts</a></div><h1 class="post-title entry-hint-parent">Understanding Separation of Concerns (SoC) in NestJS</h1><div class=post-meta><span title='2025-08-19 00:00:00 +0000 UTC'>August 19, 2025</span>&nbsp;·&nbsp;<span>1 min</span>&nbsp;·&nbsp;<span>78 words</span>&nbsp;·&nbsp;<span>Saurav Dhakal</span></div></header><div class=toc><details><summary accesskey=c title="(Alt + C)"><span class=details>Table of Contents</span></summary><div class=inner><nav id=TableOfContents><ul><li><a href=#what-is-separation-of-concerns-and-why-it-matters>What is Separation of Concerns and Why it Matters?</a></li></ul></nav></div></details></div><div class=post-content><p>When building applications, one of the most important design principles to keep in mind is <strong>Separation of Concerns (SoC)</strong>. NestJS, with its modular architecture, makes applying SoC almost effortless — but understanding <em>why</em> it matters and <em>how</em> to use it properly will help you write cleaner, testable, and future-proof code.</p><h2 id=what-is-separation-of-concerns-and-why-it-matters>What is Separation of Concerns and Why it Matters?<a hidden class=anchor aria-hidden=true href=#what-is-separation-of-concerns-and-why-it-matters>#</a></h2><p>The basic idea is:</p><blockquote><p>A program should be divided into distinct sections, where each section addresses a single responsibility.</p></blockquote></div><footer class=post-footer><ul class=post-tags><li><a href=https://sauravdhakal.com.np/tags/nestjs/>Nestjs</a></li><li><a href=https://sauravdhakal.com.np/tags/typescript/>Typescript</a></li><li><a href=https://sauravdhakal.com.np/tags/architecture/>Architecture</a></li></ul><ul class=share-buttons><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on x" href="https://x.com/intent/tweet/?text=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS&amp;url=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f&amp;hashtags=nestjs%2ctypescript%2carchitecture"><svg viewBox="0 0 512 512" height="30" width="30" fill="currentColor"><path d="M512 62.554V449.446C512 483.97 483.97 512 449.446 512H62.554C28.03 512 0 483.97.0 449.446V62.554C0 28.03 28.029.0 62.554.0H449.446C483.971.0 512 28.03 512 62.554zM269.951 190.75 182.567 75.216H56L207.216 272.95 63.9 436.783h61.366L235.9 310.383l96.667 126.4H456L298.367 228.367l134-153.151H371.033zM127.633 110h36.468l219.38 290.065H349.5z"/></svg></a></li><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on linkedin" href="https://www.linkedin.com/shareArticle?mini=true&amp;url=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f&amp;title=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS&amp;summary=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS&amp;source=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f"><svg viewBox="0 0 512 512" height="30" width="30" fill="currentColor"><path d="M449.446.0C483.971.0 512 28.03 512 62.554v386.892C512 483.97 483.97 512 449.446 512H62.554c-34.524.0-62.554-28.03-62.554-62.554V62.554c0-34.524 28.029-62.554 62.554-62.554h386.892zM160.461 423.278V197.561h-75.04v225.717h75.04zm270.539.0V293.839c0-69.333-37.018-101.586-86.381-101.586-39.804.0-57.634 21.891-67.617 37.266v-31.958h-75.021c.995 21.181.0 225.717.0 225.717h75.02V297.222c0-6.748.486-13.492 2.474-18.315 5.414-13.475 17.767-27.434 38.494-27.434 27.135.0 38.007 20.707 38.007 51.037v120.768H431zM123.448 88.722C97.774 88.722 81 105.601 81 127.724c0 21.658 16.264 39.002 41.455 39.002h.484c26.165.0 42.452-17.344 42.452-39.002-.485-22.092-16.241-38.954-41.943-39.002z"/></svg></a></li><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on reddit" href="https://reddit.com/submit?url=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f&title=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS"><svg viewBox="0 0 512 512" height="30" width="30" fill="currentColor"><path d="M449.446.0C483.971.0 512 28.03 512 62.554v386.892C512 483.97 483.97 512 449.446 512H62.554c-34.524.0-62.554-28.03-62.554-62.554V62.554c0-34.524 28.029-62.554 62.554-62.554h386.892zM446 265.638c0-22.964-18.616-41.58-41.58-41.58-11.211.0-21.361 4.457-28.841 11.666-28.424-20.508-67.586-33.757-111.204-35.278l18.941-89.121 61.884 13.157c.756 15.734 13.642 28.29 29.56 28.29 16.407.0 29.706-13.299 29.706-29.701.0-16.403-13.299-29.702-29.706-29.702-11.666.0-21.657 6.792-26.515 16.578l-69.105-14.69c-1.922-.418-3.939-.042-5.585 1.036-1.658 1.073-2.811 2.761-3.224 4.686l-21.152 99.438c-44.258 1.228-84.046 14.494-112.837 35.232-7.468-7.164-17.589-11.591-28.757-11.591-22.965.0-41.585 18.616-41.585 41.58.0 16.896 10.095 31.41 24.568 37.918-.639 4.135-.99 8.328-.99 12.576.0 63.977 74.469 115.836 166.33 115.836s166.334-51.859 166.334-115.836c0-4.218-.347-8.387-.977-12.493 14.564-6.47 24.735-21.034 24.735-38.001zM326.526 373.831c-20.27 20.241-59.115 21.816-70.534 21.816-11.428.0-50.277-1.575-70.522-21.82-3.007-3.008-3.007-7.882.0-10.889 3.003-2.999 7.882-3.003 10.885.0 12.777 12.781 40.11 17.317 59.637 17.317 19.522.0 46.86-4.536 59.657-17.321 3.016-2.999 7.886-2.995 10.885.008 3.008 3.011 3.003 7.882-.008 10.889zm-5.23-48.781c-16.373.0-29.701-13.324-29.701-29.698.0-16.381 13.328-29.714 29.701-29.714 16.378.0 29.706 13.333 29.706 29.714.0 16.374-13.328 29.698-29.706 29.698zM160.91 295.348c0-16.381 13.328-29.71 29.714-29.71 16.369.0 29.689 13.329 29.689 29.71.0 16.373-13.32 29.693-29.689 29.693-16.386.0-29.714-13.32-29.714-29.693z"/></svg></a></li><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on facebook" href="https://facebook.com/sharer/sharer.php?u=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f"><svg viewBox="0 0 512 512" height="30" width="30" fill="currentColor"><path d="M449.446.0C483.971.0 512 28.03 512 62.554v386.892C512 483.97 483.97 512 449.446 512H342.978V319.085h66.6l12.672-82.621h-79.272v-53.617c0-22.603 11.073-44.636 46.58-44.636H425.6v-70.34s-32.71-5.582-63.982-5.582c-65.288.0-107.96 39.569-107.96 111.204v62.971h-72.573v82.621h72.573V512h-191.104c-34.524.0-62.554-28.03-62.554-62.554V62.554c0-34.524 28.029-62.554 62.554-62.554h386.892z"/></svg></a></li><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on whatsapp" href="https://api.whatsapp.com/send?text=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS%20-%20https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f"><svg viewBox="0 0 512 512" height="30" width="30" fill="currentColor"><path d="M449.446.0C483.971.0 512 28.03 512 62.554v386.892C512 483.97 483.97 512 449.446 512H62.554c-34.524.0-62.554-28.03-62.554-62.554V62.554c0-34.524 28.029-62.554 62.554-62.554h386.892zm-58.673 127.703c-33.842-33.881-78.847-52.548-126.798-52.568-98.799.0-179.21 80.405-179.249 179.234-.013 31.593 8.241 62.428 23.927 89.612l-25.429 92.884 95.021-24.925c26.181 14.28 55.659 21.807 85.658 21.816h.074c98.789.0 179.206-80.413 179.247-179.243.018-47.895-18.61-92.93-52.451-126.81zM263.976 403.485h-.06c-26.734-.01-52.954-7.193-75.828-20.767l-5.441-3.229-56.386 14.792 15.05-54.977-3.542-5.637c-14.913-23.72-22.791-51.136-22.779-79.287.033-82.142 66.867-148.971 149.046-148.971 39.793.014 77.199 15.531 105.329 43.692 28.128 28.16 43.609 65.592 43.594 105.4-.034 82.149-66.866 148.983-148.983 148.984zm81.721-111.581c-4.479-2.242-26.499-13.075-30.604-14.571-4.105-1.495-7.091-2.241-10.077 2.241-2.986 4.483-11.569 14.572-14.182 17.562-2.612 2.988-5.225 3.364-9.703 1.12-4.479-2.241-18.91-6.97-36.017-22.23C231.8 264.15 222.81 249.484 220.198 245s-.279-6.908 1.963-9.14c2.016-2.007 4.48-5.232 6.719-7.847 2.24-2.615 2.986-4.484 4.479-7.472 1.493-2.99.747-5.604-.374-7.846-1.119-2.241-10.077-24.288-13.809-33.256-3.635-8.733-7.327-7.55-10.077-7.688-2.609-.13-5.598-.158-8.583-.158-2.986.0-7.839 1.121-11.944 5.604-4.105 4.484-15.675 15.32-15.675 37.364.0 22.046 16.048 43.342 18.287 46.332 2.24 2.99 31.582 48.227 76.511 67.627 10.685 4.615 19.028 7.371 25.533 9.434 10.728 3.41 20.492 2.929 28.209 1.775 8.605-1.285 26.499-10.833 30.231-21.295 3.732-10.464 3.732-19.431 2.612-21.298-1.119-1.869-4.105-2.99-8.583-5.232z"/></svg></a></li><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on telegram" href="https://telegram.me/share/url?text=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS&amp;url=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f"><svg viewBox="2 2 28 28" height="30" width="30" fill="currentColor"><path d="M26.49 29.86H5.5a3.37 3.37.0 01-2.47-1 3.35 3.35.0 01-1-2.47V5.48A3.36 3.36.0 013 3 3.37 3.37.0 015.5 2h21A3.38 3.38.0 0129 3a3.36 3.36.0 011 2.46V26.37a3.35 3.35.0 01-1 2.47 3.38 3.38.0 01-2.51 1.02zm-5.38-6.71a.79.79.0 00.85-.66L24.73 9.24a.55.55.0 00-.18-.46.62.62.0 00-.41-.17q-.08.0-16.53 6.11a.59.59.0 00-.41.59.57.57.0 00.43.52l4 1.24 1.61 4.83a.62.62.0 00.63.43.56.56.0 00.4-.17L16.54 20l4.09 3A.9.9.0 0021.11 23.15zM13.8 20.71l-1.21-4q8.72-5.55 8.78-5.55c.15.0.23.0.23.16a.18.18.0 010 .06s-2.51 2.3-7.52 6.8z"/></svg></a></li><li><a target=_blank rel="noopener noreferrer" aria-label="share Understanding Separation of Concerns (SoC) in NestJS on ycombinator" href="https://news.ycombinator.com/submitlink?t=Understanding%20Separation%20of%20Concerns%20%28SoC%29%20in%20NestJS&u=https%3a%2f%2fsauravdhakal.com.np%2fposts%2fdemo%2f"><svg width="30" height="30" viewBox="0 0 512 512" fill="currentColor"><path d="M449.446.0C483.971.0 512 28.03 512 62.554V449.446C512 483.97 483.97 512 449.446 512H62.554C28.03 512 0 483.97.0 449.446V62.554C0 28.03 28.029.0 62.554.0H449.446zM183.8767 87.9921h-62.034L230.6673 292.4508V424.0079h50.6655V292.4508L390.1575 87.9921H328.1233L256 238.2489z"/></svg></a></li></ul></footer></article></main><footer class=footer><span>Copyright &copy; 2025 SauravDhakal</span></footer><a href=#top aria-label="go to top" title="Go to Top (Alt + G)" class=top-link id=top-link accesskey=g><svg viewBox="0 0 12 6" fill="currentColor"><path d="M12 6H0l6-6z"/></svg>
</a><script>let menu=document.getElementById("menu");if(menu){const e=localStorage.getItem("menu-scroll-position");e&&(menu.scrollLeft=parseInt(e,10)),menu.onscroll=function(){localStorage.setItem("menu-scroll-position",menu.scrollLeft)}}document.querySelectorAll('a[href^="#"]').forEach(e=>{e.addEventListener("click",function(e){e.preventDefault();var t=this.getAttribute("href").substr(1);window.matchMedia("(prefers-reduced-motion: reduce)").matches?document.querySelector(`[id='${decodeURIComponent(t)}']`).scrollIntoView():document.querySelector(`[id='${decodeURIComponent(t)}']`).scrollIntoView({behavior:"smooth"}),t==="top"?history.replaceState(null,null," "):history.pushState(null,null,`#${t}`)})})</script><script>var mybutton=document.getElementById("top-link");window.onscroll=function(){document.body.scrollTop>800||document.documentElement.scrollTop>800?(mybutton.style.visibility="visible",mybutton.style.opacity="1"):(mybutton.style.visibility="hidden",mybutton.style.opacity="0")}</script><script>document.querySelectorAll("pre > code").forEach(e=>{const n=e.parentNode.parentNode,t=document.createElement("button");t.classList.add("copy-code"),t.innerHTML="copy";function s(){t.innerHTML="copied!",setTimeout(()=>{t.innerHTML="copy"},2e3)}t.addEventListener("click",t=>{if("clipboard"in navigator){navigator.clipboard.writeText(e.textContent),s();return}const n=document.createRange();n.selectNodeContents(e);const o=window.getSelection();o.removeAllRanges(),o.addRange(n);try{document.execCommand("copy"),s()}catch{}o.removeRange(n)}),n.classList.contains("highlight")?n.appendChild(t):n.parentNode.firstChild==n||(e.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName=="TABLE"?e.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(t):e.parentNode.appendChild(t))})</script></body></html>