<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Malki L.</title>
    <description>The latest articles on Forem by Malki L. (@malki_lapidot_bf2ab753e50).</description>
    <link>https://forem.com/malki_lapidot_bf2ab753e50</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3573661%2F5b6bbc00-55c8-42c5-9096-12a8a4b3040b.jpg</url>
      <title>Forem: Malki L.</title>
      <link>https://forem.com/malki_lapidot_bf2ab753e50</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/malki_lapidot_bf2ab753e50"/>
    <language>en</language>
    <item>
      <title>Building a Fully Generic GET Engine — A Scalable Approach to Dynamic Querying</title>
      <dc:creator>Malki L.</dc:creator>
      <pubDate>Wed, 10 Dec 2025 11:02:17 +0000</pubDate>
      <link>https://forem.com/malki_lapidot_bf2ab753e50/building-a-fully-generic-get-engine-a-scalable-approach-to-dynamic-querying-516o</link>
      <guid>https://forem.com/malki_lapidot_bf2ab753e50/building-a-fully-generic-get-engine-a-scalable-approach-to-dynamic-querying-516o</guid>
      <description>&lt;h2&gt;
  
  
  Quick Links:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;The Problem: Too Many Entities, Too Much Repeated Logic&lt;/li&gt;
&lt;li&gt;The Core Idea: Describe the Resource — Don’t Hardcode It&lt;/li&gt;
&lt;li&gt;How the Generic GET Flow Works&lt;/li&gt;
&lt;li&gt;Before vs After&lt;/li&gt;
&lt;li&gt;Why This Architecture Is Powerful?&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In fast-growing systems, the simplest operation — &lt;strong&gt;fetching data&lt;/strong&gt; — slowly becomes one of the hardest to maintain.&lt;/p&gt;

&lt;p&gt;Every new entity requires its own GET endpoint, its own filters, its own search logic, and its own controller–service–repository chain. After a few months, the codebase becomes filled with &lt;strong&gt;duplicate logic&lt;/strong&gt; and &lt;strong&gt;inconsistent behaviors&lt;/strong&gt; across resources.&lt;/p&gt;

&lt;p&gt;During our Infrastructure work, we faced exactly this challenge.&lt;br&gt;
Our solution was to design a &lt;strong&gt;Generic GET Engine&lt;/strong&gt; — a single dynamic pipeline capable of handling GET operations for any resource, &lt;strong&gt;without writing any new controllers or queries&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  🛑 The Problem: Too Many Entities, Too Much Repeated Logic
&lt;/h2&gt;

&lt;p&gt;Originally, each entity implemented GET differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Events had one filtering model&lt;/li&gt;
&lt;li&gt;Processes had another&lt;/li&gt;
&lt;li&gt;Some supported search, others didn’t&lt;/li&gt;
&lt;li&gt;Some used pagination, others didn't&lt;/li&gt;
&lt;li&gt;Every new resource required writing controllers, queries, validations, and tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This resulted in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ &lt;strong&gt;Duplication&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Inconsistency&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Slow development&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Harder debugging&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system needed one unified solution.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✨ The Core Idea: Describe the Resource, Don’t Hardcode It
&lt;/h2&gt;

&lt;p&gt;Instead of writing resource-specific logic, we introduced a central &lt;strong&gt;Resource Registry&lt;/strong&gt;.&lt;br&gt;
Each resource is defined once, using &lt;strong&gt;metadata&lt;/strong&gt; that tells the system how it should behave.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example — Registering a Resource
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;registry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;event&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;entity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;alias&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;e&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;searchable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This simple definition allows the GET engine to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identify&lt;/strong&gt; the resource dynamically&lt;/li&gt;
&lt;li&gt;Know which &lt;strong&gt;entity to query&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Know which fields support &lt;strong&gt;full-text search&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build the correct SQL&lt;/strong&gt; automatically&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From this point on, the system can generate and execute queries for &lt;code&gt;event&lt;/code&gt; &lt;strong&gt;without any manual code&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚙️ How the Generic GET Flow Works
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8puuo7dymsbxkk1uotwu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8puuo7dymsbxkk1uotwu.png" alt="Flow Diagram: Before vs. After Generic GET Engine Implementation" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Request
&lt;/h3&gt;

&lt;p&gt;Client sends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /api/event?search=meeting&amp;amp;sort=createdAt:desc&amp;amp;limit=20&amp;amp;page=1

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

&lt;/div&gt;



&lt;p&gt;The engine parses parameters like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;search&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;filter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sort&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pagination&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Resolve Resource
&lt;/h3&gt;

&lt;p&gt;The system identifies the resource from the URL and loads its config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;registry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resourceName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;baseRepository&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;queryOptions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This dynamic lookup is the heart of the engine — &lt;strong&gt;nothing is hardcoded anymore&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Build Query
&lt;/h3&gt;

&lt;p&gt;The Query Builder constructs SQL based on the registry + incoming options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;Example&lt;/span&gt; &lt;span class="n"&gt;snippet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;qb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;`similarity(${alias}.name, :search) &amp;gt; 0.2`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;search&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The engine can generate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Full-text search&lt;/strong&gt; (e.g., Trigram similarity)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filters&lt;/strong&gt; (ranges, equals, lists)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sorting&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pagination&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Field selection&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All &lt;strong&gt;automatically&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Execute
&lt;/h3&gt;

&lt;p&gt;The Base Repository executes the query and returns a &lt;strong&gt;uniform structured response&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;qb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMany&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This completes the flow — &lt;strong&gt;without writing any entity-specific logic&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  📊 Before vs After
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Before (Manual Logic)&lt;/th&gt;
&lt;th&gt;After (Generic GET Engine)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GET Logic&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Each entity had its own GET logic&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;One generic GET engine&lt;/strong&gt; for all resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Consistency&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Queries and search were inconsistent&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Unified&lt;/strong&gt; search, filtering, sorting, pagination&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;New Resource&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Required manual coding of controllers and queries&lt;/td&gt;
&lt;td&gt;Requires &lt;strong&gt;only:&lt;/strong&gt; &lt;code&gt;registry.register({ ... });&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Duplication&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Zero&lt;/strong&gt; duplication&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Why This Architecture Is Powerful?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;✔️ Saves Time:&lt;/strong&gt; Dozens of repetitive controller/service/query files are eliminated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;✔️ Scales Easily:&lt;/strong&gt; Adding new entities is trivial.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;✔️ Consistency Across the System:&lt;/strong&gt; Every endpoint behaves the same: same search, sorting, filters, pagination logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;✔️ Extendable:&lt;/strong&gt; Add a feature once → all resources get it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;✔️ Cleaner Codebase:&lt;/strong&gt; Infrastructure is centralized, not scattered.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Conclusion
&lt;/h2&gt;

&lt;p&gt;The Generic GET Engine transformed our system from a patchwork of duplicated logic into a &lt;strong&gt;clean, extensible, and scalable architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By shifting from &lt;strong&gt;"write GET logic per entity"&lt;/strong&gt; to &lt;strong&gt;"describe the entity once"&lt;/strong&gt;, we created a foundation that supports rapid development and long-term maintainability.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This approach is ideal for any team working with large domain models or dynamic resource sets. Instead of writing endless boilerplate code — &lt;strong&gt;you build one smart engine&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>node</category>
      <category>architecture</category>
      <category>typescript</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
