N8N Integration
N8N is used as the workflow orchestration engine for document processing, AI extraction, and embedding generation.
Architecture
mermaid
sequenceDiagram
participant App as PIP AI Server
participant N8N as N8N Workflow
participant AI as OpenAI / LLM
participant DB as Supabase DB
participant Store as Supabase Storage
App->>N8N: Webhook trigger (with secret)
N8N->>Store: Download document (signed URL)
N8N->>AI: OCR / Extract / Embed
N8N->>DB: Upsert structured data
N8N->>App: Callback (status + results)Workflows
1. Spec Processing
Trigger: POST {N8N_BASE_URL}/webhook/pip-ai-spec-upsert
Payload:
json
{
"spec_upload_id": "uuid",
"document_id": "uuid",
"storage_path": "specs/brand/upload_id/file.pdf",
"brand_name": "Holiday Inn Express",
"area": "guest-room",
"property_name": "San Francisco Airport",
"job_id": "uuid"
}Steps:
- Download spec PDF via signed URL
- OCR/LLM extraction → structured sections
- Upsert
pip_ai_spec_sectionswith unique(spec_upload_id, spec_number) - Generate embeddings via OpenAI
text-embedding-3-small - Update processing status
- Callback to app
2. PIP Processing
Trigger: POST {N8N_BASE_URL}/webhook/pip-ai-pip-processor
Payload:
json
{
"document_id": "uuid",
"project_id": "uuid",
"storage_path": "pips/project_id/doc_id/file.pdf",
"job_id": "uuid"
}Steps:
- Download PIP PDF
- OCR/LLM extraction → structured line items
- Upsert
pip_ai_pip_itemswith unique(project_id, code) - For each item, query
pip_ai_search_specs()(filtered by brand + areas) - Insert candidate matches into
pip_ai_matches - Update processing status
- Callback to app
3. Floor Plan Processing
Trigger: POST {N8N_BASE_URL}/webhook/pip-ai-floor-plan-processor
Steps:
- Download floor plan
- Render to PNG + generate thumbnail
- OCR visible labels → extract spec codes
- Update
pip_ai_floor_plans.extracted_spec_codes[] - Link to known spec sections
- Callback to app
4. PDF Export
Handles document builder PDF generation.
5. AI Image Generation (Nano Banana)
Webhook Security
All webhooks use a shared secret for authentication:
Header: x-webhook-secret: <N8N_WEBHOOK_SECRET>Job Queue Pattern
N8N can also poll the pip_ai_upload_jobs table:
sql
-- Claim a job
UPDATE pip_ai_upload_jobs
SET status = 'processing', locked_at = now(), locked_by = 'n8n-worker'
WHERE id = '<job_id>' AND status = 'queued'
RETURNING *;Idempotency
All N8N workflows are designed to be safely re-runnable:
- Upserts use unique constraints
- Job status tracking prevents double-processing
retry_counttracks reprocessing attempts
Configuration
ini
N8N_BASE_URL=https://your-n8n-instance.com
N8N_WEBHOOK_SPEC_PROCESSOR=/webhook/pip-ai-spec-upsert
N8N_WEBHOOK_PIP_PROCESSOR=/webhook/pip-ai-pip-processor
N8N_WEBHOOK_FLOOR_PLAN_PROCESSOR=/webhook/pip-ai-floor-plan-processor
N8N_WEBHOOK_SECRET=your-shared-secret