<?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>DEV Community: Nick Goldstein</title>
    <description>The latest articles on DEV Community by Nick Goldstein (@goldsteinnick).</description>
    <link>https://dev.to/goldsteinnick</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%2F3398637%2Fecf9f406-23b7-47bd-9da7-16fce74e638f.jpg</url>
      <title>DEV Community: Nick Goldstein</title>
      <link>https://dev.to/goldsteinnick</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/goldsteinnick"/>
    <language>en</language>
    <item>
      <title>Building a Wikipedia for Your Fictional World: How Emstrata's Lore Mode Works</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Mon, 30 Mar 2026 15:25:24 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/building-a-wikipedia-for-your-fictional-world-how-emstratas-lore-mode-works-fb4</link>
      <guid>https://dev.to/goldsteinnick/building-a-wikipedia-for-your-fictional-world-how-emstratas-lore-mode-works-fb4</guid>
      <description>&lt;h1&gt;
  
  
  Building a Wikipedia for Your Fictional World: How Emstrata's Lore Mode Works
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Ever tried to keep track of a fictional world you're building? Scattered notes, contradictions, that nagging feeling you messed something up three chapters ago. What if you could build something like Wikipedia, but for your world, with an AI helping you maintain consistency?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That's what &lt;strong&gt;Emstrata's Lore Mode&lt;/strong&gt; does.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Worldbuilding Is Hard
&lt;/h2&gt;

&lt;p&gt;When you're building a fictional world, you're essentially creating an encyclopedia in your head. You need to track:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Figures&lt;/strong&gt;: Who are the important people? When did they live? What did they do?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Places&lt;/strong&gt;: Where do events happen? What are the geographic relationships?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Events&lt;/strong&gt;: What happened, when, and why? How do events connect?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Organizations&lt;/strong&gt;: What groups exist? Who founded them? What's their purpose?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technologies&lt;/strong&gt;: What's possible in this world? When were things invented?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ideas&lt;/strong&gt;: What philosophies drive your world? What belief systems exist?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The challenge? Keeping all of this consistent, interconnected, and accessible.&lt;/p&gt;

&lt;p&gt;Traditional approaches fall short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scattered notes&lt;/strong&gt;: Great for brainstorming, terrible for reference&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linear documents&lt;/strong&gt;: Hard to navigate, harder to maintain&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spreadsheets&lt;/strong&gt;: Structured but soulless, no narrative flow&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mind maps&lt;/strong&gt;: Visual but don't scale well&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What you really need is &lt;strong&gt;Wikipedia, but for your fictional world&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Solution: An Encyclopedia That Writes Itself (With Your Direction)
&lt;/h2&gt;

&lt;p&gt;Emstrata's Lore Mode is a collaborative AI-powered encyclopedia builder. You provide direction, the AI transforms it into structured, encyclopedic documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The core thesis:&lt;/strong&gt; Worldbuilding should feel like having a conversation with a research assistant who never forgets anything and maintains perfect consistency.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Makes It Different
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Wikipedia-Style Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every entry has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;General Overview&lt;/strong&gt;: The essential facts (2-3 statements)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sections&lt;/strong&gt;: Logical groupings of related information&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Statements&lt;/strong&gt;: Individual facts that form cohesive prose&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-references&lt;/strong&gt;: Links to related entries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Opportunity Links (Wiki-Style Discovery)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you mention an entity that doesn't have an entry yet, it becomes a clickable link. Click it, and that entry gets created based on context.&lt;/p&gt;

&lt;p&gt;Three opportunity links appear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Commander Vralic → Click to create Figure entry&lt;/li&gt;
&lt;li&gt;Imperial Guard → Click to create Organization entry
&lt;/li&gt;
&lt;li&gt;Poopok Square → Click to create Place entry&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's Wikipedia's links, but AI-assisted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Encyclopedia Voice (Always)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The AI maintains documentary precision:&lt;/p&gt;

&lt;p&gt;❌ Novelistic: &lt;em&gt;"The empire crumbled like autumn leaves, a once-mighty civilization reduced to whispers"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;✅ Encyclopedic: &lt;em&gt;"The Kalesh Empire collapses in 1247, fragmenting into seven successor states within six months"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Present tense, concrete details, neutral tone. No drama, just documentation.&lt;/p&gt;




&lt;h2&gt;
  
  
  How It Actually Works: The Three-Layer Architecture
&lt;/h2&gt;

&lt;p&gt;Emstrata's Lore Mode uses a three-layer AI architecture working in sequence. Each layer has a specific job:&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 1: Inquirer Layer
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Job:&lt;/strong&gt; Identify what context the Encyclopedian will need&lt;/p&gt;

&lt;p&gt;When you say "Create an entry for Uncle Tim, a martyred figure from shortly after the Betrayal," Inquirer examines your request and generates questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does "The Great Betrayal" exist in the population?&lt;/li&gt;
&lt;li&gt;If yes, what are the key facts about it?&lt;/li&gt;
&lt;li&gt;What year did it occur?&lt;/li&gt;
&lt;li&gt;What were the immediate consequences?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inquirer passes these questions to Archivist.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 2: Archivist (Context Retrieval)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Job:&lt;/strong&gt; Answer Inquirer's questions with established facts&lt;/p&gt;

&lt;p&gt;Archivist receives Inquirer's questions and responds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yes, "The Great Betrayal" exists&lt;/li&gt;
&lt;li&gt;It occurred in 848 AC&lt;/li&gt;
&lt;li&gt;Celestial dragons severed their bond with human civilization&lt;/li&gt;
&lt;li&gt;All dragons vanished simultaneously on winter solstice&lt;/li&gt;
&lt;li&gt;Celestial energy networks were disrupted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Critical principle:&lt;/strong&gt; No hallucination. Archivist only returns documented facts or explicitly states when information doesn't exist.&lt;/p&gt;

&lt;p&gt;Archivist passes these answers to Encyclopedian.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 3: Encyclopedian (Content Generation)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Job:&lt;/strong&gt; Use Archivist's context to generate consistent encyclopedia content&lt;/p&gt;

&lt;p&gt;Encyclopedian receives Archivist's answers and your original request, then:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Structures information into sections and statements&lt;/li&gt;
&lt;li&gt;Generates encyclopedic prose grounded in established facts&lt;/li&gt;
&lt;li&gt;Cross-references related entries (The Great Betrayal)&lt;/li&gt;
&lt;li&gt;Creates opportunity links for new entities mentioned&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The AI isn't just writing text—it's building structured data.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every section gets an ID. Every statement gets an index. This enables surgical editing later—change one sentence without touching anything else.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Flow in Action
&lt;/h2&gt;

&lt;p&gt;Let's see the three layers work together:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your request:&lt;/strong&gt; "Create an entry for Uncle Tim, a martyred figure from shortly after the Betrayal"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inquirer generates questions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does "The Great Betrayal" entity exist?&lt;/li&gt;
&lt;li&gt;What year did The Great Betrayal occur?&lt;/li&gt;
&lt;li&gt;What were the political consequences?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Archivist answers:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yes, entity exists&lt;/li&gt;
&lt;li&gt;Occurred 848 AC&lt;/li&gt;
&lt;li&gt;Emergency martial laws established, dragon-sympathizers persecuted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Encyclopedian generates:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncle Tim (Figure)
├─ General Overview
│   "Uncle Tim dies in 851 AC, three years after the Great Betrayal,
│   becoming a rallying symbol for justice reform movements."
├─ Background
│   "Tim operates a small trading post in the border settlements..."
└─ The Accusation
    "Local authorities arrest Tim in 851 AC on charges of harboring
    dragon-sympathizers in violation of post-Betrayal emergency laws..."

Opportunity links: "Emergency Martial Laws", "Dragon-Bonded Mages"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All dates align with The Great Betrayal (848 AC). All references are consistent. Uncle Tim's execution in 851 AC is exactly "three years after" because Archivist provided that context.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Editing System: Surgical Precision
&lt;/h2&gt;

&lt;p&gt;Emstrata's Lore Mode doesn't treat entries as monolithic blobs. Everything is addressable:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entry&lt;/strong&gt; → Contains multiple &lt;strong&gt;Sections&lt;/strong&gt; → Each contains multiple &lt;strong&gt;Statements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Want to change the second sentence in the "Military Career" section? You can target that exact statement. No regenerating entire sections. No losing other content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Entry Types: The Building Blocks
&lt;/h2&gt;

&lt;p&gt;Emstrata's Lore Mode supports nine entry types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Figure&lt;/strong&gt; (People)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event&lt;/strong&gt; (Historical Occurrences)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Place&lt;/strong&gt; (Locations)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Organization&lt;/strong&gt; (Groups)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technology&lt;/strong&gt; (Inventions)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idea&lt;/strong&gt; (Philosophies)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Artifact&lt;/strong&gt; (Significant Objects)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flora-Fauna&lt;/strong&gt; (Living Organisms)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Natural-Law&lt;/strong&gt; (Physical Phenomena)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real-World Example: Building The Sundered Compact
&lt;/h2&gt;

&lt;p&gt;Request: "A world where dragons and magic once existed but mysteriously vanished"&lt;/p&gt;

&lt;p&gt;The system generates three foundational entries:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Posuukane (Figure):&lt;/strong&gt; A hermit mage of unprecedented power, born 500 AC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Great Betrayal (Event):&lt;/strong&gt; Occurs in 848 AC when celestial dragons collectively sever their bond with human civilization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vael Drake (Flora-Fauna):&lt;/strong&gt; Largest known dragon species, 45-60 feet in length.&lt;/p&gt;

&lt;p&gt;Three interconnected entries. The foundation is set. Now every subsequent entry can reference these through the Inquirer → Archivist → Encyclopedian flow.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Makes This Different
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Notion/Obsidian:&lt;/strong&gt; You're doing all the work. No AI assistance, no consistency checking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;World Anvil:&lt;/strong&gt; Templates are rigid. Structure is predefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ChatGPT/Claude conversations:&lt;/strong&gt; No structure, no persistence, no precision editing. No consistency layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Emstrata's Lore Mode:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Wikipedia-style structure with full customization&lt;/li&gt;
&lt;li&gt;✅ Three-layer consistency: Inquirer asks, Archivist answers, Encyclopedian writes&lt;/li&gt;
&lt;li&gt;✅ Surgical editing (change one statement or whole sections)&lt;/li&gt;
&lt;li&gt;✅ Opportunity links for wiki-style discovery&lt;/li&gt;
&lt;li&gt;✅ Multi-step workflows via chain interactions&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;p&gt;Emstrata's Lore Mode is live at &lt;a href="https://emstrata.com" rel="noopener noreferrer"&gt;emstrata.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start with a simple premise. Let the system generate foundational entries. Click opportunity links to expand. Watch your world emerge.&lt;/p&gt;

&lt;p&gt;The AI handles structure and consistency. You provide direction. Together, you build something coherent and very useful.&lt;/p&gt;




&lt;p&gt;*Nick Goldstein is building Emstrata, an AI-powered storytelling and worldbuilding platform. &lt;/p&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Logistician System - A new series of fixes launching soon for Emstrata</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Sat, 28 Feb 2026 03:15:10 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/the-logistician-system-a-new-series-of-fixes-launching-soon-for-emstrata-b6m</link>
      <guid>https://dev.to/goldsteinnick/the-logistician-system-a-new-series-of-fixes-launching-soon-for-emstrata-b6m</guid>
      <description>&lt;p&gt;Most of the time on Emstrata, continuity is solved. There's still a couple hiccups and types of stories that it seems to struggle with (and I'm working on ironing those out too). A couple patterns keep popping up, from my experience:&lt;/p&gt;

&lt;p&gt;The map doesn't keep up to the reality of the simulation if you move around a lot or go far distances within a turn. Overall, the map tends to lag and this can cause location-based issues in later turns.&lt;/p&gt;

&lt;p&gt;Sometimes the simulation takes a left turn and there's not an obvious mechanism to unravel the correct, but directionally wrong storyline (you can technically protest it, but that's not obvious and doesn't give you any interesting ideas to play with).&lt;/p&gt;

&lt;p&gt;Sometimes you may forget what has happened in a sim that you're revisiting after a long period of time or you're just interested and tracking the old lore of your sim and there's no current method to do that.&lt;/p&gt;

&lt;p&gt;You want to interact with an artifact but don't want to spend a turn doing something so minor.&lt;/p&gt;

&lt;p&gt;Anyway, I laid out these pain-points to get to the crux of what the Logistician is built to fix. Essentially, the Logistician is an AI scanner that looks at the last few turns and sees if it needs any fixes (mostly along the lines of the pain-points that I just laid out). Maybe the narrative is deteriorating into insanity before your eyes and you're worried it's unrecoverable because how much random shit is being tossed in there all at once, or maybe you're still at the starting coordinate on the map, when you should be halfway across the world and you keep having to protest sentences that mention your current location incorrectly. For the first issue, the Logistician would kick the request to our new Director system which will generate three fundamentally different directions to take this turn in, if selected, the turn will rewrite with the new developments. For the latter issue, the Logistician kicks to the new Cartographer system and that would move you and any other poorly positioned entities to their appropriate spots on the map when the other systems fall short.&lt;/p&gt;

&lt;p&gt;The new Ghost Writer system will pick up any manuscripts, conversations, letters, voicemails, etc. that should be readable or listenable from within the simulation, but were only summarized or represented by a short excerpt in the actual writing. Like someone mentions a letter that mentions that "David is the killer." Well, in theory, that letter is readable. It should exist, why can't I just click into it and read it? This is ultimately what the Ghost Writer system does when the Logistician contacts it.&lt;/p&gt;

&lt;p&gt;All the while, the Logistician is itself compiling a log of 'deep memories'. These are event logs of the system that are not actively tracked or factored into turn-by-turn participation. You'll be able to manually remind the Emstrata of something from the past with these if the system is being daft or just pull it up and check it out, or remind yourself what has happened. It's also great to just take a glance over there to see all the progress you've made.&lt;/p&gt;

&lt;p&gt;Now, I do want to stress that this is in progress, but I wanted to let the community know what's being built out right now.&lt;/p&gt;

&lt;p&gt;Thoughts?&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>webdev</category>
      <category>discuss</category>
      <category>ai</category>
    </item>
    <item>
      <title>All the Different Types of AI Layers</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Thu, 15 Jan 2026 01:29:33 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/all-the-different-types-of-ai-layers-m39</link>
      <guid>https://dev.to/goldsteinnick/all-the-different-types-of-ai-layers-m39</guid>
      <description>&lt;h1&gt;
  
  
  AI Layer Types: A Framework for Building Custom AI Architectures
&lt;/h1&gt;

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

