How u14app/deep-research works
Project type and purpose
• Deep Research is a full-stack web application built with Next.js (v15) and Shadcn UI.
• It serves a React‑based frontend in the browser and a set of serverless API routes for AI model proxying and web search proxying.
• It can be deployed to Vercel, Cloudflare Pages, or run in Docker.
Main components
a. Client (Browser)
• Next.js App Router (src/app)
• React Components (src/components)
• State Management & Local Storage (src/store + src/utils/storage.ts)
• Editor (MilkdownEditor)
b. Next.js Server (Serverless functions)
• API Routes under src/app/api/ai/* – proxy endpoints for AI providers (OpenAI, Gemini, Anthropic, Ollama, etc.)
• API Routes under src/app/api/search/* – proxy endpoints for search engines (SearxNG, Bocha, Exa, Firecrawl, Tavily)
• Middleware (src/middleware.ts)
c. External Services
• AI Provider APIs (Google Gemini, OpenAI, Anthropic, Deepseek, OpenRouter, Ollama, etc.)
• Web Search Engine APIs (SearxNG, Bocha, Exa, Firecrawl, Tavily)
d. Deployment / Infrastructure
• Vercel Edge Functions / Cloudflare Workers (via vercel.json, wrangler.toml)
• Docker Container (Dockerfile, docker-compose.yml)
• CDN / Static File Hosting (public/, out/)
Relationships and data flow
1. User interacts with UI in browser → triggers React state changes or form submissions.
2. Client-side code invokes Next.js API routes (under /api) via fetch calls.
3. API route receives request → applies any middleware/auth (ACCESS_PASSWORD) → proxies request to the chosen external AI or search API (using env vars, multi-key support).
4. External service returns data → API route returns JSON to browser.
5. Browser updates state/store, renders results, and persists history to localStorage.
Architectural patterns and design principles
• “API Gateway” pattern: all AI/search calls go through centralized serverless endpoints.
• Separation of concerns:
• Presentation layer (components/ui + page.tsx + layout.tsx)
• Business logic/hooks (src/hooks)
• Data layer (API routes + utils + store)
• Extensibility: each AI provider or search engine is implemented in a separate directory under src/app/api, following a plug‑in–style structure.
• Env Variables (.env / env.tpl) feeding into the Serverless layer.
• Optional paths: static export (out/ directory) vs. dynamic mode.
• Custom patterns (e.g., Hook usage, Provider context for Theme/I18n).