<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cosmo W. Q on Medium]]></title>
        <description><![CDATA[Stories by Cosmo W. Q on Medium]]></description>
        <link>https://medium.com/@cosmo.lepton?source=rss-75ba266df366------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZKlp2dfvj9CCrSbmvOuISw@2x.jpeg</url>
            <title>Stories by Cosmo W. Q on Medium</title>
            <link>https://medium.com/@cosmo.lepton?source=rss-75ba266df366------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:53:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cosmo.lepton/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Safeguarding dynamic configuration changes at scale]]></title>
            <link>https://medium.com/airbnb-engineering/safeguarding-dynamic-configuration-changes-at-scale-5aca5222ed68?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/5aca5222ed68</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 17:01:01 GMT</pubDate>
            <atom:updated>2026-03-27T20:54:24.072Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>How Airbnb ships dynamic config changes safely and reliably.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v2VDklQn1NHAx-MiR8DYMQ.png" /></figure><p>By <a href="https://www.linkedin.com/in/cosmo-qiu/">Cosmo Qiu</a>, <a href="https://www.linkedin.com/in/bo-t-b04912238/">Bo Teng</a>, <a href="https://www.linkedin.com/in/siyuan-zhou-85ba8057/">Siyuan Zhou</a>, <a href="https://www.linkedin.com/in/ankursoni/">Ankur Soni</a>, <a href="https://www.linkedin.com/in/willish/">Willis Harvey</a></p><p>Dynamic configuration is a core infrastructure capability in modern systems. It allows developers to change runtime behavior without restarting or redeploying services, even as the number of services and requests grows. In practice, that might mean rolling out a new address form for a region launch, tightening an authorization rule, or adjusting timeouts when a dependency is slow.</p><p>Like any powerful tool, dynamic configuration is a double-edged sword. While it enables fast iteration and rapid incident response, a bad change can cause regressions or even outages. This is a common challenge across the industry: balancing developer flexibility with system reliability.</p><p>In this post, we will outline the expectations of a modern dynamic configuration platform, then walk through the high-level architecture of Airbnb’s dynamic config platform and how its core components work together to enable safe, flexible config changes.</p><h3>Modern config platform essentials</h3><p>As Airbnb’s business grows, our expectations for the dynamic config platform have evolved over time through our own learnings as well as industry best practices. These shape our view of what a good dynamic config platform should provide, including:</p><ul><li><strong>A coherent experience for config management</strong>: The platform provides a streamlined, end-to-end experience for defining, reviewing, testing, and rolling out config changes. It covers the most common needs out of the box with rich built-in features, while still offering escape hatches for edge cases.</li><li><strong>Strong reliability, availability and safety guarantees</strong>: All config changes are validated, reviewed, and rolled out progressively, with clear ownership and well-defined access control. Treating config as code is a key focus: config changes are versioned, reviewed, and auditable like service code, but remain dynamic at runtime. The platform itself must be highly available so that services can reliably fetch and apply configs. Changes should be observable, with support for fast rollbacks when needed.</li><li><strong>Safe testing in isolated environments</strong>: Developers can validate config changes in isolated local or canary environments before they reach production.</li><li><strong>Flexible multi-tenant support</strong>: In a multi-tenant platform, different tenants have different risk profiles. The platform should allow config owners to customize how their configs behave per tenant, including deployment triggers, guardrails, and rollout strategy (for example, AWS zone or Kubernetes pod percentage-based rollouts).</li><li><strong>Fast and controlled incident response</strong>: During an incident, responders can ship emergency configs as needed with clear auditability. The platform also provides observability for config changes, so incident responders can tell what changed, who was affected, when the change was made, and who made the change. This enables them to effectively identify the culprit and take action.</li></ul><h3>High-level architecture</h3><p>At Airbnb, Sitar is the internal name for our dynamic config platform. It provides a common way for teams to manage runtime behavior safely. At a high level, Sitar has four main parts: a developer-facing layer, a control plane, a data plane, and the clients and agents that run alongside application code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bv62zjTLRJRCKNdcTgiazA.jpeg" /></figure><p>The developer-facing layer is where config changes are created and reviewed. By default, configs are managed through a Git-based workflow, while a few exceptions are managed in the web interface (sitar-portal), which is also used for admin operations such as emergency deployments.</p><p>The control plane is responsible for orchestrating config changes. It enforces schema validation, ownership, and access control, and decides how each change should be rolled out: for example, which environments or AWS zone to target, what percentage of Kubernetes pods to start with, and how to progress the rollout over time. The control plane also specifies how to roll back the changes when needed, and supports routing in-flight configs to specific environments or slices of subscribers for fast testing.</p><p>The data plane provides scalable storage and efficient distribution of configs. It acts as the source of truth for config values and versions, and propagates updates to services reliably, consistently, and quickly.</p><p>On the product services side, an agent sidecar running alongside each service fetches the subscribed configs from the data plane and maintains a local cache. Client libraries inside the service then read from this cache and expose configs to application logic with fast, in-process access and optional fallbacks.</p><p>Putting these together, a typical change starts from a Git flow, proceeds through control-plane validation and rollout decisions, into the data plane for distribution, and finally to agents and client libraries that apply the config updates to application logic.</p><h3>Key design choices</h3><p>In this section, we highlight a few key design choices that shape how the platform looks and is operated.</p><h4><strong>Configs as code with a Git-based workflow</strong></h4><p>Config changes are by default managed by a Git-centric workflow. We use GitHub as the primary interface for managing configs, because we have an established and responsive internal team to manage GitHub Enterprise. GitHub integrates naturally with our existing CI/CD tooling, so we can reuse rich validation and deployment pipelines without re-inventing the wheel. This approach gives developers a consistent experience to make code changes: open a pull request, get reviews, merge, and deploy. GitHub also brings additional benefits such as mandatory reviewers, review and approval flows, and a change history. Configs under the same theme are grouped into tenants, with clear owners, customizable tests, and a dedicated CD pipeline.</p><p>While the Git-based flow is the default, we keep a UI portal for teams that prefer a portal-based experience and as a shortcut for specific operational needs, such as fast emergency config updates that can bypass the normal CI/CD pipeline.</p><h4><strong>Staged rollouts and fast rollbacks</strong></h4><p>When a change is proposed, schema validation (checking that the config matches the expected structure and types) and other automated checks run in CI. The change is always reviewed and approved before rollout.</p><p>Once merged in the main branch, the control plane performs a staged rollout where the change is first deployed to a limited scope, then gradually expanded to a larger scope if things look good. At each stage of this rollout, the change is evaluated, the author and the stakeholders are notified if regressions are detected, and a fast rollback can be triggered if needed. Staged rollouts can greatly reduce the blast radius of bad changes and improve the overall reliability of the platform.</p><h4><strong>Separated control and data planes</strong></h4><p>We separate the “decide” and “deliver” responsibilities. The control plane focuses on validation, authorization, and rollout decisions, while the data plane focuses on storing configs and distributing them reliably at scale. This separation allows us to evolve rollout strategies and policies without disrupting the underlying storage and delivery mechanisms, and vice versa.</p><h4><strong>Local caching and resilient clients</strong></h4><p>On the product services side, we introduced a local caching layer between the agent sidecar and the client library to improve resilience and availability. The agent sidecar runs alongside the main service container, regardless of which language the service is written in, and periodically fetches subscribed configs from the backend and persists them locally. The client libraries then read from this local cache. Even if the backend is temporarily unavailable or degraded, services can continue operating on the last known good configs from the local cache.</p><h3>Impact on product teams</h3><p>It is essential for the Sitar system to make life easier for product teams. In practice, its architecture changes how teams ship and operate in a few ways:</p><ul><li><strong>Rollouts become safer and more predictable.</strong> New behaviors, such as refined authorization rules, can be introduced gradually, verified on a small slice of traffic or in a specific environment, and rolled back quickly if needed. Teams spend less time worrying about “big bang” releases and more time iterating on behavior.</li><li><strong>Teams get more flexibility in how their configs are managed and rolled out.</strong> Each team can tailor a config flow to its own risk profile and release schedules. For example, teams can choose between automatic, manual, or cron rollouts, select the rollout strategy, and add extra checks. This lets teams keep their existing ways of working while still benefiting from a common platform and shared guardrails.</li><li><strong>Incident mitigation becomes faster and more controlled.</strong> When something goes wrong in production, incident responders can use observability tools that integrate config events to quickly locate the culprit change, then take quick action using the portal’s emergency flow. These emergency updates are fully auditable for future review.</li></ul><p>Besides these examples, the platform includes other improvements in usability, safety, and observability that we will not cover in detail here. Together, they contribute to a smoother day-to-day experience for teams that rely on dynamic configuration.</p><h3>Conclusions and next steps</h3><p>Dynamic configuration is a foundational capability of modern infrastructure. It enables fast iteration and rapid incident response, but only when it is equipped with strong safety features and provides a good developer experience. In this post, we shared how we think about a modern dynamic config platform at Airbnb, and how we developed Sitar’s architecture to meet those expectations.</p><p>The work is ongoing. As Airbnb’s business grows, we are continuing to refine rollout strategies, improve config testing, invest in observability and smart incident response tooling, and evolve other platform components.</p><p>In future posts, we plan to dive deeper into specific areas of the platform, such as how we optimize the Kubernetes sidecar that delivers config updates and how we design the developer experience around config management.</p><p>If this type of work interests you check out our <a href="https://careers.airbnb.com/">open roles</a>.</p><h3>Acknowledgments</h3><p>Our progress with Sitar would not have been possible without the support and contributions of many people. We’d like to thank Craig Sosin, Nikolaj Nielsen, Daniel Fagnan, Alex Edwards, Xian Gao, Nick Morgan, Carolina Calderon, Hanfei Lin, Joyce Li, Yunong Liu, Alex Berghage, Brian Wolfe, Yann Ramin, Denis Sheahan, Richa Khandelwal, Swetha Vaidy, Abhishek Parmar, Adam Kocoloski, Adam Miskiewicz, and all the other engineers and teams at Airbnb who joined design reviews and offered valuable feedback, as this work would not have been possible without them.</p><p><em>All product names, logos, and brands are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5aca5222ed68" width="1" height="1" alt=""><hr><p><a href="https://medium.com/airbnb-engineering/safeguarding-dynamic-configuration-changes-at-scale-5aca5222ed68">Safeguarding dynamic configuration changes at scale</a> was originally published in <a href="https://medium.com/airbnb-engineering">The Airbnb Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Progressive Loading: A Classic Pattern to Scale Modern AI]]></title>
            <link>https://pub.towardsai.net/progressive-loading-a-classic-pattern-for-modern-scalable-ai-3e0550ff2520?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e0550ff2520</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Sun, 14 Dec 2025 18:59:23 GMT</pubDate>
            <atom:updated>2026-06-20T18:47:03.746Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpBk3AaUkxbHt02WGScmUA.png" /></figure><h4><em>How a classic engineering pattern quietly powers modern AI systems</em></h4><blockquote>Disclaimer: The opinions and works presented in this blog are solely my own and do not reflect my current or previous employer or affiliates unless explicitly stated.</blockquote><p>If you have built software long enough, you start to recognize certain patterns when they reappear in new places. The names change, the scale changes, but the gist stay the same. One of those patterns is <strong>progressive loading</strong>. It helped browsers feel fast, games feel large, and distributed systems stay alive. It is now quietly doing the same thing for modern AI systems.</p><p><a href="https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills">Claude Skill</a> is a recent example. The system scales by loading only the metadata of available capabilities upfront and deferring the full skill logic until it is actually invoked.</p><p>This blog will review how progressive loading evolved across classic engineering domains and why it is quietly becoming one of the most effective ways to scale AI today.</p><h3><strong>Definition of Progressive Loading</strong></h3><p>In software engineering, progressive loading is the practice of delivering something useful as early as possible, then gradually loading the rest only when it is needed, instead of initializing everything up front. This makes systems start small, stay responsive, and grow in sophistication as demand becomes clearer.</p><p>In AI systems, progressive loading takes on a slightly different meaning. It is not just about bytes or assets, but about <strong>intelligence</strong>. Context is retrieved only when relevant. Capabilities like tools or skills are activated only when intent demands them. Expensive computation is deferred until simpler paths are exhausted. These have shown this pattern not just an optimization but a practical and sustainable way to scale modern AI systems.</p><h3>Progressive Loading in Classic Engineering</h3><p>Long before AI systems needed to manage context, tools, and computation, engineers were already using progressive loading to cope with limited resources and unpredictable demand.</p><h4>Games</h4><p>Video game is the place we can visualize progressive loading. When you play <a href="https://en.wikipedia.org/wiki/The_Legend_of_Zelda:_Breath_of_the_Wild"><em>The Legend of Zelda: Breath of the Wild</em></a> and stand on a mountaintop, you can see vast landscapes stretching far into the distance. Mountains, rivers, sky, and even birds in flight all seem to exist at once. You may wonder how a small device like the Nintendo Switch can possibly load an entire <a href="https://en.wikipedia.org/wiki/Universe_of_The_Legend_of_Zelda#Hyrule">continent of Hyrule</a> in real time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZDC3ys8AqEg7zqYM_Fu4Q.png" /><figcaption>Source: Nintendo</figcaption></figure><p>No, it does not load everything at once. What the game renders near Link(the main character) is rich and fully interactive, while distant is represented with less details. As you move through the world, the background gradually sharpens. Textures, geometry, and objects are streamed in continuously based on where you are and where you are likely to go next.</p><p>This is progressive loading in one of its clearest forms. The game loads just enough to keep the experience smooth, then incrementally more as exploration continues. Without this approach, large open worlds would simply be impractical on consumer hardware.</p><h4>Web</h4><p>On the web, progressive loading shows up as progressive rendering and lazy loading. Pages render their structure before data arrives. Images load at low fidelity before sharpening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yH4nT-5ZerLM1vP1Wu0Hhg.png" /><figcaption>Source: ChatGPT</figcaption></figure><p>Similarly, JavaScript bundles are split so only the code needed for the current view is downloaded. The goal is not to finish loading everything as fast as possible, but to make the page usable as soon as possible.</p><h4>Mobile</h4><p>Mobile apps pushed this idea even further under tighter constraints. Apps often launch with a lightweight shell, show cached content first, and load features or data in the background.</p><p>Apple iPhone’s <a href="https://support.apple.com/guide/iphone/manage-storage-on-iphone-iph47c931112/ios"><em>Offload Unused Apps</em></a> is an OS-level example of the same idea. Rarely used apps are reduced to placeholders and fully loaded again only when you tap them again.</p><h4>Distributed Systems</h4><p>In distributed systems, progressive loading shows up as <a href="https://docs.spring.io/spring-boot/reference/features/spring-application.html#features.spring-application.lazy-initialization">lazy initialization</a>, <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes">staged startup</a>, and <a href="https://learn.microsoft.com/en-us/azure/architecture/patterns/cache-aside">demand-driven cache warming</a>. Services often come online with just enough state to serve traffic, then progressively hydrate caches, establish downstream connections, or activate heavier components as real access patterns emerge.</p><p><a href="http://medium.com/r?url=http%3A%2F%2Fnathanmarz.com%2Fblog%2Fhow-to-beat-the-cap-theorem.html">Data pipelines</a> may deliver fast, partial results before refining them in the background, while infrastructure layers gradually ramp traffic or capacity to avoid cold-start failures. Instead of eagerly loading everything up front, these systems prioritize responsiveness and stability first, becoming more complete, accurate, and efficient over time.</p><h3>Progressive Loading in Modern AI</h3><p>What makes modern AI systems challenging is not just the model itself, but everything wrapped around it.</p><ul><li>Growing context</li><li>Complicated tools and skills</li><li>Expensive computation</li></ul><p>And all of this has to happen fast enough to feel interactive but loading everything upfront quickly becomes impractical. This is where progressive loading reappears, not as a UI trick or a performance hack, but as a system-level design choice.</p><h4>4.1 Context Progressive Loading</h4><p>Context is one of the fastest-growing costs. Conversations get longer, documents get larger, and external knowledge piles up quickly. Loading everything upfront may feel safe, but it is often unnecessary and expensive.</p><p>Context progressive loading takes a different approach. The system starts with the minimum context needed to respond and pulls in more only when the task requires it. This is the idea behind <a href="https://en.wikipedia.org/wiki/Retrieval-augmented_generation">Retrieval-Augmented Generation(RAG)</a>. A small set of relevant documents is retrieved first, with deeper retrieval triggered only if the problem turns out to be more complex.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGbVrR8vnFXPJEMUED8SKw.png" /><figcaption>Source: <a href="https://www.designveloper.com/blog/what-is-retrieval-augmented-generation/">https://www.designveloper.com/blog/what-is-retrieval-augmented-generation/</a></figcaption></figure><p>The same pattern applies to long documents and conversations. Instead of loading everything at once, systems summarize earlier content and expand only the parts that matter. The assistant feels informed and responsive, while most of the context is loaded on demand.</p><h4>4.2 Capability Progressive Loading (Skills and Tools)</h4><p>As models get better, platforms naturally want them to do more. Anthropic has Claude Skills. OpenAI has <a href="https://platform.openai.com/docs/guides/tools#page-top">tools</a> and <a href="https://platform.openai.com/docs/guides/function-calling">function calling</a>. Others rely on plugins or custom integrations with different names but same goal.</p><p>In Claude’s case, that solution is <a href="https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills">Skills</a>, a folder centered around a SKILL.md . The progressive-loading part is subtle but important. A SKILL.md starts with YAML format containing <strong>required metadata</strong>: name and description.</p><p><em>Skill layout</em></p><pre>.claude/skills/pdf/<br>├─ SKILL.md          # has YAML: name + description + core instructions<br>├─ forms.md          # only needed for form filling<br>└─ scripts/<br>   └─ extract_fields.py</pre><p><em>SKILL.md(shape)</em></p><pre>---<br>name: pdf-helper<br>description: Work with PDFs (extract fields, fill forms). Use when user mentions PDFs or forms.<br>---<br><br># PDF Helper<br><br>If the task is &quot;fill a form&quot;, read [forms.md](forms.md) before proceeding.<br>For extraction, run: python scripts/extract_fields.py &lt;file.pdf&gt;</pre><blockquote>At startup, the agent pre-loads the name and description of every installed skill into its system prompt.</blockquote><p>That gives Claude a skill menu, without paying the token cost of loading every skill’s full instructions. When Claude decides a skill is relevant, it then loads the full SKILL.md into context. If the skill bundles extra files, those files are not loaded either. They are referenced from SKILL.md, and Claude reads them only when needed.</p><p>Conceptually, the agent’s startup prompt looks like</p><pre>Installed skills (metadata only):<br>- pdf-helper: Work with PDFs (extract fields, fill forms)...<br>- git-reviewer: Review PR diffs and suggest changes...<br>- ...</pre><p>That’s capability progressive loading in a nutshell: the assistant stays light by default, and only becomes specialized when needed.</p><h4>4.3 Computation Progressive Loading</h4><p>Consider how an AI assistant answers a question. It rarely needs to go straight to the most expensive reasoning path. If you ask a simple factual question, a quick response is often enough. If you ask something ambiguous or complex, the system may need to think longer, retrieve more context, or call tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfNX9HzLMcLMTKedNEf3Sw.png" /><figcaption>Source: ChatGPT</figcaption></figure><p>Computation progressive loading makes this explicit. The system starts with cheap computation first. A fast response using minimal reasoning. If that is not sufficient, it escalates. It may run a deeper analysis, fetch additional data, or validate the answer with tools. Each step adds more computation, but only when the previous step falls short.</p><h4>4.4 Interaction Progressive Loading</h4><p>From a user’s perspective, the most noticeable form of progressive loading is how an AI responds before it finishes everything.</p><p>You see this when an assistant gives a quick summary before expanding into details, or produces a rough draft before polishing it further. Sometimes the first response answers the question well enough. Other times, follow-up prompts trigger deeper reasoning, more context, or additional computation.</p><p>In practice, this is why good AI systems feel responsive and trustworthy even doing complex things. They help first, then improve, instead of insisting on finishing everything before saying anything at all.</p><h3>Final Thoughts</h3><p>It is easy to believe that modern AI works because the models are huge and the math is clever. In reality, a lot of the magic comes from classic engineering instincts: do not load everything, start small, and add complexity only needed.</p><p>Progressive loading did not suddenly become relevant because of AI but AI made the costs visible again. The systems that scale are the ones that stay disciplined about when to do more.</p><p>As fast as AI is moving, good software engineering still matters. Many of the ideas shaping modern AI are not new but simply showing up higher in the stack.</p><p>If you enjoy this blog, check out <a href="https://medium.com/@cosmo.lepton">my other articles</a> and follow my <a href="https://github.com/hackjutsu">GitHub</a>, or <a href="https://www.linkedin.com/in/cosmo-qiu">LinkedIn️</a> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e0550ff2520" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/progressive-loading-a-classic-pattern-for-modern-scalable-ai-3e0550ff2520">Progressive Loading: A Classic Pattern to Scale Modern AI</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Fully Local LLM Voice Assistant: A Practical Architecture Guide]]></title>
            <link>https://pub.towardsai.net/building-a-fully-local-llm-voice-assistant-a-practical-architecture-guide-6a506aee6020?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a506aee6020</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[large-language-models]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Mon, 08 Dec 2025 01:55:12 GMT</pubDate>
            <atom:updated>2026-06-20T18:46:21.619Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Why your next assistant might run entirely on your own hardware.</em></h4><blockquote>Disclaimer: The opinions and works presented in this blog are solely my own and do not reflect my current or previous employer or affiliates unless explicitly stated.</blockquote><p>This past Thanksgiving, I set out to build a<a href="https://github.com/hackjutsu/vibe-speech/blob/main/config.yaml"> fully local voice assistant</a> which should listen, think, act, and speak without relying on the cloud service.</p><p>Why bother? Because today’s mainstream assistants are still tied to the cloud, limited by product rules, and hard to customize. Meanwhile, the AI development in the last two years completely changed what individuals can build at home.</p><p>This guide summarizes everything I learned while building my own assistant. It’s more than a project recap — it’s a practical framework for how a modern, fully local voice assistant should be designed.</p><h3>A Voice Assistant Is Not a Pipeline but a Living Loop</h3><p>When people imagine a voice assistant, they think of a simple chain: audio in, text out, run it through a model, then speak the response.</p><pre>voice → STT → LLM → TTS → voice</pre><p>That’s how voice assistants worked a decade ago. Today, that architecture is far too limited. A modern assistant needs to carry context from moment to moment, decide what needs to happen next, call tools and APIs, and wait for your reply before continuing the loop.</p><p><strong>The right mental model looks more like a circle than a line.</strong> You speak. The assistant hears you, interprets what you meant, decides whether to think, act, respond, or ask for clarification, and then re-enters a waiting state — ready for the next turn, aware of the current task, and capable of resuming it hours or even days later.</p><h3>Breaking the System into Independent Stages</h3><p>To build this loop, it helps to decompose the assistant into independent modules. Each module can evolve on its own so that you can swap out implementations without touching the rest of the system.</p><p>And this is the architecture that holds everything together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0zcgehNLe_pcXf259vMWA.png" /><figcaption>Architecture of LLM voice assistant</figcaption></figure><p>The diagram captures the system at a glance: audio comes in, becomes text, gets cleaned, and flows into the assistant core. The core does the real thinking over your request, planning what should happen next, calling the appropriate tools, and updating its context before generating a response. That response flows back out through text-to-speech and becomes the assistant’s voice. Then the loop begins again with your next user input.</p><p>Now let’s walk through each stage in more detail.</p><h4>Stage 1: Voice Capture</h4><p>Everything begins with sound. Voice capture is simply the process of receiving audio from a microphone in your laptop or even from satellite microphones with a Raspberry Pi Hub in hour rooms.</p><p>In my experience, using a dedicated microphone helps a lot, especially if you are a non-native English speaker.</p><p>This stage does not need to understand language. Its only job is to deliver clean, low-latency audio. Once the sound arrives, the rest of the assistant can take over.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzilWFMp1ThIZJjtYJdkmw.png" /></figure><p><strong>Options</strong></p><ul><li>Laptop or phone’s built-in mic. Good enough for development.</li><li>Dedicated mic(<a href="https://a.co/d/1O73vyC">my choice</a>) which helps capture better voice quality.</li><li><a href="https://www.amazon.com/gp/product/B0D3KPXQFR/ref=ppx_yo_dt_b_search_asin_title?tag=networkchuck-20&amp;ie=UTF8&amp;psc=1&amp;geniuslink=true">Satellite mic for your Raspberry Pi</a>, which I learned from <a href="https://www.youtube.com/watch?v=XvbVePuP7NY&amp;t=805s">this YouTube video</a>.</li></ul><h4>Stage 2: Speech-to-Text</h4><p><a href="https://openai.com/index/whisper/">Whisper, OpenAI’s speech-to-text(STT) model(2022)</a>, is the most popular choice here because it is accurate, open source, and runs well on local hardware. Till 2025, <a href="https://voicewriter.io/blog/best-speech-recognition-api-2025">whisper remains the strongest open-source STT option available</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLN0WEU59SmOB2_qhe9WrA.png" /><figcaption>source: <a href="https://voicewriter.io/blog/best-speech-recognition-api-2025">https://voicewriter.io/blog/best-speech-recognition-api-2025</a></figcaption></figure><p>I tested several Whisper variants in my AI home lab (w/ Nvidia 4090), and <a href="https://github.com/SYSTRAN/faster-whisper">faster-whisper</a>, which is a re-implementation of OpenAI’s model, delivered the best balance of latency(&lt; 0.5s) and accuracy with the <a href="https://github.com/hackjutsu/vibe-stt-server?tab=readme-ov-file#get-info-response">large-v3-turbo</a> model. This model can be run in modern MacBook with unified memory but with longer latency(2~3s) for transcription.</p><p>Find Repo of my STT server: <a href="https://github.com/hackjutsu/vibe-stt-server">https://github.com/hackjutsu/vibe-stt-server</a>.</p><p>On phones, the built-in iOS and Android speech recognizers are lightweight fallbacks. I haven’t tested them myself, but both platforms should expose these features through their native SDKs.</p><h4>Stage 3: Text Cleanup</h4><p>The stage is one that most hobby projects skip, but it dramatically improves the perceived intelligence of the assistant: text cleanup.</p><p>Raw transcripts often contain filler words, broken punctuation, and grammar inconsistencies.</p><pre>Raw transcription (before cleanup):<br><br>“uh yeah so I was like trying to set up the server and it kind of didn’t <br>you know uh start properly I guess so I just like restarted it again but <br>then it still didn’t work…”<br><br>Cleaned text (after cleanup):<br><br>“I tried to set up the server, but it didn’t start properly. <br>I restarted it, but it still didn’t work.”</pre><p>I used to assume Whisper’s prompt could handle this, <a href="https://cookbook.openai.com/examples/whisper_prompting_guide">but it doesn’t behave like a standard GPT-style prompt</a>.</p><p>Luckily, a lightweight normalization pass by a small model, such as the <a href="https://ollama.com/">ollama</a>-hosted <a href="https://ollama.com/library/qwen3:4b">Qwen3:4b</a> in MacBook and <a href="https://ollama.com/library/qwen3:8b">Qwen3:8b</a> in the AI home lab, can transform a messy transcript into clean, structured output for later stages for reasoning.</p><h4>Stage 4: The Assistant Core</h4><p>Once text is cleaned, it enters the heart of the system: the <strong>assistant core, </strong>where understanding, memory, decision-making, and real-world actions come together. The core consists of three subsystems:</p><ol><li><strong>The LLM</strong> — thinks (reasoning &amp; planning)</li><li><strong>The Context Store</strong> — remembers (state &amp; memory)</li><li><strong>The Tool Layer</strong> — acts (MCP, RAG, APIs, device control)</li></ol><p><strong>4.1 LLM (Reasoning, Planning and Reflection)</strong></p><p>The LLM interprets what the user meant, not just what they said. It analyzes the cleaned transcript, infers intent, plans the next steps, chooses whether to call a tool, retrieve memory, or answer directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-EF_bDKQ6TF8gIWWRtSmDA.png" /><figcaption><em>LLM releases by year: blue cards = pre-trained models, orange cards = instruction-tuned. Top half shows open-source models, bottom half contains closed-source ones. Source: </em><a href="https://arxiv.org/abs/2307.06435?ref=blog.n8n.io"><em>https://arxiv.org/abs/2307.06435</em></a><em> &amp; </em><a href="https://blog.n8n.io/open-source-llm/">https://blog.n8n.io/open-source-llm/</a></figcaption></figure><p>Modern models such as <a href="https://ollama.com/library/qwen3">Qwen</a>, <a href="https://ollama.com/library/llama3.1">Llama</a>, <a href="https://deepmind.google/models/gemma/">Gemma</a> or <a href="https://ollama.com/library/ministral-3:latest">Ministral</a> run locally with strong performance, and thanks to quantization they can operate quickly even on modest GPUs. <a href="https://blog.n8n.io/open-source-llm/">This blog has a good summary of open-source LLMs for 2025.</a></p><p>Both <a href="https://ollama.com/">ollama</a> and <a href="https://lmstudio.ai/">LM Studio</a> can host small models(&lt; 30B) locally. Some models have stronger tool-calling reliability, which matters when integrating MCP or RAG triggers. I also noticed (as of 12/2025) <a href="https://github.com/sst/opencode/issues/1034">some issue of tool calling with ollama-hosted models</a> in another project.</p><p><strong>4.2 Context Store (Memory and State)</strong></p><p>A real assistant needs memory.</p><p>The context store maintains both <strong>short-term conversational state</strong> and <strong>long-term working state</strong> such as timers, the last device you controlled, the article you’re halfway through, a task you paused yesterday, and more.</p><p>Before the LLM reasons about a request, it reads from context. After it finishes reasoning, it writes back updates. This prevents the assistant from forgetting what it’s doing, or reviving stale tasks unintentionally.</p><p>The context store can be as simple as a local SQLite database or as structured as your system requires.</p><p><strong>4.3 Tool Layer (MCP, RAG, API and other Capabilities)</strong></p><p>If the LLM is the brain, the tool layer is the hands and senses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RRru-tIkZJGosIqBcmxtgQ.png" /></figure><p><a href="https://modelcontextprotocol.io/docs/getting-started/intro"><strong>MCP (Model Context Protocol)</strong></a> is especially powerful here, because it gives the assistant standardized access to capabilities without custom wiring.</p><p><a href="https://aws.amazon.com/what-is/retrieval-augmented-generation/"><strong>RAG (Retrieval-Augmented Generation)</strong></a><strong> </strong>is<strong> </strong>a technique that lets the assistant pull in relevant knowledge from your private data so the LLM can reason with accurate, up-to-date information.</p><p>Together, tools let the assistant:</p><ul><li>perform local searches over your private documents</li><li>call APIs</li><li>operate devices</li><li>read/write local files</li><li>trigger external automations</li><li>run computations</li><li>fetch structured web results</li></ul><p>Tools return structured results, which the LLM interprets and incorporates into the next step of reasoning. This separation between thinking and acting is what elevates the assistant beyond a chatbot.</p><blockquote>The assistant core is complex enough to deserve a separate blog on its own, so I’ll pause here and keep the focus on the high-level architecture.</blockquote><h4>Stage 5: Text-to-Speech</h4><p>Once the thinking and acting are done, the assistant needs a voice.</p><p>Text-to-speech(or TTS) used to be the weakest link in DIY projects. Today, A few open source projects offer expressive, low-latency speech that makes your assistant’s voice much more useful.</p><ul><li><a href="https://huggingface.co/coqui/XTTS-v2">xtts-v2</a>, my choice in project</li><li><a href="https://github.com/OHF-Voice/piper1-gpl">piper</a></li><li><a href="https://github.com/boson-ai/higgs-audio">higgs-audio</a> (not tested yet)</li></ul><p>This <a href="https://www.reddit.com/r/LocalLLaMA/comments/1f0awd6/best_local_open_source_texttospeech_and/">reddit post</a> summarized the popular open source TTS libraries. In my testing, most local TTS models still produce a semi-human, semi-robotic tone despite their marketing. Some offer voice cloning, but the results often feel uncanny, so I prefer sticking with their default voice.</p><p>If you prefer cloud-quality voices, services like <a href="https://www.hume.ai/">Hume.ai</a> also produce excellent audio, though they introduce a non-local component.</p><h4>Stage 6: Voice Output</h4><p>Finally, the audio leaves the system and plays through a device: your phone, your speakers, or even a group of <a href="https://www.amazon.com/gp/product/B0D3KPXQFR/ref=ppx_yo_dt_b_search_asin_title?tag=networkchuck-20&amp;ie=UTF8&amp;psc=1&amp;geniuslink=true">satellite speakers with a Raspberry hub</a>. Most of time, the first “voice capture” stage and the last “voice output” stage happen in the same device which combines the mic and speaker.</p><p>This closes the loop and returns the assistant to listening mode (see the architecture diagram below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0zcgehNLe_pcXf259vMWA.png" /><figcaption>The same architecture of LLM voice assistant</figcaption></figure><h3>Distributed Architecture: Offload Heavy Compute Wherever You Want</h3><p>A key learning when building a local assistant is that everything doesn’t have to run on one device. Whisper and your LLM can sit on a GPU server, the orchestrator can run on a tiny laptop or Raspberry Pi, and your phone can serve as both mic and speaker. All within your LAN and with minimal latency.</p><p><a href="https://github.com/hackjutsu/vibe-speech">In my project vibe-speech</a>, I started with everything running in the MacBook and ended with migrating the heavy computation to the dedicated machine with GPU. The local laptop is <a href="https://github.com/hackjutsu/vibe-speech/blob/main/config.yaml">a thin orchestrator layer</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FOyycmO5n6tHPfOoxB2AnQ.png" /><figcaption>Offload Heavy Computing to dedicated machine</figcaption></figure><h3>Final Thoughts</h3><p>This blog looks at the <strong>high-level architecture of a fully local LLM voice assistant</strong>, based my own hands-on experiments and online research.<br>If you’re not restricted to running locally, of course, the landscape is very different: plenty of cloud services can spin up a voice chatbot in minutes.</p><p>There’s also a different architectural path worth mentioning: a <strong>speech-to-speech model</strong> that takes raw voice as input and directly returns ready-to-play audio as output , without intermediate text or stitching together multiple services. I haven’t found a good one available for testing yet, but it’s an exciting direction and worth keeping on your radar.</p><p>If you enjoy this blog, check out <a href="https://medium.com/@cosmo.lepton">my other articles</a> and follow my <a href="https://github.com/hackjutsu">GitHub</a> or <a href="https://www.linkedin.com/in/cosmo-qiu">LinkedIn️</a> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a506aee6020" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/building-a-fully-local-llm-voice-assistant-a-practical-architecture-guide-6a506aee6020">Building a Fully Local LLM Voice Assistant: A Practical Architecture Guide</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Vibing to Engineering: A Case Study of Building a Character Chatbot]]></title>
            <link>https://pub.towardsai.net/from-vibing-to-engineering-a-case-study-of-building-a-character-chatbot-80ec4cd57406?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ec4cd57406</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 04:30:01 GMT</pubDate>
            <atom:updated>2025-12-15T21:51:12.243Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>TL;DR:</strong> A case study on building a mini character.ai-like chatbot with Codex, including architecture decisions, lessons learned, and the moments where AI shines or fails.</blockquote><p><em>Quick reference: </em><a href="https://github.com/hackjutsu/mini-chatbot"><em>GitHub project: mini-chatbot</em></a></p><p>The story starts with replacing my Intel-based MacBook with an M-series model, a laptop that finally lets me run local LLMs without wrestling with GPU drivers or relying on paid external APIs.</p><p>The Mac’s <a href="https://www.hoxtonmacs.co.uk/blogs/news/what-is-unified-memory">unified memory</a> feels like a return to the original personal-computer vision of using technology to empower individuals, not just big companies. It’s a gift for personal projects with LLMs where experience and joy matter.</p><h3><strong>A Taste of Local LLMs</strong></h3><p>I could not wait to download <a href="https://ollama.com/">ollama</a> and try out a few models such as llama3.1:8b. Talking to a local LLM in the terminal felt surprisingly fresh, even after years of using ChatGPT.</p><pre>brew install ollama<br>ollama pull llama3.1:8b<br>ollama run llama3.1:8b</pre><p>This new capability sparked me to build something. I haven’t launched a serious open-source project since <a href="https://github.com/hackjutsu/Lepton">Lepton</a>, a gist manager that gained some popularity.</p><p><strong>I chose to start small: a chatbot powered by Ollama-hosted LLMs, as a way to explore AI-native development.</strong></p><p>This won’t be the usual tech blog with code snippets. Instead, it focuses on the flow of working with AI and how I guided it to build the project.</p><h3>Brainstorming with Codex</h3><p>At the very beginning, I had a rough idea of what the stack for a prototype chatbot should look like.</p><pre>[Frontend] --&gt; [Backend] --&gt; [LLM facade(Ollama)]</pre><ul><li><strong>Frontend:</strong> A narrow conversation session list on the left and a large conversation panel on the right, plus an input box and a send button.</li><li><strong>Backend:</strong> Forwarding messages to Ollama, then returning the responses to the frontend. It can be extended for advanced features.</li><li><strong>LLM Facade:</strong> Ollama serves as the gateway to route requests to the selected LLM.</li></ul><p>There were no any advanced features to avoid overloading the assistant upfront. Though I used <a href="https://claude.com/product/claude-code">Claude Code</a> more often for my daily work, I chose <a href="https://openai.com/codex/">Codex</a> this time to experiment the new coding assistant.</p><p>Switching assistants is easy as long as the requirements, design, decisions are well-documented along the development journey, <a href="https://www.linkedin.com/posts/zeyongcai_this-is-what-ive-learned-from-using-claude-activity-7370169860330307584-GBb2">a practice I learned from ZY’s sharing</a>. In this project, I asked Codex to put the initial architecture in <a href="https://github.com/hackjutsu/mini-chatbot/tree/main/discussions">the folder </a><a href="https://github.com/hackjutsu/mini-chatbot/tree/main/discussions">discussions</a> and always wrote a short feature summary before and after making major changes. I intentionally made the development process more AI-native, more aligned with the trend of vibe coding.</p><p><em>→ </em><a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/arch.md"><em>link to the initial architecture doc</em></a></p><pre># this is my proposed the project structure<br>.<br>├── discussions<br>│   ├── arch.md<br>│   └── feature_x_summary.md<br>├── frontend_logic<br>│   └── xxx.js<br>├── backend_logic<br>│   └── xxx.js<br>└── other files</pre><p>We(Codex and I) also got aligned on other decisions, such as using a pure JavaScript stack for both the frontend and backend to keep the language stack simple.</p><h3>Rudimentary Implementation</h3><p><em>“What did AI give you after the first prompt?”</em></p><p>I went over my requirements with Codex, and it generated <a href="https://github.com/hackjutsu/mini-chatbot/commit/dbda0cf7ff2560a228e4da0bee4b126f507ddfd4">the first version of the chatbot</a> with the following project structure.</p><pre>.<br>├── public/index.html<br>└── server.js</pre><p>All the frontend logic sits in public/index.html, and the backend lives in server.js, which is a clean setup with minimal dependencies. The conversation sessions are stored in browser’s localStorage, a practical strategy found elsewhere.</p><p>The first version of the chatbot turned out surprisingly well, with a clean and pleasant UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8JXkqYFj6_TstG_M25VWTw.png" /></figure><h3>Support Streaming</h3><p><em>“Why does my chatbot feel so choppy?”</em></p><p>At this point, the backend sent the entire LLM response at once, which delayed replies and made messages pop up all at once. The common solution is to stream the output so the web app can print tokens as they arrive, making the conversation feel much more natural.</p><p>I let Codex research how to support the end-to-end streaming, and it gave me several options with trade-offs. After reviewing them, I picked a reasonable one. It’s pretty amazing how well modern AI tools work well if you give them a clear problem and direction.</p><p><em>→</em><a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/streaming.md"><em> link to streaming summary</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QGg1Zi53DGfIy8vUCXeQ9g.gif" /></figure><h3>Backend Session and User Management</h3><p><em>“Why can’t my chatbot remember me across browsers?”</em></p><p>The app stored sessions in the browser’s localStorage, which works for small projects, but all data gets wiped if the user changes browsers or clears their cache. To unlock more potential, I decided to move the data layer to the backend.</p><p>We soon agreed on <a href="https://github.com/hackjutsu/mini-chatbot/commit/275f6fedc9d5bc3191ed1df1a5ffcbadf770a5b0#diff-d7c9c4e37c37bdbf3fd7007e8e5a111ba1cbfecdd20b76f549a385ebc890e552R16-R44">the table schema</a>. Codex moved session logic to the backend and set up a basic user system in server.js. We used SQLite and added a db.js file for the data logic. The user system was intentionally bare-bones so I wouldn’t get sidetracked. Readers can integrate <a href="https://datatracker.ietf.org/doc/html/rfc6749">OAuth 2.0</a>, <a href="https://en.wikipedia.org/wiki/Security_Assertion_Markup_Language">SAML</a> or any auth layer as needed.</p><p>With these changes, both index.html and server.js started getting bloated but still manageable by both Codex and me.</p><pre>.<br>├── public/index.html<br>├── server.js<br>└── db.js</pre><p>Now we can register new users, and each user sees only their own conversation sessions after logging in.</p><p><em>→ </em><a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/user-system.md"><em>link to user system summary</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uaXVZmpdmkdpZ9BV8zj1wA.png" /></figure><h3>LLM Picker</h3><p><em>“Can I talk to a different LLM model?”</em></p><p>Ollama can serve any downloaded LLM seamlessly, which inspired me to add the support of switching models on the fly. Codex implemented a good enough LLM picker fast.</p><p>→ <a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/model-selection.md">link to LLM picker summary</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVszDjj56LJYR5afVw9hYA.png" /></figure><h3>Support Personal Characters</h3><p><em>“Can I choose the character I want to chat with?”</em></p><p>With user accounts added, it made sense to let people choose the bot’s persona. That organically turned into a character system. Let’s do it!</p><h4>Vibe Coding Got Stuck</h4><p>I started with design discussions around the table schemas and indexes. Once we aligned on the details, Codex wrapped up the backend implementation quickly in server.js . The frontend work lived in index.html . The character picker UI came together almost immediately.</p><p>However, it got stuck on something as simple as highlighting the selected character card.</p><p>Either the CSS or the state handling must be broken somewhere in the massive index.html. I tried multiple approaches, including plain-text explanations, screenshots, even reading through the code myself, but nothing worked. The frontend had become so cluttered that the logic was impossible to untangle without significant effort.</p><p>That’s when I knew the vibe coding phase had to be adjusted a little bit. It was time to tackle the boring but essential engineering step: refactoring.</p><h4>Frontend Refactoring</h4><p>I asked Codex to analyze the bloated frontend file, suggest refactors, and sketch a React migration plan, a task that mirrored what we often do in real projects.</p><p>Codex did a good one-shot refactor and the character card highlight bug disappeared. This could be because modular code is easier for both humans and AI to reason about.</p><p>→ <a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/frontend-modernization.md">link to frontend refactoring summary</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_TiCAkaLM3Wrv8ocunvnTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ctf7M-lyCsborqCYBoxQhg.png" /></figure><h4>Backend Refactoring</h4><p>As expected, the refactoring didn’t stop at the frontend.</p><p>The entire backend lived in a single file server.js, tightly coupling HTTP routes, database access, and streaming logic, with duplicated validation, mixed read/write semantics, and virtually no unit tests. Codex also broke down the logic and suggested refactors by theme and priority. I skipped some minor items that seemed like over-engineering for now.</p><blockquote>Tip: Ask Codex to redraw the diagram after each big change.</blockquote><p>Though Codex claimed it had separated the app layer(Express App) from the database layer(db/index.js), the diagram it drew still showed direct connections as shown below.</p><pre>┌──────────────┐            ┌──────────────┐        ┌────────────┐<br>│  Express App │───────────▶│  Routers     │───────▶│ Middleware │<br>└─────┬────────┘            └─────┬────────┘        └─┬──────────┘<br>      │                           │                   │<br>      │                    ┌──────▼──────┐            │ attaches req.user/session<br>      │                    │ Services    │◄───────────┘<br>      │                    │ (chat,      │<br>      │                    │  sessions,  │<br>      │                    │  characters)│───┐<br>      │                    └──────┬──────┘   │ format DTOs / orchestrate logic<br>      │                           │          │<br>      │                           ▼          │<br>      │                    ┌──────────────┐  │<br>      └───────────────────▶│   db.js      │◄─┘<br>                           │ better-sqlite│<br>                           └──────────────┘</pre><p>After digging deeper, I found that Codex had refactored only the chat logic and ignored the user logic. I asked it to build a separate user service to eliminate the direct calls, and that led to the cleaner diagram below.</p><pre>┌──────────────┐   mounts    ┌──────────────┐   runs    ┌────────────┐<br>│  Express App │────────────▶│  Routers     │──────────▶│ Middleware │<br>└──────────────┘             └─────┬────────┘           └──┬─────────┘<br>                                   │                       │ attaches req.user/session<br>                                   ▼                       │<br>                             ┌──────────────┐              │<br>                             │  Services    │              │<br>                             │ (chat,       │&lt;─────────────┘<br>                             │  sessions,   │<br>                             │  characters, │<br>                             │  users)      │<br>                             └─────┬────────┘<br>                                   │<br>                                   ▼<br>                             ┌──────────────┐<br>                             │   db/index.js│<br>                             │ better-sqlite│<br>                             └──────────────┘</pre><p>→ <a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/backend-refactoring.md">link to backend refactoring summary</a></p><h4>More Project Setup</h4><p>With both frontend and backend modularized, the project started to feel like proper engineering. Codex helped me set up linting, logging, and testing, and I’m now far more confident making changes. (I later refactored db.js the same way.)</p><p>Users can now create characters with custom persona.</p><h3>Character Marketplace</h3><p><em>“What if characters could be shared, discovered, and traded?”</em></p><p>After testing the app, I noticed that all characters were private to each user. The system seeded default characters, but these characters could not be shared across accounts. To keep the project fun, I decided to turn it into a character marketplace.</p><p>We decided to separate characters into their own table, adding a small state machine (draft → published), and defining how users are associated to characters. Users can pick a published character or one they created, and they can publish as many as they like. All published characters are FREE as I don’t want to overcomplicate the project with a pricing and billing system.</p><p>At this stage, we’ve essentially built a mini, “character.ai”-style chatbot.</p><p>→ <a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/character-marketplace.md">link to character marketplace summary</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFs6fdRGpQVCkpeMJelMdA.png" /></figure><h3>Case Study: Sub-optimal Cache</h3><p><em>“A place where AI did not do a good job.”</em></p><p>I asked Codex to add a cache layer for published marketplace characters, and it happily produced a chunk of code and announced the job was finished. However, since I’m generally skeptical of “too-easy” promises, I decided to take a deeper look at the code.</p><h4>Inefficient Message Flow</h4><p>The message flow is the process of taking a user message, preparing the prompt with character persona and conversation history, sending it to LLM and returning the response back to the user. Over the time, it evolved organically into an inefficient pattern, especially when preparing for the prompt with character persona:</p><ol><li>For each message receives, the backend checks if a character id is included.</li><li>If yes, it queries the database for if the character is owned by the user. If so, it uses that character’s persona, regardless of whether the character is published.</li><li>If the character is not user-owned, the system then checks whether it’s published in marketplace. If so, it uses that persona; otherwise, it falls back to the default.</li></ol><pre>POST /api/chat<br>└── chatService.prepareConversationPrompt()<br>    └── session.characterId? yes<br>        ├── check db w/ getCharacterOwnedByUser(characterId, userId)<br>        └── check db w/ getCharacterById(characterId)</pre><p>This means that in real-world scenarios, talking to a popular marketplace character will trigger at least two database queries just to get the character’s persona! Crazy. A seasoned engineer can smell it without any benchmark.</p><p>This is a typical problem appears in codebases after years of incremental feature additions without proper cleanup. AI didn’t introduce anything new here, as it simply implemented the user-private character system first and then layered marketplace-character support on top. The only difference is that it accelerates it from years into days or even hours.</p><h4>Flawed Cache Solution</h4><p>When prompted to add caching for published marketplace characters, Codex generated a rudimentary cache but didn’t optimize the broader message flow (as shown below).</p><pre>POST /api/chat<br>└── chatService.prepareConversationPrompt()<br>    └── session.characterId? yes<br>        ├── check db w/ getCharacterOwnedByUser(characterId, userId)<br>        └── check the marketplaceCharacterCache<br>               └── otherwise check db w/ getCharacterById(characterId, published:true)</pre><p>Although this improved the flow, the message request still performed at least one database query getCharacterOwnedByUser, which was unnecessary if we simply reordered the flow like this:</p><pre>POST /api/chat<br>└── chatService.prepareConversationPrompt()<br>    └── session.characterId? yes<br>        ├── check marketplaceCharacterCache<br>        |      └── otherwise check db w/ getCharacterById(characterId, published:true)<br>        └── check db w/ getCharacterOwnedByUser(characterId, userId)</pre><p>We check the marketplace cache first because most real-world traffic uses marketplace characters. We only hit the database for user-owned characters when they’re not in the marketplace, which mainly happens when users test draft characters.</p><p>→ <a href="https://github.com/hackjutsu/mini-chatbot/blob/main/discussions/cache-system.md">link to cache system summary</a></p><h4>Takeaways</h4><p>I caught this issue because I always ask Codex to examine and visualize the critical flow, instead of trusting summaries or assurances. With the right hint, like “optimize the overall message flow”, Codex could have fixed it, but expecting perfect prompts every time isn’t realistic, especially when we want to keep some “vibe” in the process.</p><p>To “vibe” is fundamentally human. Ambiguity is not a bug, it is a feature of human communication. Maybe one day a far more advanced AI system will translate such vibes into rigorous requirements and eventually even precise machine code. Or maybe this will never fully happen, because the very nature of a vibe is rooted in human ambiguity, a kind of intuitive, high-context understanding that resists being captured or formalized without losing its essence.</p><h3>Wrap-ups</h3><p>Though this blog is mainly about architecture, implementation and refactoring, Codex deserves credit for its good UI work. Most issues were solved just by dropping a screenshot into the terminal with a short note. UI polish might not matter to many open source projects, but I still want to do my due diligence and respect each pixel.</p><p>Building software with AI is fast and empowering at first where prototypes appear instantly, and the repetitive work vanishes. But as the system grows, vibe coding gives way to regular engineering, where you catch the gaps AI misses. It’s a partnership of speed plus human judgment.</p><p>For now, I’m happy with the app’s current state as a local LLM character chatbot. In the future, I may add features like <a href="https://en.wikipedia.org/wiki/Retrieval-augmented_generation">RAG</a>, <a href="https://modelcontextprotocol.io/docs/getting-started/intro">MCP</a>, history compaction, and tool integrations; or work on something else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Twl_BNImElI7u3zhGqeGLw.png" /></figure><p>If you’ve made it all the way here, thank you for sticking with me and for your interest in this little project.</p><h3><em>Reference</em></h3><p><a href="https://github.com/hackjutsu/mini-chatbot">GitHub project: mini-chatbot</a></p><p>If you enjoy this blog, check out <a href="https://medium.com/@cosmo.lepton">my other articles</a> and follow my <a href="https://github.com/hackjutsu">GitHub</a>, or <a href="https://www.linkedin.com/in/cosmo-qiu">LinkedIn️</a> ❤️</p><p><em>Disclaimer: The opinions and works presented in this blog are solely my own and do not reflect my current or previous employer or affiliates unless explicitly stated.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ec4cd57406" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/from-vibing-to-engineering-a-case-study-of-building-a-character-chatbot-80ec4cd57406">From Vibing to Engineering: A Case Study of Building a Character Chatbot</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stay safe, healthy and strong]]></title>
            <link>https://medium.com/@cosmo.lepton/stay-safe-healthy-and-strong-210c1b594fbc?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/210c1b594fbc</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[pandemic]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[covid19]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Thu, 23 Apr 2020 05:02:48 GMT</pubDate>
            <atom:updated>2020-04-23T05:02:48.438Z</atom:updated>
            <content:encoded><![CDATA[<p>To Lepton users around the world in more than 130 countries:</p><p>We hope you all stay safe, healthy, and strong as we get through the COVID-19 pandemic. Lepton will continue to be free, as always. But we have a small ask today: if you find this app helpful, we strongly encourage you to make a donation to a local or global charity of your choice to help fight against the pandemic.</p><p>We might be small as individual open source contributors, but together we can make the world a better place. ❤️</p><p><a href="https://github.com/hackjutsu/Lepton">https://github.com/hackjutsu/Lepton</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=210c1b594fbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facade Pattern]]></title>
            <link>https://medium.com/@cosmo.lepton/facade-pattern-7b01b22213af?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b01b22213af</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Mon, 20 May 2019 05:42:26 GMT</pubDate>
            <atom:updated>2019-05-20T06:36:02.974Z</atom:updated>
            <content:encoded><![CDATA[<p>Facade pattern is used when a system is difficult to understand because of the large number of interdependent classes or the unavailability of the source code. It hides the complexities of the larger system and provides a more straightforward interface to clients.</p><h4>Intent</h4><ul><li>Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.</li><li>Wrap a complicated subsystem with a simpler interface.</li></ul><h4>Implementation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*pIuW9HMSHnAlnnFC30CI_Q.png" /><figcaption>Class Diagram of Facade Pattern</figcaption></figure><p>This is an example of how a client interacts with a facade (the “computer”) to a complex system (internal computer parts, like CPU and hard drives).</p><p>Here is our CPU class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/203c47ed3cc614c9ef7ce6c13dd313ea/href">https://medium.com/media/203c47ed3cc614c9ef7ce6c13dd313ea/href</a></iframe><p>And our hard drive class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de09972ee044ef89d94382057328e3b6/href">https://medium.com/media/de09972ee044ef89d94382057328e3b6/href</a></iframe><p>Like a typically computer, we have a class for memory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18dc78b5abfe1f481c145791749f1953/href">https://medium.com/media/18dc78b5abfe1f481c145791749f1953/href</a></iframe><p>This is the facade class for our mini computer system.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98500233883c02aa7b527456ddac60d1/href">https://medium.com/media/98500233883c02aa7b527456ddac60d1/href</a></iframe><p>From a client’s perspective, instead of digging into the bootstrap arrangement among CPU, hard disks and memory, the computer can be started by merely calling ComputerFacade::start.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74d1771b87ad9bc893463a7c761541bc/href">https://medium.com/media/74d1771b87ad9bc893463a7c761541bc/href</a></iframe><p><strong>Output</strong>:</p><pre>CPU: freezing…<br>HardDrive: reading…<br>Memory: loading…<br>CPU: jumping…<br>CPU: executing…</pre><h4>Reference</h4><p><a href="https://en.wikipedia.org/wiki/Facade_pattern">Wikipedia</a></p><p><em>This series was ported from my study notes of design patterns back in 2015. It was summarized from extensive sources like books, online tutorials, videos, and offline discussion. I tried my best to recall and list all references, and please let me know if I miss something. Happy coding!</em></p><p><em>— Cosmo</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b01b22213af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Command Pattern]]></title>
            <link>https://medium.com/@cosmo.lepton/command-pattern-2b9bffc68793?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9bffc68793</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Mon, 20 May 2019 05:21:29 GMT</pubDate>
            <atom:updated>2019-05-20T06:33:23.474Z</atom:updated>
            <content:encoded><![CDATA[<p>Command Pattern issues requests to objects without knowing about the operation being requested or the receiver of the request. It wraps a request under an object as command and passes it to the invoker object. This sounds like a callback in Javascript, as the Gang of Four later says:</p><blockquote>Commands are an object-oriented replacement for callbacks.</blockquote><h4>Intent</h4><ul><li>Encapsulate a request in an object.</li><li>Allows the parameterization of clients with different requests.</li><li>Allows saving the requests in a queue.</li></ul><h4>Implementation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*knTpLz8j89hOT6_3XMf-FQ.png" /><figcaption>Class Diagram of Command Pattern</figcaption></figure><p>The Receiver knows how to perform the actions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f35434f6241ec840f1cb42e7f5a4e5e6/href">https://medium.com/media/f35434f6241ec840f1cb42e7f5a4e5e6/href</a></iframe><p>Let’s make anotherReciever implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e10ffe996a2db2c703ccaee1ec97b54/href">https://medium.com/media/3e10ffe996a2db2c703ccaee1ec97b54/href</a></iframe><p>The Command interface defines methods for operations. Some applications require us to log all the actions and be able to recover after a crash by re-invoking the recorded actions. The Command Pattern can support this with the addition of two methods: store() and load().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a56ed47e6bcf64ae8fff2af05dbc9534/href">https://medium.com/media/a56ed47e6bcf64ae8fff2af05dbc9534/href</a></iframe><p>The concrete command extends the Command interface, implementing the execute() method by invoking the corresponding operations on Receiver. It defines a link between the Receiver and the command action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f392e77fb2ec86b7277c3add5bb8649c/href">https://medium.com/media/f392e77fb2ec86b7277c3add5bb8649c/href</a></iframe><p>Here is another implementation of the Command interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df0ae04f9684c5ed31b920a7f137056f/href">https://medium.com/media/df0ae04f9684c5ed31b920a7f137056f/href</a></iframe><p>NoCommand is an example of <a href="http://www.tutorialspoint.com/design_pattern/null_object_pattern.htm">Null Object Pattern</a>. A null object is useful when we don’t have a meaningful object to return, and yet we want to remove the responsibility of handling <strong>null</strong> from the client.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62a619bbddebed82a60ca0c462c994c6/href">https://medium.com/media/62a619bbddebed82a60ca0c462c994c6/href</a></iframe><p>Invoker asks the command objects to carry out the requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36111138d9902c7d8da0eec4d5a21ec2/href">https://medium.com/media/36111138d9902c7d8da0eec4d5a21ec2/href</a></iframe><p>Finally, let’s implement our Client class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/488a23a1bba59cd226caa4d3a0e8e6f7/href">https://medium.com/media/488a23a1bba59cd226caa4d3a0e8e6f7/href</a></iframe><p>Output:</p><pre>ReceiverA do action!!<br>ReceiverB do action!!<br>ReceiverB undo action!!<br>ReceiverB do action!!</pre><h4>Java 8</h4><p>Since Java 8, we can implement Command Pattern by using the lambda expression ()-&gt;{} and method references.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b566c0bb70f2f36cc250f33b1722be5/href">https://medium.com/media/3b566c0bb70f2f36cc250f33b1722be5/href</a></iframe><p>However, we cannot define two methods with the same types when using a lambda expression. Check out this post for more information about <a href="http://tutorials.jenkov.com/java/lambda-expressions.html">lambda expression</a> and <a href="https://blog.idrsolutions.com/2015/02/java-8-method-references-explained-5-minutes/">method reference</a>.</p><h4>Reference</h4><p><a href="http://www.oodesign.com/command-pattern.html">OO Design</a><br><a href="http://gameprogrammingpatterns.com/command.html">Game Programming Patterns</a></p><p><em>This series was ported from my </em><a href="http://hackjutsu.com/categories/Design-Pattern/"><em>study notes of design patterns back in 2015</em></a><em>. It was summarized from extensive sources like books, online tutorials, videos, and offline discussion. I tried my best to recall and list all references, and please let me know if I miss something. Happy coding!</em></p><p><em>— Cosmo</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9bffc68793" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Composite Pattern]]></title>
            <link>https://medium.com/@cosmo.lepton/composite-pattern-a525ff545920?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/a525ff545920</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Mon, 20 May 2019 01:28:24 GMT</pubDate>
            <atom:updated>2019-05-20T06:33:38.286Z</atom:updated>
            <content:encoded><![CDATA[<p>Composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object. Having to query the type of each object before attempting to process it is not desirable.</p><h4>Intent</h4><ul><li>Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.</li><li>Recursive composition.</li><li>One-to-many <strong>“HAS A”</strong> up the <strong>“IS A”</strong> hierarchy.</li></ul><h4>Implementation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*tuuEXNFZKXOMmldMi97m-A.png" /><figcaption>Class Diagram of Composite Pattern</figcaption></figure><p>In a small organization, there are five employees. At the top position, there is one general manager. Under general manager, there are two employees, one is a manager, and the other is a developer. The further manager has two developers working under him. We want to print the name and salary of all employees from top to bottom.</p><p>First, we create a component interface. It has all common operations that apply to both managers and developers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d1cde7bc0a063e592877fb55772e520/href">https://medium.com/media/7d1cde7bc0a063e592877fb55772e520/href</a></iframe><p>Now we create manager(Composite class).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e701af539cc9965d02248d11450cac33/href">https://medium.com/media/e701af539cc9965d02248d11450cac33/href</a></iframe><p>We create a Developer class. This class is Leaf node, so all operations related to accessing children are empty as it has no children.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a45204b9594b429ca8c8ee31568136e/href">https://medium.com/media/9a45204b9594b429ca8c8ee31568136e/href</a></iframe><p>Let’s test the above classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b821efb6afa2b708c710825e052aaab/href">https://medium.com/media/5b821efb6afa2b708c710825e052aaab/href</a></iframe><p><strong>Output:</strong></p><pre>Name =Mark<br>Salary =50000.0</pre><pre>Name =Michael<br>Salary =20000.0</pre><pre>Name =Daniel<br>Salary =25000.0</pre><pre>Name =John<br>Salary =10000.0</pre><pre>Name =David<br>Salary =15000.0</pre><h4>More</h4><p>Here is a good discussion about whether the Composite class and the Leaf class should implement the same Component interface from <a href="https://sourcemaking.com/design_patterns/composite">SourceMaking</a>:</p><blockquote>… Being able to treat a heterogeneous collection of objects atomically (or transparently) requires that the “child management” interface be defined at the root of the Composite class hierarchy (the abstract Component class). However, this choice costs you safety, because clients may try to do meaningless things like add and remove objects from leaf objects. On the other hand, if you “design for safety”, the child management interface is declared in the Composite class, and you lose transparency because leaves and Composites now have different interfaces. … Composite doesn’t force you to treat all Components as Composites. It merely tells you to put all operations that you want to treat “uniformly” in the Component class. If add, remove, and similar operations cannot, or must not, be treated uniformly, then do not put them in the Component base class…</blockquote><h4>Reference</h4><p><a href="https://en.wikipedia.org/wiki/Composite_pattern">Wikipedia</a><br><a href="https://sourcemaking.com/design_patterns/composite">SourceMaking</a></p><p><em>This series was ported from my </em><a href="http://hackjutsu.com/categories/Design-Pattern/"><em>study notes of design patterns back in 2015</em></a><em>. It was summarized from extensive sources like books, online tutorials, videos, and offline discussion. I tried my best to recall and list all references, and please let me know if I miss something. Happy coding!</em></p><p><em>— Cosmo</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a525ff545920" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Iterator Pattern]]></title>
            <link>https://medium.com/@cosmo.lepton/iterator-pattern-f44c9839a5ff?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/f44c9839a5ff</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Mon, 20 May 2019 01:02:46 GMT</pubDate>
            <atom:updated>2019-05-20T06:31:58.446Z</atom:updated>
            <content:encoded><![CDATA[<p>Iterator Pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation. The C++ and Java standard library abstraction utilize it to decouple collection classes and algorithms.</p><h4>Intent</h4><ul><li>Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.</li></ul><h4>Implementation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*TVIvxM8WInsdj2F8IPbqvA.png" /><figcaption>Class Diagram of Iterator Pattern</figcaption></figure><p>Here is an example using Iterator Pattern to retrieve the names of all the pets in the pet repository.</p><p>Create interfaces.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b228a7d232a25b5a8eeccf20492eec8/href">https://medium.com/media/9b228a7d232a25b5a8eeccf20492eec8/href</a></iframe><p>Create concrete class implementing the Container interface. This class has inner class NameIterator implementing the Iterator interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0d0907c8a67dd36d348eb84b2930555/href">https://medium.com/media/c0d0907c8a67dd36d348eb84b2930555/href</a></iframe><p>Let’s print out our lovely pets ;)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de081a4019b7c27f0e873cfd9c9bcf86/href">https://medium.com/media/de081a4019b7c27f0e873cfd9c9bcf86/href</a></iframe><p><strong>Output</strong></p><pre>Tyrannosaurus Rex<br>Stegosaurus<br>Velociraptor<br>Triceratops<br>Pterosauria<br>Ichthyosaur<br>Tanystropheus</pre><h4>Reference</h4><ul><li><a href="http://www.tutorialspoint.com/design_pattern/iterator_pattern.htm">TutorialsPoint</a></li><li><a href="http://www.oodesign.com/iterator-pattern.html">OODesign</a></li></ul><p><em>This series was ported from my </em><a href="http://hackjutsu.com/categories/Design-Pattern/"><em>study notes of design patterns back in 2015</em></a><em>. It was summarized from extensive sources like books, online tutorials, videos, and offline discussion. I tried my best to recall and list all references, and please let me know if I miss something. Happy coding!</em></p><p><em>— Cosmo</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f44c9839a5ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strategy Pattern]]></title>
            <link>https://medium.com/@cosmo.lepton/strategy-pattern-50ad847b2c6?source=rss-75ba266df366------2</link>
            <guid isPermaLink="false">https://medium.com/p/50ad847b2c6</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Cosmo W. Q]]></dc:creator>
            <pubDate>Mon, 20 May 2019 00:53:59 GMT</pubDate>
            <atom:updated>2019-05-20T06:32:36.695Z</atom:updated>
            <content:encoded><![CDATA[<p>There are common situations when classes differ only in their behaviors. For these cases, it is a good idea to isolate the algorithms in separate classes in order to select different algorithms at runtime.</p><h4>Intent</h4><ul><li>Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.</li><li>Capture the abstraction in an interface, bury implementation details in derived classes.</li></ul><h4>Implementation</h4><p>We are going to create a Strategy interface defining action and concrete strategy classes implementing the Strategy interface. Context is a class which uses a Strategy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c055967e86843a88b9f1657714af1aa/href">https://medium.com/media/6c055967e86843a88b9f1657714af1aa/href</a></iframe><h4>Reference</h4><p><a href="http://www.tutorialspoint.com/design_pattern/strategy_pattern.htm">Design Patterns Strategy Pattern</a></p><p><em>This series was ported from my </em><a href="http://hackjutsu.com/categories/Design-Pattern/"><em>study notes of design patterns back in 2015</em></a><em>. It was summarized from extensive sources like books, online tutorials, videos, and offline discussion. I tried my best to recall and list all references, and please let me know if I miss something. Happy coding!</em></p><p><em>— Cosmo</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50ad847b2c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>