&lt;ul&gt;
&lt;li&gt;This document presents a conceptual framework for thinking about different types of AI layers when building custom AI architectures&lt;/li&gt;
&lt;li&gt;These are not strict technical definitions, but rather a practical taxonomy from building multi-layered AI systems&lt;/li&gt;
&lt;li&gt;This framework helps you design systems where the AI handles specific functions autonomously while maintaining coherence&lt;/li&gt;
&lt;li&gt;For deeper understanding, revisit Lesson 4 on Multilayered AI Architectures&lt;/li&gt;
&lt;li&gt;That lesson explores how to orchestrate these layer types into cohesive systems that put the AI in control of key functions&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Think Architecturally
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Strategize on the best ways to achieve great results for your platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consider your actual goal and break it down into steps&lt;/li&gt;
&lt;li&gt;If you were to perform this action yourself, what steps would you need to follow? Write that down. That's your workflow&lt;/li&gt;
&lt;li&gt;After formalizing your workflow, think of the data transformations you'd need throughout that process&lt;/li&gt;
&lt;li&gt;Build the prompts to automate those transformations, then chain them together&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance consideration:&lt;/strong&gt; Platforms depending on conversation history for context can cause token count and performance issues&lt;/li&gt;
&lt;li&gt;Consider whether a conversation consolidator prompt would benefit you&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Randomness consideration:&lt;/strong&gt; If you want a truly random number used in determining something in your system, have the backend serve that up to your AI&lt;/li&gt;
&lt;li&gt;Don't assume LLM training data can produce anything close to pure randomness&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Core Layer Types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Reasoning/Strategy Layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The decision-maker of your platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reasoning layers make decisions before content gets generated&lt;/li&gt;
&lt;li&gt;They evaluate the current state, consider available options, assess consequences, and choose a direction&lt;/li&gt;
&lt;li&gt;Think of them as the "planning brain" of your system&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In Emstrata:&lt;/strong&gt; Discovery layer looks at what participant wants to do, considers simulation state, evaluates what outcomes make narrative sense, determines how action should resolve&lt;/li&gt;
&lt;li&gt;It's not writing the story yet; it's deciding what should happen&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you need one:&lt;/strong&gt; If you find yourself asking an LLM to both "figure out what should happen AND write it beautifully," you're overloading a single prompt&lt;/li&gt;
&lt;li&gt;Split it. Reason first, write second&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Navigator Layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The pathfinder of circumstantial systems&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Closely related to reasoning layers but serve a distinct function&lt;/li&gt;
&lt;li&gt;Determine what the next step should be in systems where execution flow changes based on conditions&lt;/li&gt;
&lt;li&gt;Reasoning layers make decisions about content or outcomes&lt;/li&gt;
&lt;li&gt;Navigator layers make decisions about process flow&lt;/li&gt;
&lt;li&gt;In circumstantial systems, the route through your architecture changes depending on outcomes or AI direction&lt;/li&gt;
&lt;li&gt;Navigator examines current state and decides which processing path to take next&lt;/li&gt;
&lt;li&gt;Maybe an error detection layer decides whether correction is needed&lt;/li&gt;
&lt;li&gt;Maybe a routing layer examines user intent and sends request down completely different processing paths&lt;/li&gt;
&lt;li&gt;System adapts its own execution flow based on runtime conditions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you need one:&lt;/strong&gt; When your architecture needs to branch dynamically based on what happened in previous steps&lt;/li&gt;
&lt;li&gt;Navigator layers give your system the ability to choose its own path through your architecture&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Content Layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The performer of your platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Content layers generate the actual output users experience&lt;/li&gt;
&lt;li&gt;The prose, dialogue, descriptions, or interface text&lt;/li&gt;
&lt;li&gt;These layers take decisions from reasoning layers and context from memory layers, then craft the experience&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In Emstrata:&lt;/strong&gt; Narration layer receives Discovery's decisions about what happened, checks Groundskeeper's simulation state, writes the actual narrative text that players read&lt;/li&gt;
&lt;li&gt;It's optimizing for atmosphere, pacing, and emotional resonance&lt;/li&gt;
&lt;li&gt;Not logic or consistency (that's handled elsewhere)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you need one:&lt;/strong&gt; Always, unless your platform doesn't generate human-readable output&lt;/li&gt;
&lt;li&gt;This is where your system's "voice" lives&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Correction Layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The referee of your platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Correction layers catch errors after other layers have done their work&lt;/li&gt;
&lt;li&gt;They're your quality control layers&lt;/li&gt;
&lt;li&gt;They spot continuity breaks, logical inconsistencies, or constraint violations that slipped through&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In Emstrata:&lt;/strong&gt; Chron-Con layer runs after narrative is written&lt;/li&gt;
&lt;li&gt;It checks for things like: Did a character who was in the tavern suddenly appear in the forest without traveling? Did someone use an item they don't have? Are spatial coordinates consistent with the described action?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you need one:&lt;/strong&gt; If there are complex requirements and expectations that your platform needs to meet&lt;/li&gt;
&lt;li&gt;Correcting before revealing the final answer can lower the chance of bad responses&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Memory Consolidation Layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The stenographer of your platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory consolidation layers distill what just happened into something retrievable later&lt;/li&gt;
&lt;li&gt;They extract important details from verbose content and store them in a format your system can efficiently query or format into future inputs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In Emstrata:&lt;/strong&gt; Groundskeeper serves this function&lt;/li&gt;
&lt;li&gt;After Discovery determines what happens and Narration writes it, Groundskeeper updates the comprehensive memory of all entities and the emergent narrative&lt;/li&gt;
&lt;li&gt;It's maintaining the source of truth about the simulation state&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you need one:&lt;/strong&gt; In most multi-turn systems&lt;/li&gt;
&lt;li&gt;Without this, your system either forgets things or becomes bloated with unprocessed history&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Catch-All/Connector Layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The clean-up crew of your platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not every layer fits a clean category&lt;/li&gt;
&lt;li&gt;Catch-all layers are hybrids that do complementary work for multiple other layers&lt;/li&gt;
&lt;li&gt;They handle tasks that don't belong to any single specialized layer but are essential for the system to function cohesively&lt;/li&gt;
&lt;li&gt;These layers often emerge when you discover gaps&lt;/li&gt;
&lt;li&gt;Two layers need to work together but speak different "languages"&lt;/li&gt;
&lt;li&gt;Several layers all need the same preprocessing that none of them should be responsible for individually&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In Emstrata:&lt;/strong&gt; Chron-Con does more than just error correction&lt;/li&gt;
&lt;li&gt;It also tracks secrets and memories from the narrative, explicitly tagging them for Groundskeeper to integrate into system memory&lt;/li&gt;
&lt;li&gt;You don't want Narration burdened with the unrelated task of extracting and categorizing secrets while trying to write high-quality prose&lt;/li&gt;
&lt;li&gt;Groundskeeper needs these pieces explicitly labeled as "secrets" or "memories" to properly integrate them into simulation history&lt;/li&gt;
&lt;li&gt;Chron-Con bridges this gap&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you need one:&lt;/strong&gt; When you notice coordination problems between layers&lt;/li&gt;
&lt;li&gt;When there's important work that doesn't naturally belong to any existing layer&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Cyclical vs Circumstantial Systems
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;And everything in-between&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cyclical Systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run the same prompts every time&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Emstrata follows this pattern:&lt;/strong&gt; Every turn runs Discovery, then Narration, then Chron-Con, then Groundskeeper, in that exact order&lt;/li&gt;
&lt;li&gt;The flow is predictable and consistent regardless of what happens in the simulation&lt;/li&gt;
&lt;li&gt;You always know what's executing next&lt;/li&gt;
&lt;li&gt;Makes debugging straightforward and cost estimation more reliable&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Circumstantial Systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Determine the pathway based on outcomes or AI direction&lt;/li&gt;
&lt;li&gt;The route through your architecture changes depending on what happened in previous steps&lt;/li&gt;
&lt;li&gt;Maybe an error detection layer decides whether correction is needed&lt;/li&gt;
&lt;li&gt;Maybe a routing layer examines user intent and sends the request down completely different processing paths&lt;/li&gt;
&lt;li&gt;The system adapts its own execution flow based on runtime conditions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Hybrid Systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Mostly cyclical at their base, but circumstantial at times when specific conditions warrant different handling&lt;/li&gt;
&lt;li&gt;You might always run your core cycle, but branch to specialized subsystems when certain triggers fire&lt;/li&gt;
&lt;li&gt;Many real-world systems end up here&lt;/li&gt;
&lt;li&gt;It's a reliable backbone with conditional branches for edge cases&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Emstrata has circumstantial offshoots as well&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Agnostic Backend Interaction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What happens between AI layers&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Save Data Between Layers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Between AI layers, save important, transformed data to the backend for future retrieval, debugging, rerunning if there's an error, etc.&lt;/li&gt;
&lt;li&gt;Saving data allows you to present that data in interesting ways later or feed that data into other layers in the future&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Backend as Unbiased Judge
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When you need an unbiased judge, the backend is the place to go&lt;/li&gt;
&lt;li&gt;The backend is 'agnostic' to outcome, whereas the AI may or may not have a strong preference and display it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In Emstrata:&lt;/strong&gt; Consequences are rolled and use weighted randomness&lt;/li&gt;
&lt;li&gt;Discovery layer determines the likelihood something happens&lt;/li&gt;
&lt;li&gt;Then the backend returns a random number out of 1000&lt;/li&gt;
&lt;li&gt;If that number is within the set likelihood range, the backend serves the confirmed consequence to the Narration layer&lt;/li&gt;
&lt;li&gt;If it's outside of the range, it sends the failure outcome&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Data Persistence Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Store transformed outputs from each layer, not just raw AI responses&lt;/li&gt;
&lt;li&gt;Tag data with layer origin, timestamp, and any relevant metadata&lt;/li&gt;
&lt;li&gt;Consider what you'll need for debugging, analytics, or reprocessing later&lt;/li&gt;
&lt;li&gt;Backend should handle all state management - don't rely on AI to track its own history across layers&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Your Guide to Letting AI Run Your App (For Beginners)</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Thu, 15 Jan 2026 01:26:24 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/your-guide-to-letting-ai-run-your-app-for-beginners-16gp</link>
      <guid>https://dev.to/goldsteinnick/your-guide-to-letting-ai-run-your-app-for-beginners-16gp</guid>
      <description>&lt;h1&gt;
  
  
  CRUD Operations: Architecture and Implementation Guide
&lt;/h1&gt;

&lt;p&gt;This document explains how to build CRUD (Create, Read, Update, Delete) operations in an AI-powered web application backend. Essentially giving the reigns to an AI agent. We'll use a fun example to make these concepts clear.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Example Scenario: SweetBot AI
&lt;/h2&gt;

&lt;p&gt;Imagine you're building &lt;strong&gt;SweetBot AI&lt;/strong&gt;, a tech support chatbot for &lt;strong&gt;LolliPop Dreams&lt;/strong&gt;, a company that sells custom-made lollipops in hundreds of flavors. The AI chatbot helps customers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create custom lollipop orders based on flavor preferences&lt;/li&gt;
&lt;li&gt;Track order status&lt;/li&gt;
&lt;li&gt;Update flavor combinations&lt;/li&gt;
&lt;li&gt;View their order history&lt;/li&gt;
&lt;li&gt;Cancel orders&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This scenario has unique requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers can combine multiple flavors (strawberry + vanilla swirl)&lt;/li&gt;
&lt;li&gt;Orders have statuses (pending, mixing, cooling, packaging, shipped)&lt;/li&gt;
&lt;li&gt;The AI needs to learn from customer preferences&lt;/li&gt;
&lt;li&gt;Flavor combinations must be validated (some flavors don't mix well!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is CRUD?&lt;/li&gt;
&lt;li&gt;Understanding the Example Format&lt;/li&gt;
&lt;li&gt;Understanding the Basics&lt;/li&gt;
&lt;li&gt;The Request-Response Cycle&lt;/li&gt;
&lt;li&gt;Input Parsing: How Data Comes In&lt;/li&gt;
&lt;li&gt;CRUD Operations in Detail&lt;/li&gt;
&lt;li&gt;Output Formatting: How Data Goes Out&lt;/li&gt;
&lt;li&gt;Complete Example: Creating and Managing Orders&lt;/li&gt;
&lt;li&gt;Using AI to Build Endpoints&lt;/li&gt;
&lt;li&gt;Security Basics&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  What is CRUD?
&lt;/h2&gt;

&lt;p&gt;CRUD stands for the four basic operations you can perform on data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create&lt;/strong&gt;: Add new records to the database (e.g., create a new lollipop order)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read&lt;/strong&gt;: Retrieve existing records from the database (e.g., get order status)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update&lt;/strong&gt;: Modify existing records in the database (e.g., change flavor combination)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete&lt;/strong&gt;: Remove records from the database (e.g., cancel an order)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Understanding the Example Format
&lt;/h2&gt;

&lt;p&gt;Throughout this document, you'll see examples labeled as &lt;strong&gt;Input Example&lt;/strong&gt; and &lt;strong&gt;Output Example&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do these mean?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Input Example&lt;/strong&gt;: Shows what data the &lt;strong&gt;frontend sends&lt;/strong&gt; to the backend (the request)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output Example&lt;/strong&gt;: Shows what data the &lt;strong&gt;backend sends back&lt;/strong&gt; to the frontend (the response)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why this format?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you're building an endpoint, you need to know:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What format should the input be in? (Look at the Input Example)&lt;/li&gt;
&lt;li&gt;What format should the output be in? (Look at the Output Example)&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Understanding the Basics
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is an Endpoint?
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;endpoint&lt;/strong&gt; is like a specific address or phone number that your application can call to perform an action. Just like you might call a pizza place at a specific number to order pizza, your frontend calls specific endpoints to interact with your backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;https://api.lollipopdreams.com/orders&lt;/code&gt; - This is an endpoint for managing orders&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;https://api.lollipopdreams.com/customers&lt;/code&gt; - This is an endpoint for managing customers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each endpoint does a specific job. The &lt;code&gt;/orders&lt;/code&gt; endpoint handles everything related to orders.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are HTTP Methods? (GET, POST, PUT, DELETE)
&lt;/h3&gt;

&lt;p&gt;HTTP methods are like different types of requests you can make. Think of them as different actions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt;: "Hey, can I see that?" (Reading data)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST&lt;/strong&gt;: "Hey, can you create this for me?" (Creating new data)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT&lt;/strong&gt;: "Hey, can you update this?" (Modifying existing data)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE&lt;/strong&gt;: "Hey, can you remove this?" (Deleting data)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-world analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt; = Looking at a menu (you're just reading, not changing anything)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST&lt;/strong&gt; = Placing an order (you're creating something new)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT&lt;/strong&gt; = Modifying your order (you're changing something that exists)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE&lt;/strong&gt; = Canceling your order (you're removing something)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How Endpoints and Methods Work Together
&lt;/h3&gt;

&lt;p&gt;When you combine an endpoint with a method, you get a specific action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET    /orders     → "Show me all my orders"
GET    /orders/123 → "Show me order number 123"
POST   /orders     → "Create a new order"
PUT    /orders/123 → "Update order number 123"
DELETE /orders/123 → "Cancel order number 123"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The number &lt;code&gt;123&lt;/code&gt; in &lt;code&gt;/orders/123&lt;/code&gt; is called a &lt;strong&gt;parameter&lt;/strong&gt; - it's a way to specify which specific order you're talking about.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Request-Response Cycle
&lt;/h2&gt;

&lt;p&gt;Every time your frontend needs to do something with data, it follows this cycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Frontend sends a request → 2. Backend processes it → 3. Backend sends a response → 4. Frontend receives response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break this down with our lollipop example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Frontend sends a request&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice wants to see her orders&lt;/li&gt;
&lt;li&gt;Frontend sends: "GET /orders" request to the backend&lt;/li&gt;
&lt;li&gt;Includes authentication (proves Alice is who she says she is)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Backend processes it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend receives the request&lt;/li&gt;
&lt;li&gt;Checks: Is Alice authenticated? Yes ✓&lt;/li&gt;
&lt;li&gt;Queries database: "Get all orders for Alice"&lt;/li&gt;
&lt;li&gt;Formats the data nicely&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Backend sends a response&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend sends back Alice's orders in a structured format&lt;/li&gt;
&lt;li&gt;Includes status code (200 = success, 404 = not found, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Frontend receives response&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend gets the data&lt;/li&gt;
&lt;li&gt;Displays Alice's orders on the screen&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Input Parsing: How Data Comes In
&lt;/h2&gt;

&lt;p&gt;When the frontend sends data to your backend, you need to &lt;strong&gt;parse&lt;/strong&gt; it - which means reading it, understanding it, and converting it into a format your code can work with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Request Bodies
&lt;/h3&gt;

&lt;p&gt;When you create or update something, the frontend sends data in the &lt;strong&gt;request body&lt;/strong&gt;. Think of it like filling out a form - you're sending information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Creating a new order&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alice wants to create a custom lollipop order. The frontend sends this data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What the backend needs to do:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Parse&lt;/strong&gt; the JSON (read and understand the structure)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extract&lt;/strong&gt; each field (customer_id, flavor_combination, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate&lt;/strong&gt; that the data is correct:

&lt;ul&gt;
&lt;li&gt;Is customer_id a number? ✓&lt;/li&gt;
&lt;li&gt;Are the flavors valid? ✓&lt;/li&gt;
&lt;li&gt;Is size one of: "small", "medium", "large"? ✓&lt;/li&gt;
&lt;li&gt;Is quantity a positive number? ✓&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sanitize&lt;/strong&gt; special_instructions (remove any dangerous content)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Parsing Query Parameters
&lt;/h3&gt;

&lt;p&gt;For reading data (GET requests), information often comes in the &lt;strong&gt;URL as query parameters&lt;/strong&gt;. These are the parts after the &lt;code&gt;?&lt;/code&gt; in a URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Getting filtered orders&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alice wants to see only her pending orders. The frontend sends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders?customer_id=456&amp;amp;status=pending&amp;amp;page=1&amp;amp;limit=20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Breaking this down:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/orders&lt;/code&gt; = the endpoint&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;?&lt;/code&gt; = starts the query parameters&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;customer_id=456&lt;/code&gt; = filter by customer ID 456&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&lt;/code&gt; = separates parameters&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;status=pending&lt;/code&gt; = only show pending orders&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;page=1&lt;/code&gt; = show page 1&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;limit=20&lt;/code&gt; = show 20 orders per page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What the backend needs to do:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Parse&lt;/strong&gt; the query parameters&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extract&lt;/strong&gt; each parameter value&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use&lt;/strong&gt; these values to filter the database query&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Parsing URL Parameters
&lt;/h3&gt;

&lt;p&gt;Sometimes the ID of what you want is in the URL path itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Getting a specific order&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alice wants to see details of order #789:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders/789
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Breaking this down:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/orders&lt;/code&gt; = the endpoint&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/789&lt;/code&gt; = the order ID (this is a URL parameter)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What the backend needs to do:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Extract&lt;/strong&gt; the number &lt;code&gt;789&lt;/code&gt; from the URL&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use&lt;/strong&gt; it to find that specific order in the database&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Input Validation
&lt;/h3&gt;

&lt;p&gt;Before you save data, you need to &lt;strong&gt;validate&lt;/strong&gt; it - make sure it's correct and safe.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Invalid flavor combination&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Someone tries to create an order with invalid flavors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"chocolate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"mint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"garlic"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Validation checks:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do all flavors exist? "chocolate" ✓, "mint" ✓, "garlic" ✗ (not a valid flavor)&lt;/li&gt;
&lt;li&gt;Can these flavors be combined? Chocolate + mint ✓, but garlic doesn't go with anything!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Validation error response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Invalid flavor combination: 'garlic' is not a valid flavor. Please choose from our available flavors."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VALIDATION_ERROR"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Input Sanitization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Sanitization&lt;/strong&gt; means cleaning the data to remove dangerous content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Dangerous input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Someone tries to include malicious code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;script&amp;gt;alert('hack')&amp;lt;/script&amp;gt;Extra sweet, please!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After sanitization:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dangerous script tag is removed, but the legitimate text remains.&lt;/p&gt;




&lt;h2&gt;
  
  
  Input Formatting and Response Parsing
&lt;/h2&gt;

&lt;p&gt;When working with AI services, you need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Format input&lt;/strong&gt; - Convert your data into the format the AI expects&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send to AI&lt;/strong&gt; - Make the API call&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parse response&lt;/strong&gt; - Extract and structure the data from the AI's response (which comes as function calls)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save to database&lt;/strong&gt; - Store the parsed data&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Formatting Input for AI
&lt;/h3&gt;

&lt;p&gt;Before sending data to an AI service, you need to format it in a specific way. Here's how:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Formatting Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have this data from the frontend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Format it for the AI service like this:&lt;/strong&gt;&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="c1"&gt;// Define a function to format order data for the AI service&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;formatOrderForAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;customerInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create an empty string to build the formatted prompt&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Add the customer ID to the prompt with a label&lt;/span&gt;
    &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`customer-id: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Add the customer name to the prompt with a label&lt;/span&gt;
    &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`customer-name: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;customerInfo&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="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Join the flavor array into a comma-separated string and add to prompt&lt;/span&gt;
    &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`flavor-combination: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavor_combination&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Add the size to the prompt with a label&lt;/span&gt;
    &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`size: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Add the quantity to the prompt with a label&lt;/span&gt;
    &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`quantity: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if special instructions were provided&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;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;special_instructions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Add the special instructions to the prompt with quotes around the text&lt;/span&gt;
        &lt;span class="nx"&gt;formattedPrompt&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`special-instructions: "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;special_instructions&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"\n`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Return the complete formatted prompt string&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;formattedPrompt&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;&lt;strong&gt;The formatted input would be:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;customer-id: 456
customer-name: Alice Sweettooth
flavor-combination: strawberry, vanilla_swirl
size: large
quantity: 12
special-instructions: "Extra sweet, please!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Parsing AI Responses (Function Call Format)
&lt;/h3&gt;

&lt;p&gt;The AI responds with &lt;strong&gt;function calls&lt;/strong&gt;, not JSON. You need to parse these function calls to extract the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: AI Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The AI service returns this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flavors("strawberry", "vanilla_swirl", "caramel")
price(24.99)
status("pending")
production-time("2 days")
special-notes("Customer requested extra sweet - will add extra sugar")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example: Parsing the Response&lt;/strong&gt;&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="c1"&gt;// Define a function to parse the AI response that contains function calls&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseAIResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aiResponse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Split the response text into an array of lines using newline character&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aiResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Create an object to store the parsed data with default values&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;flavors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;        &lt;span class="c1"&gt;// Array to hold flavor names&lt;/span&gt;
        &lt;span class="na"&gt;price&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="c1"&gt;// Number to hold the price&lt;/span&gt;
        &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;         &lt;span class="c1"&gt;// String to hold the status&lt;/span&gt;
        &lt;span class="na"&gt;production_time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// String to hold production time&lt;/span&gt;
        &lt;span class="na"&gt;special_notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;   &lt;span class="c1"&gt;// String to hold special notes&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="c1"&gt;// Loop through each line in the response&lt;/span&gt;
    &lt;span class="k"&gt;for &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;line&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Remove whitespace from the beginning and end of the line&lt;/span&gt;
        &lt;span class="nx"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Skip to the next line if this line is empty&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line starts with the flavors function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flavors(&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="c1"&gt;// Use regex to extract everything between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/flavors&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Get the content inside the parentheses (the arguments)&lt;/span&gt;
                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flavorString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&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="c1"&gt;// Split by comma, trim each item, and remove quotes from each flavor name&lt;/span&gt;
                &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;flavorString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^"|"$/g&lt;/span&gt;&lt;span class="p"&gt;,&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="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line starts with the price function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;price(&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="c1"&gt;// Use regex to extract the number between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/price&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Convert the string number to an actual number and store it&lt;/span&gt;
                &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&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="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line starts with the status function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;status(&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="c1"&gt;// Use regex to extract the status value between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/status&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Remove quotes from the status value and store it&lt;/span&gt;
                &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&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;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^"|"$/g&lt;/span&gt;&lt;span class="p"&gt;,&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="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line starts with the production-time function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&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-time(&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="c1"&gt;// Use regex to extract the time value between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/production-time&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Remove quotes from the time value and store it&lt;/span&gt;
                &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;production_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&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;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^"|"$/g&lt;/span&gt;&lt;span class="p"&gt;,&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="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line starts with the special-notes function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;special-notes(&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="c1"&gt;// Use regex to extract the notes text between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/special-notes&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Remove quotes from the notes text and store it&lt;/span&gt;
                &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;special_notes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&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;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^"|"$/g&lt;/span&gt;&lt;span class="p"&gt;,&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="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Return the parsed object with all extracted data&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;parsed&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;&lt;strong&gt;The parsed output would be:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"caramel"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"production_time"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2 days"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Customer requested extra sweet - will add extra sugar"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example: Multiple Function Calls&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The AI might return multiple function calls on separate lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flavors("strawberry", "vanilla_swirl")
price(24.99)
status("pending")
flavors("chocolate", "mint")
price(19.99)
status("pending")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example: Parsing Multiple Function Calls&lt;/strong&gt;&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="c1"&gt;// Define a function to parse multiple function calls from AI response&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseMultipleFunctionCalls&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aiResponse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create an array to store all parsed results&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="c1"&gt;// Create an object to hold the current result being built&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;currentResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;flavors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;  &lt;span class="c1"&gt;// Array for flavor names&lt;/span&gt;
        &lt;span class="na"&gt;price&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="c1"&gt;// Number for price&lt;/span&gt;
        &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;    &lt;span class="c1"&gt;// String for status&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="c1"&gt;// Split the response into an array of lines&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aiResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Loop through each line in the response&lt;/span&gt;
    &lt;span class="k"&gt;for &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;line&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Remove whitespace from the beginning and end&lt;/span&gt;
        &lt;span class="nx"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// Skip empty lines&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line is a flavors function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;flavors(&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="c1"&gt;// Check if we already have data in currentResult (means we're starting a new item)&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;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavors&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;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Save the previous result to the results array (copy it, don't reference it)&lt;/span&gt;
                &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({...&lt;/span&gt;&lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
                &lt;span class="c1"&gt;// Reset currentResult to empty for the new item&lt;/span&gt;
                &lt;span class="nx"&gt;currentResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;flavors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="na"&gt;price&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="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&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="c1"&gt;// Extract the flavors from between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/flavors&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Get the string of flavors inside the parentheses&lt;/span&gt;
                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flavorString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&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="c1"&gt;// Split by comma, trim each, remove quotes, and store in currentResult&lt;/span&gt;
                &lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;flavorString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^"|"$/g&lt;/span&gt;&lt;span class="p"&gt;,&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="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line is a price function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;price(&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="c1"&gt;// Extract the price number from between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/price&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Convert the string to a number and store in currentResult&lt;/span&gt;
                &lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&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="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Check if this line is a status function call&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;status(&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="c1"&gt;// Extract the status value from between the parentheses&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/status&lt;/span&gt;&lt;span class="se"&gt;\(([^&lt;/span&gt;&lt;span class="sr"&gt;)&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;)\)&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="c1"&gt;// Check if a match was found&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;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Remove quotes and store the status in currentResult&lt;/span&gt;
                &lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&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;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^"|"$/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="c1"&gt;// Status is usually the last field, so we've completed this result&lt;/span&gt;
                &lt;span class="c1"&gt;// Save currentResult to results array (copy it)&lt;/span&gt;
                &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({...&lt;/span&gt;&lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
                &lt;span class="c1"&gt;// Reset currentResult for the next item&lt;/span&gt;
                &lt;span class="nx"&gt;currentResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;flavors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="na"&gt;price&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="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&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="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if there's an incomplete result left (didn't end with status)&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;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavors&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;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Save the incomplete result to the results array&lt;/span&gt;
        &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Return the array of all parsed results&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;results&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;&lt;strong&gt;The parsed output would be:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"chocolate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"mint"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;19.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complete Flow: Format → AI → Parse → Save
&lt;/h3&gt;

&lt;p&gt;Here's how it all works together:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Complete Flow&lt;/strong&gt;&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="c1"&gt;// Define an async function to create an order using AI (async means it can wait for operations)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createOrderWithAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;customerInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Step 1: Call the formatting function to convert JSON data into prompt format&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formattedInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;formatOrderForAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;customerInfo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 2: Send the formatted input to the AI service and wait for response (await pauses until done)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;aiResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendToAIService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;formattedInput&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 3: Parse the AI response to extract structured data from function calls&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsedResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseAIResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aiResponse&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 4: Create an order object using the original data and parsed AI response&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;              &lt;span class="c1"&gt;// Use customer ID from original request&lt;/span&gt;
        &lt;span class="na"&gt;flavor_combination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;parsedResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flavors&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// Use flavors from parsed AI response&lt;/span&gt;
        &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                            &lt;span class="c1"&gt;// Use size from original request&lt;/span&gt;
        &lt;span class="na"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;orderData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                    &lt;span class="c1"&gt;// Use quantity from original request&lt;/span&gt;
        &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;parsedResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                    &lt;span class="c1"&gt;// Use status from parsed AI response&lt;/span&gt;
        &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;parsedResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                     &lt;span class="c1"&gt;// Use price from parsed AI response&lt;/span&gt;
        &lt;span class="na"&gt;special_instructions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;parsedResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;special_notes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Use notes from parsed AI response&lt;/span&gt;
        &lt;span class="na"&gt;created_at&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;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;                           &lt;span class="c1"&gt;// Set current date/time as creation timestamp&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 5: Save the order object to the database and wait for it to complete&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;savedOrder&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;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 6: Return a formatted response object to send back to the frontend&lt;/span&gt;
    &lt;span class="k"&gt;return&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;Order created successfully&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// Success message for the user&lt;/span&gt;
        &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;savedOrder&lt;/span&gt;                       &lt;span class="c1"&gt;// The saved order data with database ID&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;
  
  
  Common Function Call Parsing Patterns
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pattern 1: Single argument function&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flavors("strawberry", "vanilla")
price(24.99)
status("pending")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern 2: Multiple arguments&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flavors("strawberry", "vanilla", "caramel")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern 3: Quoted strings&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;status("pending")
special-notes("Customer requested extra sweet")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern 4: Numbers (no quotes)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;price(24.99)
quantity(12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When parsing function calls, always:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use regex to extract content between parentheses: &lt;code&gt;functionName\(([^)]+)\)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Split multiple arguments by comma&lt;/li&gt;
&lt;li&gt;Remove quotes from string arguments&lt;/li&gt;
&lt;li&gt;Convert number strings to actual numbers&lt;/li&gt;
&lt;li&gt;Handle empty lines&lt;/li&gt;
&lt;li&gt;Trim whitespace&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CRUD Operations in Detail
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CREATE: Adding New Data
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it does:&lt;/strong&gt; Creates a new record in the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Creating a new lollipop order&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Create order request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;POST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/orders&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens on the backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Authenticate&lt;/strong&gt;: Verify the customer is who they say they are&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parse&lt;/strong&gt;: Read the JSON data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Check flavors exist and are compatible&lt;/li&gt;
&lt;li&gt;Check size is valid ("small", "medium", or "large")&lt;/li&gt;
&lt;li&gt;Check quantity is between 1 and 100&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sanitize&lt;/strong&gt;: Clean special_instructions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calculate&lt;/strong&gt;: Determine price based on size and quantity&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create&lt;/strong&gt;: Save the order to database with status "pending"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return&lt;/strong&gt;: Send back the created order&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Create order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order created successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T10:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The backend assigns an ID (789) automatically&lt;/li&gt;
&lt;li&gt;The backend sets default values (status: "pending")&lt;/li&gt;
&lt;li&gt;The backend calculates derived values (price: 24.99)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  READ: Retrieving Data
&lt;/h3&gt;

&lt;p&gt;There are two types of read operations:&lt;/p&gt;

&lt;h4&gt;
  
  
  Reading a Single Item
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;What it does:&lt;/strong&gt; Gets one specific record.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Get single order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders/789
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens on the backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Extract&lt;/strong&gt; order ID: 789&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authenticate&lt;/strong&gt;: Verify the customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorize&lt;/strong&gt;: Check if this order belongs to this customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query&lt;/strong&gt;: Find order #789 in database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return&lt;/strong&gt;: Send back the order details&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Get single order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"mixing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T10:30:00Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"updated_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T11:00:00Z"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Reading Multiple Items (List)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;What it does:&lt;/strong&gt; Gets multiple records, often with filtering and pagination.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Get list of orders&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders?customer_id=456&amp;amp;status=pending&amp;amp;page=1&amp;amp;limit=20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens on the backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Parse&lt;/strong&gt; query parameters:

&lt;ul&gt;
&lt;li&gt;customer_id: 456&lt;/li&gt;
&lt;li&gt;status: "pending"&lt;/li&gt;
&lt;li&gt;page: 1&lt;/li&gt;
&lt;li&gt;limit: 20&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authenticate&lt;/strong&gt;: Verify the customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build query&lt;/strong&gt;: Find orders WHERE customer_id = 456 AND status = "pending"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Count total&lt;/strong&gt;: How many orders match? (e.g., 3 orders)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply pagination&lt;/strong&gt;: Skip 0, take 20 (for page 1)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order&lt;/strong&gt;: Sort by newest first&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return&lt;/strong&gt;: Send back the list with pagination info&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Get list of orders response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T10:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;788&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"chocolate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"mint"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"medium"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;12.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-14T15:20:00Z"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"pagination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"limit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"total_pages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pagination helps when there are many results&lt;/li&gt;
&lt;li&gt;Filters let users see only what they want&lt;/li&gt;
&lt;li&gt;Total count helps the frontend show "Page 1 of 3" etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  UPDATE: Modifying Existing Data
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it does:&lt;/strong&gt; Changes an existing record.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Update order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;PUT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/orders/&lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"caramel"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens on the backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Extract&lt;/strong&gt; order ID: 789&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authenticate&lt;/strong&gt;: Verify the customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorize&lt;/strong&gt;: Check if order #789 belongs to this customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check rules&lt;/strong&gt;: Can this order be updated? (Maybe only "pending" orders can be changed)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parse&lt;/strong&gt; update data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate&lt;/strong&gt;: Check new flavor combination is valid&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update&lt;/strong&gt;: Change only the provided fields&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recalculate&lt;/strong&gt;: Update price based on new quantity&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return&lt;/strong&gt;: Send back the updated order&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Update order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order updated successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"caramel"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;49.98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"updated_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T11:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only the fields provided are updated (partial update)&lt;/li&gt;
&lt;li&gt;Other fields stay the same&lt;/li&gt;
&lt;li&gt;Derived values (like price) are recalculated&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  DELETE: Removing Data
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What it does:&lt;/strong&gt; Removes a record (or marks it as deleted).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Cancel order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE /orders/789
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens on the backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Extract&lt;/strong&gt; order ID: 789&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authenticate&lt;/strong&gt;: Verify the customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorize&lt;/strong&gt;: Check if order #789 belongs to this customer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check rules&lt;/strong&gt;: Can this order be canceled? (Maybe "shipped" orders can't be canceled)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete&lt;/strong&gt;: Remove from database OR mark as "canceled" (soft delete)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handle side effects&lt;/strong&gt;: Process refund if needed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return&lt;/strong&gt;: Send confirmation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Delete order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order canceled successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"refund_amount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"refund_processed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always verify ownership before deleting&lt;/li&gt;
&lt;li&gt;Check business rules (when can things be deleted?)&lt;/li&gt;
&lt;li&gt;Handle related actions (refunds, notifications, etc.)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Output Formatting: How Data Goes Out
&lt;/h2&gt;

&lt;p&gt;After processing a request, the backend needs to send a &lt;strong&gt;response&lt;/strong&gt; back to the frontend. This response should be consistent and well-structured.&lt;/p&gt;

&lt;h3&gt;
  
  
  Consistent Response Structure
&lt;/h3&gt;

&lt;p&gt;All responses should follow the same format so the frontend knows what to expect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Success Response Format:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Operation completed successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;actual&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;data&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;*/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"pagination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;it's&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;*/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error Response Format:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Human-readable error message"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ERROR_CODE"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  HTTP Status Codes
&lt;/h3&gt;

&lt;p&gt;Status codes tell the frontend if the request succeeded or failed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;200 OK&lt;/strong&gt;: Everything worked! (for GET, PUT, DELETE)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;201 Created&lt;/strong&gt;: Successfully created something new (for POST)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;400 Bad Request&lt;/strong&gt;: The data you sent is invalid&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;401 Unauthorized&lt;/strong&gt;: You're not logged in&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;403 Forbidden&lt;/strong&gt;: You're logged in, but you don't have permission&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;404 Not Found&lt;/strong&gt;: The thing you're looking for doesn't exist&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;500 Internal Server Error&lt;/strong&gt;: Something went wrong on the server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Success response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order created successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Status code: &lt;strong&gt;201 Created&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Error response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order not found"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"NOT_FOUND"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Status code: &lt;strong&gt;404 Not Found&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Formatting Related Data
&lt;/h3&gt;

&lt;p&gt;Sometimes you need to include related information in your response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Order with customer details&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"mixing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"customer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Alice Sweettooth"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"loyalty_points"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1250&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_details"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Sweet and fruity"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Creamy vanilla"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives the frontend all the information it needs in one response, so it doesn't have to make multiple requests.&lt;/p&gt;




&lt;h2&gt;
  
  
  Complete Example: Creating and Managing Orders
&lt;/h2&gt;

&lt;p&gt;Let's walk through a complete scenario where Alice creates and manages her lollipop orders.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Alice Creates a New Order
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Create order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;POST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/orders&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Headers:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bearer abc123token"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Body:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend processing:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract customer from token (Alice, customer_id: 456)&lt;/li&gt;
&lt;li&gt;Parse the JSON body&lt;/li&gt;
&lt;li&gt;Validate flavors, size, quantity&lt;/li&gt;
&lt;li&gt;Sanitize special_instructions&lt;/li&gt;
&lt;li&gt;Calculate price: $24.99&lt;/li&gt;
&lt;li&gt;Create order in database&lt;/li&gt;
&lt;li&gt;Return created order&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Create order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order created successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T10:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Alice Views Her Orders
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input Example: List orders&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders?status=pending&amp;amp;page=1&amp;amp;limit=10
Headers: {
    "Authorization": "Bearer abc123token"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend processing:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract customer_id from token (456)&lt;/li&gt;
&lt;li&gt;Parse query: status=pending, page=1, limit=10&lt;/li&gt;
&lt;li&gt;Query database: WHERE customer_id = 456 AND status = "pending"&lt;/li&gt;
&lt;li&gt;Count total: 3 orders&lt;/li&gt;
&lt;li&gt;Apply pagination&lt;/li&gt;
&lt;li&gt;Return results&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: List orders response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T10:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"pagination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"limit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"total_pages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Alice Views a Specific Order
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Get single order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders/789
Headers: {
    "Authorization": "Bearer abc123token"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend processing:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extract customer_id from token (456)&lt;/li&gt;
&lt;li&gt;Extract order ID: 789&lt;/li&gt;
&lt;li&gt;Query: WHERE id = 789 AND customer_id = 456&lt;/li&gt;
&lt;li&gt;Return order details&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Get single order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;24.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet, please!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T10:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Alice Updates Her Order
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Update order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;PUT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/orders/&lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Headers:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bearer abc123token"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Body:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"caramel"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend processing:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify ownership (order 789 belongs to customer 456)&lt;/li&gt;
&lt;li&gt;Check if order can be updated (status is "pending" ✓)&lt;/li&gt;
&lt;li&gt;Validate new flavor combination&lt;/li&gt;
&lt;li&gt;Recalculate price: $49.98&lt;/li&gt;
&lt;li&gt;Update order&lt;/li&gt;
&lt;li&gt;Return updated order&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Update order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order updated successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"flavor_combination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"strawberry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vanilla_swirl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"caramel"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"large"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pending"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;49.98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"updated_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-01-15T11:30:00Z"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Alice Cancels Her Order
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Cancel order&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE /orders/789
Headers: {
    "Authorization": "Bearer abc123token"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend processing:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify ownership&lt;/li&gt;
&lt;li&gt;Check if order can be canceled (status is "pending" ✓)&lt;/li&gt;
&lt;li&gt;Mark order as "canceled"&lt;/li&gt;
&lt;li&gt;Process refund&lt;/li&gt;
&lt;li&gt;Return confirmation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Cancel order response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order canceled successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"order_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;789&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"refund_amount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;49.98&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"refund_processed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Using AI to Build Endpoints
&lt;/h2&gt;

&lt;p&gt;If you're using an AI-powered IDE (like Cursor, GitHub Copilot, or similar), you can use prompts to help build your endpoints. Here are example prompts you can use, based on the patterns in this document.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prompt Template for Creating an Endpoint
&lt;/h3&gt;

&lt;p&gt;Use this template and fill in the details for your specific endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I need to build a [CREATE/READ/UPDATE/DELETE] endpoint for [resource name].

The endpoint should:
1. Accept input in this format: [paste Input Example from the document]
2. Format this input using the formatting pattern shown in the "Formatting Input" section (convert JSON to prompt format)
3. Send the formatted input to an AI service
4. Receive a response from the AI in function call format (like flavors("strawberry"), price(24.99), status("pending"))
5. Parse the AI response using the parsing pattern shown in the "Parsing the Response" section (extract data from function calls like flavors(), price(), status())
6. Save the parsed data to the database
7. Return this format to the frontend: [paste Output Example from the document]

Please include frequent comments throughout the code explaining what each line does so I can learn as I go. Also include:
- Input validation
- Authentication check
- Authorization check (verify ownership)
- Error handling with appropriate HTTP status codes
- Consistent response formatting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example Prompts
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Creating a "Create Order" Endpoint
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I need to build a CREATE endpoint for lollipop orders.

The endpoint should:
1. Accept input in this format:
{
    "customer_id": 456,
    "flavor_combination": ["strawberry", "vanilla_swirl"],
    "size": "large",
    "quantity": 12,
    "special_instructions": "Extra sweet, please!"
}

2. Format this input using the formatting pattern from the "Formatting Input" section (convert JSON to prompt format)
3. Send the formatted input to an AI service to generate order suggestions
4. Receive a response from the AI in function call format: flavors("strawberry", "vanilla_swirl"), price(24.99), status("pending")
5. Parse the AI response using the parsing pattern from the "Parsing the Response" section (extract data from function calls like flavors(), price(), status())
6. Save the parsed order data to the database
5. Return this format to the frontend:
{
    "message": "Order created successfully",
    "order": {
        "id": 789,
        "customer_id": 456,
        "flavor_combination": ["strawberry", "vanilla_swirl"],
        "size": "large",
        "quantity": 12,
        "status": "pending",
        "price": 24.99,
        "created_at": "2024-01-15T10:30:00Z"
    }
}

Please include frequent comments throughout the code explaining what each line does so I can learn as I go. Also include:
- Input validation (check flavors exist, size is valid, quantity is 1-100)
- Authentication check (verify user is logged in)
- Authorization check (verify customer_id matches authenticated user)
- Error handling with appropriate HTTP status codes (400 for validation errors, 401 for auth errors, 500 for server errors)
- Consistent response formatting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating a "Get Orders" Endpoint
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I need to build a READ endpoint to get a list of orders.

The endpoint should:
1. Accept query parameters: ?customer_id=456&amp;amp;status=pending&amp;amp;page=1&amp;amp;limit=20
2. Query the database for orders matching these filters
3. Return this format to the frontend:
{
    "orders": [
        {
            "id": 789,
            "flavor_combination": ["strawberry", "vanilla_swirl"],
            "size": "large",
            "quantity": 12,
            "status": "pending",
            "price": 24.99,
            "created_at": "2024-01-15T10:30:00Z"
        }
    ],
    "pagination": {
        "page": 1,
        "limit": 20,
        "total": 3,
        "total_pages": 1
    }
}

Please include frequent comments throughout the code explaining what each line does so I can learn as I go. Also include:
- Parse query parameters with defaults (page=1, limit=20, max limit=100)
- Authentication check (verify user is logged in)
- Authorization check (only return orders for the authenticated user)
- Pagination logic (calculate offset, total pages)
- Error handling with appropriate HTTP status codes
- Consistent response formatting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating an "Update Order" Endpoint
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I need to build an UPDATE endpoint for orders.

The endpoint should:
1. Accept the order ID from the URL: /orders/789
2. Accept input in this format:
{
    "flavor_combination": ["strawberry", "vanilla_swirl", "caramel"],
    "quantity": 24
}

3. Format this input using the formatting pattern from the "Formatting Input" section (convert JSON to prompt format)
4. Send the formatted input to an AI service to validate the update
5. Receive a response from the AI in function call format: flavors("strawberry", "vanilla_swirl", "caramel"), price(49.98), status("pending")
6. Parse the AI response using the parsing pattern from the "Parsing the Response" section (extract data from function calls)
7. Update the order in the database with the parsed data
6. Recalculate the price based on new quantity
7. Return this format to the frontend:
{
    "message": "Order updated successfully",
    "order": {
        "id": 789,
        "flavor_combination": ["strawberry", "vanilla_swirl", "caramel"],
        "size": "large",
        "quantity": 24,
        "status": "pending",
        "price": 49.98,
        "updated_at": "2024-01-15T11:30:00Z"
    }
}

Please include frequent comments throughout the code explaining what each line does so I can learn as I go. Also include:
- Extract order ID from URL parameter
- Parse and validate input
- Authentication check (verify user is logged in)
- Authorization check (verify order belongs to authenticated user)
- Business rule check (can this order be updated? maybe only "pending" orders)
- Partial update logic (only update provided fields)
- Price recalculation
- Error handling with appropriate HTTP status codes (404 if not found, 403 if not authorized)
- Consistent response formatting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating a "Delete Order" Endpoint
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I need to build a DELETE endpoint for orders.

The endpoint should:
1. Accept the order ID from the URL: /orders/789
2. Verify the order exists and belongs to the authenticated user
3. Check if the order can be canceled (business rules - maybe only "pending" orders)
4. Mark the order as "canceled" in the database (soft delete)
5. Process a refund if needed
6. Return this format to the frontend:
{
    "message": "Order canceled successfully",
    "order_id": 789,
    "refund_amount": 24.99,
    "refund_processed": true
}

Please include frequent comments throughout the code explaining what each line does so I can learn as I go. Also include:
- Extract order ID from URL parameter
- Authentication check (verify user is logged in)
- Authorization check (verify order belongs to authenticated user)
- Business rule check (can this order be canceled?)
- Soft delete logic (mark as canceled, don't actually delete)
- Refund processing
- Error handling with appropriate HTTP status codes (404 if not found, 403 if not authorized, 400 if can't be canceled)
- Consistent response formatting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tips for Using AI Prompts
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Be specific about the format&lt;/strong&gt;: Always include the exact input and output formats you want&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Request comments&lt;/strong&gt;: Always ask for frequent comments so you can learn&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Include security&lt;/strong&gt;: Always mention authentication, authorization, and validation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specify error handling&lt;/strong&gt;: Tell the AI what status codes to use for different errors&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mention consistency&lt;/strong&gt;: Ask for consistent response formatting&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Complete Flow
&lt;/h3&gt;

&lt;p&gt;When building an endpoint with AI, the flow should be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Frontend sends request → 
2. Backend receives and parses input → 
3. Backend formats input for AI service → 
4. Backend sends to AI service → 
5. Backend receives AI response → 
6. Backend parses AI response → 
7. Backend saves to database → 
8. Backend formats response → 
9. Backend returns response to frontend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure your AI prompt covers all these steps!&lt;/p&gt;




&lt;h2&gt;
  
  
  Security Basics
&lt;/h2&gt;

&lt;p&gt;Security is critical for any application. Here are the essential concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Authentication: Who Are You?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt; answers: "Who are you?" It verifies that a user is who they claim to be.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User logs in with email and password&lt;/li&gt;
&lt;li&gt;Backend verifies the credentials&lt;/li&gt;
&lt;li&gt;Backend creates a &lt;strong&gt;token&lt;/strong&gt; (like a temporary ID card)&lt;/li&gt;
&lt;li&gt;Backend sends token to frontend&lt;/li&gt;
&lt;li&gt;Frontend includes token in all future requests&lt;/li&gt;
&lt;li&gt;Backend validates token to identify the user&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Login request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;POST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/login&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alice@example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"securepassword123"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output Example: Login response&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"expires_in"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"customer_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;456&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Subsequent requests include the token:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Authenticated request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders
Headers: {
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The backend extracts the token, validates it, and knows this is Alice (customer_id: 456).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key principles:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Never store passwords in plain text (always hash them)&lt;/li&gt;
&lt;li&gt;Tokens should expire after a reasonable time&lt;/li&gt;
&lt;li&gt;Always use HTTPS to encrypt data in transit&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Authorization: What Are You Allowed to Do?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt; answers: "What are you allowed to do?" It determines what resources a user can access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Order ownership check&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alice tries to view order #789:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Authorized request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders/789
Headers: {
    "Authorization": "Bearer alice_token"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend checks:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is this a valid token? → Yes, it's Alice (customer_id: 456)&lt;/li&gt;
&lt;li&gt;Does order 789 belong to customer 456? → Yes ✓&lt;/li&gt;
&lt;li&gt;Return order data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;If Bob tries to access Alice's order:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Unauthorized request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /orders/789
Headers: {
    "Authorization": "Bearer bob_token"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Backend checks:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is this a valid token? → Yes, it's Bob (customer_id: 789)&lt;/li&gt;
&lt;li&gt;Does order 789 belong to customer 789? → No!&lt;/li&gt;
&lt;li&gt;Return 403 Forbidden&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Authorization error&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Access denied. This order does not belong to you."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"FORBIDDEN"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  API Keys: Never Expose on Frontend
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why this matters:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend code is visible to anyone&lt;/li&gt;
&lt;li&gt;API keys in frontend can be stolen&lt;/li&gt;
&lt;li&gt;Stolen keys can be used to make unauthorized requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bad approach (DON'T DO THIS):&lt;/strong&gt;&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="c1"&gt;// ❌ NEVER DO THIS - Anyone can see this!&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sk_live_1234567890abcdef&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Good approach:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend calls YOUR backend&lt;/li&gt;
&lt;li&gt;YOUR backend calls external services with the API key&lt;/li&gt;
&lt;li&gt;API key stays on the server, never exposed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Frontend to backend&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;POST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/api/generate-lollipop-suggestion&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"preferences"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sweet"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The frontend doesn't know about any external API keys. Your backend handles that securely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key principle:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store secrets (API keys, passwords) in environment variables on the server&lt;/li&gt;
&lt;li&gt;Never commit secrets to version control&lt;/li&gt;
&lt;li&gt;Never send secrets to the frontend&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rate Limiting: Preventing Abuse
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What is rate limiting?&lt;/strong&gt;&lt;br&gt;
Rate limiting prevents abuse by limiting how many requests a user can make in a given time period.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevents API abuse&lt;/li&gt;
&lt;li&gt;Protects against attacks&lt;/li&gt;
&lt;li&gt;Ensures fair resource usage&lt;/li&gt;
&lt;li&gt;Controls costs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
A customer tries to create 100 orders in 1 minute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Without rate limiting:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All 100 orders are processed&lt;/li&gt;
&lt;li&gt;Server is overwhelmed&lt;/li&gt;
&lt;li&gt;Costs skyrocket&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;With rate limiting:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First 10 requests succeed&lt;/li&gt;
&lt;li&gt;Remaining 90 requests return error&lt;/li&gt;
&lt;li&gt;Server stays healthy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output Example: Rate limit error&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Rate limit exceeded. Please wait before making another request."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"RATE_LIMIT_EXCEEDED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"retry_after"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Common limits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Free tier: 10 requests per hour&lt;/li&gt;
&lt;li&gt;Premium tier: 1000 requests per hour&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Input Validation and Sanitization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why validate input?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevents malicious data from entering your system&lt;/li&gt;
&lt;li&gt;Ensures data integrity&lt;/li&gt;
&lt;li&gt;Protects against attacks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Validation checks:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Type&lt;/strong&gt;: Is quantity actually a number?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Range&lt;/strong&gt;: Is quantity between 1 and 100?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Format&lt;/strong&gt;: Are flavors from the approved list?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sanitization&lt;/strong&gt;: Remove dangerous HTML/scripts&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Input Example: Invalid input&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"quantity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"not a number"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output Example: Validation error&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Invalid input: 'quantity' must be a number"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VALIDATION_ERROR"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Input Example: Dangerous input&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;script&amp;gt;alert('hack')&amp;lt;/script&amp;gt;Extra sweet!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After sanitization:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"special_instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Extra sweet!"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dangerous script is removed.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTTPS: Encrypting Data
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Always use HTTPS in production:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encrypts data in transit&lt;/li&gt;
&lt;li&gt;Prevents man-in-the-middle attacks&lt;/li&gt;
&lt;li&gt;Required for sensitive data (passwords, payment info)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What HTTPS does:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encrypts data between client and server&lt;/li&gt;
&lt;li&gt;Verifies server identity&lt;/li&gt;
&lt;li&gt;Protects against eavesdropping&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Key Principles
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Always authenticate and authorize&lt;/strong&gt; before processing requests&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate and sanitize&lt;/strong&gt; all input data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use consistent response formats&lt;/strong&gt; for success and error cases&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Include ownership checks&lt;/strong&gt; in all database queries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handle errors gracefully&lt;/strong&gt; with appropriate HTTP status codes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provide pagination&lt;/strong&gt; for list endpoints&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structure responses&lt;/strong&gt; for easy frontend consumption&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The CRUD Flow
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Create:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parse input → Validate → Create in database → Return created record&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Read:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parse parameters → Authenticate → Query database → Return results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parse input → Verify ownership → Validate → Update database → Return updated record&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Delete:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify ownership → Check rules → Delete from database → Return confirmation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Security Checklist
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ Implement authentication (verify who the user is)&lt;/li&gt;
&lt;li&gt;✅ Implement authorization (verify what they can access)&lt;/li&gt;
&lt;li&gt;✅ Never expose API keys on the frontend&lt;/li&gt;
&lt;li&gt;✅ Use environment variables for secrets&lt;/li&gt;
&lt;li&gt;✅ Implement rate limiting&lt;/li&gt;
&lt;li&gt;✅ Validate and sanitize all input&lt;/li&gt;
&lt;li&gt;✅ Use HTTPS in production&lt;/li&gt;
&lt;li&gt;✅ Don't expose sensitive information in error messages&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This guide provides a foundation for building robust, secure CRUD operations. Remember: security is not optional—it's essential for protecting your users and your application.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Conversion Funnels &amp; the Banality of Success</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Wed, 07 Jan 2026 18:45:53 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/conversion-funnels-the-banality-of-success-1be7</link>
      <guid>https://dev.to/goldsteinnick/conversion-funnels-the-banality-of-success-1be7</guid>
      <description>&lt;h1&gt;
  
  
  Conversion Funnels &amp;amp; the Banality of Success
&lt;/h1&gt;

&lt;p&gt;What happens after you build &lt;strong&gt;the thing&lt;/strong&gt;? Some might expect a profound feeling of satisfaction or some kind of parade, either figurative or literal. Maybe a media blitz of stupefied journalists amazed by your accomplishment. Maybe an outpouring of interest from a myriad of Venture Capital firms and an invite to a couple billionaire parties. If only it was that easy. After you build the thing, you’ve only just begun.&lt;/p&gt;

&lt;p&gt;Few people actually get to this point, so kudos if you have. Maybe if the world were fair we would hold a parade in your honor. You accomplished something incredibly difficult, but… no one knows it or you exist, which is a bit of an issue if you intend to make any money whatsoever.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Slog of Messaging
&lt;/h2&gt;

&lt;p&gt;Now, I don’t mean to speak as if I’m above it all and know the ins and outs of this because, admittedly, I’m in the slog of messaging as well. I’m slowly shifting from &lt;strong&gt;insane creative full-stack mad scientist developer mode&lt;/strong&gt; into a lowly content creator who’s completely new to this set of processes and workflows. I might as well be writing this essay to myself in a way. Maybe I can inspire myself to record something after this, but who knows, maybe Emstrata needs a thousand more features first.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Founder-to-Influencer Jump
&lt;/h2&gt;

&lt;p&gt;The jump from founder to influencer is jarring. I don’t think of myself as a person that needs all this attention on me, so being the face of a project is a tough one to compute. There are other concerns that people don’t talk about quite as often, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;‘What will person X I knew from high school think about me if I’m actually trying to follow my dreams?’&lt;/li&gt;
&lt;li&gt;‘What if I’m creating a living record of a future failure and this project doesn’t pan out to the level of my most grandiose fantasies?’ &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The answer to all these things I suppose, is &lt;strong&gt;‘Do YOU actually care?’&lt;/strong&gt; or is this just some sort of failsafe evolutionarily rooted mechanism hardwired into human beings to prevent us from falling out of the in-group? I’d say that you need to make a decision about how much you want this or not, but by this point, you probably should’ve already had that conversation with yourself, so… just live with it and trudge on anyway because videos don’t record themselves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creativity vs. Persistence
&lt;/h2&gt;

&lt;p&gt;The other counterintuitive thing to understand and reframe in your mind is that while development rewards creativity and brilliant architectural decisions, content creation rewards &lt;strong&gt;disciplined, incremental improvement and persistence&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Keeping yourself organized, building out sustainable workflows, templatizing things that work, and building on small successes is much more important in this new paradigm. Also, you’ll likely need to spend some money on promotion without clear expectations for a great return.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Methodical Approach
&lt;/h2&gt;

&lt;p&gt;My advice for paid promotion is to collect useful analytics early so you can track improvement and develop clear pipelines for signup and subscriptions. I’m doing this now. I’ve setup a whole dashboard that tracks my signup conversion funnel so I can see what might be preventing people who are trying an Emstrata demo from signing up for the real thing. &lt;/p&gt;

&lt;p&gt;Without these analytics, it could be a thousand things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maybe the demo is boring.&lt;/li&gt;
&lt;li&gt;Maybe the fundamentals aren’t as interesting as I think.&lt;/li&gt;
&lt;li&gt;Maybe it’s just too difficult and unobvious to signup. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For instance, I just recently added Google signups to my authentication system to make it even more simple to get started with Emstrata and now I can track how much of a dent that makes.&lt;/p&gt;

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

&lt;p&gt;So yes, we’re not in fantasy creation land anymore. We’re building according to the numbers now. We’re turning in our visionary ambitions for a methodical, numbers-based approach. It’s worth mentioning that the analytics collection and the conversion funnels are the sacrifices that visionary founders need to make so that their message doesn’t fall on deaf ears and maybe one day that parade will come.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nicholasmgoldstein.com/articles/conversion-funnels-and-the-banality-of-success" rel="noopener noreferrer"&gt;Read the original article on my site&lt;/a&gt;&lt;/p&gt;

</description>
      <category>startup</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>marketing</category>
    </item>
    <item>
      <title>Build AI Worlds with Emstrata</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Tue, 06 Jan 2026 01:03:24 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/build-ai-worlds-with-emstrata-gco</link>
      <guid>https://dev.to/goldsteinnick/build-ai-worlds-with-emstrata-gco</guid>
      <description>&lt;p&gt;Emstrata is a new, powerful AI storytelling platform that puts people in the driver's seat. You control the narrative, Emstrata tracks the plot, and builds out the world as you progress.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Can Build
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Interactive Fiction &amp;amp; Games&lt;/strong&gt;&lt;br&gt;
Run campaigns where the AI acts as dungeon master, generating content on the fly while keeping the world consistent. Participants explore, make choices, face real consequences without you needing to prep every scenario in advance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Language Learning&lt;/strong&gt;&lt;br&gt;
Want to practice Spanish? Run a simulation where you manage a Barcelona café, deal with customers, handle supplier problems, navigate local regulations. You're not drilling vocabulary. You're using the language in context that actually matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Professional Training&lt;/strong&gt;&lt;br&gt;
Practice difficult conversations before they happen. Negotiate with a demanding client. Handle a performance review. Manage a crisis. The AI creates realistic scenarios with actual consequences, letting you develop judgment without real-world stakes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collaborative Stories&lt;/strong&gt;&lt;br&gt;
Multiple participants inhabit the same world with separate characters and goals. Everyone pursues their own agenda. Secrets stay secret. Alliances form and break. The story emerges from genuine interaction, not scripted events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Historical Exploration&lt;/strong&gt;&lt;br&gt;
Experience historical events from inside. Make decisions in real-time. Understand why people acted the way they did by facing the constraints they faced. This isn't reading about history. It's operating within it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Techniques That Work
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Start with Clear Stakes&lt;/strong&gt;&lt;br&gt;
Don't just drop into a fantasy world to "explore." Give yourself or your participants a concrete problem: retrieve something, escape somewhere, convince someone, solve something. Stakes create direction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let Complications Build&lt;/strong&gt;&lt;br&gt;
When the Injector System throws chaos at you (unexpected arrivals, environmental problems, new characters), lean into it instead of trying to force your original plan. The best moments come from adapting to circumstances you didn't anticipate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use the Invisible Hand for Pacing&lt;/strong&gt;&lt;br&gt;
When you want something to happen but your character wouldn't logically cause it, use the Invisible Hand. It weaves your suggestion into the narrative naturally: weather changes, a specific person arrives, tension escalates. You're orchestrating without breaking character.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protest Immediately&lt;/strong&gt;&lt;br&gt;
If the AI contradicts established facts or generates something that breaks the simulation, hit Protest right away. Small errors compound into narrative collapse if you let them slide. Fix them immediately and keep moving.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Track What Matters in Notes&lt;/strong&gt;&lt;br&gt;
Don't try to remember everything. Use the notes function to track relationships, clues, promises, suspicious details. This frees you to focus on the current moment instead of trying to hold the entire simulation in your head.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coordinate in Multi-Participant Sims&lt;/strong&gt;&lt;br&gt;
When multiple people are involved, communicate out-of-character about pacing and turn order. The simulation stays immersive, but you still need to coordinate as participants to keep things moving.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Works
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Give Yourself Direction&lt;/strong&gt;&lt;br&gt;
"I explore the town" works better when you have a reason: something to find, someone to locate, a problem to solve. Stakes give your actions purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let Consequences Build&lt;/strong&gt;&lt;br&gt;
The simulation remembers. Antagonize someone powerful and that relationship degrades. Make a deal with conditions and those conditions come due. Your actions ripple forward through the story.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plan Loosely&lt;/strong&gt;&lt;br&gt;
You can plan things out if you want, but keep plans flexible. Set up situations and let them develop. Leave room for complications when they arrive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embrace What Happens&lt;/strong&gt;&lt;br&gt;
When things don't go your way, roll with it. Failure makes better stories than success. Your plan collapses because an injector fired? That's the platform working.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Character Perspective&lt;/strong&gt;&lt;br&gt;
Your Eyes Only sections add depth. Internal conflict, private doubts, things your character wouldn't say out loud. This creates richness that action alone can't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples in Practice
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Sunken Temple (Fantasy Adventure)&lt;/strong&gt;&lt;br&gt;
You're a rogue hired to retrieve an artifact from a flooded temple. The entrance collapses behind you. Your torch is running low. You hear something moving in the water. The map you bought shows a chamber that doesn't exist. Do you trust the merchant who hired you?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Barcelona Café (Language Learning)&lt;/strong&gt;&lt;br&gt;
You run a small café in Barcelona. Customers come in speaking Spanish. Your supplier calls about a delayed shipment. The health inspector shows up. Your employee calls in sick during lunch rush.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Corporate Crisis (Professional Training)&lt;/strong&gt;&lt;br&gt;
You're the VP of Communications. A product defect just went viral on social media. Legal wants you to say nothing. The CEO wants aggressive pushback. A journalist is calling in twenty minutes. Engineering is blaming Marketing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Inheritance Mystery (Collaborative Fiction)&lt;/strong&gt;&lt;br&gt;
Participants are estranged siblings meeting at their father's estate. Each has private information about the family. The will has strange conditions. One sibling knows about the debt. Another knows about the affair. Another knows about the offshore accounts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Frontier Caravan (D&amp;amp;D Campaign)&lt;/strong&gt;&lt;br&gt;
Participants are guards escorting a merchant caravan through contested territory. One participant is secretly working for bandits. Another is hiding a noble identity. Another is tracking someone in the caravan. Another just wants the pay. Bandits attack. A wheel breaks. Supplies go missing. Someone gets sick.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start Building
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://emstrata.com" rel="noopener noreferrer"&gt;Go to Emstrata&lt;/a&gt; and create your first simulation. Pick a scenario that matters to you: a skill you want to develop, a situation you want to understand, a story you want to tell. Set clear stakes. Make choices. Adapt to complications. See what emerges.&lt;/p&gt;

&lt;p&gt;The platform works best when you treat it as creative infrastructure, not a predetermined story generator. You bring direction and judgment. Emstrata maintains consistency and introduces unpredictability. Together you build worlds neither could create alone.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>tutorial</category>
      <category>discuss</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Why Emstrata is the Best AI Storytelling App</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Sat, 20 Dec 2025 01:07:49 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/why-emstrata-is-the-best-ai-storytelling-app-gp5</link>
      <guid>https://dev.to/goldsteinnick/why-emstrata-is-the-best-ai-storytelling-app-gp5</guid>
      <description>&lt;h1&gt;
  
  
  How We Built an AI Storytelling Platform That Actually Works
&lt;/h1&gt;

&lt;p&gt;I storytelling platforms promise collaborative narrative experiences where you and artificial intelligence co-create stories that feel alive and unpredictable. The reality? Most deliver chatbot conversations with a creative writing bent. Characters forget their own names. Locations shift properties mid-scene. The AI manipulates outcomes to serve convenient plot beats instead of genuine simulation.&lt;/p&gt;

&lt;p&gt;Emstrata is different. It's an emergent narrative engine built on a four-layer AI architecture designed to solve the core problems plaguing collaborative AI storytelling: consistency failures, fake probability, information leakage, and the systematic replacement of human creative agency with algorithmic convenience.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Emstrata Cycle: Four-Layer AI Architecture for Narrative Consistency
&lt;/h2&gt;

&lt;p&gt;Most AI storytelling apps use single-layer LLM systems that generate text in response to user input. This approach fails for extended narratives because one system can't simultaneously maintain continuity, manage spatial relationships, generate compelling prose, and track information compartmentalization.&lt;/p&gt;

&lt;p&gt;Emstrata's four-layer architecture—The Emstrata Cycle—assigns specialized roles to distinct AI systems:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Groundskeeper: Persistent Memory and Knowledge Management
&lt;/h3&gt;

&lt;p&gt;The Groundskeeper functions as institutional memory for your simulation. It maintains detailed records of established facts: character descriptions, personality traits, location properties, relationship dynamics, revealed secrets, and world-building elements. When other layers need information about existing entities, they query The Groundskeeper's verified database instead of regenerating from degraded context.&lt;/p&gt;

&lt;p&gt;This prevents redescription—the common failure where AI systems inconsistently reframe previously established elements. Your merchant with calloused hands keeps those calloused hands across hundreds of turns. Your cramped tavern basement doesn't mysteriously become a spacious wine cellar. Character personalities remain stable because there's an actual system enforcing consistency.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Discovery Layer: Spatial Reasoning and Consequence Planning
&lt;/h3&gt;

&lt;p&gt;The Discovery Layer handles what happens when you act. It uses the Simulation Positioning System (SPS), a coordinate-based mapping architecture that tracks where you are and what exists around you. When you open doors, travel to new locations, or search rooms, The Discovery Layer determines outcomes based on established continuity, narrative logic, and dramatic potential—not convenience.&lt;/p&gt;

&lt;p&gt;The Discovery Layer also plans ripple effects from participant actions. Antagonize a powerful character? The system tracks that relationship degradation and plans how it might manifest later. Make a deal with consequences? Those consequences get scheduled into future simulation events. This creates genuine cause-and-effect chains instead of episodic encounters that reset between scenes.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Narration Layer: Prose Generation and Character Interiority
&lt;/h3&gt;

&lt;p&gt;The Narration Layer writes the text you read. It synthesizes structural decisions from The Discovery Layer, continuity requirements from The Groundskeeper, and quality checks from The Chron-Con into flowing narrative prose.&lt;/p&gt;

&lt;p&gt;The Narration Layer also generates "Your Eyes Only" sections—private character thoughts and internal reactions invisible to other participants. This creates the experience of inhabiting a character's consciousness, not just observing their external actions. You know what your character thinks about situations, even when those thoughts remain unspoken.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Chron-Con: Quality Control and Continuity Verification
&lt;/h3&gt;

&lt;p&gt;The Chron-Con (Chronology Context) reviews generated narrative for logical consistency, timeline accuracy, and character behavior coherence. When it detects errors or contradictions, it replaces problematic text with corrected versions before the narrative finalizes.&lt;/p&gt;

&lt;p&gt;The Chron-Con also manages character stat tracking (Health, Essence, Tether) and catalogs information revelation, feeding updates back to The Groundskeeper so future narrative generation accounts for changed circumstances. This creates a feedback loop where the simulation's knowledge state stays current with narrative developments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Genuine Probability Mechanics Instead of Narrative Convenience
&lt;/h2&gt;

&lt;p&gt;AI storytelling platforms commonly suffer from probability punditry—the unconscious bias toward dramatically convenient outcomes. The AI "knows" that finding the hidden item would advance the plot, so you find it. The AI "knows" that character death would be inconvenient, so your risky action succeeds. Every outcome feels predetermined by dramatic logic rather than emerging from genuine simulation.&lt;/p&gt;

&lt;p&gt;Emstrata implements explicit probability rolls handled by backend systems, not LLM judgment. When outcomes depend on chance, the platform runs weighted randomness calculations that account for character capabilities, environmental factors, and established context—but remain genuinely probabilistic. The AI reports results; it doesn't choose convenient outcomes.&lt;/p&gt;

&lt;p&gt;This preserves collaborative uncertainty. Success feels earned because failure was genuinely possible. Exploration feels meaningful because you can't predict what you'll discover. Risk actually carries weight because the simulation isn't protecting you from consequences.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Injector System: Structured Unpredictability
&lt;/h2&gt;

&lt;p&gt;The Injector System introduces complications into narratives 20% of the time, creating structured unpredictability that prevents AI storytelling from becoming too convenient or predictable:&lt;/p&gt;

&lt;p&gt;Subversive Injectors (15% activation rate) bring environmental complications—weather changes, unexpected arrivals, missing items, circumstances that disrupt plans.&lt;/p&gt;

&lt;p&gt;Archetypal Injectors (5% activation rate) introduce new characters who complicate social dynamics and create fresh dramatic tension.&lt;/p&gt;

&lt;p&gt;Afterlife Injectors handle character death by transforming it from "game over" into narrative transition, keeping players engaged even after their character dies.&lt;/p&gt;

&lt;p&gt;When you see "Emstrata's Turn" instead of your input field, the simulation is taking control to introduce chaos. Sometimes injectors cascade—multiple injectors firing on consecutive turns—creating intense sequences where plans collapse and you can only watch circumstances spiral. This is rare but creates the genuine unpredictability that makes simulation feel real.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Participant AI Storytelling with Information Compartmentalization
&lt;/h2&gt;

&lt;p&gt;Most AI storytelling platforms struggle with multi-participant scenarios because maintaining separate information streams for different players requires sophisticated state management. Information leaks between player perspectives. Secrets become public knowledge. Private character thoughts appear in shared narrative.&lt;/p&gt;

&lt;p&gt;Emstrata handles multi-participant simulations through rigorous information compartmentalization:&lt;/p&gt;

&lt;p&gt;Separate Knowledge States: The Groundskeeper maintains distinct knowledge records for each character, tracking what each participant knows independently.&lt;/p&gt;

&lt;p&gt;Your Eyes Only Sections: Private character interiority remains invisible to other participants, preserving asymmetric information dynamics.&lt;/p&gt;

&lt;p&gt;Spatial Separation: The SPS ensures participants in different locations receive appropriate environmental context based on their position.&lt;/p&gt;

&lt;p&gt;Secret Management: Information revelation is tracked precisely, ensuring secrets stay secret until narratively disclosed.&lt;/p&gt;

&lt;p&gt;This enables genuine collaborative storytelling where multiple participants pursue separate agendas with different information sets, creating emergent social dynamics impossible in single-player scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creative Control Tools for Human Agency
&lt;/h2&gt;

&lt;p&gt;Emstrata prioritizes human creative agency over algorithmic optimization. The platform provides tools that let participants maintain narrative control while leveraging AI capability:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Invisible Hand
&lt;/h3&gt;

&lt;p&gt;The Invisible Hand lets participants inject narrative elements without taking character action. Want weather to change? Environmental complications to emerge? A specific character to arrive? The Invisible Hand weaves these suggestions seamlessly into the narrative without requiring awkward character behavior to justify them.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Protest Function
&lt;/h3&gt;

&lt;p&gt;The Protest Function lets participants reject AI-generated content that contradicts established facts or doesn't serve their creative vision. Hit protest, and the system regenerates while accounting for why the previous version was inadequate. This prevents small errors from compounding into narrative collapse.&lt;/p&gt;

&lt;h3&gt;
  
  
  Orchestrator Mode
&lt;/h3&gt;

&lt;p&gt;Orchestrator Mode gives simulation designers comprehensive control over narrative mechanics. Edit probability parameters before rolls occur. Modify instructions to The Narration Layer. Predefine Injector System interventions. Manipulate simulation state directly. This transforms Emstrata from collaborative tool into authorial instrument for educators, trainers, game masters, and narrative designers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pela: The Artistic Discipline of AI-Mediated Narrative Simulation
&lt;/h2&gt;

&lt;p&gt;Pela (Performing Emergent Lives Artistically) represents the artistic discipline enabled by Emstrata's architecture. Like jazz improvisation or live theater, Pela combines structure with spontaneity—participants and AI co-create narratives neither could produce alone.&lt;/p&gt;

&lt;p&gt;The best Pela moments happen when collaboration creates unexpected but perfect outcomes, when simulations surprise everyone involved, when you forget you're working with AI and just experience the story. These moments can't be forced, but Emstrata's architecture creates conditions where they become possible.&lt;/p&gt;

&lt;p&gt;Pela applications extend beyond entertainment into experiential learning, skills training, scenario planning, and professional development. Want to learn Spanish? Run a simulation where you operate a Barcelona café. Practice difficult workplace conversations? Simulate them with realistic consequences. Understand historical events? Experience them from inside, making decisions in real-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Applications for AI Storytelling Technology
&lt;/h2&gt;

&lt;p&gt;Emstrata serves multiple use cases through the same architectural foundation:&lt;/p&gt;

&lt;p&gt;Interactive Fiction and Narrative Games: The platform functions as an infinitely flexible game master, generating content on the fly while maintaining world consistency.&lt;/p&gt;

&lt;p&gt;Experiential Learning: Complex simulations for language acquisition, historical education, and subject matter exploration through lived experience.&lt;/p&gt;

&lt;p&gt;Skills Development: Workplace scenario training, negotiation practice, crisis response preparation, and soft skills development in consequence-free environments.&lt;/p&gt;

&lt;p&gt;Collaborative Entertainment: Multi-participant narrative experiences ranging from casual storytelling to ambitious collaborative fiction projects.&lt;/p&gt;

&lt;p&gt;Scenario Planning: Organizations can model complex decisions in simulated environments, exploring potential outcomes before real-world implementation.&lt;/p&gt;

&lt;p&gt;The same systems preventing character inconsistency in fiction also ensure training scenarios maintain behavioral realism. The same probability mechanics creating unpredictable adventures also make skills training feel authentic. The same information compartmentalization enabling mystery narratives also creates realistic scenario planning with asymmetric knowledge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Architecture Matters for AI Storytelling Apps
&lt;/h2&gt;

&lt;p&gt;The difference between functional and compelling AI storytelling lies in architectural sophistication. Surface-level chatbot interfaces can generate impressive text snippets, but extended narrative experiences require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Persistent memory systems for entity and world consistency&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explicit probability mechanics for genuine randomness&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Information compartmentalization for logical knowledge boundaries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-layer coordination for maintaining coherence at scale&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Human control tools that preserve creative agency&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Emstrata's four-layer architecture, genuine probability mechanics, information management systems, and human control tools represent comprehensive solutions to problems other platforms ignore or paper over with impressive-sounding promises.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>discuss</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Multilayered Architectures - Build AI Platforms From Scratch #4</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Tue, 16 Dec 2025 15:39:45 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/multilayered-architectures-build-ai-platforms-from-scratch-4-2neo</link>
      <guid>https://dev.to/goldsteinnick/multilayered-architectures-build-ai-platforms-from-scratch-4-2neo</guid>
      <description>&lt;h1&gt;
  
  
  What Is a Multilayered AI Architecture?
&lt;/h1&gt;

&lt;h2&gt;
  
  
  And how can it supercharge the power of your app?
&lt;/h2&gt;

&lt;p&gt;If one prompt takes an input and runs it through a series of filters and rules and fundamentally transforms the input data, then outputs it to you, &lt;strong&gt;multiple coordinated prompts compound those transformations substantially&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The separation of concerns between AI layers not only makes these systems more manageable, but also helps avoid confusing the AI with a million tasks—bolstering performance for the most important functionalities.&lt;/p&gt;

&lt;p&gt;This approach is especially useful for systems aiming for near-perfect performance or simply more consistent results.&lt;/p&gt;




&lt;h2&gt;
  
  
  An Example from Emstrata
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Emstrata Cycle
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Emstrata Cycle&lt;/strong&gt; is a standardized series of prompts that run on every turn in an Emstrata simulation.&lt;/p&gt;

&lt;p&gt;This cycle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retains a comprehensive memory of all entities in the simulation
&lt;/li&gt;
&lt;li&gt;Plans and positions entities on an interactive coordinate plane
&lt;/li&gt;
&lt;li&gt;Writes prose according to exacting instructions
&lt;/li&gt;
&lt;li&gt;Captures secrets and memories
&lt;/li&gt;
&lt;li&gt;Corrects all continuity errors &lt;em&gt;after&lt;/em&gt; the narrative is written
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No single prompt—or backend wizardry—could accomplish this alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simplified Layers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Groundskeeper&lt;/strong&gt; (system memory)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discovery&lt;/strong&gt; (planning / consequence handling)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Narration&lt;/strong&gt; (writing the narrative)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chron-Con&lt;/strong&gt; (correcting minor errors)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Think Architecturally
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Strategize for better platform results
&lt;/h3&gt;

&lt;p&gt;Start with your &lt;strong&gt;actual goal&lt;/strong&gt;, then break it down into steps.&lt;/p&gt;

&lt;p&gt;If you were to perform this action yourself:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What steps would you follow?&lt;/li&gt;
&lt;li&gt;What decisions would you make?&lt;/li&gt;
&lt;li&gt;What information would you need at each stage?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Write that down. That’s your &lt;strong&gt;workflow&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once the workflow is formalized, identify the &lt;strong&gt;data transformations&lt;/strong&gt; required at each step. Build prompts to automate those transformations—and then &lt;strong&gt;chain them together&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Illustrative example
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If your platform relies heavily on conversation history, token count and performance can suffer.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;conversation consolidation layer&lt;/strong&gt; may help.&lt;/li&gt;
&lt;li&gt;If you need &lt;em&gt;true randomness&lt;/em&gt;, serve it from the backend instead of relying on LLM training data to approximate it.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Correction Layers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The referee of your platform
&lt;/h3&gt;

&lt;p&gt;Correction layers catch errors &lt;em&gt;after&lt;/em&gt; other layers have completed their work. They are your quality control.&lt;/p&gt;

&lt;p&gt;They detect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Continuity breaks
&lt;/li&gt;
&lt;li&gt;Logical inconsistencies
&lt;/li&gt;
&lt;li&gt;Constraint violations
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In Emstrata:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Chron-Con&lt;/strong&gt; layer runs after the narrative is written and checks things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did a character teleport without traveling?&lt;/li&gt;
&lt;li&gt;Did someone use an item they don’t possess?&lt;/li&gt;
&lt;li&gt;Are spatial coordinates consistent with the described action?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When you need one:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Use correction layers when your platform has complex requirements. Correcting &lt;em&gt;before&lt;/em&gt; revealing the final answer significantly reduces bad outputs.&lt;/p&gt;




&lt;h2&gt;
  
  
  Reasoning / Strategy Layers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The decision-maker of your platform
&lt;/h3&gt;

&lt;p&gt;Reasoning layers decide &lt;em&gt;what should happen&lt;/em&gt; before anything is written.&lt;/p&gt;

&lt;p&gt;They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Evaluate the current state
&lt;/li&gt;
&lt;li&gt;Consider available options
&lt;/li&gt;
&lt;li&gt;Assess consequences
&lt;/li&gt;
&lt;li&gt;Choose a direction
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In Emstrata:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Discovery&lt;/strong&gt; handles this. It evaluates participant intent, simulation state, and narrative logic to determine outcomes—&lt;em&gt;without writing prose&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
If you’re asking an LLM to both &lt;strong&gt;decide what happens&lt;/strong&gt; &lt;em&gt;and&lt;/em&gt; &lt;strong&gt;write it beautifully&lt;/strong&gt;, you’re overloading a single prompt.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Reason first. Write second.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Memory Consolidation Layers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The stenographer of your platform
&lt;/h3&gt;

&lt;p&gt;These layers distill what just happened into structured, retrievable memory.&lt;/p&gt;

&lt;p&gt;They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract important details from verbose content
&lt;/li&gt;
&lt;li&gt;Store data efficiently for future querying
&lt;/li&gt;
&lt;li&gt;Maintain a system’s source of truth
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In Emstrata:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Groundskeeper&lt;/strong&gt; updates the comprehensive simulation state after Discovery and Narration complete their work.&lt;/p&gt;




&lt;h2&gt;
  
  
  Content Layers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The performer of your platform
&lt;/h3&gt;

&lt;p&gt;Content layers generate the output users actually experience.&lt;/p&gt;

&lt;p&gt;They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take decisions from reasoning layers
&lt;/li&gt;
&lt;li&gt;Pull context from memory layers
&lt;/li&gt;
&lt;li&gt;Optimize for tone, pacing, and emotional resonance
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In Emstrata:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;Narration&lt;/strong&gt; layer writes the prose players read. It focuses on atmosphere—not logic or consistency (those are handled elsewhere).&lt;/p&gt;




&lt;h2&gt;
  
  
  Catch-All / Connector Layers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The clean-up crew of your platform
&lt;/h3&gt;

&lt;p&gt;Some layers don’t fit neatly into one category. These hybrid layers handle glue-work between systems.&lt;/p&gt;

&lt;p&gt;They often emerge when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Layers speak different “languages”&lt;/li&gt;
&lt;li&gt;Multiple layers need the same preprocessing&lt;/li&gt;
&lt;li&gt;No single layer should own a task outright&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In Emstrata:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Chron-Con&lt;/strong&gt; also extracts and tags secrets and memories for Groundskeeper.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Narration shouldn’t stop to categorize secrets
&lt;/li&gt;
&lt;li&gt;Groundskeeper needs them explicitly labeled
&lt;/li&gt;
&lt;li&gt;Chron-Con bridges the gap&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Cyclical vs Circumstantial Systems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  And everything in-between
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Cyclical systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Same prompts, same order, every time
&lt;/li&gt;
&lt;li&gt;Predictable execution
&lt;/li&gt;
&lt;li&gt;Easier debugging and cost estimation
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Emstrata runs:&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Discovery → Narration → Chron-Con → Groundskeeper&lt;/p&gt;

&lt;h3&gt;
  
  
  Circumstantial systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Execution path changes based on outcomes
&lt;/li&gt;
&lt;li&gt;Routing layers determine what runs next
&lt;/li&gt;
&lt;li&gt;More adaptive, more complex
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Hybrid systems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A reliable core cycle
&lt;/li&gt;
&lt;li&gt;Conditional branches for edge cases
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most real-world systems land here—including Emstrata.&lt;/p&gt;




&lt;h2&gt;
  
  
  Agnostic Backend Interaction
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What happens between AI layers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why the backend matters:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data persistence:&lt;/strong&gt; save transformed data for debugging and replay
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability:&lt;/strong&gt; present or reuse data later
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unbiased judgment:&lt;/strong&gt; the backend has no “opinions”
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Emstrata example: Weighted randomness
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Discovery determines likelihood&lt;/li&gt;
&lt;li&gt;Backend rolls a number (1–1000)&lt;/li&gt;
&lt;li&gt;Backend confirms success or failure&lt;/li&gt;
&lt;li&gt;Narration receives the outcome&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;True randomness belongs outside the LLM.&lt;/p&gt;




&lt;h2&gt;
  
  
  Randomness Injection
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A jolt of creativity
&lt;/h3&gt;

&lt;p&gt;If your outputs feel trope-y or predictable, try &lt;strong&gt;Random Concept Injection&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Use randomness to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate novel character names
&lt;/li&gt;
&lt;li&gt;Inject unexpected concepts
&lt;/li&gt;
&lt;li&gt;Build characters from abstract archetypes
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any list of random strings can be injected into a decision-making process to break pattern lock-in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cost Considerations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Usage costs will increase
&lt;/h3&gt;

&lt;p&gt;Multilayered systems cost more.&lt;/p&gt;

&lt;p&gt;Each layer is an API call. A four-layer cycle can cost ~4× a single prompt.&lt;/p&gt;

&lt;p&gt;The real question isn’t:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“How do I add layers cheaply?”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Does the quality improvement justify the cost?”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Optimization tips
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use cheaper models for correction layers
&lt;/li&gt;
&lt;li&gt;Cache aggressively in cyclical systems
&lt;/li&gt;
&lt;li&gt;Cut layers that don’t earn their keep
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Performance Considerations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Speed vs quality
&lt;/h3&gt;

&lt;p&gt;More layers = more latency.&lt;/p&gt;

&lt;p&gt;However:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Independent layers can run &lt;strong&gt;in parallel&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Sometimes &lt;strong&gt;fewer, stronger prompts&lt;/strong&gt; outperform many weak ones
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Layering helps—but it’s not always the answer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hallucination Considerations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Avoid compounding errors
&lt;/h3&gt;

&lt;p&gt;Hallucinations compound across layers.&lt;/p&gt;

&lt;p&gt;If:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A reasoning layer invents a fact
&lt;/li&gt;
&lt;li&gt;A content layer writes it confidently
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You’ve produced &lt;em&gt;beautifully wrong output&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Critical rule:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Correction must happen &lt;strong&gt;before memory consolidation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Bad data in memory becomes permanent—and grows worse over time.&lt;/p&gt;




&lt;h2&gt;
  
  
  Major Takeaways
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What to remember
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Multilayered architectures compound transformations
&lt;/li&gt;
&lt;li&gt;Layer types give you a vocabulary for intentional design
&lt;/li&gt;
&lt;li&gt;Cyclical, circumstantial, and hybrid systems each have trade-offs
&lt;/li&gt;
&lt;li&gt;Backends handle what LLMs shouldn’t: randomness, persistence, determinism
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  System Prompt Generator Tool
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A great way to get started
&lt;/h3&gt;

&lt;p&gt;Available here:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://nicholasmgoldstein.com/system-prompt-generator" rel="noopener noreferrer"&gt;https://nicholasmgoldstein.com/system-prompt-generator&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prebuilt modular system prompt skeleton
&lt;/li&gt;
&lt;li&gt;Easy to extend with your own rulesets and logic
&lt;/li&gt;
&lt;li&gt;Copy into Notion, Docs, Word, or anywhere you work
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  External Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Repo: Build AI Platforms From Scratch&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/goldsteinnicholas/build-ai-platforms-from-scratch" rel="noopener noreferrer"&gt;https://github.com/goldsteinnicholas/build-ai-platforms-from-scratch&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;System Prompt Generator&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://nicholasmgoldstein.com/system-prompt-generator" rel="noopener noreferrer"&gt;https://nicholasmgoldstein.com/system-prompt-generator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Emstrata&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://emstrata.com/" rel="noopener noreferrer"&gt;https://emstrata.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PLATO5&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://plato5.us/" rel="noopener noreferrer"&gt;https://plato5.us/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>tutorial</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Official Emstrata Tutorial</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Sun, 14 Dec 2025 20:25:53 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/official-emstrata-tutorial-1628</link>
      <guid>https://dev.to/goldsteinnick/official-emstrata-tutorial-1628</guid>
      <description>&lt;h1&gt;
  
  
  Official Emstrata Tutorial
&lt;/h1&gt;

&lt;p&gt;Emstrata is an emergent narrative engine—a collaborative AI-powered platform where stories emerge like lived experiences. Unlike traditional storytelling where you follow a predetermined path, Emstrata simulations feel real and unpredictable, with outcomes that surprise everyone involved.&lt;/p&gt;

&lt;p&gt;The platform uses four AI systems working together (Discovery Layer, Narration Layer, Groundskeeper, and Chron-Con) to keep your story consistent while staying genuinely unpredictable. Stories emerge from your choices combined with unexpected complications the system throws at you, creating experiences that feel both spontaneous and coherent.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Get Started on Emstrata - Official Tutorial
&lt;/h2&gt;

&lt;p&gt;Learn how to get started with Emstrata and understand the platform's core features and interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Thesis&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The main story premise that guides your simulation. Think of it as the foundation of your story world—it stays consistent throughout, providing the "rules" of your reality while everything else evolves around it. A good Thesis gives you enough structure to stay coherent while leaving room for surprises.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sentience&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The difference between characters you control and those managed by the AI. You're the "sentient" character—the one making choices and driving the story forward. Everything else (other characters, the environment, the world's responses) is managed by Emstrata's AI systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Probabilities&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
When you take an action, the system calculates what could happen. It's like rolling dice, but the dice are weighted by the story context and your character's abilities. This means your actions can actually fail—success feels earned because failure was genuinely possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovery Layer&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The AI that figures out what happens when you act. It uses a coordinate-based mapping system (SPS) to track where you are and what's around you. When you open a door, travel somewhere new, or search a room, Discovery Layer decides what you find based on the story so far and what makes dramatic sense. It also tracks how your choices ripple outward and create consequences later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Narration Layer&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Where the magic happens—the AI turns everything into flowing prose. It takes Discovery Layer's decisions, Groundskeeper's memory of what's happened, and Chron-Con's quality checks, then writes the text you read. It handles both the shared story (what everyone sees) and "Your Eyes Only" sections (your character's private thoughts that other players can't see).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Groundskeeper&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The simulation's memory keeper. Groundskeeper tracks what the world knows, what each character knows, and what's still secret. It remembers relationships, environmental details, and story threads that become important later. When something gets revealed or circumstances change, Groundskeeper updates the simulation's knowledge so future events stay consistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chron-Con (Chronology Context)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The quality control system. Chron-Con checks generated text for logical consistency and catches mistakes. When it finds errors or contradictions, it fixes them on the spot. It also tracks character stats and logs which secrets get revealed, feeding that information back to Groundskeeper to keep everything straight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Motif Play&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The system notices recurring themes and symbols in your story and brings them back at perfect moments. These patterns emerge naturally from your actions and the AI's responses, then reappear later to create the kind of artistic resonance you find in great literature—except nobody planned it in advance.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Emstrata Cycle
&lt;/h3&gt;

&lt;p&gt;These four AI systems work together in a cycle: Discovery Layer figures out what happens, Narration Layer writes it, Chron-Con checks it for errors, and Groundskeeper remembers it for later. This lets the system stay creative and surprising while keeping everything consistent.&lt;/p&gt;




&lt;h3&gt;
  
  
  Platform Features
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Star Exceptional Responses&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Help us make Emstrata better by starring AI responses you think are great. Your feedback directly improves the platform for everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Share Your Simulations&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Upload your completed simulations for others to explore and build on. All you need is a thumbnail image. Sharing adds your story to Emstrata's library where it can become a starting point for other users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notes Function&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Click the notes button in the right sidebar to jot down thoughts, track important details, or mark story threads you want to explore. Your notes stick around for the whole simulation and help you keep track of what's happening.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;World Map&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
See where you are in your story's geography and what's around you. The map updates as you explore, helping you visualize how different locations connect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Turn Order Display&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
In multi-player simulations, this shows who's turn it is and what the rotation looks like. Keeps everyone coordinated about when they get to act.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text-to-Speech&lt;/strong&gt;&lt;br&gt;
Listen to your story as it unfolds. The audio narration adds another dimension to the experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI Image Generation (Coming Soon)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Visual generation capabilities will allow participants to create images of scenes, characters, and key moments from their simulations, adding a visual layer to the narrative.&lt;/p&gt;




&lt;h3&gt;
  
  
  Special Features
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Invisible Hand&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Want to nudge the story without breaking the flow? The Invisible Hand lets you whisper suggestions that the AI weaves naturally into the next passage. Instead of explicitly stating "I want X to happen," you use this to drop hints that appear seamlessly in the narrative. It's like having a magic wand that makes your ideas show up organically in the story.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protest Function&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Your quality control tool for keeping the story consistent. If the AI generates something that contradicts what's already happened or breaks the simulation's rules, hit the Protest Function. The system will acknowledge the mistake and smoothly correct it without breaking immersion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Injector System&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Emstrata throws complications at you 20% of the time to keep things unpredictable. When an injector fires, you see "Emstrata's Turn" instead of your input field—the simulation takes control and introduces chaos:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subversive Injectors (15% of turns)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Bring environmental complications—sudden weather changes, unexpected arrivals, missing items, or circumstances that throw off your plans.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Archetypal Injectors (5% of turns)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Introduce new characters who complicate your social dynamics and create fresh dramatic tension.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Afterlife Injectors&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Handle character death by turning it into a story transition instead of game over. Even after your character dies, you stay engaged with the narrative.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cascading Turns&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
When injectors fire on back-to-back turns affecting you, that's called "cascading" or "getting cascaded." You lose multiple turns in a row while the simulation throws chaos at you and can only watch. It's rare but intense—significantly raises the stakes and can destroy plans you were carefully building.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Art of Pela
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pela (Performing Emergent Lives Artistically)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Pela is the artistic discipline of collaborative storytelling through AI-mediated simulation. Like jazz improvisation, Pela combines structure with spontaneity—you and the AI co-create narratives that neither of you could make alone.&lt;/p&gt;

&lt;p&gt;The best Pela moments happen when the collaboration creates something unexpected but perfect, when the simulation surprises everyone involved, when you forget you're working with an AI and just experience the story. You can't force these moments, but Emstrata creates the conditions where they can happen.&lt;/p&gt;

&lt;p&gt;Pela is a new art form with its own strengths and limitations—stories that feel lived rather than written, narratives that emerge from exploration rather than planning, fiction created through the collaboration between human creativity and AI capability.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>architecture</category>
      <category>learning</category>
    </item>
    <item>
      <title>The Common Roadblocks for AI Storytelling</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Sun, 14 Dec 2025 20:21:28 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/the-common-roadblocks-for-ai-storytelling-1m69</link>
      <guid>https://dev.to/goldsteinnick/the-common-roadblocks-for-ai-storytelling-1m69</guid>
      <description>&lt;h1&gt;
  
  
  Roadblocks in AI Storytelling and How Emstrata Solves Them
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;By The Emstrata Team&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;AI storytelling systems face a consistent set of technical and philosophical problems that undermine their ability to create coherent, engaging collaborative narratives. These aren't minor bugs or edge cases but fundamental architectural challenges. Understanding these roadblocks is essential because they determine whether systems enhance human creativity or frustrate it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Redescription: "The Consistency Problem"
&lt;/h2&gt;

&lt;p&gt;Redescription occurs when an AI inconsistently recontextualizes previously established simulation elements.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A character might shift from "the young merchant with calloused hands" to "the elderly innkeeper with soft palms" with no explanation.
&lt;/li&gt;
&lt;li&gt;Locations can suddenly change size or purpose arbitrarily.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; LLM memory limitations and context drift. Earlier descriptions fall out of active memory, and the AI regenerates based on partial context.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact:&lt;/strong&gt; Destroys narrative trust. Participants cannot invest in a world where facts shift arbitrarily.&lt;/p&gt;




&lt;h2&gt;
  
  
  Probability Punditry: The Convenience Problem
&lt;/h2&gt;

&lt;p&gt;Probability Punditry occurs when AI biases outcomes toward convenient, dramatically satisfying results.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A participant finds a hidden item immediately because the AI needs the plot to advance.
&lt;/li&gt;
&lt;li&gt;Dangerous situations resolve safely because death would be inconvenient.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; AI conflates "good storytelling" with "convenient plotting."  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact:&lt;/strong&gt; Erodes collaborative uncertainty; outcomes feel hollow because success is guaranteed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Entity Drift: The Erosion Problem
&lt;/h2&gt;

&lt;p&gt;Entity Drift is the gradual, unjustified shift in an entity’s traits, behaviors, or abilities.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Characters act against their established personality.
&lt;/li&gt;
&lt;li&gt;Locations or objects change properties without narrative cause.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Difference from Redescription:&lt;/strong&gt; Redescription is contradictory description; Entity Drift is inconsistent development over time.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact:&lt;/strong&gt; Makes long-term narrative investment impossible; character arcs lose coherence.&lt;/p&gt;




&lt;h2&gt;
  
  
  Groundless Sims: The Structure Problem
&lt;/h2&gt;

&lt;p&gt;Groundless Sims lack structural foundation in genres, arcs, or thematic coherence.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Events happen, but nothing matters.
&lt;/li&gt;
&lt;li&gt;Simulations generate text, not story.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; AI prioritizes immediate responsiveness over meaningful narrative structure.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact:&lt;/strong&gt; Participants ask "what's the point?" as the simulation fails to engage beyond novelty.&lt;/p&gt;




&lt;h2&gt;
  
  
  Shielding Breaks: The Information Problem
&lt;/h2&gt;

&lt;p&gt;Shielding Breaks occur when information compartmentalization fails.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Characters know secrets they shouldn’t.
&lt;/li&gt;
&lt;li&gt;Participants’ private thoughts leak into public knowledge.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Impact:&lt;/strong&gt; Breaks trust, ruins mystery, and collapses dramatic tension. Essential narrative mechanics fail.&lt;/p&gt;




&lt;h2&gt;
  
  
  Replacementism: The Philosophical Problem
&lt;/h2&gt;

&lt;p&gt;Replacementism is the belief that AI should or will replace human creativity in storytelling.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Systems generate complete stories with minimal human input.
&lt;/li&gt;
&lt;li&gt;AI prioritizes "optimal" outcomes over participant agency.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Impact:&lt;/strong&gt; Misunderstands narrative value. Human intuition, emotion, and lived experience are irreplaceable in creating meaningful stories.&lt;/p&gt;




&lt;h2&gt;
  
  
  Emstrata's Architectural Solutions
&lt;/h2&gt;

&lt;p&gt;Emstrata addresses these roadblocks with a &lt;strong&gt;multi-layer architecture and design philosophy&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Groundskeeper:&lt;/strong&gt; Persistent memory to prevent Redescription and Entity Drift.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chron Con:&lt;/strong&gt; Real-time consistency verification and continuity enforcement.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit Probability Mechanics:&lt;/strong&gt; Weighted randomness preserves genuine uncertainty.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Genre and Dramatic Frameworks:&lt;/strong&gt; Maintain structure to prevent Groundless Sims.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Information Compartmentalization:&lt;/strong&gt; Ensures logical knowledge boundaries to prevent Shielding Breaks.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human-Centric Philosophy:&lt;/strong&gt; Features like the Invisible Hand and Protest Function prioritize human creative agency over AI control.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Reliable, coherent, and engaging collaborative storytelling where AI supports rather than replaces participants.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Architecture Matters
&lt;/h2&gt;

&lt;p&gt;Surface-level fixes are insufficient. Comprehensive architectural solutions are required to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maintain entity consistency
&lt;/li&gt;
&lt;li&gt;Ensure genuine probabilistic outcomes
&lt;/li&gt;
&lt;li&gt;Provide structural and thematic coherence
&lt;/li&gt;
&lt;li&gt;Protect information boundaries
&lt;/li&gt;
&lt;li&gt;Uphold human creative agency
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Emstrata demonstrates one approach, but these roadblocks are universal. How you solve them determines whether AI storytelling technology &lt;strong&gt;enhances or undermines human creativity&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>writing</category>
      <category>llm</category>
      <category>architecture</category>
      <category>ai</category>
    </item>
    <item>
      <title>Introduction to Pela</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Sun, 14 Dec 2025 20:17:54 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/introduction-to-pela-h47</link>
      <guid>https://dev.to/goldsteinnick/introduction-to-pela-h47</guid>
      <description>&lt;h1&gt;
  
  
  Pela: Performing Emergent Lives Artistically with AI
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;By The Emstrata Team&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pela&lt;/strong&gt; stands for &lt;em&gt;Performing Emergent Lives Artistically&lt;/em&gt;, the artistic discipline of collaborative storytelling through AI-mediated narrative simulation. It represents a fundamental shift in how we think about narrative creation, moving away from the author-as-sole-creator model toward something closer to live performance art.  &lt;/p&gt;

&lt;p&gt;Where traditional storytelling involves a writer crafting a fixed narrative that readers consume passively, Pela treats narrative as a living, breathing collaboration between human participants and sophisticated AI systems. The result is stories that emerge rather than being written, experiences that feel lived rather than read, and outcomes that surprise everyone involved, including the systems generating them.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Core Insight of Pela
&lt;/h2&gt;

&lt;p&gt;The most compelling narratives aren’t always the ones meticulously plotted in advance. Sometimes the best stories come from &lt;strong&gt;structured improvisation&lt;/strong&gt;: setting up the right conditions and constraints and then letting something unexpected emerge.  &lt;/p&gt;

&lt;p&gt;This is why jazz remains vital, why improv theater can feel electrifying, and why tabletop RPG sessions can be more memorable than most novels. Pela captures that improvisational energy while leveraging AI to maintain &lt;strong&gt;narrative coherence, continuity, and dramatic structure&lt;/strong&gt; at a scale impossible for humans alone.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Emstrata Cycle
&lt;/h2&gt;

&lt;p&gt;Pela is made possible by &lt;strong&gt;Emstrata's multi-layer AI architecture&lt;/strong&gt;, the Emstrata Cycle. It employs four distinct AI layers working in concert:&lt;/p&gt;

&lt;h3&gt;
  
  
  Groundskeeper
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Serves as the simulation's institutional memory and secret keeper
&lt;/li&gt;
&lt;li&gt;Tracks who knows what and ensures continuity when secrets are revealed
&lt;/li&gt;
&lt;li&gt;Maintains a living knowledge base so the world remains consistent
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Discovery Layer
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Handles spatial reasoning and consequence planning via the SPS (Simulation Positioning System)
&lt;/li&gt;
&lt;li&gt;Determines what exists beyond participants’ immediate perception
&lt;/li&gt;
&lt;li&gt;Plans ripple effects of participant actions to ensure decisions feel earned
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Narration Layer
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The prose engine generating the narrative text participants read
&lt;/li&gt;
&lt;li&gt;Synthesizes structural decisions from Discovery Layer and continuity from Groundskeeper
&lt;/li&gt;
&lt;li&gt;Handles &lt;strong&gt;Your Eyes Only&lt;/strong&gt; sections, revealing private character thoughts and interpretations
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Chron Con (Chronology Context)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Continuity enforcer and quality control system
&lt;/li&gt;
&lt;li&gt;Detects errors, contradictions, and timeline breaks, correcting them in real-time
&lt;/li&gt;
&lt;li&gt;Manages character stat adjustments and logs secret/memory revelations
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Engineering Unpredictability
&lt;/h2&gt;

&lt;p&gt;AI narrative generation tends toward &lt;strong&gt;convenience bias&lt;/strong&gt;, producing predictable or overly neat outcomes. Emstrata combats this with its &lt;strong&gt;injector system&lt;/strong&gt;, introducing structured unpredictability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subversive Injectors&lt;/strong&gt; (15% chance): environmental changes or complications
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Archetypal Injectors&lt;/strong&gt; (5% chance): new characters altering social dynamics
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Afterlife Injectors&lt;/strong&gt;: handle character death, allowing new narrative possibilities
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Additionally, &lt;strong&gt;probability rolls&lt;/strong&gt; throughout the Emstrata Cycle introduce weighted randomness, ensuring outcomes are meaningful and not predetermined.&lt;/p&gt;




&lt;h2&gt;
  
  
  Practical Applications Beyond Art
&lt;/h2&gt;

&lt;p&gt;While Pela represents Emstrata’s highest artistic expression, the technology also enables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Experiential learning&lt;/strong&gt;: immersive, consequence-free simulations for language learning, history, or other skills
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skills development&lt;/strong&gt;: realistic practice environments for negotiation, crisis response, management, and more
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Role-playing and interactive fiction&lt;/strong&gt;: AI acting as flexible game master maintaining consistency
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scenario planning &amp;amp; strategic exploration&lt;/strong&gt;: testing decisions and second-order effects in complex simulated environments
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The line between art and utility is fluid; simulations can be educational, entertaining, or artistically meaningful simultaneously.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Artistic Ethos
&lt;/h2&gt;

&lt;p&gt;Pela emphasizes &lt;strong&gt;emotional truth and narrative craft&lt;/strong&gt;. Its artistic challenge lies in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collaborating effectively with AI
&lt;/li&gt;
&lt;li&gt;Knowing when to guide or release control
&lt;/li&gt;
&lt;li&gt;Setting up conditions for emergent narrative without over-determining outcomes
&lt;/li&gt;
&lt;li&gt;Developing aesthetic judgment for simulation premises and narrative threads
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best Pela moments occur when the simulation produces something neither participant nor AI intended, but both recognize as true — when narrative logic leads to unexpected yet inevitable outcomes.&lt;/p&gt;




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

&lt;p&gt;Pela doesn’t replace traditional storytelling; it offers a &lt;strong&gt;new medium&lt;/strong&gt;. Like photography expanded visual art, Pela expands narrative art: storytelling that feels lived rather than written, exploration rather than exposition, fiction emerging from collaboration between human creativity and machine capability.  &lt;/p&gt;

&lt;p&gt;It is early days for the art form, but the &lt;strong&gt;core insight is clear&lt;/strong&gt;: structured emergence has intrinsic artistic value, and Pela is the discipline of learning to harness it effectively.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>architecture</category>
      <category>learning</category>
    </item>
    <item>
      <title>The Emstrata Toolset: Building Better Collaborative Narratives</title>
      <dc:creator>Nick Goldstein</dc:creator>
      <pubDate>Sun, 14 Dec 2025 20:14:22 +0000</pubDate>
      <link>https://dev.to/goldsteinnick/the-emstrata-toolset-building-better-collaborative-narratives-4kon</link>
      <guid>https://dev.to/goldsteinnick/the-emstrata-toolset-building-better-collaborative-narratives-4kon</guid>
      <description>&lt;h1&gt;
  
  
  Emstrata: Designing Tools for Collaborative AI Storytelling
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;By The Emstrata Team&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Emstrata's feature set reflects a fundamental design philosophy: collaborative storytelling requires tools that enhance human creative agency rather than replace it. Every feature serves one of three purposes: maintaining narrative integrity, enabling collaborative control, or reducing friction in the creative process. This isn't a kitchen-sink approach where features get added just because they're technically possible. Each capability exists to solve a specific problem that emerges from the architectural challenges of AI-mediated narrative simulation.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Narrative Control and Intervention
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Invisible Hand
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Invisible Hand&lt;/strong&gt; allows participants to weave narrative elements into the story without taking direct character action. Want a rainstorm to start, a character to arrive, or a complication to emerge naturally? The Invisible Hand injects these elements as authorial interventions rather than participant actions, preserving character integrity while enabling narrative orchestration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Protest Function
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Protest Function&lt;/strong&gt; addresses error compounding, a common issue in AI-generated narratives. Participants can immediately reject AI-generated content that is inconsistent or unhelpful, triggering regeneration that corrects the issue. It also allows creative control: if a narrative direction is uninteresting, participants can guide the AI toward more compelling possibilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Orchestrator Mode
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Orchestrator Mode&lt;/strong&gt; provides the most comprehensive level of narrative control. It lets users:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit probability parameters before rolls
&lt;/li&gt;
&lt;li&gt;Modify final instructions to the Narration Layer
&lt;/li&gt;
&lt;li&gt;Predefine injector system notes for future AI interventions
&lt;/li&gt;
&lt;li&gt;Manipulate simulation state beyond direct character actions
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is invaluable for designers, educators, and artists seeking fine-grained control while retaining the benefits of Emstrata's continuity systems and probability-driven narrative mechanics.&lt;/p&gt;




&lt;h2&gt;
  
  
  Collaborative Infrastructure
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Multi-Participant Simulations
&lt;/h3&gt;

&lt;p&gt;These allow turn-based collaboration with multiple characters, perspectives, and information streams. Participants can form alliances, pursue intersecting agendas, or compete, while the AI manages coherence and world state.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simulation Positioning System (SPS)
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;SPS&lt;/strong&gt; provides spatial and logical consistency. It defines what participants perceive based on their location, ensuring that environments remain stable and interactions remain meaningful across participants.&lt;/p&gt;




&lt;h2&gt;
  
  
  Knowledge Management and Sharing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Note-Taking &amp;amp; Note Pack Sharing
&lt;/h3&gt;

&lt;p&gt;Participants can capture insights without affecting the canonical narrative. &lt;strong&gt;Note Pack Sharing&lt;/strong&gt; allows these collections to be shared across the community, reducing repetitive discovery while preserving personal engagement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sim Templates &amp;amp; Template Publishing
&lt;/h3&gt;

&lt;p&gt;Successful simulation designs can be codified into templates and published for others to instantiate. This builds a community library of proven narrative structures while allowing each simulation to evolve uniquely.&lt;/p&gt;




&lt;h2&gt;
  
  
  Character and World Tracking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  HET Stats
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Health, Essence, Tether (HET)&lt;/strong&gt; track character state across physical, capability, and psychological dimensions. These stats inform AI behavior subtly, creating coherent character progression without manual tracking or rigid mechanics.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quality of Life Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Text-to-Speech&lt;/strong&gt;: Enables hands-free participation or alternative modes of engagement.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your Eyes Only Sections&lt;/strong&gt;: Private narrative content, hidden information, and internal character thoughts remain inaccessible to other participants, maintaining immersion and information compartmentalization.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Creative Support Tools
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Emory Chatbot
&lt;/h3&gt;

&lt;p&gt;Emory helps participants brainstorm, develop simulation concepts, and structure narratives without writing the story for them. It bridges creative ideas and executable simulation architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  In-Sim Inquiries
&lt;/h3&gt;

&lt;p&gt;Participants can query Emory about locations, characters, or events within active simulations. This provides contextual information without breaking immersion or revealing unknown secrets.&lt;/p&gt;




&lt;h2&gt;
  
  
  Design Philosophy
&lt;/h2&gt;

&lt;p&gt;All features share a common thread: enhancing participant agency without limiting AI capability, maintaining narrative integrity while enabling flexibility, and reducing friction without sacrificing depth. Emstrata systematically addresses practical challenges in collaborative AI storytelling, ensuring humans and AI co-create narratives neither could produce alone.&lt;/p&gt;

</description>
      <category>writing</category>
      <category>tooling</category>
      <category>design</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
