<?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: Clean Code Studio</title>
    <description>The latest articles on Forem by Clean Code Studio (@cleancodestudio).</description>
    <link>https://forem.com/cleancodestudio</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%2F386677%2F4f170830-7e2c-4f3e-81fe-b666a90b7e3f.gif</url>
      <title>Forem: Clean Code Studio</title>
      <link>https://forem.com/cleancodestudio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cleancodestudio"/>
    <language>en</language>
    <item>
      <title>TS Dependency Injection with @Findhow/Container No Decorators Required 🔥</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Wed, 02 Oct 2024 00:15:19 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/ts-dependency-injection-with-findhowcontainer-no-decorators-required-4hjj</link>
      <guid>https://forem.com/cleancodestudio/ts-dependency-injection-with-findhowcontainer-no-decorators-required-4hjj</guid>
      <description>&lt;h2&gt;
  
  
  @findhow/container
&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;A TypeScript-based Dependency Injection (DI) container supporting various binding types (singleton, transient, scoped), contextual bindings, middleware, circular dependency detection, and Zod schema validation for runtime type safety.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub Repo&lt;/a&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🚀 Unleash the Power of TypeScript Dependency Injection with &lt;code&gt;@findhow/container&lt;/code&gt; 🔥&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;@findhow/container Compared&lt;/li&gt;
&lt;li&gt;🚀 Key Features Breakdown&lt;/li&gt;
&lt;li&gt;
Examples

&lt;ul&gt;
&lt;li&gt;Basic Container Binding&lt;/li&gt;
&lt;li&gt;Singleton Binding&lt;/li&gt;
&lt;li&gt;Contextual Binding&lt;/li&gt;
&lt;li&gt;Middleware Usage&lt;/li&gt;
&lt;li&gt;Circular Dependency Detection&lt;/li&gt;
&lt;li&gt;Tagging Services&lt;/li&gt;
&lt;li&gt;Scoped Instances&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zod Schema Validation Examples&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Zod Schema Validation on Binding&lt;/li&gt;
&lt;li&gt;Invalid Schema Detection&lt;/li&gt;
&lt;li&gt;Schema Validation with Nested Objects&lt;/li&gt;
&lt;li&gt;Schema Validation for Contextual Bindings&lt;/li&gt;
&lt;li&gt;Conditional Schema Validation&lt;/li&gt;
&lt;li&gt;Async Binding with Zod Schema Validation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Other Dependency Injection Examples&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Multiple Implementations with Interfaces&lt;/li&gt;
&lt;li&gt;Nested Dependencies&lt;/li&gt;
&lt;li&gt;Property Injection with Optional Dependencies&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Why @findhow/container?&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Check out the GitHub repository&lt;/a&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  @findhow/container Compared
&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;@findhow/container&lt;/th&gt;
&lt;th&gt;Inversify&lt;/th&gt;
&lt;th&gt;NestJS&lt;/th&gt;
&lt;th&gt;TypeDI&lt;/th&gt;
&lt;th&gt;TSyringe&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TypeScript Support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;No Decorator-based DI Required&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Constructor Injection&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Property Injection&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Method Injection&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Circular Dependency Detection&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Lazy Injection&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Named Injections&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Tagged Injections&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scoped Injections&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Async Injection&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Middleware Support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Zod Schema Validation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Framework Integration&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅ (Full)&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Compare full feature set on GitHub&lt;/a&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Key Features Breakdown
&lt;/h2&gt;

&lt;p&gt;Here are some key features that make &lt;code&gt;@findhow/container&lt;/code&gt; a great choice for dependency injection in TypeScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Singleton, Transient, and Scoped Bindings&lt;/strong&gt;: Control the lifecycle of your services with different binding strategies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contextual Bindings&lt;/strong&gt;: Bind different values depending on the context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zod Schema Validation&lt;/strong&gt;: Validate resolved instances against Zod schemas for type safety.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Middleware Support&lt;/strong&gt;: Intercept and modify resolution logic using middleware.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async Bindings&lt;/strong&gt;: Resolve dependencies that require asynchronous initialization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circular Dependency Detection&lt;/strong&gt;: Prevent infinite loops by detecting circular dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tagging and Aliasing&lt;/strong&gt;: Bind services to tags or aliases for more flexible resolution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Explore these features in the GitHub repository&lt;/a&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/zhorton34/container/tree/HEAD/examples" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;View all examples on GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Container Binding
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example demonstrates how to bind a simple class to the container and resolve it. It's useful for basic dependency injection where you want to decouple your code from direct instantiations.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Logger&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Logger&lt;/span&gt;&lt;span class="o"&gt;&amp;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;Logger&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, World!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container/tree/HEAD/examples/basic-usage.ts" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;See this example on GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Singleton Binding
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example demonstrates how to bind a class as a singleton. This ensures that the same instance is returned every time the service is resolved, useful when you want to maintain shared state.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Config&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;singleton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Config&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="o"&gt;&amp;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;Config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="o"&gt;&amp;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;Config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;config2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container/tree/HEAD/examples/singleton-binding.ts" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;See this example on GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Zod Schema Validation on Binding
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example shows how to use Zod schema validation when binding a service to ensure that the resolved instance meets the expected schema. This is useful for enforcing runtime type safety.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema for the service&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind the service and validate it against the Zod schema&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UserService&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;UserService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: UserService { id: 1, name: 'Alice' }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Invalid Schema Detection
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example demonstrates how the container throws an error if the resolved instance does not conform to the Zod schema, helping catch errors early during service resolution.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema for validation&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InvalidUserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c1"&gt;// Invalid types&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Try binding the invalid service and validate against the schema&lt;/span&gt;
  &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;InvalidUserService&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InvalidUserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;one&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;InvalidUserService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;InvalidUserService&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;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="c1"&gt;// Output: Invalid schema for InvalidUserService: Expected number, received string...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Schema Validation with Nested Objects
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example shows how Zod can be used to validate more complex services with nested objects, ensuring that the entire structure is type-safe at runtime.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a nested Zod schema&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;configSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConfigService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="nl"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind the service with schema validation&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ConfigService&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ConfigService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5432&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;abc123&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;span class="nx"&gt;configSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;configService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ConfigService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;ConfigService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;configService&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;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: localhost&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Conditional Schema Validation
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example shows how you can use conditional logic inside Zod schemas to handle more dynamic validation scenarios during dependency injection, such as checking optional fields based on other conditions.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a schema with conditional fields&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="c1"&gt;// Optional field&lt;/span&gt;
  &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enum&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&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;user&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;span class="nf"&gt;refine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Admin users must have an email&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;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind a user with valid schema (admin with email)&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UserServiceAdmin&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&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;alice@example.com&lt;/span&gt;&lt;span class="dl"&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;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userServiceAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;UserServiceAdmin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userServiceAdmin&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: UserService { id: 1, name: 'Alice', email: 'alice@example.com', role: 'admin' }&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Try binding a user without an email for an admin role (invalid)&lt;/span&gt;
  &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UserServiceInvalid&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;UserServiceInvalid&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;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Admin users must have an email&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Async Binding with Zod Schema Validation
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example demonstrates how you can use Zod schema validation with asynchronous services, ensuring that even services resolved asynchronously meet the expected type safety criteria.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema for validation&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Simulate async service creation&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Async Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind the async service and validate against the schema&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UserService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolveAsync&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;UserService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userService&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: UserService { id: 1, name: 'Async Alice' }&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Contextual Binding with Zod Schema Validation
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example shows how Zod schema validation can be combined with contextual bindings, ensuring that each context adheres to the correct schema.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;configSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConfigService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind a default config service&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ConfigService&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ConfigService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5432&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="nx"&gt;configSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Contextual binding with different config&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;when&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AdminService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ConfigService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;give&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ConfigService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin-host&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3306&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="nx"&gt;configSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;defaultConfigService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ConfigService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;ConfigService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;defaultConfigService&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="c1"&gt;// Output: { host: 'localhost', port: 5432 }&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;adminConfigService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ConfigService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;ConfigService&lt;/span&gt;&lt;span class="dl"&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;AdminService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;adminConfigService&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="c1"&gt;// Output: { host: 'admin-host', port: 3306 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Zod Schema Validation with Bound Object
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example demonstrates how Zod schema validation can be used to validate the structure of a bound object in the container. It ensures that the object conforms to the defined schema when resolved.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind an object that matches the Zod schema&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&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;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: { id: 1, name: 'Alice' }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Invalid Zod Schema Error
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example shows how the container throws an &lt;code&gt;InvalidSchemaError&lt;/code&gt; when the bound object doesn't conform to the expected Zod schema.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;InvalidSchemaError&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./errors.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Attempt to bind an object that doesn't conform to the schema&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;InvalidObject&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;span class="o"&gt;=&amp;gt;&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="mi"&gt;123&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;InvalidSchemaError&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: true&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Invalid schema for InvalidObject&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Async Binding with Zod Schema Validation
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This example demonstrates how you can bind an asynchronous service and validate it against a Zod schema after it's resolved. It ensures that even async services are validated for type safety.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@findhow/container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a Zod schema for validation&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;serviceSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AsyncService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AsyncService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;getValue&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Bind the async service and validate against the schema&lt;/span&gt;
&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AsyncService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AsyncService&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;serviceSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolveAsync&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AsyncService&lt;/span&gt;&lt;span class="o"&gt;&amp;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;AsyncService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getValue&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: AsyncService&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;@findhow/container GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;These examples demonstrate the flexibility of combining Zod schema validation with the &lt;code&gt;@findhow/container&lt;/code&gt; dependency injection system to ensure runtime safety for both synchronous and asynchronous services. You can enforce validation in various contexts, including conditional logic and nested structures.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why &lt;code&gt;@findhow/container&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Unlike other DI libraries, &lt;code&gt;@findhow/container&lt;/code&gt; doesn't require decorators, supports Zod for validation, and is highly flexible with contextual and scoped bindings.&lt;/p&gt;

