Architecture

How Tempo is wired.

AI doesn't assist the workflow — it drives it. Below is how the system is designed.

System stack

Next.js 16

App Router, API Routes, Middleware Auth

Auth Layer

NextAuth JWT, per-route validation, role hierarchy

AI Engine

LLM with tool_use for agentic workflows

Tool Execution

8 tools: search, update, remind, note, query, bulk ops

Supabase

Postgres, RLS, Storage, real-time

Agentic loop

The AI agent uses tool_use to reason and act in a loop. Each iteration: the AI decides what to do, the system validates and executes the tool, then returns the result for the next reasoning step.

User Message
AI Reasoning
Tool Validation
Execute & Log
Return Result
Final Response

while (iterations < MAX_TOOL_CALLS) {
  response = ai.messages.create(tools, messages)
  if (no tool_use) return response.text
  for (tool in response.tool_use) {
    validate(tool.name) // reject hallucinated tools
    result = executeTool(tool) // try/catch with error recovery
    messages.push(tool_result)
  }
}

Safety layers

JWT Auth

Every API route validates NextAuth token before processing

Zod Validation

Request bodies validated against strict schemas — rejects malformed input

Tool Whitelist

Agent can only call 7 predefined tools — hallucinated tool names are rejected

Error Recovery

Tool failures return structured errors to the AI — agent recovers gracefully

Field Whitelist

Only specific claim fields can be modified — no arbitrary DB writes

Audit Trail

Every agent action logged with timestamp, tool name, and outcome

Production roadmap

What I'd add before deploying to enterprise customers:

Response streaming (SSE) for real-time token display
Exponential backoff with jitter on API failures
Per-organization cost tracking and usage limits
Sentry error tracking with source maps
Rate limiting per user (Upstash / Vercel KV)
Multi-tenant data isolation via org_id scoping
Prompt versioning and A/B testing framework
OpenTelemetry tracing for end-to-end observability
Tech stack
Next.js 16React 19TypeScriptSupabaseAI (LLM)Tailwind CSS v4shadcn/uiZodNextAuthVercel