How ikueisou/morphic works
Project type and purpose
• This is a full-stack, AI-powered search engine web application named “Morphic,” built on Next.js App Router and TypeScript. It provides a React-based Generative UI for chat and search, integrates with multiple AI and search providers, and optionally persists chat history in Redis.
File structure
• Top-level “app” directory contains Next.js pages and API routes (app/page.tsx, app/api/chat/route.ts, app/api/advanced-search/route.ts).
• “components” holds UI components (chat panels, search sections, shadcn/ui wrappers).
• “lib” contains business logic and services:
• actions (chat orchestration)
• agents (related-questions, researcher)
• tools (question, retrieve, search, video-search)
• streaming (Vercel AI SDK streams)
• redis config
• utils & hooks
• “public/config/models.json” supplies model configurations.
• Dockerfile/docker-compose.yaml for containerized deployment.
• Middleware (middleware.ts) for routing or auth.
Additional README insights
• Next.js + React Server Components, Vercel AI SDK streaming, Tailwind CSS + shadcn/ui for styling.
• AI providers via SDK; search providers via HTTP.
• Redis (local or Upstash) for optional chat history.
• Supports SearXNG, Tavily, Exa search engines.
Main components & relationships
a. Browser Client (Next.js React pages & RSCs)
b. Next.js Server / Edge Functions (App Router handlers + API Routes)
c. Lib Service Layer
• Agents & Tools: encapsulate search and AI-orchestration logic
• Streaming sub-layer: handles Vercel AI SDK streams
d. Data Store: Redis (Upstash or local)
e. External Services:
• AI Providers (OpenAI, Anthropic, Google AI, etc.)
• Search Providers (Tavily, SearXNG, Exa, Video APIs)
f. Public Assets & Config (models.json, static images)
Interactions:
1) User enters query → Browser Client UI component → invokes API route (/api/chat or /api/advanced-search)
2) API handler pulls in lib/actions which delegate to agents/tools
3) Tools call external search provider(s) over HTTP, then feed to AI via Vercel AI SDK streaming
4) Streaming responses flow back through API to Browser Client
5) If history enabled → lib/redis stores or retrieves chat history
Architectural patterns & principles
• Separation of concerns: UI (components) ↔ API Routes ↔ Service layer (lib) ↔ External integrations
• Streaming data flow via Vercel AI SDK (event-driven)
• React Server Components & Edge Functions for low-latency rendering
• Config-driven providers (public/config, .env)