&lt;p&gt;This library stands out because it offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Decorator-free&lt;/strong&gt; DI: You don’t need to clutter your codebase with decorators.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zod validation&lt;/strong&gt;: Runtime schema validation is integrated directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/zhorton34/container" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Discover more benefits on GitHub&lt;/a&gt;
&lt;br&gt;
&lt;a href="https://cleancode.studio" rel="noopener noreferrer"&gt;Clean Code Studio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>deno</category>
      <category>typescript</category>
      <category>node</category>
    </item>
    <item>
      <title>(NEW) [Product Initiative] Requirements Gathering Automation with AI Agents</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Sat, 20 Apr 2024 22:57:02 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/new-product-initiative-requirements-gathering-automation-with-ai-agents-4k49</link>
      <guid>https://forem.com/cleancodestudio/new-product-initiative-requirements-gathering-automation-with-ai-agents-4k49</guid>
      <description>&lt;p&gt;&lt;small&gt;&lt;em&gt;(Product Initiative)&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements Gathering Capable AI Agents
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This document compiles all relevant information regarding a product initiative intending to use AI agents as a way to streamline and automate the Requirements Gathering and Ticket Refinement process.&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;We have five documents within this page we are creating before doing any code work.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Product requirements doc&lt;/li&gt;
&lt;li&gt;Product technical design doc&lt;/li&gt;
&lt;li&gt;Product system design doc (normally a visual diagram)&lt;/li&gt;
&lt;li&gt;Product user guide doc &lt;/li&gt;
&lt;li&gt;AI agent responsibility &amp;amp; prompt engineering strategy&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Product Requirements Doc (PRD)
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Develop an AI-powered agent that automates and refines the software development requirements gathering process to increase accuracy and efficiency across project teams.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Goals
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Business Goals
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Reduce the time to gather and refine development requirements by 30%.&lt;/li&gt;
&lt;li&gt;Minimize errors in requirements documentation by enhancing accuracy and traceability.&lt;/li&gt;
&lt;li&gt;Improve stakeholder satisfaction with the development process through better alignment and communication.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  User Goals
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Provide developers and project managers with a streamlined, automated tool for requirements gathering that reduces manual effort and ambiguity.&lt;/li&gt;
&lt;li&gt;Enhance collaboration and clarity among stakeholders through more effective communication and documentation practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Non-Goals
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;This tool will not replace the need for initial human-based requirements analysis.&lt;/li&gt;
&lt;li&gt;It will not serve as a project management tool for tasks beyond requirements gathering and refinement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  User Stories
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;As a project manager, I want to initiate requirements gathering with the AI agent so that I can ensure all necessary inputs are collected without manual oversight. &lt;/li&gt;
&lt;li&gt;As a developer, I want the tool to automatically notify me of any ambiguities in the requirements so that I can clarify or provide additional information promptly.&lt;/li&gt;
&lt;li&gt;As a stakeholder, I want to receive periodic updates from the AI agent about the status of requirements refinement so that I remain informed without attending frequent meetings.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  User Experience
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Initiation: The user initiates the AI agent from within their existing project management tools.&lt;/li&gt;
&lt;li&gt;Data Collection: The agent gathers data from multiple sources, including interviews, existing documentation, and system analysis.&lt;/li&gt;
&lt;li&gt;Clarification Requests: When ambiguities are detected, the agent sends automated requests for clarification to the relevant parties.&lt;/li&gt;
&lt;li&gt;Feedback Loop: Stakeholders provide feedback through preferred communication channels, which the agent uses to refine requirements.&lt;/li&gt;
&lt;li&gt;Documentation: The agent maintains an up-to-date repository of requirements that stakeholders can access at any time.&lt;/li&gt;
&lt;li&gt;Notifications: Users receive alerts about changes or needed inputs through integrated communication tools.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Success Metrics
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Reduction in time required to gather and refine requirements.&lt;/li&gt;
&lt;li&gt;Decrease in the number of errors or inconsistencies in requirements documentation.&lt;/li&gt;
&lt;li&gt;User satisfaction ratings from stakeholders and developers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Technical Considerations
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Integration with existing tools such as JIRA and Confluence.&lt;/li&gt;
&lt;li&gt;Compliance with data privacy and security standards.&lt;/li&gt;
&lt;li&gt;Scalability to accommodate projects of varying sizes and complexities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Milestones &amp;amp; Sequencing
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Requirements Definition and Planning - XX weeks&lt;/li&gt;
&lt;li&gt;Prototype Development and Initial Testing - XX weeks&lt;/li&gt;
&lt;li&gt;Integration with Existing Tools and Systems - XX weeks&lt;/li&gt;
&lt;li&gt;Beta Testing with Key Stakeholders - XX weeks&lt;/li&gt;
&lt;li&gt;Launch and Iterative Refinements - XX weeks&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Narrative
&lt;/h4&gt;

&lt;p&gt;Imagine a world where project managers and developers spend less time in meetings clarifying what needs to be done and more time actually doing it. Our AI requirements agent not only automates the mundane parts of requirements gathering but also ensures that every piece of information is precisely where it should be, clear and actionable. This tool will revolutionize how projects are initiated, making the entire development process smoother and more efficient.&lt;/p&gt;

