Adding AI to Existing Apps
The #1 question devs ask: 'I have an existing app — how do I add AI?' Today you'll learn the patterns: AI-powered search, smart autocomplete, content generation, automated tagging, and intelligent routing. You'll take a standard Next.js CRUD app and add 3 AI features without rewriting anything.
Use this at work tomorrow
Pick the highest-value feature in your app and add AI — search, autocomplete, or auto-tagging.
Learning Objectives
- 1Identify which features in existing apps benefit most from AI
- 2Add AI-powered search to replace keyword search (Day 2 → production)
- 3Implement smart autocomplete and content suggestions
- 4Add automated content tagging and classification
- 5Ship 3 AI features into an existing Next.js app — zero rewrites
Ship It: AI features in an existing Next.js app
By the end of this day, you'll build and deploy a ai features in an existing next.js app. This isn't a toy — it's a real project for your portfolio.
I can audit an existing app for AI opportunities, add AI features progressively, and keep graceful degradation when AI is unavailable.
In reality, how will you most often use AI engineering skills?
Adding AI to Existing Apps: The Real-World Skill
Most AI tutorials build from scratch. In reality, you'll add AI to existing CRUD apps that already have users, databases, and business logic. This is the hardest and most valuable skill: identifying WHERE AI adds value in an existing product and adding it WITHOUT breaking what already works. Today's lesson is a surgical guide to AI integration.
Why is adding AI to existing apps harder than building from scratch?
The AI Opportunity Audit: Where to Add AI
Audit your existing app with this framework: (1) Text generation — anywhere users need to write (emails, descriptions, comments). (2) Search — anywhere users search or filter (replace keyword search with semantic search). (3) Classification — anywhere users categorize things manually (tagging, prioritization, routing). (4) Extraction — anywhere users read and extract data (form filling from documents, data entry). (5) Summarization — anywhere users read long content (meeting notes, reports, threads).
Which type of AI enhancement typically has the best effort-to-impact ratio?
What's the safest way to add AI to an existing feature?
Pattern: Progressive AI Enhancement
Don't rip out your existing features. Enhance them progressively. Start with "AI suggestions" alongside existing UI — user can accept or ignore. Then make AI the default with easy override. Finally, automate fully for high-confidence cases. Example: search bar → add "AI Answer" card above regular results. Form → add "Auto-fill with AI" button. Listing → add "AI-generated description" draft. Each step is independently shippable and testable.
What's the first step in progressive AI enhancement?
Pattern: AI-Augmented CRUD
Most web apps are CRUD. Add AI at each step: Create — auto-generate draft content, suggest categories, validate with AI. Read — summarize long items, highlight key info, AI-powered search. Update — suggest changes, auto-complete fields, detect anomalies. Delete — confirm impact with AI analysis ('this will affect 3 downstream records'). Each makes your existing app significantly more useful without rewriting it.
Integration Architecture: Where AI Code Lives
Keep AI code isolated from business logic. Create an /api/ai/ namespace for AI endpoints. Use the adapter pattern: AIService wraps your LLM calls and returns typed results that your existing code consumes. Your React components call the AI service just like any other API. This way, you can swap models, add caching, or remove AI features without touching business logic.
Why isolate AI code behind an adapter/service pattern?
The Full Evolution
Watch one function evolve through every concept you just learned.
Production Gotchas
AI features MUST be optional and gracefully degradable. If the AI API is down, your app should still work — show the original UI without AI enhancements. Set aggressive timeouts (3-5 seconds) — users will tolerate 'AI unavailable' more than a frozen page. Feature-flag every AI integration so you can kill it instantly. Start with the lowest-risk, highest-value feature first. Get real user feedback before expanding. Most users want AI to save time, not to be 'smart' — optimize for speed.
Code Comparison
Regular Search vs AI-Enhanced Search
Adding AI to an existing search feature without replacing it
// Existing search: keyword matching
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const query = searchParams.get("q") || "";
// SQL LIKE search
const results = await db.products.findMany({
where: {
OR: [
{ name: { contains: query } },
{ description: { contains: query } },
],
},
take: 20,
});
return Response.json({ results });
}
// "comfortable office chair for back pain"
// → Matches: "chair", "office"
// → Misses: "ergonomic", "lumbar support"
// → 3 results, none great// Enhanced search: AI + existing, side by side
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const query = searchParams.get("q") || "";
// Keep existing search (always works)
const keywordResults = await db.products.findMany({
where: {
OR: [
{ name: { contains: query } },
{ description: { contains: query } },
],
},
take: 10,
});
// Add AI search (optional enhancement)
let aiResults: any[] = [];
let aiSummary = "";
try {
const embedding = await embed(query);
aiResults = await vectorSearch(embedding, 5);
const { text } = await generateText({
model: openai("gpt-4o-mini"),
prompt: `Summarize the best match for:
"${query}" from: ${JSON.stringify(
aiResults.map(r => r.name)
)}`,
});
aiSummary = text;
} catch {
// AI fails gracefully — keyword results
// still show, app still works
}
return Response.json({
aiSummary, // "Based on your needs..."
aiResults, // Semantic matches
results: keywordResults, // Always works
});
}
// "comfortable office chair for back pain"
// AI: "ergonomic", "lumbar support", "posture"
// → 5 semantic matches + summaryKEY DIFFERENCES
- Keyword search stays as fallback — app always works
- AI search runs in parallel, wrapped in try/catch
- AI adds semantic matches + natural language summary
- Gradual enhancement: keyword → keyword + AI → AI primary
Bridge Map: Existing codebase → AI-enhanced features
Click any bridge to see the translation
Hands-On Challenges
Build, experiment, and get AI-powered feedback on your code.
AI-Enhanced Existing App
Take an existing CRUD app (todos, notes, tasks, or any project you've built before) and add 3 AI features without rewriting anything: auto-categorization, semantic search, and AI content generation. This is the #1 skill companies hire for — adding AI to existing products.
Acceptance Criteria
- Start with an existing CRUD app (build a simple one if needed, or use an open-source template)
- Add AI auto-categorization that classifies new items automatically with confidence scores
- Replace keyword search with semantic search while keeping keyword search as fallback
- Add 'Generate with AI' buttons for text fields (descriptions, summaries, etc.)
- Each AI feature must have a feature flag toggle (on/off)
- All AI features must fail gracefully — the app works fine without them
- Deploy to a public URL (Vercel, Netlify, etc.)
Build Roadmap
0/6Either use an existing CRUD app you've built, clone an open-source template, or quickly scaffold a todo/notes app with Next.js. The app needs: create, read, update, delete, and a list view.
A simple todo or notes app is perfect — the AI features are what matterIf building from scratch: npx create-next-app + a MongoDB or JSON file backendMake sure it works fully before adding any AIDeploy Tip
Push to GitHub and import into Vercel. Pre-populate with sample data so all AI features are visible immediately. This project proves you can add AI to real products — the #1 skill companies want.
Sign in to submit your deployed project.
I can audit an existing app for AI opportunities, add AI features progressively, and keep graceful degradation when AI is unavailable.