AI Agent

Technical documentation for the portfolio app built with Node.js, n8n and Supabase.

PT-BR

Demo

Live interaction flow of the chat UI with the current deployed environment.

AI Agent app demo showing chat interaction and responses

Overview

AI Agent is a general AI portfolio project with a chat interface and an integration-first backend. The app sends user prompts to an n8n webhook flow and returns the response in a simple chat UX. Interactions and execution metadata can be persisted in Supabase for observability.

Architecture

UI (public/) -> POST /api/agent -> rate-limit middleware -> controller -> service -> n8n webhook
                          \-> saveInteractionLog -> Supabase
UI (public/) -> GET /api/agent/metrics -> controller -> Supabase aggregate (fallback: runtime)

API

POST /api/agent

Send a user message to the assistant.

{
  "message": "Explain this timeout"
}

GET /health

{ "ok": true }

GET /api/agent/metrics

Returns real-time dashboard metrics from Supabase (or in-memory runtime fallback when unavailable).

{
  "ok": true,
  "totalExecutions": 12842,
  "criticalErrors": 12,
  "avgResponseTimeMs": 248,
  "durationSampleSize": 500,
  "source": "supabase"
}

Environment Variables

PORT=3000
N8N_WEBHOOK_URL=https://your-n8n-instance/webhook/agent
SUPABASE_URL=https://.supabase.co
SUPABASE_SERVICE_ROLE_KEY=
SUPABASE_TABLE=agent_messages

# n8n retry policy (429)
N8N_RETRY_MAX=2
N8N_RETRY_BASE_DELAY_MS=800

# API rate limit (per IP)
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=20
RATE_LIMIT_BLOCK_MS=30000

# Metrics sampling
METRICS_SAMPLE_LIMIT=500

Local Setup

  1. Install dependencies: npm install
  2. Configure .env from .env.example
  3. Run app: npm run dev
  4. Open http://localhost:3000

Supabase Table

create table if not exists public.agent_messages (
  id bigserial primary key,
  created_at timestamptz not null default now(),
  message text,
  response_body jsonb,
  ok boolean not null default false,
  error_message text
);

Troubleshooting

Recent Changes