&lt;p&gt;This document serves as the foundation for the AI Requirements Agent, outlining the product vision, target audience, goals, user stories, and success metrics. It provides a high-level overview of the user experience, technical considerations, and development roadmap.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Technical Design Document (TDD): AI Requirements Agent
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The TDD delves into the technical intricacies of the AI Requirements Agent. It details the multi-agent system architecture, individual agent design, data management strategies, deployment procedures, and future considerations for expansion and improvement.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Introduction&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This document details the technical design of the AI Requirements Agent, a multi-agent system designed to automate and refine the software development requirements gathering process. The agent aims to improve efficiency, accuracy, and collaboration among project stakeholders.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. System Architecture&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The AI Requirements Agent is a distributed, multi-agent system composed of four primary agents, each specializing in a specific aspect of requirements gathering and analysis:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Documentation Agent:&lt;/strong&gt; Analyzes existing project documentation, extracting relevant information and identifying potential gaps or inconsistencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Analysis Agent:&lt;/strong&gt; Reviews the code base, suggesting requirements based on current system functionalities and limitations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stakeholder Interview Agent:&lt;/strong&gt; Conducts and analyzes stakeholder interviews, deriving requirements from natural language input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback Coordination Agent:&lt;/strong&gt; Manages the feedback loop, integrating input from stakeholders and other agents to refine requirements iteratively.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;2.1 Agent Communication and Interaction&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The agents communicate and exchange information asynchronously through a message queue system. Each agent publishes messages to specific topics on the queue, and other agents subscribe to relevant topics to receive updates and requests. A standardized data format (e.g., JSON) ensures seamless communication and interoperability between agents.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;2.2 Data Flow&lt;/strong&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Project Initiation:&lt;/strong&gt; The user provides initial project information and goals through a web interface or API. This information is published to the message queue, triggering the data collection process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data Collection:&lt;/strong&gt; Each agent independently gathers data from relevant sources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation Agent:&lt;/strong&gt; Accesses and parses project documents stored in a document repository (e.g., Confluence) using APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Analysis Agent:&lt;/strong&gt; Analyzes code from a version control system (e.g., GitHub) using APIs and static code analysis tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stakeholder Interview Agent:&lt;/strong&gt; Conducts interviews with stakeholders via video conferencing or chat platforms, transcribing and analyzing the conversations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirement Generation:&lt;/strong&gt; Each agent generates initial requirement suggestions based on its analysis. These suggestions are published to the message queue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback Loop:&lt;/strong&gt; The Feedback Coordination Agent collects feedback from stakeholders through various channels (e.g., email, surveys) and distributes it to relevant agents for further analysis and refinement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirement Refinement:&lt;/strong&gt; Agents iteratively refine requirements based on feedback and collaboration, updating the requirements document stored in a central repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Agent Design&lt;/strong&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;3.1 Documentation Agent&lt;/strong&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Natural Language Processing (NLP):&lt;/strong&gt; Utilizes NLP libraries such as spaCy and NLTK for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Named Entity Recognition (NER):&lt;/strong&gt; Identifies key entities (e.g., system components, users, actions) within documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part-of-Speech (POS) Tagging:&lt;/strong&gt; Analyzes grammatical structure to understand the context and relationships between entities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Parsing:&lt;/strong&gt; Extracts relationships between words to identify actions, subjects, and objects, building a semantic understanding of requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Topic Modeling:&lt;/strong&gt; Identifies latent topics and themes within the documentation to understand the high-level scope and functionalities.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirement Extraction:&lt;/strong&gt; Employs rule-based and machine learning models trained on labeled data to extract requirements from unstructured text.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;3.2 Code Analysis Agent&lt;/strong&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Code Analysis:&lt;/strong&gt; Leverages tools like SonarQube or PMD to analyze code for potential issues, design patterns, and code complexity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Machine Learning Models:&lt;/strong&gt; Utilizes models trained on code repositories to identify potential features, functionalities, and limitations based on existing code structure and patterns.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;3.3 Stakeholder Interview Agent&lt;/strong&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Speech-to-Text:&lt;/strong&gt; Employs speech recognition APIs (e.g., Google Cloud Speech-to-Text) to transcribe stakeholder interviews.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Natural Language Understanding (NLU):&lt;/strong&gt; Leverages NLU models to interpret the meaning and intent behind stakeholder statements, identifying key requirements and concerns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dialogue Management:&lt;/strong&gt; Utilizes dialogue management techniques to maintain context and generate relevant follow-up questions during interviews.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;3.4 Feedback Coordination Agent&lt;/strong&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback Aggregation:&lt;/strong&gt; Collects and categorizes feedback from various sources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Conflict Resolution:&lt;/strong&gt; Identifies and resolves conflicting feedback through voting mechanisms, consensus-building techniques, or escalation to human supervisors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prioritization:&lt;/strong&gt; Prioritizes feedback based on severity, urgency, and relevance to project goals.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Data Management&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; A NoSQL database (e.g., MongoDB) will be used for flexible and scalable storage of project data, requirements, and feedback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Security:&lt;/strong&gt; Data at rest and in transit will be encrypted using industry-standard encryption algorithms. Access control mechanisms and user authentication will be implemented to restrict unauthorized access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Anonymization:&lt;/strong&gt; When handling sensitive information, techniques like data masking and differential privacy will be employed to protect confidentiality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5. Deployment and Maintenance&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Platform:&lt;/strong&gt; Google Cloud Platform (GCP) will be used for its scalability, reliability, and security features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Containerization:&lt;/strong&gt; Docker containers will be used to package and deploy the agent microservices, ensuring portability and ease of management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Orchestration:&lt;/strong&gt; Kubernetes will manage container deployment, scaling, and service discovery.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitoring and Logging:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prometheus and Grafana&lt;/strong&gt; for monitoring system performance and resource utilization.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Logging&lt;/strong&gt; for centralized logging and analysis of system events.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD Pipeline:&lt;/strong&gt; A continuous integration and continuous delivery (CI/CD) pipeline will automate the build, testing, and deployment process.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;6. Future Considerations&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration with additional AI tools:&lt;/strong&gt; Explore integration with natural language generation tools for automated documentation generation, and machine learning platforms for incorporating predictive analytics and anomaly detection capabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expansion of agent capabilities:&lt;/strong&gt; Develop specialized agents for tasks like user interface design, testing, and risk assessment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Incorporate Explainable AI (XAI) techniques:&lt;/strong&gt; Provide insights into the reasoning and decision-making processes of the AI agents, enhancing transparency and trust.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;7. Technical Design Doc Conclusion&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The AI Requirements Agent offers a novel approach to automating and refining requirements gathering in software development. The multi-agent architecture allows for specialized expertise, scalability, and adaptability to various project needs. By leveraging NLP, machine learning, and robust data management, the system promotes efficiency, accuracy, and collaboration among stakeholders, ultimately contributing to successful project outcomes.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  3. User Guide
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Getting Started:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access:&lt;/strong&gt; The AI Requirements Agent is accessible via a web interface or API integration, depending on your preferred workflow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Project Setup:&lt;/strong&gt; Create a new project within the platform and input basic information like project name, description, and objectives.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Source Integration:&lt;/strong&gt; Connect the AI Agent to relevant data sources such as document repositories (e.g., Confluence), code repositories (e.g., GitHub), and communication channels for stakeholder feedback.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Using the AI Agent:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initiation:&lt;/strong&gt; Provide the AI Agent with initial project information and goals. This can include uploading relevant documents, specifying code repositories, and scheduling stakeholder interviews.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirement Review:&lt;/strong&gt; The AI Agent will process the data and generate an initial set of requirements. Review these requirements and provide feedback or clarification as needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback Loop:&lt;/strong&gt; Respond to prompts from the AI Agent to clarify ambiguities or provide additional information. This feedback will be used to refine the requirements iteratively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Documentation:&lt;/strong&gt; Access the continuously updated requirements document generated by the AI Agent. You can export the document in various formats for further use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Notifications:&lt;/strong&gt; Stay informed about the progress of requirements gathering and refinement through notifications and alerts sent by the AI Agent.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Troubleshooting and FAQs:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; Difficulty connecting to data sources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Ensure you have the correct access credentials and permissions for the data sources. Contact your system administrator if necessary.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; Ambiguous or incomplete requirements generated.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Provide additional context and feedback to the AI Agent through prompts and clarification requests.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; Conflicting feedback from stakeholders.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; The AI Agent will identify and highlight conflicting feedback. Collaborate with stakeholders to reach a consensus or escalate the issue to a human supervisor if needed.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;For more detailed troubleshooting and FAQs, please refer to the dedicated support documentation (normally link to further support documentation).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  4. System Design Diagram
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This (normally a flowchart, not text) visually depicts the system design of the AI Requirements Agent, outlining the data flow, agent interactions, and key processes involved in requirements gathering and refinement. It provides a high-level overview of how the system functions and interacts with external data sources and user feedback.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Flowchart Elements:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terminator:&lt;/strong&gt; Represents the start and end points of the process (oval shape).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Process:&lt;/strong&gt; Represents an action or operation performed by the system (rectangle shape).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decision:&lt;/strong&gt; Represents a point where the flow branches based on a condition (diamond shape).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data:&lt;/strong&gt; Represents data input or output (parallelogram shape).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subroutine:&lt;/strong&gt; Represents a reusable set of actions (rounded rectangle shape).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Document:&lt;/strong&gt; Represents a document or report (rectangle with wavy bottom).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Flowchart Flow:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Start:&lt;/strong&gt; The process begins with the user initiating the AI Requirements Agent and providing initial project information (e.g., project description, goals).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data Collection:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation Agent:&lt;/strong&gt; Accesses and parses project documents from a document repository (e.g., Confluence).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Analysis Agent:&lt;/strong&gt; Analyzes code from a version control system (e.g., GitHub).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stakeholder Interview Agent:&lt;/strong&gt; Conducts interviews with stakeholders and transcribes the conversations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirement Generation:&lt;/strong&gt; Each agent analyzes the gathered data and generates initial requirement suggestions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Feedback Loop:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feedback Collection:&lt;/strong&gt; The Feedback Coordination Agent gathers feedback from stakeholders through various channels (e.g., email, surveys).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feedback Analysis:&lt;/strong&gt; The Feedback Coordination Agent analyzes and categorizes the feedback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conflict Resolution:&lt;/strong&gt; The Feedback Coordination Agent resolves conflicting feedback through voting, consensus building, or escalation.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirement Refinement:&lt;/strong&gt; Agents refine requirements based on the feedback received, iteratively improving accuracy and completeness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Requirements Documentation:&lt;/strong&gt; The refined requirements are compiled into a comprehensive document accessible to all stakeholders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Notifications:&lt;/strong&gt; The AI Agent sends alerts to users about updates, changes, or required actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;End:&lt;/strong&gt; The process concludes with a well-defined set of requirements documented and accessible for software development.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Functional Requirements (represented by process boxes):&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Gather data from various sources (documents, code, interviews).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Analyze data using NLP and ML techniques.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate initial requirement suggestions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collect and analyze stakeholder feedback.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resolve conflicting feedback.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Refine requirements based on feedback.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate requirements documentation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Send notifications to users.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Non-Functional Requirements (implicitly represented):&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance:&lt;/strong&gt; The system should be responsive and efficient in processing data and generating outputs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; The system should be able to handle projects of different sizes and complexities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security:&lt;/strong&gt; The system should protect sensitive project information and comply with data privacy regulations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Availability:&lt;/strong&gt; The system should be accessible to users when needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usability:&lt;/strong&gt; The user interface should be intuitive and easy to use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintainability:&lt;/strong&gt; The system should be easy to maintain and update.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; The system should function consistently and reliably.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Additional Notes:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The flowchart can be further elaborated to show the specific NLP and ML techniques used by each agent.
&lt;/li&gt;
&lt;li&gt;Decision points can be added to illustrate conditional branching based on specific criteria (e.g., confidence level of generated requirements).
&lt;/li&gt;
&lt;li&gt;Data inputs and outputs can be labeled with specific data formats (e.g., JSON, text files).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;By visualizing the system design with a flowchart, we gain a clearer understanding of the AI Requirements Agent's workflow and the functional and non-functional requirements that guide its development and implementation.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Agent Responsibilities and Prompting Techniques:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This document details the prompting techniques and interaction strategies employed by the AI Requirements Agent to facilitate efficient and accurate requirements gathering and refinement. We will explore how each agent leverages prompts to elicit information, generate suggestions, and collaborate with other agents.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Documentation Agent:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Responsibility:&lt;/strong&gt; Analyze existing project documentation, extract relevant information, and identify potential gaps or inconsistencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompting Techniques:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Information Extraction Prompts:&lt;/strong&gt; These prompts guide the agent to extract specific information from documents, such as functional requirements, use cases, and user stories.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gap Analysis Prompts:&lt;/strong&gt; These prompts help the agent identify missing or incomplete information in the documentation, prompting further investigation or clarification requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency Check Prompts:&lt;/strong&gt; These prompts guide the agent to compare information across different documents and identify inconsistencies or contradictions.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Code Analysis Agent:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Responsibility:&lt;/strong&gt; Review the code base, suggesting requirements based on current system functionalities and limitations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompting Techniques:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Functionality Identification Prompts:&lt;/strong&gt; These prompts guide the agent to identify functionalities implemented in the code, helping to define functional requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limitation Detection Prompts:&lt;/strong&gt; These prompts guide the agent to identify limitations or constraints imposed by the current codebase, informing non-functional requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design Pattern Recognition Prompts:&lt;/strong&gt; These prompts help the agent identify design patterns and architectural decisions, offering insights into potential system requirements.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Stakeholder Interview Agent:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Responsibility:&lt;/strong&gt; Conduct and analyze stakeholder interviews, deriving requirements from natural language input.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompting Techniques:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Open-Ended Interview Prompts:&lt;/strong&gt; These prompts encourage stakeholders to share their needs, expectations, and concerns openly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specific Inquiry Prompts:&lt;/strong&gt; These prompts are used to clarify specific details or gather additional information on particular topics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Follow-up Prompts:&lt;/strong&gt; These prompts are generated dynamically based on stakeholder responses to probe deeper into specific areas of interest.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Feedback Coordination Agent:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Responsibility:&lt;/strong&gt; Manage the feedback loop, integrating input from stakeholders and other agents to refine requirements iteratively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prompting Techniques:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feedback Categorization Prompts:&lt;/strong&gt; These prompts help the agent categorize feedback based on its nature (e.g., clarification, suggestion, concern).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conflict Identification Prompts:&lt;/strong&gt; These prompts guide the agent to identify conflicting feedback or opinions from different stakeholders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consensus Building Prompts:&lt;/strong&gt; These prompts facilitate discussion and collaboration between stakeholders to reach consensus on requirements.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Agent Communication and Prompt Chaining:
&lt;/h4&gt;

