How sakshamagarwalm2/synthia works
Project Type and Purpose
• Synthia is a full-stack AI-driven web application built with Next.js (App Router). It offers intelligent search and research capabilities by integrating multiple external services (Google Custom Search, Gemini AI) and a managed backend (Supabase, Clerk, Inngest).
File Structure Analysis
• Top-level folders:
• app/ – Next.js routes and React server/client components.
• components/ – Reusable UI primitives (Shadcn UI + Radix UI wrappers).
• context/, hooks/ – React context providers and custom hooks.
• api routes under app/api/ – Next.js serverless functions.
• inngest/ – Inngest client and functions for background jobs.
• Services/ – External service configuration (Supabase client).
• lib/ – Helper utilities.
• Configuration: next.config.mjs, tsconfig.json, middleware.js for Clerk auth.
Key Insights from README
• Frontend: Next.js + Tailwind + Shadcn UI + Lucide React + Radix UI components.
• Authentication: Clerk.
• Database: Supabase (Users, Librery, Chats tables).
• Asynchronous tasks: Inngest triggered by /api/llm-model to generate AI summaries.
• External APIs: Google Custom Search for search results; Gemini AI for summarization.
Main Components
a. Client (Browser)
• UI pages (Home, Search Results, Library, Discover)
• Shared components (AppSidebar, ChatInputBox, CreditPopup, Tabs)
b. Next.js Application
• App Router (app/ pages + layout)
• API Routes:
• /api/search-api → Google Custom Search
• /api/llm-model → Gemini AI + Inngest trigger
• /api/inngest → Inngest webhook handler
• /api/get-inngest-status → Poll job status
• Middleware: Clerk authentication guard
c. Backend Services
• Supabase (PostgreSQL):
• Users table (authentication, credits)
• Librery table (search sessions)
• Chats table (search results, AI responses)
• Inngest Serverless Functions: background processing of AI responses
d. External APIs
• Google Custom Search API
• Gemini AI API (summarization)
• Clerk (Auth as a Service)
Relationships and Data Flows
1. User interacts with UI in Browser → sends requests to Next.js front end.
2. On search submission:
• Next.js API /api/search-api calls Google Custom Search → returns raw search results.
• Results are saved to Supabase.Chats and Librery (if authenticated).
• Next.js API /api/llm-model triggers an Inngest job with search data → Inngest calls Gemini AI → writes AI summary back to Supabase.Chats.
• Frontend polls /api/get-inngest-status to receive updated AI summary in real time.
3. UI reads data from Supabase via direct fetches in server components or via client SDK (supabase.jsx).
4. Auth flow: Clerk middleware ensures protected routes are only accessible to logged-in users; guest users have limited functionality.
Architectural Patterns and Design Principles
• Separation of Concerns:
• UI layer (React components)
• API layer (Next.js serverless functions)
• Data layer (Supabase)
• Background processing (Inngest)
• Event-Driven Asynchrony: Inngest functions decouple AI summarization from synchronous request flow.
• Contextual State Management: React Context for user details, custom hooks for responsive behavior.
• Modular Component Architecture: Shadcn UI + Radix UI primitives, local _components vs shared components.
Final Advice
• Every path: user authentication → search → storage → AI summarization → real-time update.
• Don’t overcomplicate – show each major component and its interactions.