How theaiautomators/insights-lm-public works
Project Type and Purpose
• InsightsLM is a full-stack, self-hostable, retrieval-augmented generation (RAG) web application.
• Frontend: a React + TypeScript single-page app (SPA) built with Vite, Tailwind CSS, and shadcn-ui.
• Backend: Supabase (PostgreSQL database, authentication, storage) plus Supabase Edge Functions for custom logic, and n8n for workflow automation and integration with AI services (OpenAI, Gemini).
File Structure
• Top-level directories:
• src/ — the entire frontend code (components, hooks, pages, contexts, services).
• supabase/ — database migrations and Edge Functions (TypeScript handlers).
• n8n/ — JSON exports of workflow definitions that run on the n8n server.
• Configuration files:
• supabase/config.toml — Supabase project config.
• tailwind.config.ts, postcss.config.js — CSS build setup.
• vite.config.ts — frontend bundler config.
• .github/workflows/deploy.yml — CI/CD pipeline for deployment.
• Scripts:
• patch-supabase.js — one-time DB patch tool.
Key Architectural Components
a. Client Browser (User)
b. React SPA (frontend)
c. Supabase:
– Database (PostgreSQL + vector extension)
– Auth & Storage
– Edge Functions (HTTP endpoints in supabase/functions/)
d. n8n Workflow Engine
– Hosted separately or via cloud
– Workflows imported from n8n/*.json
e. External AI Services
– OpenAI, Gemini (for embeddings, chat, transcription, TTS)
f. CI/CD
– GitHub Actions deploy pipeline
Relationships and Data Flows
1. User interacts with the React SPA in their browser.
2. SPA uses the Supabase client (src/integrations/supabase/client.ts) to authenticate and read/write data.
3. For complex operations (document processing, chat, podcast generation):
• SPA calls a Supabase Edge Function (e.g., send-chat-message).
• Edge Function issues an authenticated webhook request to n8n.
• n8n workflow orchestrates calls to AI services and Supabase (vector upserts, row inserts).
• n8n returns results, Edge Function persists final data in Supabase, or triggers real-time updates.
4. SPA subscribes or polls database tables for new chat messages, notes, audio URLs, etc.
Architectural Patterns and Design Principles
• Microservices Style:
• Each Edge Function is its own HTTP micro-endpoint.
• n8n represents a separate service for business-logic workflows.
• RAG Pattern:
• Documents are processed into embeddings stored in the Supabase vector extension.
• Chat queries perform vector searches, then run LLM calls.
• Real-time / Event-Driven:
• Supabase Realtime for pushing updates to the UI when new data arrives.
• Separation of Concerns:
• UI (React) vs. Business Logic (Edge Functions + n8n) vs. Data Storage (PostgreSQL).
Detailed Capture
• N8n/Import_Insights_LM_Workflows.json as the master workflow that deploys sub-workflows.
• Database table for vectors and notes, referencing the migration SQL.
• Supabase Secrets used for secure webhook authentication.