How supermemoryai/opensearch-ai works
Project type and purpose
• This is a full-stack AI-powered search application built with Next.js.
• The README describes it as a personalized AI search engine (“OpenSearch GPT”) that remembers user context via Mem0 and powers chat queries with GPT-4-mini.
File structure
• Top-level files/configs: package.json, tsconfig.json, next.config.mjs, tailwind.config.ts, postcss.config.js, wrangler.toml (for Cloudflare Pages).
• “app/” directory: Next.js 13+ App Router pages and layouts (page.tsx, layout.tsx, not-found.tsx, chatpage.tsx).
• “app/api/”: serverless API routes for NextAuth (app/api/[...nextauth]/route.ts) and chat (app/api/chat/route.ts).
• “server/”: server-side logic (e.g., auth.ts).
• “components/”: reusable UI pieces (hooks, UI primitives, search-results etc.).
• “lib/”: shared utilities (utils.ts).
• “public/” & “app/assets/”: static assets (fonts, manifest).
Insights from README
• Core dependencies: Next.js, Vercel AI ADK, Tailwind CSS with Shadcn UI, Cobe for globe animation, Mem0 for memory retrieval, GPT-4-mini inference.
• Deployment target: Cloudflare Pages via wrangler.toml.
Main components
a. Frontend (Next.js App Router)
• UI layers: Layout, Pages, Glossy components (Blobs, Card, Globe).
• Styling: Tailwind + Shadcn UI.
b. API layer (serverless routes)
• Auth: NextAuth route (OAuth, session handling).
• Chat: /api/chat route invoking GPT-4-mini and Mem0 calls.
c. Memory store (Mem0)
• External service handling user memory ingestion & retrieval.
d. AI inference (OpenAI GPT-4-mini)
• External LLM endpoint.
e. Static assets & CDN
• Public assets served via Cloudflare Pages.
f. Deployment & hosting
• Cloudflare Pages + Wrangler for build & deploy.
Relationships & data flow
• User interacts with Frontend (browser).
• Frontend fetches data via Fetch/Axios to /api/chat or NextAuth endpoints.
• /api/chat:
1) receives user query
2) calls Mem0 to retrieve context
3) forwards context + query to GPT-4-mini
4) sends AI response back to client
• Authentication flows via NextAuth callbacks in /api/[...nextauth].
• Static files served directly from CDN.
Architectural patterns & design principles
• Full-stack serverless pattern (Next.js App Router + API routes).
• Separation of concerns: UI components vs. business logic (lib/utils & server/).
• Extensibility: modular components folder & hooks.
• Cloud-native deployment (Cloudflare Workers / Pages).
Final checklist
• Clear, consistent component boundaries
• Labels for protocols, framework names, and file-group origins (e.g., “app/api/chat/route.ts”)