&lt;p&gt;The AI agents communicate and collaborate using a message queue system and a standardized data format. This enables prompt chaining, where the output of one agent's prompts can become the input for another agent's prompts, creating an iterative refinement process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples of Agent Interactions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation Agent to Stakeholder Interview Agent:&lt;/strong&gt; If the Documentation Agent identifies missing information or inconsistencies, it can generate prompts for the Stakeholder Interview Agent to ask specific clarifying questions during interviews.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Analysis Agent to Documentation Agent:&lt;/strong&gt; If the Code Analysis Agent identifies functionalities not documented, it can prompt the Documentation Agent to review specific code sections and update the documentation accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stakeholder Interview Agent to Feedback Coordination Agent:&lt;/strong&gt; The Stakeholder Interview Agent provides transcribed interviews and summarized insights to the Feedback Coordination Agent, enabling targeted feedback collection and analysis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback Coordination Agent to all agents:&lt;/strong&gt; The Feedback Coordination Agent distributes categorized feedback to relevant agents, triggering further analysis and refinement of requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Iterative Prompt Generation and Tuning:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prompt Templates:&lt;/strong&gt; Each agent utilizes pre-defined prompt templates tailored to their specific tasks and responsibilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Prompt Generation:&lt;/strong&gt; Based on the context and information gathered, agents dynamically generate prompts to gather additional details, clarify ambiguities, and refine requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prompt Tuning:&lt;/strong&gt; The effectiveness of prompts is continuously monitored and evaluated. Agents can learn from feedback and adapt their prompting techniques to improve accuracy and efficiency.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;By implementing these prompt engineering techniques and inter-agent communication strategies, the AI Requirements Agent facilitates a collaborative and iterative process, leading to well-defined, comprehensive, and accurate software requirements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Citation close&lt;/p&gt;




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

&lt;p&gt;The AI Requirements Agent, with its comprehensive documentation encompassing PRD, TDD, User Guide, System Design Diagram, and Prompt Engineering strategies, provides a robust and transparent framework for automating and refining the software requirements process. This initiative promises to significantly improve efficiency, accuracy, and collaboration, leading to more successful software development projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Glossary of AI Agent Types
&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;&lt;br&gt;
In artificial intelligence, the concept of an agent refers to a computer program or system designed to perceive its environment and act towards achieving specific goals. Agents can operate autonomously and are fundamental to many applications, including robotics, gaming, and intelligent systems.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Here’s an overview of different types of agents and their use cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple Reflex Agents&lt;/strong&gt;: Operate on a direct condition-action basis, responding only to current percepts. Their use is limited to highly predictable environments where every percept can be accounted for with a specific action. They are not suitable for environments where past or future states need consideration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Model-Based Reflex Agents&lt;/strong&gt;: These agents maintain an internal state to handle partially observable environments. They rely on a model of the world to decide actions, considering both the current percept and the knowledge of how the world works. These agents are more adaptable to changing conditions than simple reflex agents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Goal-Based Agents&lt;/strong&gt;: These agents act to achieve specific goals and make decisions based on the likelihood of actions bringing them closer to these goals. They are used in complex environments where several paths might achieve the desired outcome, requiring planning and decision-making capabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Utility-Based Agents&lt;/strong&gt;: They not only aim to achieve goals but also do so with an optimal performance metric, maximizing their perceived happiness or utility. This approach is useful in scenarios where there are multiple possible satisfactory outcomes, and some are preferable over others.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learning Agents&lt;/strong&gt;: These agents can improve their performance over time based on experience, adapting to new conditions and requirements without direct programming. Learning agents are vital in environments that evolve or where initial information is incomplete.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Agent Systems (MAS)&lt;/strong&gt;: Involving multiple interacting agents, MAS can solve problems that are too large or complex for a single agent. These systems are categorized based on whether the agents cooperate, compete, or both. Applications include automated trading systems, robotic teams, and complex simulation environments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hierarchical Agents&lt;/strong&gt;: Organized in a tiered structure, these agents delegate responsibilities from higher-level agents down to lower-level agents who handle specific tasks. This setup is effective in managing complex systems with multiple interacting components, such as manufacturing and transportation management systems.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each type of agent is suited to particular environments and tasks, from simple automation and responses to complex problem-solving and learning scenarios. The deployment of these agents depends significantly on the specific requirements and constraints of the application area.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio"&gt;Clean Code Studio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>agile</category>
      <category>ai</category>
      <category>career</category>
      <category>careerdevelopment</category>
    </item>
    <item>
      <title>There's a reason neurologist don't do open heart surgery.</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Mon, 20 Nov 2023 20:03:36 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/theres-a-reason-neurologist-dont-do-open-heart-surgery-2gg3</link>
      <guid>https://forem.com/cleancodestudio/theres-a-reason-neurologist-dont-do-open-heart-surgery-2gg3</guid>
      <description>&lt;p&gt;There’s a reason Neurologist don’t do open heart surgery.&lt;/p&gt;

