How goatninja10/unify-ai works
Project Type and Purpose
• This is a full-stack web application built with Next.js (frontend + backend API routes) that provides a unified interface for interacting with multiple large language models (LLMs).
• It integrates headless browser automation (Playwright) for the Scira model and calls external AI services (Together AI for DeepSeek R1 and Meta-LLaMA).
• It persists user sessions and chat history in a local SQLite database via Prisma ORM.
File Structure Analysis
• Top-level:
• app/ – Next.js “app” directory containing UI pages, layouts, and API routes under app/api.
• components/ui/ – ShadCN/Tailwind UI primitives.
• lib/ – utility functions and type definitions.
• prisma/ – database schema, migration files, and dev.db.
• public/, styles/, tailwind.config.ts – styling and static assets.
• next.config.mjs, tsconfig.json – framework and TypeScript config.
• Key patterns:
• API routes for ai-chat, auth (NextAuth), health.
• Prisma for data access.
• Playwright wrapper invoked in the ai-chat route.
• Markdown processing pipeline using remark plugins.
README Insights
• Multi-model modes: scira, deepseek, chained, meta-llama.
• Chaining logic (Scira → cleanup → Together AI).
• Tech stack: Next.js 15, React 19, Tailwind, ShadCN, Playwright, remark, Prisma, SQLite.
Main Components
A. Client Browser (Next.js React SPA)
B. Next.js Server (Node.js)
1. API Layer
• /api/ai-chat route
• /api/auth routes (NextAuth)
• /api/health route
2. Service Modules
• Playwright Scira Scraper
• Markdown Processor (remark-gfm, remark-math, cleanup logic)
• Together AI Client for DeepSeek R1 & Meta-LLaMA
3. Database Access
• Prisma ORM → SQLite (dev.db)
C. External Services
• Scira website (via headless Chromium)
• Together AI endpoints (DeepSeek R1, Meta-LLaMA)
Relationships and Data Flows
• User in browser interacts with React components → triggers ai-chat fetch.
• Next.js API route receives POST /api/ai-chat.
• Depending on mode:
• If “scira” or “chained”: spawn Playwright to scrape Scira; handle timeouts.
• Clean up Scira’s markdown output.
• If “deepseek” or “chained”: forward cleaned output to Together AI.
• Optional Meta-LLaMA calls for meta-llama modes.
• Aggregate responses, store conversation record via Prisma.
• Return JSON with per-model responses and final output.
• Frontend renders finalOutput, history, metrics.
Architectural Patterns and Design Principles
• Clear separation of concerns: UI layer, API layer, service wrappers, data access.
• Modular service clients for each LLM integration.
• Single database for user/session/chat persistence.
• Error handling and retry logic encapsulated in service modules.
• Pipeline composition for chained operations.
Final Advice
• Conditional paths (scira only vs. deepseek vs. chained).