How zkarimi22/multi-model works
Project Type & Purpose
• This is a full-stack web application built on Next.js 15 (App Router) that streams and displays side-by-side AI model responses.
• It includes both client-side UI and server-side API routes for proxying requests to OpenAI and OpenRouter.
File Structure
• src/app
– page.tsx, layout.tsx, globals.css: entry points for pages & global styling
– api/models/route.ts: serverless API route that orchestrates model calls
• src/components
– layout/: header, footer
– open-mode/: UI modal for entering custom API keys
– ui/: buttons, cards, dialogs, inputs, theme toggle, toast notifications
• src/hooks
– useChat.ts: client hook to manage chat state & streaming
– useOpenRouter.ts: hook for interacting with OpenRouter endpoints
• src/providers
– theme-provider.tsx: context for light/dark mode
• src/lib/utils.ts, src/config/models.ts, src/types/index.ts: shared utilities, type definitions
• Public & Config Files
– public/: static assets and Open Graph image
– Tailwind, ESLint, Next.js config files
README for Tech Stack & Features
• Next.js 15 (App Router) + TypeScript
• Tailwind CSS + Radix UI primitives
• OpenAI SDK & OpenRouter API for streaming AI responses
• “Open Mode” allows injecting your own API key
Main Components & Their Relationships
A. Client Browser (React on Next.js)
– Renders UI components, layouts, theme toggle
– Uses useChat & useOpenRouter hooks to open WebSocket or HTTP streams
B. Next.js Server (App Router + API Routes)
– SSR / SSG for initial page load via page.tsx
– API Route at /api/models that accepts prompts & model selections, then forwards requests
– Streams AI responses back to the client
C. External AI Services
– OpenAI (via their SDK)
– OpenRouter (via REST endpoints)
D. CDN / Static Assets
– Served from public/ via Next.js’ static file handling
E. (Optional) Monitoring / Logging / Analytics
– Not present now, but leave room for future observability components
Architectural Patterns & Design Principles
• Separation of Concerns: clear split between UI, state management (hooks), business logic (API routes), and utilities.
• Serverless Functions: each file in src/app/api becomes a serverless endpoint (e.g., Vercel, Netlify).
• Streaming Data Flow: responses from AI providers are piped through streams to the browser, enabling real-time comparison.
• Component-Driven UI: Radix + Tailwind for reusable, accessible building blocks.