&lt;p&gt;The medical field is too large for any single doctor to know everything.&lt;/p&gt;

&lt;p&gt;The technology field is the same way.&lt;/p&gt;

&lt;p&gt;Being deliberate, choosing a path, and following thru with daily disciplined practice is a requirement for mastery in the technology field as well.&lt;/p&gt;

&lt;p&gt;It’s easy to forget this lesson sometimes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio"&gt;Clean Code Studio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Don't Eat the 🍪 [All In One Bite]</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Sun, 05 Nov 2023 22:48:28 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/dont-eat-the-all-in-one-bite-7l0</link>
      <guid>https://forem.com/cleancodestudio/dont-eat-the-all-in-one-bite-7l0</guid>
      <description>&lt;h2&gt;
  
  
  So it Began...
&lt;/h2&gt;

&lt;p&gt;I was 22 years of age, it was the year of 2019 nearing the now historic year of 2020.&lt;/p&gt;

&lt;p&gt;My dedication, or &lt;strong&gt;more specifically&lt;/strong&gt; my &lt;em&gt;unconstrained willingness to give enormous amounts of my time beyond 40 hours in order to get ahead early in my corporate career&lt;/em&gt;, provided me with a great deal of “real world” experience that empowered me to handle many complex(ish) tasks from an early age before most had even graduated from college.&lt;/p&gt;

&lt;p&gt;Gazing thru second story windows that arched 25 feet and spanned hundreds of feet from wall to wall, I would often allow myself to zone out into the mind palace as I playfully gazed with twinkled eyes at the airplane lanes as toylike planes that were all but toys came tuttering down from the clouds as if to want to greet you first hand while others fluttered from inches off the ground as they sped off into the distance until they were miles in the sky and nothing more than a distance spec as they went on their way without ever as much as an audible goodbye. &lt;/p&gt;

&lt;p&gt;Each and every day, good weather permitting, these little private airplanes came cruising on in and fluttering on off within this magnificent vantage point that was accessible to those who were fortunate to have the benefit of working at a Marketing Agency like VMLY&amp;amp;R who used such a perspective as a way to aww their potential clients and captivate fortune 500 companies by walking them from the runway directly into the board meeting rooms one sliding door away from the very private airplane the executives who came to do business flew into Kansas City on. &lt;/p&gt;

&lt;p&gt;VMLY&amp;amp;R quite brilliantly re-modeled an old downtown Kansas City airport into an eye catching spectacle that one could call a marketing agency's dream of a corporate Head Quarters that intended and succeeded in capturing interest and attention from the many clients they courted from the Fortune 500 list including the likes of Wendy's, United Rentals, Ford, Heinz, Gatorade, Taco Bell, and several more easily recognizable brands.&lt;/p&gt;

&lt;p&gt;Visualize a “Google-esc” design with the added meditative benefits of small planes dazzling your vantage points with fascination thru out the day as things that are as intrinsically interesting as flight tend to do when it comes to directing a statistically measurable amount of the human attention into a given direction relative to other potential stimuli that are simply often less fascinating than the pursuits of flight. &lt;/p&gt;

&lt;p&gt;VMLY&amp;amp;R had an impressive Authority in the Marketing world in which they pinnacled their Digital Marketing excellence for display to the world at that remodeled Kansas City Airport they dubbed as their marketing empire's Home Base.&lt;/p&gt;

&lt;h2&gt;
  
  
  Out of context Wisdom, captivated my curiosity
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;“Don’t eat the 🍪 all in one bite.”&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Whoa...I thought for half a second, was that my own sub-conscience? &lt;/p&gt;

&lt;p&gt;It was so profound in terms of its timing and quality. The kind of advice that just sank into the very being of your essence as it was both the information and within the right location in which you were traveling thru space time to have profound impact to the point of it becoming a life long memory. &lt;/p&gt;

&lt;p&gt;After a second of realizing my conscience hadn’t suddenly actualized part of its essence into a Yoda like essense to transcend the normal internal communication and perception capabilities -- I came to realize I had to focus on the physical world outside of my own thoughts which had previously engulfed my entire attention span with ideas drifted off into space alongside the airplanes flying in and eventually taking off from the run ways. A place where thought was unconfined by prior ideas and was just freely wondering - I was in my own mind palace that day and very content being there at that.&lt;/p&gt;

