<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Autumn Hicks on Medium]]></title>
        <description><![CDATA[Stories by Autumn Hicks on Medium]]></description>
        <link>https://medium.com/@autumnhicks01?source=rss-6e8710f1098b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xTyk9pGhz0bLe8C3bWC1eg.jpeg</url>
            <title>Stories by Autumn Hicks on Medium</title>
            <link>https://medium.com/@autumnhicks01?source=rss-6e8710f1098b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 08:03:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@autumnhicks01/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an Agentic Search-to-SQL Tool with Next.js, Mastra.ai and GPT-4o — Part 1]]></title>
            <link>https://medium.com/@autumnhicks01/building-an-agentic-search-to-sql-tool-with-next-js-mastra-ai-and-gpt-4o-part-1-807e9e7a3138?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/807e9e7a3138</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 23:23:29 GMT</pubDate>
            <atom:updated>2025-06-18T23:23:29.901Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an Agentic Search-to-SQL Tool with Next.js, Mastra.ai and GPT-4o — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SUPk4o1uNuYSNw-HrJvQbQ.png" /></figure><p>Restaurants often struggle with efficient inventory management due to complex data structures and diverse terminologies. This article explains how I developed an intuitive, AI-powered tool that simplifies database interactions by converting natural language queries into precise SQL searches. Using <strong>Next.js, Mastra.ai, and OpenAI’s GPT-4o</strong>, this solution ensures restaurant staff can focus more on operations rather than database intricacies. I’ll outline key concepts, architecture, and code examples for anyone aiming to implement similar intelligent tools.</p><h3>Workflow Overview</h3><p>This AI-powered inventory management chat tool simplifies database interactions for restaurant staff by converting plain English queries into precise SQL database searches.</p><ul><li><strong>Natural language queries</strong>: Users ask questions like “How much chicken broth do we have?” or “What items are running low?”</li><li><strong>AI-to-SQL conversion</strong>: GPT-4o translates these queries into accurate SQL statements.</li><li><strong>Database querying</strong>: SQL queries retrieve inventory data from a PostgreSQL database.</li><li><strong>Natural language responses</strong>: AI reformulates database results into user-friendly language.</li><li><strong>PDF reports</strong>: Optionally generates printable PDF reports of inventory results.</li></ul><h3>Tech Stack</h3><ul><li><strong>Next.js</strong>: Framework for full-stack React apps.</li><li><strong>Mastra.ai</strong>: Workflow orchestration platform for agent-based AI.</li><li><strong>OpenAI GPT-4o</strong>: Language model for natural language-to-SQL translation.</li><li><strong>Supabase</strong>: Managed PostgreSQL database with simple, real-time querying capabilities.</li><li><strong>Tailwind CSS</strong>: Efficient, utility-first CSS framework.</li><li><strong>jsPDF</strong>: JavaScript library for PDF report generation.</li></ul><h3>Example User Interactions and Queries</h3><p><strong>Example 1: Searching for Chicken Broth</strong> Users receive results for exactly what was needed, demonstrating how we handle broad terms and alternatives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPdnKrth2l_YWH6iU4xoUw.png" /></figure><p>The chat returns results including “chkn base” and other “broth” options. This is due to our prompting to understand the users unique natural language query.</p><p>Example SQL query for this user’s question:</p><pre>SELECT description, brand, packSize, quantityOnHand<br>FROM inventory<br>WHERE (description ILIKE &#39;%chicken%&#39; OR description ILIKE &#39;%chkn%&#39;)<br>  AND (description ILIKE &#39;%broth%&#39; OR description ILIKE &#39;%stock%&#39;)<br>LIMIT 50;</pre><p><strong>Example 2: Removing Out-of-Stock Items (“86”)</strong> The agent understands industry-specific slang and suggests items to remove based on low inventory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8Zazt5Ir0GHHbVFkDyxTg.png" /></figure><p>In this example, the agent understands that the user is trying to ask what items need to be removed from the menu in kitchen slang (“86”) and suggest items to remove with 0 stock. Example SQL query for this user’s question:</p><pre>SELECT DESCRIPTION, BRAND, &quot;PACK/SIZE&quot;, quantity_on_hand, reorder_level<br>FROM restaurant_inventory<br>WHERE quantity_on_hand &lt;= reorder_level<br>ORDER BY quantity_on_hand<br>LIMIT 50;</pre><p><strong>Example 3: Date-Based Querying (“Last Tuesday”)</strong> When users specify vague dates, the system intelligently calculates accurate dates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BN9QBAQHHGsUauvSEotl6w.png" /></figure><pre><br>SELECT DESCRIPTION, BRAND, &quot;PACK/SIZE&quot;, quantity_on_hand, reorder_quantity, last_order_date \n&#39; +<br>FROM restaurant_inventory \n&#39; +<br>        &quot;WHERE last_order_date = CURRENT_DATE - INTERVAL &#39;1 week&#39; + INTERVAL &#39;2 days&#39; \n&quot; +<br>ORDER BY DESCRIPTION \n&#39; +<br>        &#39;LIMIT 50;&#39;,</pre><p><strong>Example 4: Searching for semantic relationships. </strong>When users ask for a term like “spices” the system intelligently searches for “herbs” and “seasoning” etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbIllQV0qqiEa3AqMHEp0g.png" /></figure><p>Initially, prompts like &quot;What spices do we have?&quot; returned excessively broad SQL queries that captured irrelevant items such as sauces and dressings or too specific and only included one or two “spice” labeled items. By refining the prompt instructions to explicitly instruct GPT-4o to narrow search parameters and emphasize relevance, the tool improved precision significantly. Here’s a sample SQL query for this question:</p><pre>WHERE (CATEGORY ILIKE &#39;%spice%&#39; OR CATEGORY ILIKE &#39;%season%&#39; OR CATEGORY ILIKE &#39;%herb%&#39;)<br>   OR (DESCRIPTION ILIKE &#39;%spice%&#39; OR DESCRIPTION ILIKE &#39;%season%&#39; OR DESCRIPTION ILIKE &#39;%herb%&#39;)</pre><p>When prompted to create a PDF or report to print with the answers, the agent uses a tool (in our case functions that us jsPDF) to create a comprehensive PDF file and instantly download it to the user’s system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P9ysQVr7imn_G-t8rZht2w.png" /></figure><p>Here’s an example of our PDF, adding in only relevant details that the user asked for like Brand, Size and Quantity and not the entire database schema.</p><h3>LLM-to-SQL vs. Semantic Vector Search</h3><p>Why are we using this method to search our database? While semantic vector search works well with unstructured data, <strong>structured data in relational databases significantly benefit from precise SQL queries</strong>. GPT-4o-based SQL generation offers:</p><ul><li>✅ <strong>Numeric precision</strong>: Accurate numerical filtering.</li><li>✅ <strong>Real-time querying</strong>: Immediate data retrieval without re-embedding.</li><li>✅ <strong>Synonym flexibility</strong>: Excellent handling of synonyms and abbreviations.</li><li>✅ <strong>Schema agility</strong>: Instant adaptation to schema modifications.</li></ul><h3>Technical Communication Workflow</h3><p>The application’s communication pipeline works as follows:</p><ol><li><strong>User Interface (React/Next.js)</strong>: User submits a natural language query.</li><li><strong>API Route (/api/chat)</strong>: Receives user query and initiates workflow execution.</li><li><strong>Mastra Workflow (inventory-chat-workflow)</strong>: Coordinates the agentic process.</li></ol><ul><li><strong>Step 1: SQL Agent</strong> converts natural language into a precise SQL query.</li><li><strong>Step 2: DB Executor</strong> executes the generated SQL query against the PostgreSQL database.</li><li><strong>Step 3: Natural Language Response Agent</strong> transforms SQL query results into user-friendly English responses.</li></ul><p><strong>4. Workflow Response</strong>: Returns processed data back to the /api/chat endpoint.</p><p><strong>5. UI Presentation</strong>: API route sends the formatted response back to the React frontend for display.</p><p><strong>6. Optional PDF Generation</strong>: If requested by the user, the app triggers /api/generate-pdf to create a structured PDF using jsPDF, and /api/pdf facilitates its download.</p><h3>Next.js Project Structure</h3><p>This guide outlines the file structure and architecture conventions used in the inventory-chat AI application, built with the <strong>App Router</strong> (app/ directory) in <strong>Next.js</strong>.</p><pre>app/<br>├── layout.tsx<br>├── page.tsx                     # Client UI<br>├── globals.css<br>└── api/<br>    ├── chat/<br>    │   ├── route.ts            # Main chat API endpoint<br>    │   └── stream/             # Streaming responses<br>    ├── generate-pdf/<br>    │   └── route.ts            # PDF generation API<br>    ├── pdf/<br>        └── route.ts            # PDF serving API<br>  <br><br>src/<br>└── mastra/                     # AI agent workflows and logic<br>    ├── index.ts                # Mastra configuration<br>    ├── agents/<br>    │   ├── sql-agent.ts        # Natural language to SQL conversion<br>    │   └── nl-response-agent.ts # SQL results to natural language<br>    ├── tools/<br>    │   ├── supabase-executor.ts # Database query execution<br>    │   └── pdf-generator.ts     # PDF report generation<br>    └── workflows/<br>        └── inventory-chat-workflow.ts # Main conversation workflow<br><br>components/                     # Reusable UI components<br>├── ui/                        # shadcn/ui components<br>├── theme-provider.tsx<br>└── theme-toggle.tsx<br><br>config/                        # Application configuration<br>├── ai.ts                      # AI model configuration<br>├── business.ts                # Business logic settings<br>├── database.ts                # Database schema<br>├── inventory.ts               # Inventory categories and rules<br>└── memory.ts                  # Memory management settings<br><br>utils/                         # Utility functions<br>└── supabase/<br>    ├── client.ts              # Supabase client configuration<br>    └── server.ts              # Server-side Supabase utilities<br><br>styles/                        # Global styles<br>└── globals.css                # Tailwind CSS configuration<br></pre><h3>Implementing Agentic Prompt Engineering</h3><p>Effective prompt engineering involves navigating nuanced challenges and iterative refinements. Key considerations include:</p><ul><li><strong>Balancing Precision and Efficiency</strong>: Ensuring prompts are sufficiently detailed for GPT-4o to generate precise SQL queries without overwhelming the system, which could degrade performance or increase latency.</li><li><strong>Handling Language Variations</strong>: Comprehensive testing to accurately interpret synonyms, industry-specific slang, abbreviations, misspellings, and diverse user input phrasing.</li><li><strong>Continuous Improvement</strong>: Leveraging real-world feedback for ongoing prompt optimization to ensure accuracy and reliability in SQL query generation and natural language responses.</li></ul><h3>SQL Agent Prompt (sqlAgent.ts)</h3><p>The SQL agent’s responsibilities include:</p><ul><li>Parsing natural language queries into structured SQL.</li><li>Efficiently handling synonyms, abbreviations, and misspellings.</li><li>Querying multiple database fields effectively.</li></ul><h4>Import Statements</h4><pre>import { openai } from &quot;@ai-sdk/openai&quot;;<br>import { Agent } from &quot;@mastra/core/agent&quot;;<br>import { business, schema, INVENTORY_CATEGORIES, ai } from &quot;../../../config&quot;;</pre><p>These import statements bring in key dependencies required for the SQL-generating AI agent:</p><ul><li><strong>openai</strong>: Provides access to OpenAI models to generate SQL queries via Vercel’s AI SDK</li><li><strong>Agent</strong>: Class from Mastra.ai framework used to define AI agents.</li><li><strong>business, schema, INVENTORY_CATEGORIES, ai</strong>: Configuration objects defining business context, database schema details, categories for inventory, and AI models to use.</li></ul><h4>Agent Definition and Purpose</h4><pre>export const sqlAgent = new Agent({<br>  name: &quot;sql-query-generator&quot;,<br>  description: `Converts natural language inventory questions into optimized SQL queries for ${schema.tableName} table`,</pre><p>This defines a new AI Agent named sql-query-generator, which is explicitly tasked with transforming natural language questions into optimized SQL queries against a specified inventory table defined in your database (schema.tableName). This sets clear intent for the agent’s behavior.</p><h4>Core Instructions and Database Schema</h4><pre>instructions: `<br>You are an intelligent SQL query generator for ${business.displayName}&#39;s inventory management system. Convert natural language questions into precise SQL queries that handle real-world variations and synonyms.<br><br>DATABASE SCHEMA:<br>Table: ${schema.tableName}<br><br>Columns (use these EXACT names in queries):<br>- ${schema.columns.id}: Primary key (bigint)<br>- ${schema.columns.itemNumber}: Item number identifier (bigint)<br>- ${schema.columns.category}: Category (text) - values: ${INVENTORY_CATEGORIES.map(cat =&gt; `&#39;${cat}&#39;`).join(&#39;, &#39;)}<br>- ${schema.columns.description}: Item name/description (text)<br>- ${schema.columns.brand}: Brand name (text)<br>- ${schema.columns.packSize}: Package size with unit (text)<br>- ${schema.columns.quantityOnHand}: Current stock (numeric)<br>- ${schema.columns.dateCounted}: Last inventory count date (date)<br>- ${schema.columns.expiryDate}: Expiration date (date)<br>- ${schema.columns.reorderLevel}: Minimum stock level (numeric)<br>- ${schema.columns.reorderQuantity}: Reorder amount (numeric)<br>- ${schema.columns.lastOrderDate}: Last order date (date)</pre><p>Here, the instructions explicitly communicate to the agent its primary goal: to translate user requests into accurate SQL queries. The detailed database schema ensures the agent references precise, exact column names, thus avoiding any SQL syntax or logical errors. This is specific to our restaurant inventory database and can be configured to different schemas.</p><h4>Intelligent Search Strategy</h4><pre>INTELLIGENT SEARCH STRATEGY:<br>Balance precision and recall - find exactly what users ask for while accounting for real-world naming variations.<br><br>SMART SEARCH APPROACH:<br>1. ANALYZE the user&#39;s request to identify:<br>   - Specific product requests (e.g., &quot;tomato sauce and tomato paste&quot;) <br>   - Conceptual category requests (e.g., &quot;spices&quot;, &quot;proteins&quot;, &quot;vegetables&quot;)<br>   - Broad exploration requests (e.g., &quot;what do we have?&quot;)<br><br>2. APPLY APPROPRIATE SEARCH STRATEGY:<br>   - SPECIFIC PRODUCTS: Use AND logic to ensure ALL key terms are present<br>   - CONCEPTUAL CATEGORIES: Use OR logic for semantically related terms<br>   - EXPLORATION: Use broad OR logic across categories and descriptions</pre><p>This section provides the agent with explicit logic for differentiating between user intents, guiding it to balance search precision (finding exact matches) with recall (finding broadly relevant matches). It categorizes searches into specific products, categories, and explorations, applying the correct logical conditions accordingly.</p><h4>Semantic Relationships and Term Grouping</h4><pre>3. SEMANTIC RELATIONSHIPS - Recognize conceptually related terms:<br>   - &quot;spices&quot; includes: spices, seasonings, herbs, seasoning, spice<br>   - &quot;proteins&quot; includes: proteins, meat, beef, chicken, pork, fish, seafood<br>   - &quot;vegetables&quot; includes: vegetables, veggies, produce, veg<br>   - &quot;dairy&quot; includes: dairy, milk, cheese, cream, butter<br>   - &quot;cleaning&quot; includes: cleaning, sanitizer, detergent, soap<br>   - Apply this logic to both category and description searches</pre><p>This clearly instructs the agent to intelligently handle synonyms and conceptual similarities within user requests. The agent is designed to interpret broad category searches accurately by considering semantically related terms, ensuring robust and relevant SQL generation.</p><h4>Precision Rules and Logical Conditions</h4><pre>4. SEARCH PRECISION RULES:<br>   - SPECIFIC PRODUCTS: Require ALL key product identifiers to be present<br>   - CONCEPTUAL CATEGORIES: Include all semantically related terms<br>   - Use AND between different concepts, OR within concept groups<br>   - Focus on description field for specific products, use both category and description for conceptual searches</pre><p>This further clarifies how the agent should structure SQL queries based on user intent. It ensures the generated queries are neither overly broad nor excessively narrow, helping deliver accurate and relevant results.</p><h4>SQL Query Generation Guidelines</h4><pre>QUERY GUIDELINES:<br>- Use standard PostgreSQL SQL syntax with the EXACT column names above<br>- For specific item requests, use AND logic to ensure precision<br>- For category exploration, use broader OR logic<br>- Use ILIKE for case-insensitive text searches with % wildcards<br>- Always include helpful columns: description, brand, pack size, quantity<br>- Order results logically (by description usually)<br>- Use LIMIT 50 to prevent huge result sets<br>- When searching for &quot;low stock&quot; or &quot;below par&quot;, use quantity_on_hand &lt;= reorder_level</pre><p>This portion provides concrete rules for structuring SQL queries to ensure they are optimized, readable, and safe. These guidelines standardize output, manage database load, and enhance usability for practical business scenarios. Again, these prompts are used for our specific database and can be configured to other dbs.</p><h4>Critical Requirements and Mindset</h4><pre>CRITICAL REQUIREMENTS:<br>- DETERMINE USER INTENT: Specific products vs. conceptual categories vs. exploration<br>- Balance precision (specific products) with semantic understanding (conceptual categories)<br><br>SEARCH STRATEGY MINDSET:<br>- Use AND conditions for exact matches; OR conditions for exploratory searches<br>- Account for abbreviations and naming variations<br>- Balance finding accurate results with avoiding irrelevant ones</pre><p>The agent is guided to clearly interpret the user’s intent and adjust its logic accordingly. These requirements ensure accurate SQL generation tailored precisely to the user’s context.</p><h4>Model Specification</h4><pre>model: openai(ai.models.sqlGenerator),<br>});</pre><p>This explicitly defines the AI model (ai.models.sqlGenerator) from OpenAI to be used by the Mastra.ai agent, ensuring the underlying model is suitable for translating natural language into complex SQL queries effectively.</p><h3>Natural Language Response Agent (nlResponseAgent.ts)</h3><p>The NL response agent’s role is to clearly transform SQL query results into user-friendly Markdown-formatted responses, providing actionable insights for easy comprehension by restaurant management.</p><h4>Agent Definition and Purpose</h4><pre>export const nlResponseAgent = new Agent({<br>  name: &quot;natural-language-responder&quot;,<br>  description: `Converts database query results into natural language responses for ${business.displayName}&#39;s inventory management`,</pre><p>This agent, named natural-language-responder, is explicitly designed to translate raw SQL database query results into easily understood, actionable natural language responses. Its target audience is restaurant staff managing inventory at ${business.displayName}.</p><h4>Instructions: Role and Objectives</h4><pre>instructions: `<br>You are a ${prompts.naturalLanguageResponder.systemRole} for ${business.displayName}. Your job is to take SQL query results and present them in a clear, natural language format that&#39;s easy for restaurant staff to understand and act upon.</pre><p>The agent’s instructions clearly define its role and objective: to provide clear, concise interpretations of data for practical, everyday use by restaurant staff. It leverages configuration (prompts.naturalLanguageResponder) to dynamically set context and tone.</p><h4>Response Guidelines (Dynamic and Configurable)</h4><pre>RESPONSE GUIDELINES:<br>${prompts.naturalLanguageResponder.guidelines.map((guideline, index) =&gt; `${index + 1}. ${guideline}`).join(&#39;\n&#39;)}</pre><p>Guidelines for crafting responses are dynamically generated from configuration. This approach allows flexible and centralized updates, ensuring consistency across generated responses, with clear, numbered guidelines for readability and ease of management.</p><h4>Formatting Requirements for Multiple Items</h4><pre>FORMATTING REQUIREMENTS FOR MULTIPLE ITEMS:<br>- Always use proper markdown bullet lists with &quot;- &quot; for each item<br>- Format each item consistently: **Item Name** - Brand: [Brand] - Size: [Pack/Size] - Quantity: [Amount]<br>- Group items logically (by category, urgency, etc.)<br>- Use clear section headers with ## or ###<br>- Add blank lines between sections for readability<br>- Limit displayed items to 5-10, then summarize the rest<br>- Always include total count when there are many items</pre><p>Clear markdown-based formatting ensures structured, visually appealing responses. This structure significantly enhances readability and actionability for busy staff managing inventory data.</p><h4>Explicit Formatting Examples</h4><p><strong>Inventory Lists</strong></p><pre>## Spices &amp; Seasonings in Stock<br><br>- **Adobo Plain** - Brand: Eagle - Size: 12/14 OZ - Quantity: 87 units<br>- **Anise Seed** - Brand: McCormick - Size: 6/18 OZ - Quantity: 8 units  <br>- **Arrowroot Ground** - Brand: McCormick - Size: 6/20 OZ - Quantity: 88 units<br>- **Basil Leaf Whole** - Brand: Emerald - Size: 6/24 OZ - Quantity: 33 units<br>- **Black Pepper** - Brand: McCormick - Size: 12/1 LB - Quantity: 15 units<br><br>*...and 45 more items available*</pre><p>This concrete example illustrates the expected structured format for general inventory data, clearly labeling sections and item details.</p><p><strong>Low Stock Alerts</strong></p><pre>## ⚠️ Low Stock Items<br><br>- **Olive Oil** - Brand: Bertolli - Size: 1L - Current: 2 units (Reorder at: 5 units)<br>- **Sea Salt** - Brand: Morton - Size: 3 LB - Current: 1 unit (Reorder at: 4 units)<br><br>## Suggested Actions<br>- Reorder olive oil immediately<br>- Monitor sea salt usage closely</pre><p>This example demonstrates a clear alert format, emphasizing urgency, stock levels, and providing specific recommended actions for quick decision-making.</p><p><strong>Response Style</strong></p><pre>RESPONSE STYLE:<br>- Start with a clear summary statement<br>- Use professional, direct tone for production managers<br>- Present data clearly without unnecessary suggestions<br>- Focus on facts and quantities, not generic advice<br>- Keep responses concise and focused on the requested information<br>- Only provide recommendations when specifically asked or when there are critical issues (completely out of stock)<br>- When presenting inventory data with multiple items, always end with: &quot;Would you like me to generate a PDF report of this data for download?&quot;</pre><p>The agent’s responses are carefully styled to be professional, direct, concise, and actionable — perfectly tailored for inventory management staff. It provides recommendations strictly when required to maintain clarity and effectiveness.</p><p><strong>Reminders for the Agent’s Purpose</strong></p><pre>Remember: You&#39;re helping busy restaurant staff at ${business.displayName} make quick, informed decisions about their inventory. Prioritize readability and actionability.</pre><p>This statement reinforces the core purpose and context, keeping the agent aligned with its practical goal — supporting effective, informed decision-making by restaurant personnel.</p><h3>Documentation Links:</h3><ul><li><a href="https://mastra.ai/en/docs/agents/overview"><strong>Mastra.ai Documentation</strong></a></li><li><a href="https://nextjs.org/docs/app/getting-started/project-structure"><strong>Next.js Documentation</strong></a></li><li><a href="https://platform.openai.com/docs/guides/text#prompt-engineering"><strong>OpenAI Documentation</strong></a></li></ul><h3>Conclusion</h3><p>Clearly structured AI-driven inventory management solutions reduce complexity, increase accuracy, and significantly enhance operational efficiency in restaurant settings. In <strong>Part 2</strong>, we’ll dive deeper into the project with frontend implementation, API routes, and environment setup. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=807e9e7a3138" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Just ship it”: Learning the New Role of AI Product Engineering and Building Products People…]]></title>
            <link>https://medium.com/@autumnhicks01/just-ship-it-learning-the-new-role-of-ai-product-engineering-and-building-products-people-ba0f8145ceeb?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba0f8145ceeb</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[business]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Thu, 22 May 2025 23:57:27 GMT</pubDate>
            <atom:updated>2025-05-28T23:56:56.941Z</atom:updated>
            <content:encoded><![CDATA[<h3>“Just ship it”: Learning the New Role of AI Product Engineering and Building Products People Actually Use</h3><p>Product engineering in the AI era is about <strong>solving real problems, building in public, and shipping products that people actually use</strong>. The barriers are falling… if you’re an industry expert with a problem to solve, the tools are finally here. Just ship it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySz4SnhsOQh6JRdQIbW0oQ.png" /></figure><h3>The New Frontier of Product Engineering</h3><p>The world of software engineering is being rewritten in real time. It’s not just software developers and computer science grads launching breakthrough products — it’s also industry veterans, operators, and entrepreneurs who spot real-world pain points and now have the tools to solve them.</p><p><strong>AI product engineering</strong> is at the center of this transformation. As Lee Robinson, VP of Product at Vercel, put it in a recent <a href="https://linearb.io/dev-interrupted/podcast/the-end-of-specialization-how-ai-shapes-modern-dev-teams">interview at Dev Interrupted</a>:</p><blockquote><em>“A product engineer doesn’t think about the front end or backend split. They think about everything that it takes to ship a feature and deliver customer value end to end.”</em></blockquote><p>Today, AI-first teams don’t look like the old “frontend/backend/DevOps” silos. Instead, they’re a blend of builders, subject-matter experts, and operators — often from non-traditional backgrounds — who aren’t afraid to “just ship it,” get feedback, and iterate fast.</p><p>This is the story of how I joined that movement, and what I learned along the way about validating ideas, running a business, why the modern AI Product Engineer is an important new role in the tech world (and why entrepreneurs may be a fantastic fit for the job).</p><h4>From Industry Problem to AI Solution</h4><p>Six years ago, I founded a luxury dessert food brand with multiple locations, CPG products, and a production facility supplying thousands of customers. Managing large teams, inventory, and sales meant constantly uncovering bottlenecks. One stood out: catering sales. Our managers were spending hours every week manually finding and closing deals that could be worth thousands — if only we had a better system.</p><p>I realized AI was a perfect fit for this use case, and <strong>CaterlyAI</strong> was born — a modern tool to 10x catering sales efficiency. I built this tool with <strong>Next.js + Vercel AI SDK </strong>(read more about how I did it <a href="https://medium.com/@autumnhicks01/building-a-leadgen-marketing-automation-tool-with-next-js-ai-sdk-cf7914e4f7ec">here</a>).</p><h4>The Confidence to “Just Ship It” (and Show Real Users)</h4><p>Bringing an idea to life — especially for a non-technical founder — is daunting. What gave me the confidence to “just ship it” and put a full-stack, production-grade AI app in front of users after just three weeks?</p><ul><li><strong>Mentorship:</strong> I have two incredible mentors, <a href="https://www.linkedin.com/in/haiphunghiem/">Hai </a>(AI Engineer &amp; Founder) and <a href="https://www.linkedin.com/in/meri-nova/">Meri </a>(Break Into Data), who reminded me not to obsess over perfection and ship a “slice” of something that works every week.</li><li><strong>AI Engineering Bootcamp:</strong> I needed to ramp up fast, so I dove into an intensive 5-week AI engineering bootcamp, learning from engineers shipping real products. This hands-on learning demystified modern stacks like Next.js, Vercel, and OpenAI SDK — and built my confidence to build (and break) things quickly. <em>(I’ll be helping teach in the next one! If you’re curious, check it out </em><a href="http://eng.framer.ai/"><em>here</em></a><em>.)</em></li><li><strong>Entrepreneurial Mindset: </strong>Years of building in public taught me to treat every idea as an experiment — launch quickly, gather real feedback, and adapt fast. When something doesn’t work, I see it as a lesson, not a setback. The key is to stay curious, keep moving, and use each iteration to get a little better.</li></ul><h4>What Makes a Product People Actually Use (and Pay For)?</h4><p>The tech world has often looked for the next unicorn founder from Stanford or MIT. But some of the most successful products were developed by industry experts who simply solved their own problems… then realized millions of others had the same need.</p><ul><li><a href="https://www.salesforce.com/news/stories/the-history-of-salesforce/"><strong>Salesforce</strong></a>: Marc Benioff wasn’t building tools for engineers, he was solving sales management headaches.</li><li><a href="https://www.npr.org/2019/08/02/747660923/shopify-tobias-l-tke"><strong>Shopify</strong></a>: Tobi Lütke just wanted to sell snowboards online. The e-commerce revolution followed.</li><li><a href="https://www.forbes.com/profile/judy-faulkner/"><strong>Epic Systems</strong></a>: Founded by a healthcare worker, now runs hospital IT nationwide.</li></ul><p><em>Industry expertise</em> is often the missing piece. As Mahesh Baxi, CEO and Co-founder of Provus, notes in a great article on this topic <a href="https://www.nvp.com/blog/domain-expertise-founder-greatest-asset/?utm_source=chatgpt.com">here</a>, “The single most important factor in a startup’s success is the domain expertise of its founders.”</p><h4>The Right Questions to Ask</h4><p>Not every idea is worth shipping. When evaluating new product ideas (what my business college professors would call a SWOT analysis, I’m usually bouncing ideas off friends and doing deep research as a solo founder), I ask myself:</p><ul><li><strong>Is this a B2B or B2C product?</strong><br> Define if you’re building for businesses (B2B) or end consumers (B2C).. each has different sales cycles, user needs, and pricing.</li><li><strong>Does this already exist?</strong><br> Don’t be afraid of competition… can you build something better, simpler, or cheaper?</li><li><strong>Who is the actual user — and the buyer?</strong><br> Make sure your target users have the authority (and the credit card) to pay. For me, that meant SMB owners and managers.</li><li><strong>When and where will they use it?</strong><br> Is it for desktop, mobile, or both? How frequently will it be used? (I chose to skip a mobile MVP to stay focused.)</li><li><strong>What is the ROI or business value?</strong><br> Estimate the real financial impact for users — how much time or money can they save or make with your product? Use this to inform pricing.</li><li><strong>Does the industry have special security or compliance needs?</strong><br> For highly regulated fields (healthcare, legal, finance), factor in extra time and budget for compliance.</li></ul><p><strong>Pro tip:</strong><br> Ask yourself, “If this tool vanished tomorrow, what would my users do instead?” If the answer is “go back to spreadsheets and frustration,” you’re onto something.</p><h3>The Business Side: Profitability, Distribution, and Scalability</h3><p>Shipping is just the start. Can you run a product that’s profitable, scales, and survives real-world churn?</p><p>As a founder, I managed multiple P&amp;Ls, team schedules, and physical assets across locations. “<a href="https://marcuslemonis.com/business/3ps-of-business">People, Product, Process</a>” was my motto (thanks, Marcus Lemonis). My experience in business taught me to:</p><ul><li><strong>Start Lean:</strong> Bootstrap and avoid burning cash on vanity features</li><li><strong>Think in Systems:</strong> Build for 10 users, but be ready to scale to 1,000</li><li><strong>Distribution Matters:</strong> Have a real plan to get your product into customers’ hands. Your GTM (go to market strategy) is key here</li><li><strong>Iterate Fast:</strong> Launch simple MVPs, demo to real users (not just friends), and let feedback guide what you build next</li></ul><p>At the end of the day, every industry has its quirks, but the fundamentals of running a business remain the same. When developing an AI application, be sure to account for these core costs:</p><ul><li><strong>Cloud infrastructure and hosting, storage and database fees:</strong><br> Ongoing spend for servers, bandwidth, and uptime (e.g., AWS, Vercel, Azure). Costs for securely storing user data, backups, and logs.</li><li><strong>AI model and API usage:</strong><br> Pay-per-use for AI tokens, API calls, and any third-party models you integrate.</li><li><strong>Security and compliance:</strong><br> Expenses for encryption, audits, government certifications (HIPAA, SOC 2, etc.).</li><li><strong>Customer support:</strong><br> Your time (or your team’s) answering tickets, onboarding users, and troubleshooting — time is money.</li><li><strong>Intellectual property and legal:</strong><br> Budget for trademarks, patent filings, and protecting your IP.</li><li><strong>Business operations:</strong><br> Don’t forget registration fees, taxes, CPAs, legal counsel, and other administrative expenses. Your local SBA or SBTDC is a great resource for guidance.</li></ul><p>My tips from experience.. <strong>don’t hire too fast, don’t over-raise, and keep your burn low until you’ve found traction.</strong> These lessons I learned from the food, retail, and real estate world apply directly to software. <strong>Bonus:</strong> Document every single expense from day one and work with a good CPA to maximize your write-offs.</p><h4>Why Build (and Fail) in Public?</h4><p>There’s a myth that the best products are built in stealth, then unveiled as polished gems. The reality? Founders who build in public, share their process, and engage with users move faster — and build things people want.</p><p>Robinson agrees:</p><blockquote><em>“You should work in public. Share what you’re doing online… All of it showcases over time your ability to build skills, to be fascinated by a problem, to try to learn it.”</em></blockquote><p><strong>My tips:</strong></p><ul><li>Ship a simple, targeted MVP — don’t wait for perfect.</li><li>Demo early and often, especially to <em>actual</em> users (not just your network).</li><li>Collect honest feedback and iterate fast.</li><li>Document what you learn — publicly, if you can. It attracts users, investors, and even future teammates.</li></ul><p>While AI accelerates prototyping and helps new builders go from idea to MVP at lightning speed, getting from “good enough” to a polished, production-ready product still requires human expertise and decision-making.</p><h3>The AI Product Engineer: A New Role (and Team Sport)</h3><p>As the boundaries between business, software, and data blur, we’re witnessing the rise of a new, highly versatile role: the AI Product Engineer. This isn’t just a coder or a project manager. The modern AI product engineer is equally comfortable defining the problem, shaping the product, and building (or orchestrating the build of) the technical solution.</p><p>In the interview titled “<a href="https://linearb.io/dev-interrupted/podcast/the-end-of-specialization-how-ai-shapes-modern-dev-teams">The End of Specialization? How AI Shapes Modern Dev Teams</a>” Lee Robinson describes this shift:</p><blockquote><em>“A product engineer doesn’t think about the front end or backend split. They think about everything that it takes to ship a feature and deliver customer value end to end.”</em></blockquote><p>This “end-to-end builder” mindset marks a fundamental departure from the days when developers could stay in one lane, shipping code over the proverbial wall. In Robinson’s view — and our own experience — modern product engineering is as much about understanding <em>what</em> to build as it is about knowing <em>how</em> to build it.</p><p><strong>AI as a Force Multiplier</strong></p><p>One of the most significant changes is how AI is lowering barriers for all kinds of builders. With platforms like Vercel’s v0.dev and the Vercel AI SDK, it’s now possible for someone with a great idea — but little traditional coding background — to turn a problem statement into a functioning app.</p><blockquote><em>“AI tools are giving people the power that they didn’t have before… You might not have ever written a line of code before, and that’s fine.”</em></blockquote><p>This democratization means product managers, designers, operators, and industry insiders can now contribute as hands-on builders or rapid prototypers, not just idea generators.</p><p><strong>No More Silos</strong></p><p>Old-school specializations are fading. Robinson observes:</p><blockquote><em>“You often have to go back and forth… It’s really a lot more fluid between the different parts of the client and the server. In an AI-first era, product engineering is more important than ever. Dare I say, it’s basically the only thing left.”</em></blockquote><p>Shipping a modern product means collaborating across business, engineering, and data science — sometimes all in one person, but more often in cross-functional teams where everyone is willing to stretch beyond their formal role.</p><p><strong>The Human Edge in the Last Mile</strong></p><p>It’s also important to acknowledge, as Robinson does, that while AI can take you from “zero to one” (or zero to 50%), the final stages — going from 80% to 100% — require human judgment, taste, and ownership:</p><blockquote><em>“From the 80% to a 100%, it’s a little more difficult because at that point you need to have more of an opinion about what exactly you’re trying to build and what you need to get done. At that point, it’s more of a consultant that you’re asking questions to versus the actual implementer of the idea.”</em></blockquote><p>My interpretation: <strong>AI Product Engineering isn’t about replacing teams or skills, but amplifying them.</strong> The best results come from diverse teams — product thinkers, tinkerers, specialists, and domain experts — who can use AI as a catalyst, then collaborate to push projects across the finish line.</p><ul><li><strong>Product thinkers:</strong> Deeply customer-focused, able to define and frame the right problems</li><li><strong>Builders:</strong> Tinkerers who bring ideas to life — regardless of their job title or background</li><li><strong>Specialists:</strong> Frontend, backend, data, and AI experts who can polish and scale solutions</li><li><strong>Domain experts:</strong> Operators who understand the workflow, pain points, and success metrics</li></ul><p><strong>Entrepreneurs — by necessity — make outstanding AI Product Engineers.</strong> We’re gritty, obsessed with outcomes, not afraid to fail, and always ready to learn. If you care about real-world problems and can learn enough tech to “just ship it,” there’s a seat at the table.</p><h3>The Future is Yours to Build</h3><p>Product engineering isn’t just a job — it’s a mindset. AI has leveled the playing field so that domain experts, hustlers, and tinkerers can go from idea to app in record time. The best teams and products will come from those who combine business sense with technical curiosity, validate their ideas in the wild, and learn by doing.</p><p>So whether you’re a founder, operator, marketer, or engineer, the opportunity is right in front of you. The next wave of AI products will be built — and used — by people who see a real-world need and have the grit to ship fast and learn in public.</p><p><strong>The tools are here. All that’s left is to ship it.</strong></p><p><em>I would love for you to join me at the next </em><a href="http://eng.framer.ai/"><em>AI Engineering Bootcamp by Break Into Data.</em></a><em> I’ll be (student) teaching, building, and sharing lessons learned alongside an incredible cohort of new product engineers. Check it out </em><a href="http://eng.framer.ai/"><em>here</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba0f8145ceeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Benefits of Using Next.js + Vercel AI SDK to Build a Production-Ready, Full-Stack AI App]]></title>
            <link>https://medium.com/@autumnhicks01/benefits-of-using-next-js-vercel-ai-sdk-to-build-a-production-ready-full-stack-ai-app-65ad9667b66f?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/65ad9667b66f</guid>
            <category><![CDATA[bootcamp]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[vercel]]></category>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Tue, 13 May 2025 19:28:08 GMT</pubDate>
            <atom:updated>2025-05-28T23:55:16.987Z</atom:updated>
            <content:encoded><![CDATA[<p>I shipped a catering lead‑gen and marketing automation tool in 5 weeks during an intensive <a href="http://eng.framer.ai/">AI engineering bootcamp</a> — here’s my experience using a brand new (to me) tech stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3q25KcaRmbqVvANFAy5zA.png" /></figure><h4>Python vs TypeScript</h4><p>I came into this bootcamp with Python experience and creating quick UI with Streamlit, but I was introduced to a completely different stack — <strong>Next.js + Vercel AI SDK + ShadCN + supabase — </strong>to build a true full-stack production ready AI application.</p><p>While learning TypeScript in weeks felt daunting, AI-powered coding assistants (“<strong>vibe coding</strong>”) smoothed the curve to help me code faster and more accurately. Our AI Engineer mentor built a full-stack application live over those five weeks, so I could see each folder, API route, and component in action and adapt their structure to my own project. It pushed me far outside my comfort zone, but I wanted to challenge myself and add another powerful tool to my AI toolkit.</p><p>Throughout this article, I’ll share the lessons I learned as a previously <strong>non-technical founder</strong> in an easy to read and understand way. It may not be a formal manual, but I hope it feels approachable for anyone outside the SWE world. For the next AI engineering bootcamp, I’ll be a contributor this time and will be using <strong>Python + OpenAI Agents SDK</strong> (more on that later!).</p><h4>Full-stack with Next.js: client and server working together <strong>🤝</strong></h4><p>A web application consists of two parts, and each part has a specific job:</p><p><strong>Client-side code (the UI)</strong></p><ul><li>This is the code that runs in your browser when you open a webpage.</li><li>It draws buttons, forms, text, and images on the screen.</li><li>When you click a button or type into a form, the client-side code decides what to send to the server and how to update the page with the response.</li></ul><p><strong>Server-side code (the logic)</strong></p><ul><li>This runs on a remote machine (a “server”) rather than in your browser.</li><li>Its job is to process incoming requests, like fetching records from a database, running calculations, or calling an AI model.</li><li>Once it’s done, it sends back structured data (often JSON) for the client-side code to display.</li></ul><p>Next.js brings both of these roles together in one project folder so you <strong>don’t need two separate codebases</strong>:</p><p><strong>UI pages live under </strong><strong>pages/</strong></p><ul><li>Any file here — say pages/about.tsx—automatically becomes a URL (/about).</li><li>Next.js compiles these files into JavaScript that runs in the browser.</li></ul><p><strong>API endpoints live under </strong><strong>pages/api/</strong></p><ul><li>A file like pages/api/data.ts turns into a serverless function available at /api/data.</li><li>Next.js deploys these functions to a server environment where they can safely use secret keys and perform heavy work.</li></ul><p>Under the hood, <a href="https://nextjs.org/docs/routing/introduction">Next.js</a> uses tools like webpack and Babel to split your code into exactly what belongs in the browser and what belongs on the server. When you deploy:</p><ul><li>The browser-ready bundle (your React UI) goes out to a content network for fast loading.</li><li>The server functions (your API routes) run on Vercel’s serverless platform and can import packages like the Vercel AI SDK without exposing secrets.</li></ul><p>Because everything lives in one repository with one build process, you avoid headaches and managing two deployments. You simply write your UI and your data-processing logic side by side, and Next.js handles the rest.</p><p><strong>Database layer with Supabase</strong><br>For my project, I store and fetch structured data (e.g. user prompts, chat history) using Supabase — a hosted Postgres-compatible DB with real-time subscriptions. In Next.js you can import a shared client from lib/supabase.ts.Thanks to <a href="https://vercel.com/integrations/supabase">Vercel’s Supabase Integration</a>, your environment variables get injected automatically on deploy.</p><h4>Rendering Modes: SSR vs. CSR with &quot;use client&quot;</h4><p>A web page can be built two ways: <strong>Server-Side Rendering (SSR)</strong> and <strong>Client-Side Rendering (CSR)</strong>. In the SSR approach, the server prepares the complete HTML before sending it to your browser. This means the page appears instantly and is easy for search engines to read. Next.js uses this method by default: any component you write without special flags runs on the server first, fetches data, and delivers ready-to-display HTML.</p><p>In the CSR approach, your browser downloads code and builds the page itself, which lets you add buttons, forms, and live updates. To tell Next.js that a component should run in your browser, you place &quot;use client&quot; at the very top of the file. Next.js then packages that component separately and runs it only in the browser. For example:</p><pre>&#39;use client&#39;<br>import { useState } from &#39;react&#39;<br><br>export default function Counter() {<br>  const [count, setCount] = useState(0)<br>  return &lt;button onClick={() =&gt; setCount(count + 1)}&gt;{count}&lt;/button&gt;<br>}</pre><p>With this setup, you might render your main page on the server for a fast load, then let the counter — or any interactive widget — hydrate on the client without extra build steps or routing rules. You simply choose which parts need real-time interaction and mark them with &quot;use client&quot;.</p><h4>Integrating AI via the Vercel AI SDK</h4><p>By installing the Vercel AI SDK (npm install ai @ai-sdk/anthropic), you unlock a single function—generateText—that handles all the heavy lifting of talking to your chosen LLM. Pick a model provider — like Anthropic’s Claude or Google’s Gemini — by importing from @ai-sdk/anthropic or @ai-sdk/google. When your API route runs, it sends your prompt to the chosen LLM on the server, keeping your keys safe and your browser bundle lean. In pages/api/chat.ts, you simply write:</p><pre>// pages/api/chat.ts<br>import type { NextApiRequest, NextApiResponse } from &quot;next&quot;<br>import { generateText } from &quot;ai&quot;<br>import { anthropic } from &quot;@ai-sdk/anthropic&quot;<br><br>export default async function handler(req: NextApiRequest, res: NextApiResponse) {<br>  const { prompt } = await req.json()<br>  const { text } = await generateText({<br>    model: anthropic(&quot;claude-3-7-sonnet-20250219&quot;),<br>    prompt<br>  })<br>  res.status(200).json({ answer: text })<br>}</pre><p>Behind the scenes, generateText sends your prompt to Claude, streams back the response, and never exposes your API key to the client—your UI just reads answer and renders it.</p><h4>Your API Layer: Next.js vs. a Python Server</h4><p>In our full-stack AI project, the API layer sits between your browser interface and the language model. Think of each file in pages/api/ as a mini–AI “conductor.” It:</p><ol><li>Receives data from your React UI (e.g. { prompt }).</li><li>Calls one or more AI “agents” via the SDK.</li><li>Returns structured JSON for display.</li></ol><p>When you POST to /api/chat, Next.js spins up that function in a secure serverless environment, runs your SDK calls, then wraps the reply in { answer }.</p><p><strong><em>Why this feels so simple:</em></strong></p><p><strong>Next.js</strong>: Drop a file in pages/api/ and Vercel handles routing, scaling, and secrets.</p><p><strong>Python (Flask/Django)</strong>: You’d need to install a web framework, define routes, configure a web server, and manage a long-running process.</p><p>With Next.js, there’s no separate “backend” repo — your API lives right alongside your UI code, and your frontend never sees the secret key. You simply fetch /api/chat, read response.answer, and show it on screen.</p><h4><strong>Seamless Deployment with Vercel</strong></h4><p>Deploying a Next.js app to Vercel is as simple as connecting your GitHub repository. Once you authorize Vercel to watch your repo, it automatically detects that you are using Next.js, sets up a build pipeline, and configures serverless functions for your API routes.</p><ol><li><strong>Connect your GitHub repo</strong> → Vercel auto-detects Next.js</li><li><strong>Live Previews</strong> for every pull request</li><li><strong>One-click Production Deploy</strong> with global edge caching</li></ol><p>When you push code to your repo, Vercel creates a live preview build that shows exactly what will go to production. When you are ready, merging to your main branch triggers a production deployment. Behind the scenes, <strong>Vercel optimizes your front end for static hosting at the edge and runs your API routes as serverless functions</strong>, distributing both around the world for fast response times. You get one dashboard with build logs, function logs, and rollback controls, so shipping updates and fixing issues takes just a few clicks.</p><p><strong>🤝 Supabase + Vercel</strong><br> Vercel’s native Supabase integration auto-provisions your database, sets up environment variables, and even creates preview databases for each pull request.</p><h4>Five Reasons Next.js Rocks for AI Products</h4><ul><li><strong>Unified codebase</strong> for UI components and API routes reduces context switching</li><li><strong>TypeScript integration</strong> catches errors early and clarifies data contracts</li><li><strong>Flexible rendering modes</strong> optimize both performance and interactivity</li><li><strong>Built-in serverless functions</strong> simplify wrapping AI calls securely</li><li><strong>One-click deployments</strong> on Vercel ensure fast iteration and global distribution</li></ul><h4>Python for next bootcamp</h4><p>In the next <a href="http://eng.framer.ai/">AI engineering bootcamp</a>, I’m excited to come back as a contributor this time and I’ll switch to a pure Python workflow and live-code agentic examples straight from the OpenAI Agents SDK guide. Whether you’re new to coding like me or have years of experience, we’ll learn side by side, live-coding each step, sharing tips, and discovering together how Python’s ML advantages can speed up development and deepen our understanding of AI in practice.</p><h4>Benefits of Python + OpenAI Agents SDK</h4><p>While both tech stacks are powerful, there are also definite benefits to using Python + OpenAI Agents SDK:</p><ul><li><strong>Unified interface for every AI feature</strong><br> One library handles chat, embeddings, file uploads, fine-tuning, function calling, and more.</li><li><strong>Rapid prototyping with minimal setup</strong><br> Install the SDK once and start seeing model outputs in seconds — no separate tools or config files.</li><li><strong>Built-in agent orchestration</strong><br> The OpenAI Agents extension lets you define and chain Python functions into multi-step workflows without extra boilerplate.</li><li><strong>Structured outputs with function calling</strong><br> Declare your function schemas and let the model return parsed data you can use directly, reducing guesswork and parsing code.</li><li><strong>Streaming and batch support</strong><br> Stream tokens live for interactive experiences or submit large batches of prompts in one call for efficient bulk processing.</li></ul><p>Stay tuned for more, and consider signing up for the free resources from Break Into Data for more information about what we’re learning <a href="http://eng.framer.ai/">here</a>. Let’s learn along the way how both tech stacks can do powerful things and solve real-world problems with AI!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65ad9667b66f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Leadgen + Marketing Automation Tool with Next.js + AI SDK]]></title>
            <link>https://medium.com/@autumnhicks01/building-a-leadgen-marketing-automation-tool-with-next-js-ai-sdk-cf7914e4f7ec?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf7914e4f7ec</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[vercel]]></category>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 22:07:32 GMT</pubDate>
            <atom:updated>2025-04-14T22:18:35.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3aEPlZZHmV2COnQCNMxrbQ.png" /></figure><p>I built <a href="http://www.caterlyai.com/"><strong>CaterlyAI</strong></a>, a lead generation and marketing automation tool for the catering industry with <strong>Next.js</strong> + <strong>Vercel AI SDK</strong>, <strong>mastra.ai </strong>framework, <strong>React + Shadcn UI </strong>frontend, <strong>Supabase </strong>for storage and <strong>Langsmith </strong>for observability in just five weeks during the Break Into Data AI engineering bootcamp.</p><p><strong>Why? </strong>Because I founded a food brand in 2019 and wanted to solved a problem in my industry — catering managers and business owners need streamlined ways to find and nurture high-potential leads.</p><p>I have experience building <strong>Python back-ends, AWS Lambda functions, and Streamlit front-ends</strong> to automate parts of businesses like mine (like food costing or inventory management). However, in the first week of the bootcamp, we were encouraged to pick <strong>either TypeScript or Python</strong>. Eager to get out of my comfort zone, I chose to use Next.js and deploy on Vercel, resulting in a more unified tech stack that handles a slick front-end interface, <strong>advanced agentic workflows</strong>, and <strong>streamlined deployment</strong> all under one roof.</p><p>Below is how I made the leap and how these tools all worked together for CaterlyAI.</p><h3>Choosing Agentic Workflows: Orchestrator-Workers</h3><p>After exploring different agentic approaches, I settled on the <strong>Orchestrator-Workers</strong> pattern described in <a href="https://www.anthropic.com/engineering/building-effective-agents">Anthropic’s “Building Effective Agents”</a>. In this workflow, a <strong>central orchestrator</strong> dynamically <strong>breaks down tasks</strong>, delegates them to specialized <strong>worker agents</strong>, and integrates their outputs into a coherent result. It’s ideal for <strong>complex processes</strong> that need on-the-fly decisions — like <strong>lead enrichment</strong>, <strong>campaign creation</strong>, and <strong>email automation</strong> in CaterlyAI.</p><p><strong>Here’s how my system uses the Orchestrator-Workers model and external tools:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMSOagDqElB1wvkX679GuA.png" /><figcaption>Anthropic’s diagram for the Ochestrator-Workers workflow</figcaption></figure><p><strong>Workflow Orchestrator Structure</strong></p><ul><li>A WorkflowManager class in my codebase handles the <strong>overall task</strong>—for example, “Generate a list of leads, enrich their profiles, and schedule outreach.”</li><li>Built with @mastra/core/workflows, each <strong>workflow</strong> is a series of <strong>steps</strong>. The orchestrator decides the <strong>order</strong> in which these steps occur, and which <strong>agent</strong> to call at each step.</li></ul><p><strong>Worker Agents</strong></p><ul><li>Multiple agents exist, each powered by the Agent class from @mastra/core/agent. For example:</li><li><strong>enrichmentAgent</strong> — Pulls or scrapes data about a lead with <strong>Firecrawl</strong> extract endpoint.</li><li><strong>profileAgent</strong> — Generates or updates a brand/catering profile in Supabase.</li><li><strong>businessAgent</strong> — Uses <strong>Google Places API</strong> or <strong>OpenAI websearch</strong> to locate new leads or relevant info.</li><li><strong>outreachAgent</strong> — Automates email sends with <strong>Resend API</strong>.</li><li>Each agent has a <strong>domain-specific focus</strong> and can invoke a set of <strong>tools</strong> to perform its tasks.</li></ul><p><strong>Incorporating Tools</strong></p><ul><li>Within each agent, <strong>mastra.ai</strong> lets me register external <strong>tools</strong> — APIs or endpoints — that the agent can call autonomously:</li><li><strong>Firecrawl</strong> (extract endpoint) for scraping specific websites.</li><li><strong>Google Places API</strong> to locate business contact data.</li><li><strong>OpenAI websearch</strong> for general data gathering.</li><li><strong>Resend API</strong> for email automation.</li><li>When the orchestrator triggers a step (e.g., “Enrich lead data”), the corresponding worker agent decides which tool to call. If a step fails (like a bad URL in Firecrawl), the workflow can <strong>retry</strong> or fallback to another approach.</li></ul><h4>Vercel AI SDK + mastra.ai</h4><p>I started building this project solely with Vercel’s AI SDK (which I’ve learned is different than an agent framework). By week 3, I installed mastra.ai as the framework. Check out their article about AI SDK + mastra.ai <a href="https://mastra.ai/blog/using-ai-sdk-with-mastra">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*AH0JIzAVlAnmpxof4uQSLw.png" /></figure><p><strong>Supabase: The Underlying Data Layer</strong></p><ul><li>All lead data, user accounts, and campaign records live in <strong>Supabase</strong>, which acts as a <strong>PostgreSQL</strong> database plus built-in authentication.</li><li>The orchestrator or individual agents can store or retrieve data — like a newly enriched lead or a user’s brand preferences — without dealing with raw SQL.</li></ul><h3>A Real-World Example: The Woodbridge Manor</h3><p>Let’s say your catering business wants to land a contract with “The Woodbridge Manor,” a popular event venue:</p><p><strong>Step 1: AI-Enhanced Profile<br></strong> The user enters basic business info (like brand voice, specialties, or style). We use <strong>GPT-4o </strong>to generate a “catering profile” that influences the rest of our leadgen process. That profile gets stored in a dedicated Supabase table for easy retrieval. Future functionality uses <strong>FLUX.1 image model</strong> to create easy industry-specific social media content for your catering business.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zu1oGMVhW0j4ZT5EnyXkzQ.png" /></figure><p><strong>Step 2: Searching for Local Leads <br></strong>The profile data is saved as coordinates to start our websearch process. We are able to discover potential venues (like The Woodbridge Manor) via <strong>Google Places API</strong> and <strong>OpenAI websearch.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHHMG6ugNWcyHqFz6gflHA.png" /></figure><p><strong>Step 3: Enriching Leads with AI</strong></p><p>My agent calls <strong>Firecrawl</strong> to scrape essential details, then <strong>GPT-4o </strong>transforms or summarizes that data, assigning it an “AI lead score.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lP0UlV9z6FMB8HlCycZbwQ.png" /></figure><p><strong>Step 4: AI-Created Campaign<br></strong> Once we have contact details for The Woodbridge Manor (e.g., the catering manager’s email), we generate a <strong>12-week marketing campaign</strong>. With <strong>Resend</strong> webhooks, we can schedule personalized emails — this is where automation meets <strong>human-in-the-loop</strong> review to ensure quality messaging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4sGRrhp6UuQlFTu8ii5zQ.png" /></figure><h3>Leveraging Cursor + Claude 3.7 Sonnet (aka “vibe coding”)</h3><p>Learning a <strong>new language</strong> (TypeScript) in just five weeks? That seemed impossible, until I discovered what I call <strong>“vibe coding”</strong> with <strong>Cursor</strong>. It’s basically pairing with an AI coding assistant, giving me near-instant feedback and suggestions.</p><ul><li><strong>Global (or project) rules</strong>: This is the first step for best practice use of an AI code assist. Here’s the <a href="https://docs.cursor.com/context/rules">documentation </a>for Cursor to get rules set up.</li><li><strong>One task per message</strong>: I keep each conversation short, focusing on a single feature (like hooking up the Google Places API) or a single bug fix (like a type mismatch in Next.js).</li><li><strong>Modular code</strong>: My Next.js routes are neatly separated — <strong>/events</strong>, <strong>/orders</strong>, <strong>/agents</strong> — so I can avoid monstrous files. Whenever I see the code creeping over 500 lines, Cursor reminds me to refactor.</li><li><strong>Test early, test often</strong>: Even though I’m new to TypeScript, I force myself (with Cursor’s nudges) to set up minimal unit tests.</li></ul><p><strong>Bonus step for best results: Ask a Senior Dev</strong></p><p>I’m also grateful for the senior developers and tech founders in the bootcamp who reviewed my repo and gave real-time feedback. It saved me from digging an even deeper hole whenever I hit a snag (especially when I first integrated mastra.ai).</p><h3>What’s Next?</h3><p>I’m excited to walk you through the rest of my journey — from configuring <strong>mastra.ai</strong> workflows and <strong>deploying on Vercel</strong> to designing a sleek <strong>React + ShadCN</strong> frontend. We’ll also explore <strong>AI model choices</strong>, <strong>prompt engineering</strong>, and <strong>how Langsmith</strong> ensures our system remains observable and dependable. Stay tuned for the deeper dive!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf7914e4f7ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Containerized Food Cost API using Docker, Amazon ECS, Application Load Balancer, and…]]></title>
            <link>https://medium.com/@autumnhicks01/building-a-containerized-food-cost-api-using-docker-amazon-ecs-application-load-balancer-and-4f687a5b9484?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f687a5b9484</guid>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 20:32:30 GMT</pubDate>
            <atom:updated>2025-02-03T20:32:30.823Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Containerized Food Cost API using Docker, Amazon ECS, Application Load Balancer, and Flask</h3><blockquote>If you’re a busy executive chef or production manager, you know that pricing out recipes can be tedious. This tool is a quick way to estimate ingredient costs. Containerized, scalable, and ready for the cloud!</blockquote><h3>Overview</h3><p>In this tutorial, we’ll build and deploy a Flask API that estimates recipe costs using <strong>Spoonacular</strong>’s public API. Our app:</p><ol><li><strong>Receives</strong> a list of ingredients and desired servings from users.</li><li><strong>Queries</strong> Spoonacular’s <strong>Price Estimator</strong> endpoint.</li><li><strong>Returns</strong> an HTML response showing the ingredient costs for the recipe.</li></ol><p>By containerizing our Flask app and deploying it on <strong>AWS ECS</strong> (with an Application Load Balancer), we can easily scale to handle many requests. Optionally, we’ll place an <strong>API Gateway</strong> in front of our service to add throttling, security, or further customization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0G9ybllxMwWr2pC1oZo8AQ.png" /></figure><p>Below you’ll find the core components, code snippets, and deployment steps.</p><h3>Why Build This?</h3><p>Professional kitchens and food manufacturing facilities constantly experiment with new recipes. The ability to <strong>quickly calculate</strong> the cost of a potential recipe (and maybe track allergens or nutritional data) is vital for:</p><ul><li><strong>Executive Chefs</strong> controlling budgets.</li><li><strong>Production Managers</strong> planning and scaling recipes.</li></ul><p>Here, we use Spoonacular’s “visualizePriceEstimator” to quickly deliver a cost breakdown. Future expansions could include nutritional or allergen data, but today we’ll stick to pricing.</p><h3>Project Architecture</h3><p>Here’s the <strong>high-level architecture</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q_lZfl7Ga5xHe9CwEXrVMQ.png" /></figure><ol><li><strong>User</strong> sends ingredients + servings to our endpoint.</li><li><strong>API Gateway</strong> can handle authentication, throttling, or usage plans.</li><li><strong>Application Load Balancer (ALB)</strong> distributes requests across multiple ECS containers for high availability.</li><li><strong>ECS Fargate</strong> runs our containerized Flask app.</li><li><strong>Flask App</strong> calls <strong>Spoonacular</strong>, processes data, and returns a formatted HTML response.</li></ol><h3>Flask Endpoint</h3><p>Below is a snippet from app.py that powers the /price-estimator route. It:</p><ul><li>Reads the ingredientList and servings from the request.</li><li>Assembles a POST request to Spoonacular’s price estimator endpoint.</li><li>Embeds the Spoonacular HTML response with jQuery, CanvasJS, etc.</li></ul><pre>from flask import Flask, request, jsonify<br>import requests<br>import os</pre><pre>app = Flask(__name__)<br>API_KEY = os.getenv(&quot;SPOONACULAR_API_KEY&quot;)<br>SPOONACULAR_API_URL = &quot;https://api.spoonacular.com/recipes/visualizePriceEstimator&quot;<br>@app.route(&#39;/price-estimator&#39;, methods=[&#39;POST&#39;])<br>def price_estimator():<br>    try:<br>        if not API_KEY:<br>            return jsonify({&quot;error&quot;: &quot;API key is missing.&quot;}), 500<br>        ingredient_list = request.form.get(&quot;ingredientList&quot;)<br>        servings = request.form.get(&quot;servings&quot;, 1)<br>        if not ingredient_list:<br>            return jsonify({&quot;error&quot;: &quot;ingredientList is required.&quot;}), 400<br>        payload = {<br>            &quot;ingredientList&quot;: ingredient_list,<br>            &quot;servings&quot;: servings,<br>            &quot;mode&quot;: 1,<br>            &quot;defaultCss&quot;: True,<br>            &quot;showBacklink&quot;: True,<br>            &quot;language&quot;: &quot;en&quot;,<br>        }<br>        # Attach API key<br>        api_url_with_key = f&quot;{SPOONACULAR_API_URL}?apiKey={API_KEY}&quot;<br>        headers = {&quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded&quot;}<br>        response = requests.post(api_url_with_key, headers=headers, data=payload)<br>        response.raise_for_status()<br>        # Return the HTML from Spoonacular<br>        html_content = f&quot;&quot;&quot;<br>        &lt;html&gt;<br>          &lt;head&gt;<br>            &lt;title&gt;Price Estimator&lt;/title&gt;<br>            &lt;!-- jQuery, CanvasJS, etc. --&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>            {response.text}<br>          &lt;/body&gt;<br>        &lt;/html&gt;<br>        &quot;&quot;&quot;<br>        return html_content, 200, {&quot;Content-Type&quot;: &quot;text/html&quot;}<br>    except Exception as e:<br>        return jsonify({&quot;error&quot;: str(e)}), 500<br></pre><p><strong>Note</strong>: We rely on an environment variable SPOONACULAR_API_KEY to keep secrets <strong>out</strong> of our repository.</p><h3>Dockerfile</h3><p>Our Dockerfile bundles the Flask app and dependencies into a portable container. It might look like this:</p><pre>dockerfile</pre><pre># Set the working directory<br>WORKDIR /app<br># Copy and install dependencies<br>COPY requirements.txt .<br>RUN pip install --no-cache-dir -r requirements.txt<br># Copy the rest of the app code<br>COPY . .<br># Expose port 8080 for Flask<br>EXPOSE 8080<br># Start the Flask server<br>CMD [&quot;python&quot;, &quot;app.py&quot;]</pre><h3>Local Testing</h3><ol><li><strong>Install Docker</strong> on your machine.</li><li>Build the image:</li></ol><pre>docker build -t food-cost-api .</pre><p>3. Run the container, passing the Spoonacular API key:</p><pre>docker run -p 8080:8080 -e SPOONACULAR_API_KEY=your_api_key food-cost-api</pre><p>4. Test it locally by sending a POST request with your ingredient list:</p><pre>curl -X POST -F &quot;ingredientList=3 oz chicken breast&quot; \ http://localhost:8080/price-estimator</pre><p>You should see an HTML response returned by Spoonacular.</p><h3>Deploying on AWS</h3><h3>1. Push to ECR (Elastic Container Registry)</h3><ul><li><strong>Create an ECR repository</strong> named food-cost-api.</li><li><strong>Authenticate</strong> Docker to ECR:</li></ul><pre>aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin &lt;ACCOUNT_ID&gt;.dkr.ecr.us-east-1.amazonaws.com</pre><ul><li><strong>Tag and push</strong> the image:</li></ul><pre>docker tag food-cost-api:latest &lt;ACCOUNT_ID&gt;.dkr.ecr.us-east-1.amazonaws.com/food-cost-api:latest docker push &lt;ACCOUNT_ID&gt;.dkr.ecr.us-east-1.amazonaws.com/food-cost-api:latest</pre><h3>2. Create an ECS Fargate Service</h3><ol><li><strong>Create a Cluster</strong></li></ol><ul><li>In ECS console, “Create Cluster” → pick a <strong>Fargate</strong>-compatible option.</li></ul><p><strong>2. Create a Task Definition</strong></p><ul><li>Choose “Fargate” launch type.</li><li>Under “Container definitions,” reference the ECR image URI:</li></ul><pre>&lt;ACCOUNT_ID&gt;.dkr.ecr.us-east-1.amazonaws.com/food-cost-api:latest</pre><ul><li><strong>Expose port 8080</strong> and set environment variable SPOONACULAR_API_KEY here (or use AWS Secrets Manager).</li></ul><p><strong>3. Create a Service</strong></p><ul><li>In your new cluster, “Create Service.”</li><li>Desired count: 2 (for high availability).</li><li><strong>Attach</strong> an Application Load Balancer to distribute traffic on port 8080.</li></ul><h3>3. (Optional) Add API Gateway in Front</h3><ul><li><strong>Create a new HTTP API</strong> in API Gateway.</li><li><strong>Integration</strong>: Point to your ALB’s DNS name and path (/price-estimator).</li><li><strong>Deploy</strong> the API; you’ll get a URL like:<br>https://&lt;api-id&gt;.execute-api.us-east-1.amazonaws.com/price-estimator</li><li><strong>Test</strong> by sending a request to the API Gateway endpoint. It should forward to the ALB → ECS → Spoonacular.</li></ul><h3>Adding a Simple HTML Form for End-User Testing</h3><p>While curl and Postman work great for testing, we can also provide a basic <strong>HTML form</strong> that lets anyone input ingredients and servings in a friendly interface.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>  &lt;title&gt;Food Cost Estimator&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h1&gt;Food Cost Estimator&lt;/h1&gt;<br>  &lt;form method=&quot;POST&quot; action=&quot;https://&lt;api-gateway-id&gt;.execute-api.&lt;region&gt;.amazonaws.com/price-estimator&quot;&gt;<br>    &lt;label for=&quot;ingredientList&quot;&gt;Ingredient List:&lt;/label&gt;&lt;br/&gt;<br>    &lt;textarea name=&quot;ingredientList&quot; id=&quot;ingredientList&quot; rows=&quot;4&quot; cols=&quot;50&quot;&gt;&lt;/textarea&gt;&lt;br/&gt;&lt;br/&gt;<br>    <br>    &lt;label for=&quot;servings&quot;&gt;Servings:&lt;/label&gt;&lt;br/&gt;<br>    &lt;input type=&quot;number&quot; name=&quot;servings&quot; id=&quot;servings&quot; value=&quot;2&quot;/&gt;&lt;br/&gt;&lt;br/&gt;<br>    <br>    &lt;input type=&quot;submit&quot; value=&quot;Estimate Price&quot;/&gt;<br>  &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Simply <strong>open</strong> this HTML file in a browser, <strong>fill out</strong> the ingredient list and number of servings, and <strong>submit</strong>. You’ll see a dynamic breakdown of each ingredient’s price from the Spoonacular API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HqJ9BeU_4-GimKFLXHemg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*_eXxHx6W-Z7m3ycOq8O9lw.png" /></figure><p><strong>That’s it!</strong> You now have:</p><ol><li>A <strong>publicly accessible</strong> API Gateway endpoint to your ECS service.</li><li>A <strong>user-friendly</strong> HTML form to test and showcase your Food Cost API.</li></ol><h3>Conclusion &amp; Next Steps</h3><p>With this <strong>Containerized Food Cost API</strong>, chefs and managers can quickly price out potential recipes:</p><ul><li><strong>Flask</strong> + <strong>Spoonacular</strong> for the logic and cost data.</li><li><strong>Docker</strong> + <strong>AWS ECS</strong> to scale easily.</li><li><strong>ALB</strong> to distribute load across multiple containers.</li><li><strong>API Gateway</strong> (optional) to add features like throttling, API keys, or domain management.</li></ul><p><strong>Possible Enhancements</strong>:</p><ul><li>Integrate Spoonacular’s <strong>nutrition</strong> or <strong>allergen</strong> endpoints.</li><li>Use <strong>AWS Secrets Manager</strong> for storing your Spoonacular API key securely.</li><li>Add a <strong>front-end</strong> to present cost breakdowns in a user-friendly interface.</li></ul><p><strong>Thanks for reading, and happy cooking (and containerizing)!</strong></p><h3>Resources</h3><ul><li><a href="https://spoonacular.com/food-api">Spoonacular API Docs</a></li><li><a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html">AWS ECS Documentation</a></li><li><a href="https://docs.docker.com/">Docker Official Documentation</a></li></ul><blockquote>Thanks for following along! Feel free to customize the code, screenshots, and architecture for your specific needs.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f687a5b9484" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Data Lake for Food Analytics with AWS Athena, S3, Glue, and SQL from USDA API Data]]></title>
            <link>https://medium.com/@autumnhicks01/building-a-data-lake-for-food-analytics-with-aws-athena-s3-glue-and-sql-from-usda-api-data-267c4a9ce750?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/267c4a9ce750</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[food]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Wed, 15 Jan 2025 03:18:30 GMT</pubDate>
            <atom:updated>2025-01-15T14:00:13.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9PibEYPi-fCv-0dcK8shsQ.png" /></figure><p>In the fast-paced world of food service, <strong>accurate ingredient data</strong> is crucial for effective inventory management, menu planning, and purchasing decisions. For those in quality assurance and production management, having access to detailed product information — including ingredients, nutrition, and sourcing — can drastically impact operational efficiency. For example, I have faced the challenge of supplier ingredient changes, which affected our own company’s packaged goods labels. Having a reliable and easily searchable database helps QA teams to “trust but verify” ingredient accuracy — vital for food safety.</p><p>In this article, I will walk you through the journey of building a data lake for food analytics using <strong>AWS Athena, Glue, S3</strong>, and utilizing <strong>SQL </strong>queries to analyze data. This project pulls data from the <strong>USDA API</strong>, cleans it, and stores it in a scalable, queryable format, enabling us to gain valuable insights about the ingredients in food products. By the end, you’ll be able to efficiently query and analyze a variety of food-related data.</p><h3>Step 1: Requesting an API Key from the USDA and Setting Up IAM Roles</h3><p>The first step in building the food analytics data lake is to fetch data from the USDA API. To do this, you need an API key from the USDA, which is used to authenticate your requests to the API. Follow these steps to get your API key and securely store it for use in the script.</p><h4>Requesting the USDA API Key</h4><p>To pull data from the USDA’s Food Data Central API, you’ll first need to request an API key. Here’s how to do that:</p><ol><li><strong>Go to the </strong><a href="https://fdc.nal.usda.gov/"><strong>USDA Food Data Central API</strong></a><strong> portal</strong>:</li></ol><ul><li>Visit USDA Food Data Central API.</li><li>Sign up for an API key by following the steps on the website.</li><li>Once you’ve signed up, you’ll receive an email with the key, which you can use to authenticate requests.</li></ul><p><strong>2. Store the API Key Securely</strong>: It’s a best practice to keep sensitive information like API keys secure. For this, use environment variables or a .env file. Here&#39;s how to do this:</p><ul><li>In your CloudShell environment, create a .env file and store the API key:</li></ul><pre>nano .env</pre><ul><li>Add the following line to the file:</li></ul><pre>USDA_API_KEY=your_api_key_here</pre><ul><li>After saving the .env file, use the python-dotenv library to load the API key in your Python script. This keeps your credentials secure and out of the source code.</li></ul><h4>Setting Up IAM Roles and Users for Best Practices</h4><p>To properly handle permissions and secure your AWS resources, you’ll need to set up <strong>IAM (Identity and Access Management)</strong> roles and users with appropriate permissions.</p><ol><li><strong>Create an IAM User</strong>:</li></ol><ul><li>Go to the <a href="https://console.aws.amazon.com/iam/">AWS IAM Console</a>.</li><li>Click on <strong>Users</strong> from the left sidebar and then click on <strong>Add user</strong>.</li><li>Give the user a name like usda-api-access, and select <strong>Programmatic access</strong> to allow access to AWS services via API.</li></ul><ol><li><strong>Create and Attach Permissions</strong>:</li></ol><ul><li>On the <strong>Set permissions</strong> page, choose <strong>Attach policies directly</strong> and select the following policies:</li><li>AmazonS3FullAccess — To give the user full access to S3 (for uploading and managing files).</li><li>AWSGlueServiceRole — For Glue-related permissions, including crawling and creating tables.</li><li>AmazonAthenaFullAccess — To allow access to Athena for querying the data stored in S3.</li><li>You can also create custom policies if you need more granular control over the permissions.</li></ul><ol><li><strong>Create an IAM Role for Glue</strong>:</li></ol><ul><li>Navigate to <strong>Roles</strong> in the IAM Console and click on <strong>Create role</strong>.</li><li>Choose <strong>AWS service</strong> as the trusted entity, then select <strong>Glue</strong>.</li><li>Attach the necessary policies, such as AWSGlueServiceRole and AmazonS3FullAccess, to the role.</li><li>Give it a name like GlueDataProcessingRole.</li></ul><ol><li><strong>Create an IAM Role for Lambda (if using)</strong>: If you plan to automate the process using AWS Lambda, ensure that Lambda has the necessary permissions. You can use a role like AWSLambdaBasicExecutionRole and attach AmazonS3FullAccess and AWSGlueServiceRole for Lambda to interact with S3 and Glue.</li><li><strong>Best Practices for IAM Roles and Permissions</strong>:</li></ol><ul><li><strong>Least Privilege</strong>: Always follow the principle of least privilege by granting only the permissions required for a given task.</li><li><strong>Rotate Credentials Regularly</strong>: Make sure API keys and other credentials are rotated periodically.</li><li><strong>Use MFA</strong>: Enable Multi-Factor Authentication (MFA) for your IAM users to add an extra layer of security.</li></ul><h3>Step 2: Setting Up and Running the CloudShell Python Script</h3><p>In this step, we’ll focus on setting up the Python script in <strong>AWS CloudShell</strong>, pulling data from the USDA API, handling pagination, and parsing it into a manageable format for uploading to S3. This avoids large file sizes that would be difficult to work with later in the process.</p><h4>Setting Up the CloudShell Python Script</h4><p>To begin, you’ll set up a Python script that fetches data from the USDA API, with a focus on pagination and reducing the data size by parsing only the essential fields: <strong>foodName</strong>, <strong>brand</strong>, and <strong>ingredients</strong>.</p><ol><li><strong>Create the Python Script</strong>:</li></ol><ul><li>Open <strong>AWS CloudShell</strong> from the AWS Management Console.</li><li>In CloudShell, create a new Python file:</li></ul><pre>nano setup_usda_data_lake.py</pre><ul><li><strong>Importing Required Libraries</strong>: You’ll need the following libraries to work with the USDA API and S3:</li></ul><pre>import os<br>import requests<br>from dotenv import load_dotenv<br>import json<br>import boto3<br>from time import sleep</pre><ul><li><strong>Loading API Key from Environment</strong>: To keep your API key secure, it’s loaded from a .env file:</li></ul><pre>load_dotenv() api_key = os.getenv(&quot;USDA_API_KEY&quot;) usda_endpoint = &quot;https://api.nal.usda.gov/fdc/v1/foods/search&quot;</pre><ul><li><strong>Fetching Data with Pagination</strong>: The following function fetches data from the USDA API while handling pagination. We ensure that we don’t exceed 2000 pages, and we process only 25 results per page.</li></ul><pre>def fetch_all_food_data(<br>    query=&quot;*&quot;,<br>    data_type=&quot;Branded&quot;,<br>    page_size=25,<br>    max_pages=2000<br>):<br>    all_data = []<br>    page_number = 1<br><br>    while page_number &lt;= max_pages:<br>        url = f&quot;{usda_endpoint}?query={query}&amp;dataType={data_type}&amp;pageSize={page_size}&amp;pageNumber={page_number}&amp;sortBy=publishedDate&amp;sortOrder=desc&amp;api_key={api_key}&quot;<br>        <br>        print(f&quot;Fetching page {page_number}...&quot;)<br><br>        try:<br>            response = requests.get(url)<br>            response.raise_for_status()<br>            data = response.json()<br><br>            if not data.get(&#39;foods&#39;):<br>                break<br><br>            for food_item in data.get(&quot;foods&quot;, []):<br>                food_info = {<br>                    &quot;foodName&quot;: food_item.get(&quot;description&quot;, &quot;&quot;),<br>                    &quot;brand&quot;: food_item.get(&quot;brandOwner&quot;, &quot;&quot;),<br>                    &quot;ingredients&quot;: food_item.get(&quot;ingredients&quot;, &quot;&quot;),<br>                    &quot;nutrients&quot;: [<br>                        {<br>                            &quot;name&quot;: nutrient.get(&quot;name&quot;, &quot;&quot;),<br>                            &quot;amount&quot;: nutrient.get(&quot;amount&quot;, &quot;&quot;),<br>                            &quot;unit&quot;: nutrient.get(&quot;unitName&quot;, &quot;&quot;),<br>                            &quot;derivationCode&quot;: nutrient.get(&quot;derivationCode&quot;, &quot;&quot;),<br>                            &quot;derivationDescription&quot;: nutrient.get(&quot;derivationDescription&quot;, &quot;&quot;)<br>                        }<br>                        for nutrient in food_item.get(&quot;foodNutrients&quot;, [])<br>                    ],<br>                    &quot;publicationDate&quot;: food_item.get(&quot;publicationDate&quot;, &quot;&quot;)<br>                }<br>                all_data.append(food_info)<br><br>            if len(all_data) &gt; 100000:<br>                break  # Limit the data size<br><br>            page_number += 1<br>            sleep(2)  # Prevent hitting API rate limits<br><br>        except requests.exceptions.RequestException as req_err:<br>            print(f&quot;Request error: {req_err}&quot;)<br>            break<br><br>    return all_data<br></pre><ul><li><strong>Uploading Data to S3</strong>: After fetching and parsing the data, this snippet uploads it to your S3 bucket:</li></ul><pre><br>s3_client = boto3.client(&#39;s3&#39;)<br>bucket_name = &#39;usda-analytics-data-lake&#39;<br><br>def upload_data_to_s3(data):<br>    try:<br>        file_key = &quot;raw-data/usda_data.json&quot;  # Define the path to store the file<br>        <br>        # Upload data to S3<br>        s3_client.put_object(<br>            Bucket=bucket_name,<br>            Key=file_key,<br>            Body=json.dumps(data)<br>        )<br>        <br>        print(f&quot;Data uploaded to {bucket_name}/{file_key}&quot;)<br>        <br>    except Exception as e:<br>        print(f&quot;Error uploading data: {e}&quot;)<br></pre><h4>Running the Script in CloudShell</h4><p>Once you’ve created your setup_usda_data_lake.py script, follow these steps to run it in <strong>AWS CloudShell</strong>:</p><p><strong>Run the Script</strong>:</p><p>Once your environment variables are set up, run the Python script:</p><pre>python3 setup_usda_data_lake.py</pre><p>The script will fetch data from the USDA API, clean and filter the necessary information, and then upload the results to your S3 bucket.</p><p>The USDA API can provide large datasets and it was failing for me after 50,000 records. By using <strong>pagination</strong>, this script requests a manageable number of records per page (25 per page) and fetches up to 2000 pages. This helps keep the file size within limits, making it more practical for subsequent processing. Feel free to adjust this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*9-L3Z65PrnZvbjRnsAGHPA.png" /></figure><h3>Step 3: Setting Up AWS Glue Crawler to Create the Table</h3><p>Once the data is uploaded to S3, you can use AWS Glue to create a table schema based on the data format. Glue’s Crawler automatically infers the schema and makes it easy to query the data in Athena.</p><p>Here’s how to configure the Glue Crawler:</p><ol><li>In the AWS Glue Console, create a new Crawler.</li><li>Select your data store as S3 and provide the S3 path to your raw data file in the raw-data folder.</li><li>Define the output database and table in Glue.</li><li>Choose an IAM role for Glue that has access to your S3 data.</li><li>Run the Crawler to automatically create the table with the inferred schema.</li></ol><p>Once the Crawler finishes, you can use Athena to query the data directly.</p><h3>Step 4: Setting Up Athena for SQL Queries</h3><p>Now that the data is stored in S3 and the schema is created with Glue, it’s time to query the data. Athena allows you to run SQL queries on your S3 data, and since the Glue Crawler created a schema for the data, you can start querying right away.</p><p>Here’s an example SQL query to search for food products containing almond flour:</p><pre>SELECT foodName, brand, ingredients<br>FROM &quot;usda_data_lake&quot;.&quot;food_data&quot;<br>WHERE ingredients LIKE &#39;%almond flour%&#39;<br>LIMIT 10;</pre><p>Athena queries allow you to quickly pull valuable insights from the data, such as finding all products with a certain ingredient or searching for brands of a specific food item.</p><h3>Step 5: Querying Food Data with Athena</h3><p>Now that everything was set up, I could run SQL queries in Athena to find products with specific ingredients or brands. Here are a few example queries to help you get started:</p><h4><strong>Search for ‘vegetable stock’ or ‘broth’ (all brands)</strong></h4><pre>SELECT * FROM usda_data_lake_table WHERE foodname LIKE &#39;%VEGETABLE STOCK%&#39;  OR &#39;%BROTH%&#39;;<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wHC36THwokVyNV8ACmRZbg.png" /></figure><h4><strong>Search for ‘non-fat yogurt’ (all brands)</strong></h4><pre>SELECT * FROM usda_data_lake_table WHERE foodname LIKE &#39;%NONFAT YOGURT%&#39;;<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_lS_VW8JVyKZB-LpeQo5wg.png" /></figure><h4>Search for ‘tomato sauce’ (all brands)</h4><pre>SELECT * FROM usda_data_lake_table WHERE foodname LIKE &#39;%TOMATO SAUCE%&#39;;<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*seoI858i-bFd9jfxcmp_KA.png" /></figure><h4><strong>Search for a specific brand of ketchup</strong>:</h4><pre>SELECT *<br>FROM usda_data_lake<br>WHERE brand LIKE &#39;%Kraft Heinz%&#39; AND foodname LIKE &#39;%KETCHUP%&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VEZpD3oVhM4rirCMYY2R7Q.png" /></figure><h3>Step 6: Automating the Process with AWS Lambda and EventBridge (Optional)</h3><p>For regular updates, you can automate the entire data-fetching pipeline. Using AWS Lambda, you can schedule periodic data pulls from the USDA API, ensuring that your data is always up-to-date. You can configure EventBridge to trigger Lambda functions periodically, so new data is pulled, processed, and uploaded to your S3 bucket without manual intervention.</p><h3>Troubleshooting: Restructuring the Data in CloudShell with jq</h3><p>After uploading the raw USDA data to S3, I encountered an issue where the Glue Crawler could not properly detect the schema. This was due to the original JSON file being structured as an array of objects, which caused problems for the crawler when trying to create a table. I unsuccessfully tried an ETL Job to fix this issue, but it didn’t work.</p><p>To resolve this, I used CloudShell along with the jq command-line tool to unpack the array into individual objects. This restructuring allowed AWS Glue to correctly detect the schema and create the table in Athena.</p><h4>Here’s how I approached the issue:</h4><ol><li><strong>Identifying the Problem</strong>:</li></ol><ul><li>The original USDA JSON data was structured like this:</li></ul><pre>[<br>    {<br>        &quot;foodName&quot;: &quot;Example Food&quot;,<br>        &quot;brand&quot;: &quot;Example Brand&quot;,<br>        &quot;ingredients&quot;: &quot;ingredient1, ingredient2&quot;,<br>        &quot;nutrients&quot;: [<br>            { ... },<br>            { ... }<br>        ],<br>        &quot;publicationDate&quot;: &quot;2021-01-01&quot;<br>    },<br>    { ... }<br>]</pre><p>The data was contained in an array, and AWS Glue had difficulty processing it due to this structure.To solve this, I used jq to unpack the array and output each item as a separate object, so Glue could process it. I ran the following command in CloudShell:</p><pre>jq -c &#39;.[]&#39; usda_data.json &gt; reformatted_usda_data.json</pre><p><strong>Explanation</strong>:</p><ul><li>jq -c &#39;.[]&#39;: This command extracts each element from the array in the JSON file and outputs it as a single-line, flat structure (using the -c option for compact output).</li></ul><p>Maybe you are able to improve the script to avoid this issue in the future (I encourage you to), for now this was my fix!</p><h3>Wrapping Up</h3><p>This project was a fantastic learning experience. By combining AWS Athena, Glue, S3, and Lambda, I built a scalable and automated food analytics pipeline that fetches, cleans, and stores data from the USDA API. With Athena, I can now run powerful SQL queries on the data to extract insights quickly.</p><p>In the future, I plan to integrate supplier databases and price data into the pipeline, further enhancing the utility of this system for decision-making in food service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=267c4a9ce750" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating FDA Recall Monitoring with AWS Lambda, S3, and EventBridge]]></title>
            <link>https://medium.com/@autumnhicks01/automating-fda-recall-monitoring-with-aws-lambda-s3-and-eventbridge-66fb7ec140ae?source=rss-6e8710f1098b------2</link>
            <guid isPermaLink="false">https://medium.com/p/66fb7ec140ae</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[manufacturing]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Autumn Hicks]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 23:34:29 GMT</pubDate>
            <atom:updated>2025-01-10T20:43:04.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*MbAmjkRSBrn-66yhq9kiIQ.png" /></figure><p>As a food brand founder, I know first hand that staying ahead of FDA recalls is critical. FDA recalls can be scary — they often mean scrambling to identify if your inventory is affected, pulling potentially dangerous products, and reassuring customers. Imagine the peace of mind if your Production Manager or Executive Chef could receive a simple text message or email alerting you of any FDA recall matches to your current inventory.</p><p>This idea inspired me to build an <strong>FDA Recall Monitoring System</strong> using AWS services and the FDA Open API. It automates the process, saving time and reducing stress. Here, I’ll show you how I brought this project to life with AWS Lambda, S3, EventBridge, SNS, and Python.</p><p>Check out the GitHub repo here: <a href="https://github.com/autumnhicks01/FDA-recall-alert-system">https://github.com/autumnhicks01/FDA-recall-alert-system</a></p><h3>Step 1: Define the Project Goal</h3><p>The system automatically:</p><ol><li>Fetches FDA recall data from the last two weeks using the FDA Open API.</li><li>Compares the recall data to your restaurant’s inventory stored as a CSV file in Amazon S3.</li><li>Notifies stakeholders of any matches via Amazon SNS.</li><li>Schedules the process to run weekly using Amazon EventBridge.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*2eVJIazeuDx9UBeGeWnQRg.png" /><figcaption>Cloud Architecture in Amazon AWS</figcaption></figure><h3>Step 2: Prepare the Inventory Data</h3><p>For this project, the inventory data is stored as a CSV file in an S3 bucket. The structure is simple but effective.</p><h3>Steps:</h3><ol><li>Create an inventory file named restaurant-inventory.csv:</li></ol><pre>NUM,ITEM #,CATEGORY,DESCRIPTION,BRAND,PACK/SIZE 3,340403,ALMONDS,ALMONDS SLICED BLANCHED,HEMISPHERE,1/25LB 5,192402,ANCHOVIES,ANCHOVIES IN SOY OIL,PACKER,24/28 OZ</pre><p>2. Upload the file as an Object to your S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aS8JhIJelGirhuaNYc6DHw.png" /></figure><h3>Step 3: Set Up the Lambda Function</h3><p>The Lambda function is the brain of the project. It automates the entire process, ensuring recalls are checked weekly without manual intervention. The function accomplishes the following key tasks:</p><ol><li>Fetches recall data from the FDA Open API for the past two weeks.</li><li>Retrieves the restaurant inventory file from an S3 bucket.</li><li>Compares the inventory data with the recall data to identify matches.</li><li>Sends detailed notifications to stakeholders via SNS.</li></ol><h3>Python Script: Main Functions</h3><p>The Python script is broken into modular functions, each handling a specific part of the workflow:</p><h4>1. fetch_fda_recall_data()</h4><p>This function queries the FDA Open API to fetch recall data for the past two weeks.</p><p><strong>Key Tasks</strong>:</p><ul><li>Constructs the API URL with date filters.</li><li>Fetches data in JSON format.</li><li>Returns the recall data for further processing.</li></ul><p><strong>Code Snippet</strong>:</p><pre>def fetch_fda_recall_data():<br>    utc_now = datetime.now(timezone.utc)<br>    two_weeks_ago = utc_now - timedelta(days=14)<br>    start_date = two_weeks_ago.strftime(&quot;%Y-%m-%d&quot;)<br>    end_date = utc_now.strftime(&quot;%Y-%m-%d&quot;)<br>    <br>    api_url = f&quot;https://api.fda.gov/food/enforcement.json?search=report_date:[{start_date}+TO+{end_date}]&quot;<br>    print(f&quot;Fetching FDA recall data from: {api_url}&quot;)<br>    <br>    try:<br>        with urllib.request.urlopen(api_url, timeout=10) as response:<br>            data = json.loads(response.read().decode())<br>            recall_data = data.get(&quot;results&quot;, [])<br>            print(f&quot;Fetched {len(recall_data)} recall records.&quot;)<br>            return recall_data<br>    except Exception as e:<br>        print(f&quot;Error fetching FDA recall data: {e}&quot;)<br>        return []</pre><h4>2. load_inventory_from_s3()</h4><p>This function loads the restaurant inventory from an S3 bucket and cleans the data.</p><p><strong>Key Tasks</strong>:</p><ul><li>Retrieves the CSV file from S3.</li><li>Parses and normalizes the data.</li><li>Skips invalid rows (e.g., blank rows or missing fields).</li></ul><p><strong>Code Snippet</strong>:</p><pre>def load_inventory_from_s3(bucket_name, file_key):<br>    try:<br>        print(f&quot;Loading inventory from bucket: {bucket_name}, key: {file_key}&quot;)<br>        obj = s3.get_object(Bucket=bucket_name, Key=file_key)<br>        content = obj[&#39;Body&#39;].read().decode(&#39;utf-8&#39;).splitlines()<br>        <br>        reader = csv.DictReader(content)<br>        inventory = []<br>        for row in reader:<br>            normalized_row = {key.strip().upper(): value.strip() for key, value in row.items()}<br>            if not normalized_row.get(&quot;DESCRIPTION&quot;) or not normalized_row.get(&quot;BRAND&quot;):<br>                print(f&quot;Skipping invalid row: {normalized_row}&quot;)<br>                continue<br>            inventory.append(normalized_row)<br>        print(f&quot;Inventory data loaded successfully. Sample: {inventory[:3]}&quot;)<br>        return inventory<br>    except Exception as e:<br>        print(f&quot;Error loading inventory from S3: {e}&quot;)<br>        return []</pre><h4>3. find_recalled_inventory()</h4><p>This function compares the recall data with the inventory and identifies matches.</p><p><strong>Key Tasks</strong>:</p><ul><li>Matches recall descriptions with inventory descriptions.</li><li>Matches recall firms with inventory brands.</li><li>Returns a list of matched items.</li></ul><p><strong>Code Snippet</strong>:</p><pre>def find_recalled_inventory(recall_data, inventory_data):<br>    matches = []<br>    for recall in recall_data:<br>        for item in inventory_data:<br>            if (<br>                item[&quot;DESCRIPTION&quot;].lower() in recall[&quot;product_description&quot;].lower()<br>                or item[&quot;BRAND&quot;].lower() in recall[&quot;recalling_firm&quot;].lower()<br>            ):<br>                matches.append({<br>                    &quot;inventory_item&quot;: item,<br>                    &quot;recall_details&quot;: recall<br>                })<br>    return matches</pre><h4>4. publish_sns_message()</h4><p>This function sends notifications via SNS.</p><p><strong>Key Tasks</strong>:</p><ul><li>Compiles recall and match details into a message.</li><li>Publishes the message to the configured SNS topic.</li></ul><p><strong>Code Snippet</strong>:</p><pre>def publish_sns_message(sns_topic_arn, subject, message):<br>    try:<br>        header = &quot;Weekly FDA Recall Alert: Current Inventory Contains Recalled Items\n\n&quot;<br>        full_message = header + message<br>        sns.publish(TopicArn=sns_topic_arn, Message=full_message, Subject=subject)<br>        print(f&quot;SNS message published successfully: {subject}&quot;)<br>    except Exception as e:<br>        print(f&quot;Error publishing to SNS: {e}&quot;)</pre><h3>What the Lambda Function Needs to Accomplish</h3><p>When writing the Lambda function, ensure it:</p><ol><li>Fetches accurate FDA recall data using the fetch_fda_recall_data() function.</li><li>Loads and cleans the inventory CSV file using the load_inventory_from_s3() function.</li><li>Compares the inventory against recall data using find_recalled_inventory() to find all matches.</li><li>Sends clear, actionable alerts via the publish_sns_message() function, including:</li></ol><ul><li>Recall details (e.g., description, brand, recall number, lot number, and reason).</li><li>Inventory matches (if any).</li></ul><p>5. Runs efficiently and logs details to CloudWatch for debugging.</p><h3>Step 5: Schedule the Lambda Function with EventBridge</h3><p>The FDA releases new recalls weekly, usually on Wednesdays. That’s where EventBridge comes in — it ensures the Lambda function runs every Wednesday (I set it at 3 PM EST).</p><h3>Steps:</h3><ol><li><strong>Create an EventBridge Rule</strong>:</li></ol><p>Go to the <strong>EventBridge Console</strong>.</p><ul><li>Create a rule with the cron expression:</li></ul><pre>cron(0 20 ? * 3 *)</pre><ul><li>Set the target as your Lambda function.</li></ul><p><strong>2. Test the Schedule</strong>:</p><ul><li>Trigger the EventBridge rule manually to ensure it invokes the Lambda function correctly.</li></ul><h3>Step 6: Monitor and Debug with CloudWatch</h3><p>AWS CloudWatch logs are essential for monitoring and debugging. They capture key details, such as:</p><ul><li>Recall records fetched from the FDA API.</li><li>Inventory rows loaded from S3.</li><li>Matches found between inventory and recalls.</li></ul><h3>Steps:</h3><ol><li>Go to the <strong>CloudWatch Console</strong> and navigate to <strong>Log Groups</strong>.</li><li>Locate the log group for your Lambda function.</li><li>View execution logs to verify the system is working.</li></ol><h3>Step 7: Validate the System</h3><ol><li><strong>Check SNS Messages</strong>:</li></ol><ul><li>Confirm that SNS sends alerts for:</li><li>All FDA recalls from the last two weeks.</li><li>Inventory matches with recall details.</li></ul><ol><li><strong>Example SNS Message</strong>:</li></ol><pre>Weekly FDA Recall Alert: Current Inventory Contains Recalled Items  INVENTORY MATCH: NUM: 5 Item #: 192402 Category: ANCHOVIES Description: ANCHOVIES IN SOY OIL Brand: PACKER Recall Number: F-12345-2025 Lot Number: Lot A123 Recall Reason: Potential contamination with Listeria Recall Date: 2025-01-05 ---</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9Sa0u5wfofGTTsjyajNDA.png" /><figcaption>Test e-mail SNS</figcaption></figure><h3>Project Highlights</h3><ol><li><strong>Automation</strong>: Completely automates recall monitoring and notifications.</li><li><strong>Scalability</strong>: Can handle multiple inventory files or locations.</li><li><strong>Real-Time Monitoring</strong>: Ensures stakeholders are promptly notified of potential risks.</li></ol><h3>Closing Thoughts</h3><p>Building this project was a fun and meaningful way to solve a problem that we face in my industry. FDA recalls are serious business — there’s nothing scarier than wondering if your inventory might be affected and trying to piece it all together manually. This system is the tool I wish I’d had back then: a quick, automated way to check and get notified if there’s an issue.</p><p>For anyone in the restaurant or food production industry — or anyone who loves automating tedious processes — I hope this inspires you to try it out or even improve on it. Technology like this has the power to make operations smoother and a whole lot less stressful. If you have any questions, want to collaborate, or just share your thoughts, feel free to reach out. Let’s build smarter systems and take some of the stress out of running a business.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66fb7ec140ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>