Overview

The AI feature demonstrates a reusable way to plug intelligent capabilities into product flows without heavy boilerplate. It keeps calls on the server, returns schema‑validated data, and lets users preview results instantly in the UI.

What’s included

  • An example Branding Generator that turns short inputs into a style guide (colors, font, and philosophy).
  • A server‑first integration using server actions for validation and execution.
  • A preview UX that applies or resets generated styles without persisting changes.

Add to env

# OpenAI
OPENAI_API_KEY=

Keep API keys server-only. Do not expose them to client code. Use separate keys for local, staging, and production.

General pattern

  • Collect inputs in a Client Component (dialog/form).
  • Send to a Server Action for validation and execution.
  • Call OpenAI in a service module and return typed, JSON‑safe data.
  • Render results immediately and offer Preview / Reset controls.

Adapt the example

Use the same pattern for:

  • Onboarding checklists, step plans, or role‑based playbooks.
  • Product copy: feature blurbs, release notes, CTA variants.
  • Seed/demo data: mock projects, tasks, or content blocks.
  • Structured outputs: tables, JSON configs, CSV‑ready rows.

Prompt and schema tips

  • Give concise context, constraints, and examples; favor clarity over length.
  • Return structured JSON and validate it before rendering.
  • Design UI to bind to typed fields and handle missing data gracefully.
  • Log errors without leaking user inputs or secrets.

Security & performance

  • Run model calls on the server (server actions/API routes) and sanitize inputs.
  • Avoid logging secrets or full prompts in production; redact sensitive data.
  • Cache, debounce, or cap requests where appropriate; surface friendly errors.

Local development

  1. Add OPENAI_API_KEY to .env.local, then restart the dev server.
  2. Open Dashboard → Branding Generator to test end-to-end.
  3. Iterate on prompts and the result schema together to keep the UI stable.

Notes

  • The Branding Generator is an example-swap prompts and schemas to power your own ideas.
  • Keep the service small and testable; keep client components focused on UX.
  • Add persistence later (e.g., save accepted outputs) when the UX is proven.