&lt;p&gt;Yet, once I had shifted and properly interfaced my attention towards the physical world immediately around me again, I quickly was caught off guard by the fact my mentor - an older dude named logan (one of the best mentors I've ever had with decades of experience on me at the time) had just dropped some timeless old man wisdom on me during the exact moment in which my mind was completely caught off guard to the point of genuine curiosity being the default state as I was surprised by the very voice -- and then overwhelmed with happiness at the content of the words spoken.&lt;/p&gt;

&lt;p&gt;Wisdom is both well said as well as said at the right time and in a place in which the thing being said has the potential to genuinely be heard.&lt;/p&gt;

&lt;p&gt;“Huh?” I asked - as if I hadn't heard it. But I had, what I lacked was an understanding of the context in which Logan decided it was of value to randomly drop such a profound statement of wisdom in which appeared from my perspective to be coming out of the blue of nothingness which felt as profound as a color being derived from the color-less.&lt;/p&gt;

&lt;p&gt;Logan expanded the context to allow my attention to direct towards a shared point within his attention span in which the reasoning for such profound wisdom being dropped made more contextual since.&lt;/p&gt;

&lt;p&gt;Adding context to his of his original remark, Logan continued &lt;/p&gt;

&lt;p&gt;“Your PR man, a lot of your PRs actually, they’re good but these things are absolutely freaking huge. You’re trying to tackle very complex things all in one go. The problem isn’t the quality or how your tackling the problem in terms of design or architecture - the problem is the size of the 🍪. You're trying to eat it all in one bite. &lt;/p&gt;

&lt;p&gt;Don’t do that, break it up into smaller bites. Quit trying to eat the 🍪 all in one bite and break it up into smaller more digestible chunks” &lt;/p&gt;

&lt;p&gt;Logan’s Wisdom stunned me with the [now paraphrased] quote because he was right - and I had not noticed in the least bit until then. I had always liked eating cookies in one bite (and yes, I mean both literally and metaphorically).&lt;/p&gt;

&lt;p&gt;The truth was, that - although simple - it was (and still is) the best advice I have ever received in my career as an engineer. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Don’t eat the 🍪 all in one bite.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio"&gt;Clean Code Studio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Mastering Binary Search</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Mon, 16 Oct 2023 00:22:28 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/mastering-binary-search-3li6</link>
      <guid>https://forem.com/cleancodestudio/mastering-binary-search-3li6</guid>
      <description>&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;br&gt;
LeetCode Practice Problems for each Binary Search Implementation and Variation Linked Below&lt;br&gt;
&lt;/small&gt;&lt;/small&gt;&lt;br&gt;
&lt;/p&gt;


&lt;center&gt;(My personal study notes)&lt;/center&gt;




&lt;ul&gt;
&lt;li&gt;
Mastering Binary Search

&lt;ul&gt;
&lt;li&gt;
Variations of Binary Search (patterns to practice)

&lt;ul&gt;
&lt;li&gt;1. Classic Binary Search&lt;/li&gt;
&lt;li&gt;2. Modified Binary Search&lt;/li&gt;
&lt;li&gt;3. Find the Closest Element to a Target&lt;/li&gt;
&lt;li&gt;4. Find the Peak Element&lt;/li&gt;
&lt;li&gt;5. Find Rotation Point in a Rotated Sorted Array&lt;/li&gt;
&lt;li&gt;6. Find First and Last Position of an Element&lt;/li&gt;
&lt;li&gt;When to Use Binary Search&lt;/li&gt;
&lt;li&gt;When Not to Use Binary Search&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;LeetCode Binary Search &lt;/li&gt;
&lt;li&gt;Points of note to study&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Variations of Binary Search (patterns to practice)
&lt;/h2&gt;

&lt;p&gt;Worth knocking these into muscle memory&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Classic Binary Search
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&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;mid&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Modified Binary Search
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;modifiedBinarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// Initialize result&lt;/span&gt;

  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Exact match&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="c1"&gt;// For the first occurrence, keep going left&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Standard binary search logic&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&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;result&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;Remember, the "Modified Condition" is the part you'd customize based on what specific problem you're tackling.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Find the Closest Element to a Target
&lt;/h3&gt;

&lt;p&gt;Here, you have to find the closest element to a given target in a sorted array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;closestElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&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;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&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;start&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;h3&gt;
  
  
  4. Find the Peak Element
&lt;/h3&gt;

&lt;p&gt;In an array where adjacent elements are distinct, find a peak element. An element is considered peak if it is greater than its neighbors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;findPeakElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&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;start&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;h3&gt;
  
  
  5. Find Rotation Point in a Rotated Sorted Array
&lt;/h3&gt;

&lt;p&gt;For a rotated sorted array, find the index where the smallest element is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;findRotationPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&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;start&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;h3&gt;
  
  
  6. Find First and Last Position of an Element
&lt;/h3&gt;

&lt;p&gt;In a sorted array with duplicates, find the starting and ending position of a given target value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;searchRange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;last&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;Knowing when to use binary search depends on several factors, such as the problem constraints and the properties of the data. Here are some general guidelines:&lt;/p&gt;

&lt;h3&gt;
  
  
  When to Use Binary Search
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sorted Data&lt;/strong&gt;: The most fundamental prerequisite for binary search is that the data must be sorted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt;: If the problem requires better than O(n)O(n)O(n) time complexity, binary search often becomes a candidate with its O(log⁡n)O(\log n)O(logn) time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Constant Space&lt;/strong&gt;: If you need to solve the problem with constant extra space, binary search can be a good choice since it only requires pointers like &lt;code&gt;start&lt;/code&gt;, &lt;code&gt;end&lt;/code&gt;, and &lt;code&gt;mid&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multiple Queries&lt;/strong&gt;: In cases where there are multiple queries on static data, preparing a sorted structure for binary search might be beneficial in the long run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Search Conditions&lt;/strong&gt;: If the problem involves searching for a particular condition rather than a specific element (e.g., find the point where a function changes behavior), binary search could apply.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  When Not to Use Binary Search
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unsorted Data&lt;/strong&gt;: If the data is not sorted and cannot be sorted in better than O(nlog⁡n)O(n \log n)O(nlogn) time, then binary search is likely not a fit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Updates&lt;/strong&gt;: If the data set is being updated frequently, maintaining the sorted order might be costly unless specialized data structures like balanced trees are used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Linear Scanning is Enough&lt;/strong&gt;: For smaller datasets or when O(n)O(n)O(n) time complexity is acceptable, a simpler linear search might suffice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exact Matches&lt;/strong&gt;: If you're looking for a range or pair of values rather than an exact match, binary search might require modifications and might not be the most straightforward approach.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Space Complexity&lt;/strong&gt;: When extra space is not a constraint, other techniques like Hashing might be simpler and more suitable for certain types of search problems.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When approaching a problem, look at the constraints and see if binary search can give you an edge in time complexity, or if the problem's nature naturally lends itself to a binary search approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  LeetCode Binary Search
&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;&lt;small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Standard Binary Search (Standard Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/binary-search/"&gt;Binary Search&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Find First and Last Position of Element in Sorted Array (Standard Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/"&gt;Find First and Last Position of Element in Sorted Array&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Search in Rotated Sorted Array (Rotated Array Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/search-in-rotated-sorted-array/"&gt;Search in Rotated Sorted Array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/search-in-rotated-sorted-array-ii/"&gt;Search in Rotated Sorted Array II&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Find Minimum in Rotated Sorted Array (Rotated Array Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/"&gt;Find Minimum in Rotated Sorted Array&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/"&gt;Find Minimum in Rotated Sorted Array II&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Closest Element to a Target (Standard Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/closest-binary-search-tree-value/"&gt;Closest Binary Search Tree Value&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Find Peak Element (Modified Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-peak-element/"&gt;Find Peak Element&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Find the Smallest or Largest Element Greater Than a Given Number (Modified Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/first-bad-version/"&gt;First Bad Version&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Find Kth Element (Modified Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/"&gt;Kth Smallest Element in a Sorted Matrix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/find-k-th-smallest-pair-distance/"&gt;Find Kth Smallest Pair Distance&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Variable Length Arrays (String, Range Queries) (Modified Binary Search)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/longest-increasing-subsequence/"&gt;Longest Increasing Subsequence&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/range-sum-query-immutable/"&gt;Range Sum Query - Immutable&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Others (Miscellaneous)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/search-a-2d-matrix/"&gt;Search a 2D Matrix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/search-a-2d-matrix-ii/"&gt;Search a 2D Matrix II&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;h2&gt;
  
  
  Points of note to study
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Classic Binary Search vs. Modified Binary Search
&lt;/li&gt;
&lt;li&gt; &lt;code&gt;while(start &amp;lt;= end)&lt;/code&gt; vs. &lt;code&gt;while(start &amp;lt; end)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cleancode.studio"&gt;Clean Code Studio&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cleancode.studio/algorithms/mastering-binary-search"&gt;Binary Search Algorithm&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>datastructures</category>
      <category>algorithms</category>
      <category>interview</category>
      <category>javascript</category>
    </item>
    <item>
      <title>I built an industrial scale web scraper. Here's what I learned.</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Tue, 18 Jul 2023 01:44:54 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/i-built-an-industrial-scale-web-scraper-heres-what-i-learned-p6d</link>
      <guid>https://forem.com/cleancodestudio/i-built-an-industrial-scale-web-scraper-heres-what-i-learned-p6d</guid>
      <description>&lt;p&gt;Recently, I built an industrial scale web scraper. Here's what I learned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Why build a scalable scraper/crawler?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Google's primary product (their Search Engine) is empowered by web scrapers &amp;amp; crawl extracting data from the internet at an unfathomable level of scale.&lt;/li&gt;
&lt;li&gt;Open AI's capability (and willingness) to access data using scrapers &amp;amp; crawlers at internet wide scale is what empowered them to build (and continually improve) ChatGPT.&lt;/li&gt;
&lt;li&gt;Unlike last decade, intelligence is something you can build, use, and sell with the one catch being you require an immense amount of one resource to do so and that resource is a hell of a lot of data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;2. Using chromium programmatically is helpful (I chose Puppeteer)&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Industrial scale requires using proxies (I rotated between residential proxies)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;4. Bots can find rules via a robots.txt file for a site (Ask SEO experts about it)&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Bypassing captchas, although ethically questionable, doesn't seem to be an illegal act to program your robot to take. (I explored Github python programs that were capable of this to satisfy my own curiosity).&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why cross-platform apps looking to scale should use RPC (over plain old IPC and instead of REST)</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Fri, 09 Jun 2023 23:13:54 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/ipc-inter-process-communication-vs-rpc-remote-procedure-call-44k0</link>
      <guid>https://forem.com/cleancodestudio/ipc-inter-process-communication-vs-rpc-remote-procedure-call-44k0</guid>
      <description>&lt;p&gt;IPC (Inter-process communication) and RPC (Remote procedure call) are both methods of communication between processes. However, there are some key differences between the two methods that make RPC a more suitable choice for cross-platform desktop applications.&lt;/p&gt;

&lt;p&gt;IPC is a general term for any method of communication between processes. It can be implemented in a variety of ways, including shared memory, pipes, and sockets. IPC is typically used for communication between processes on the same machine.&lt;/p&gt;

&lt;p&gt;RPC is a more specific type of IPC that allows processes to communicate with each other over a network. RPC is typically implemented using a client-server model. The client process makes a request to the server process, and the server process returns a response.&lt;/p&gt;

&lt;p&gt;There are several reasons why using RPC over IPC is important for cross-platform desktop applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; RPC can be used to implement security features, such as authentication and authorization. This is important for cross-platform desktop applications, as they may need to communicate with servers that are not under the control of the application developer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; RPC can be used to scale applications. For example, an application can use RPC to communicate with a server that is running on a different machine. This can help to improve the performance of the application, as it can offload some of the processing to the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability:&lt;/strong&gt; RPC is a more portable method of communication than IPC. This is because RPC is typically implemented using a standard protocol, such as the Remote Procedure Call (RPC) Protocol. This means that RPC can be used to communicate between processes that are running on different platforms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, RPC is a more secure, scalable, and portable method of communication than IPC. This makes RPC a more suitable choice for cross-platform desktop applications.&lt;/p&gt;

&lt;p&gt;RPC (Remote Procedure Call) and REST (Representational State Transfer) are both methods of communication between a client and a server. However, there are some key differences between the two methods that make RPC a more suitable choice for cross-platform desktop applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RPC&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;RPC is a method of communication that allows a client to call a procedure on a server as if it were calling a local procedure. This is done by sending a message to the server that contains the name of the procedure and the arguments to be passed to the procedure. The server then executes the procedure and returns a message to the client containing the results of the procedure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REST&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;REST is a method of communication that uses HTTP requests to access resources on a server. This is done by sending an HTTP request to the server that specifies the resource to be accessed and the desired action to be performed on the resource. The server then returns an HTTP response that contains the requested resource or an error message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why RPC is important for cross-platform desktop applications that want to scale&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are several reasons why RPC is important for cross-platform desktop applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; RPC can be more efficient than REST for cross-platform desktop applications because it can avoid the overhead of HTTP requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; RPC can be more secure than REST for cross-platform desktop applications because it can use authentication and authorization mechanisms to protect data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability:&lt;/strong&gt; RPC can be more portable than REST for cross-platform desktop applications because it is not tied to a specific protocol.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why REST is not as suitable for cross platform apps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;REST is not suitable for cross-platform desktop applications because it is not as efficient, secure, or portable as RPC.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Efficiency:&lt;/strong&gt; REST is less efficient than RPC because it requires the client to make an HTTP request for every resource that it needs to access. This can add overhead and latency to the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security:&lt;/strong&gt; REST is less secure than RPC because it does not support authentication and authorization mechanisms. This can make it easier for unauthorized users to access sensitive data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Portability:&lt;/strong&gt; REST is less portable than RPC because it is tied to the HTTP protocol. This can make it difficult to use REST with applications that are not web-based.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, RPC is a more suitable choice for cross-platform desktop applications than REST. RPC is more efficient, secure, and portable than REST, which makes it a better choice for applications that need to be performant, secure, and portable.&lt;/p&gt;

&lt;p&gt;By implementing RPC based on something like &lt;a href="https://www.jsonrpc.org/specification"&gt;JSON RPC 2.0&lt;/a&gt; and using an RPC implementation as a layer on top of your IPC communication you are able to decouple the data layer from the GUI layer of your cross platform application and ultimately expand beyond the constraints put on you, your team, and your project by default when building a cross platform desktop app's like when building out applications when any of the following technologies: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://tauri.app/v1/references/architecture/inter-process-communication/"&gt;Tauri (Build Cross Platform Desktop apps with Rust+Wry/front-end agnostic way)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.electronjs.org/docs/latest/tutorial/ipc"&gt;Electron (Build Cross Platform Desktop apps with Node/Chromium)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://wails.io/docs/reference/runtime/events"&gt;Wails (Build Cross Platform Apps with Go/Chromium[at least I think it's chromium])&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;While RPC APIs, REST APIs, and IPC communication can all be used together, our industry has a bias towards using REST over RPC and IPC due to a lack of knowledge and a lack of need for tools that allow processes to communicate with each other.&lt;/p&gt;

&lt;p&gt;Using REST instead of RPC can make it difficult to build applications that need to have services communicate with each other via server-side streaming, client-side streaming, or bi-directional streaming. &lt;/p&gt;

&lt;p&gt;My team needed to create a click and point GUI alternative around an existing command line interface, and command line interface programs come with a lot of streaming of data. &lt;/p&gt;

&lt;p&gt;Rest wasn't an option, IPC was our default because for Tauri, Electron, and Wails that's what is in the documentation. &lt;/p&gt;

&lt;p&gt;But the best option is to implement IPC via some sort of RPC specification and decouple the data layer from the GUI layer.  &lt;/p&gt;

&lt;p&gt;Using IPC without a specification, such as the JSON RPC 2.0 spec, can make it difficult to authenticate users and can limit an application's data layer to only communicating between processes on the same machine. This can prevent an application from being able to run as a process on any device or server and as a cross platform application scales and grows, the monolithic nature of distributed artifacts will constrain the ability to build cool things while also greatly slowing down the software development cycle as the User Interface and User Experience becomes inhibited by any cross platform concerns and bugs.&lt;/p&gt;

&lt;p&gt;Instead, from the get go, use RPC for IPC communication and decouple your front-end GUI from your back-end data layer while setting your self, your project, and your team up for long term success by eliminating any constraints. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Chat GPT-4 Already Used In the Wild (Stripe, Duolingo, Khan Academy, etc...)</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Thu, 16 Mar 2023 02:41:20 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/chat-gpt-4-already-used-in-the-wild-stripe-duolingo-khan-academy-etc-29nb</link>
      <guid>https://forem.com/cleancodestudio/chat-gpt-4-already-used-in-the-wild-stripe-duolingo-khan-academy-etc-29nb</guid>
      <description>&lt;h2&gt;
  
  
  Stripe
&lt;/h2&gt;

&lt;p&gt;Stripe, a leading online payment processing platform, is leveraging ChatGPT-4 to enhance its customer support experience. &lt;a href="https://openai.com/customer-stories/stripe"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automating customer support responses&lt;/li&gt;
&lt;li&gt;Assisting human agents with accurate information&lt;/li&gt;
&lt;li&gt;Reducing response times for customer queries&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Duolingo
&lt;/h2&gt;

&lt;p&gt;Duolingo, a popular language-learning platform, is using ChatGPT-4 to improve its language learning tools and user experience. &lt;a href="https://openai.com/customer-stories/duolingo"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enhancing language learning exercises&lt;/li&gt;
&lt;li&gt;Generating contextual language examples&lt;/li&gt;
&lt;li&gt;Offering personalized feedback to users&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Khan Academy
&lt;/h2&gt;

&lt;p&gt;Khan Academy, an educational organization providing free online courses, is utilizing ChatGPT-4 to supplement its learning materials. &lt;a href="https://openai.com/customer-stories/khan-academy"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Providing instant feedback on student work&lt;/li&gt;
&lt;li&gt;Generating additional practice questions&lt;/li&gt;
&lt;li&gt;Assisting teachers in creating personalized learning experiences&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Be My Eyes
&lt;/h2&gt;

&lt;p&gt;Be My Eyes, an app that connects blind and low-vision individuals with sighted volunteers, is implementing ChatGPT-4 to offer real-time assistance. &lt;a href="https://openai.com/customer-stories/be-my-eyes"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Translating text in images for visually impaired users&lt;/li&gt;
&lt;li&gt;Providing instant support through AI-based responses&lt;/li&gt;
&lt;li&gt;Reducing dependency on human volunteers for text recognition tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Morgan Stanley
&lt;/h2&gt;

&lt;p&gt;Morgan Stanley, a multinational investment bank and financial services company, is employing ChatGPT-4 for various financial applications. &lt;a href="https://openai.com/customer-stories/morgan-stanley"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analyzing financial documents&lt;/li&gt;
&lt;li&gt;Generating market insights and summaries&lt;/li&gt;
&lt;li&gt;Enhancing customer support in finance-related queries&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Government of Iceland
&lt;/h2&gt;

&lt;p&gt;The Government of Iceland, in collaboration with Almannarómur and Miðeind, is using ChatGPT-4 to preserve the Icelandic language. &lt;a href="https://openai.com/customer-stories/government-of-iceland"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Training GPT-4 on Icelandic grammar and cultural knowledge&lt;/li&gt;
&lt;li&gt;Developing voice assistant apps (Embla) for fluent Icelandic conversations&lt;/li&gt;
&lt;li&gt;Creating Icelandic-speaking chatbots for company websites&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  AI Technology
&lt;/h2&gt;

&lt;p&gt;Each of these companies is using ChatGPT-4 in unique ways to improve their products, services, and user experience, demonstrating the versatility and potential of AI technology across various industries available as of today.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://cleancode.studio"&gt;Clean Code Studio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>programming</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Insertion Sort (Python Algorithms)</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Sun, 05 Feb 2023 14:12:53 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/insertion-sort-python-algorithms-4cob</link>
      <guid>https://forem.com/cleancodestudio/insertion-sort-python-algorithms-4cob</guid>
      <description>&lt;p&gt;&lt;a href="https://cleancode.studio/python/algorithms-in-python/python-insertion-sort-algorithm" rel="noopener noreferrer"&gt;Insertion sort&lt;/a&gt; is a &lt;a href="https://cleancode.studio/algorithms/sorting" rel="noopener noreferrer"&gt;simple sorting algorithm&lt;/a&gt; that builds the final sorted &lt;a href="https://cleancode.studio/data-structures/arrays" rel="noopener noreferrer"&gt;array&lt;/a&gt; (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as &lt;a href="https://cleancode.studio/algorithms/sorting/quick-sort-algorithm" rel="noopener noreferrer"&gt;quicksort&lt;/a&gt;, &lt;a href="https://cleancode.studio/algorithms/sorting/heap-sort-algorithm" rel="noopener noreferrer"&gt;heapsort&lt;/a&gt;, or &lt;a href="https://cleancode.studio/algorithms/sorting/merge-sort-algorithm" rel="noopener noreferrer"&gt;merge sort&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;insertion_sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
        &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time complexity of &lt;a href="https://cleancode.studio/algorithms/sorting/insertion-sort-algorithm" rel="noopener noreferrer"&gt;insertion sort&lt;/a&gt; is O(n^2).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio/python" rel="noopener noreferrer"&gt;Python&lt;/a&gt; &lt;br&gt;
&lt;a href="https://cleancode.studio/algorithms" rel="noopener noreferrer"&gt;Algorithms&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/algorithms/sorting" rel="noopener noreferrer"&gt;Sorting Algorithms&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/algorithms/insertion-sort-algorithm" rel="noopener noreferrer"&gt;Insertion Sorting Algorithm&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/python/algorithms-in-python/python-insertion-sort-algorithm" rel="noopener noreferrer"&gt;Python Insertion Sorting Algorithm&lt;/a&gt;   &lt;/p&gt;

</description>
      <category>devto</category>
      <category>web3</category>
      <category>announcement</category>
      <category>offers</category>
    </item>
    <item>
      <title>Bubble Sort (Python Algorithms)</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Sun, 05 Feb 2023 14:04:40 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/bubble-sort-python-algorithms-3fng</link>
      <guid>https://forem.com/cleancodestudio/bubble-sort-python-algorithms-3fng</guid>
      <description>&lt;p&gt;&lt;a href="https://cleancode.studio/algorithms/sorting/bubble-sort-algorithm" rel="noopener noreferrer"&gt;Bubble sort&lt;/a&gt; is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The &lt;a href="https://www.cleancode.studio/python/algorithms-in-python/python-bubble-sort-algorithm" rel="noopener noreferrer"&gt;algorithm&lt;/a&gt; gets its name from the way smaller elements "bubble" to the top of the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;bubble_sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
                &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time complexity of bubble sort is O(n^2).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio" rel="noopener noreferrer"&gt;Clean Code Studio&lt;/a&gt; ~ &lt;a href="https://cleancode.studio/python" rel="noopener noreferrer"&gt;Python&lt;/a&gt; ~ &lt;a href="https://cleancode.studio/python/algorithms" rel="noopener noreferrer"&gt;Algorithms&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devrel</category>
      <category>announcement</category>
      <category>devto</category>
      <category>community</category>
    </item>
    <item>
      <title>Liskov's Substitution Principle (Python Design Patterns)</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Sun, 05 Feb 2023 13:40:17 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/liskovs-substitution-principle-python-design-patterns-31c2</link>
      <guid>https://forem.com/cleancodestudio/liskovs-substitution-principle-python-design-patterns-31c2</guid>
      <description>&lt;p&gt;The &lt;a href="https://cleancode.studio/design-patterns" rel="noopener noreferrer"&gt;Liskov Substitution Principle (LSP)&lt;/a&gt; states that objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program. This means that a subclass should be a subtype of its superclass, and the behavior of the program should remain the same whether we use the superclass or a subclass. Here's an example in &lt;a href="https://cleancode.studio/python" rel="noopener noreferrer"&gt;Python&lt;/a&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
In this example, the &lt;code&gt;Rectangle&lt;/code&gt; class defines the behavior for rectangles, and the &lt;code&gt;Square&lt;/code&gt; class inherits from it and represents squares. The &lt;code&gt;use_it&lt;/code&gt; function uses a rectangle-like object, such as a &lt;code&gt;Rectangle&lt;/code&gt; or a &lt;code&gt;Square&lt;/code&gt;, to calculate its area. The function calls the &lt;code&gt;set_height&lt;/code&gt; method and then asserts that the area is correct.

&lt;p&gt;When we pass a &lt;code&gt;Rectangle&lt;/code&gt; object to &lt;code&gt;use_it&lt;/code&gt;, it works as expected and the assertion is true. When we pass a &lt;code&gt;Square&lt;/code&gt; object to &lt;code&gt;use_it&lt;/code&gt;, it also works and the assertion is true, even though the &lt;code&gt;Square&lt;/code&gt; class overrides the behavior of the &lt;code&gt;set_width&lt;/code&gt; and &lt;code&gt;set_height&lt;/code&gt; methods. This means that the &lt;code&gt;Square&lt;/code&gt; class is a subtype of the &lt;code&gt;Rectangle&lt;/code&gt; class, and objects of the &lt;code&gt;Square&lt;/code&gt; class can be used wherever objects of the &lt;code&gt;Rectangle&lt;/code&gt; class are expected, without affecting the correctness of the program. This adheres to the &lt;a href="https://sites.google.com/view/cleancodestudio/design-patterns/liskovs-substitution-design-pattern" rel="noopener noreferrer"&gt;Liskov Substitution Principle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio/python" rel="noopener noreferrer"&gt;Python&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/design-patterns" rel="noopener noreferrer"&gt;Design Patterns&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio" rel="noopener noreferrer"&gt;Clean Code Studio&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/python/design-patterns" rel="noopener noreferrer"&gt;Python Design Patterns&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/python/design-patterns/liskovs-substitution-design-pattern" rel="noopener noreferrer"&gt;Python Liskov's Substitution Principle Design Pattern&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.cleancode.studio/design-patterns/liskovs-substitution-design-pattern" rel="noopener noreferrer"&gt;Liskov Substitution Design Pattern&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devto</category>
      <category>announcement</category>
      <category>support</category>
      <category>community</category>
    </item>
    <item>
      <title>Python Open Closed Design Pattern (Python SOLID Principles)</title>
      <dc:creator>Clean Code Studio</dc:creator>
      <pubDate>Sun, 05 Feb 2023 13:25:42 +0000</pubDate>
      <link>https://forem.com/cleancodestudio/python-open-closed-design-pattern-python-solid-principles-1b5i</link>
      <guid>https://forem.com/cleancodestudio/python-open-closed-design-pattern-python-solid-principles-1b5i</guid>
      <description>&lt;p&gt;The &lt;a href="https://cleancode.studio/design-patterns/open-closed-design-pattern" rel="noopener noreferrer"&gt;Open/Closed Principle&lt;/a&gt; states that a module (such as a class, function, etc.) should be open for extension but closed for modification. In other words, a module should be designed in such a way that it can be easily extended without changing its existing code. &lt;/p&gt;

&lt;p&gt;Here's an example in &lt;a href="https://cleancode.studio/python" rel="noopener noreferrer"&gt;Python&lt;/a&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In this example, the &lt;code&gt;Shape&lt;/code&gt; class is an abstract base class that defines the interface for all shapes, and the &lt;code&gt;Circle&lt;/code&gt; and &lt;code&gt;Rectangle&lt;/code&gt; classes inherit from it and provide concrete implementations of the area method. The &lt;code&gt;calculate_area&lt;/code&gt; function takes a list of shapes and calculates the total area by calling the area method on each shape.&lt;/p&gt;

&lt;p&gt;By using inheritance and an abstract base class, the existing code can be extended to support new shapes without having to modify the existing code. For example, if we wanted to add a square shape, we could simply create a &lt;code&gt;Square&lt;/code&gt; class that inherits from &lt;code&gt;Shape&lt;/code&gt;and provide an implementation of the area method. This adheres to the Open/Closed Principle as the existing code remains closed for modification, while new functionality can be added through extension.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cleancode.studio/python" rel="noopener noreferrer"&gt;Python&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/design-patterns" rel="noopener noreferrer"&gt;Design Patterns&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio" rel="noopener noreferrer"&gt;Clean Code Studio&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/python/design-patterns" rel="noopener noreferrer"&gt;Python Design Patterns&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/python/design-patterns/open-closed-design-pattern" rel="noopener noreferrer"&gt;Python Open Closed Principle Design Pattern&lt;/a&gt;&lt;br&gt;
&lt;a href="https://cleancode.studio/design-patterns/open-closed-design-pattern" rel="noopener noreferrer"&gt;Open Closed Principle (OCP)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devto</category>
      <category>announcement</category>
      <category>web3</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
