How mudasir345/perplexityai-clone works
Project Type and Purpose
• This is a full-stack, AI-powered search engine inspired by Perplexity AI.
• It incorporates multiple search modes (normal search, academic, image, video, Reddit, Wolfram Alpha, etc.) along with advanced features like similarity search and support for local LLMs (for example, via Ollama).
• Its goal is to enable both traditional web search and intelligent querying with AI-driven query enhancements.
File Structure to Define Main Components
• Backend (located in the "src" directory):
• Contains separate subdirectories for:
∙ Agents: Individual search strategy implementations (e.g., academicSearchAgent.ts, imageSearchAgent.ts, etc.) that abstract specific search functionalities.
∙ Routes: API endpoints (e.g., routes for chats, configs, models, search, suggestions, etc.) that define how external clients can interact with the backend.
∙ Database: Components under src/db that include schema definitions and database connection logic.
∙ Websocket: Modules managing real-time communication (connectionManager.ts, websocketServer.ts, messageHandler.ts) to support interactive features.
∙ Libraries/Utils: General-purpose libraries (e.g., providers for external APIs like OpenAI or Anthropic, output parsers, similarity computations, etc.) that encapsulate business logic.
• Frontend (located in the "ui" directory):
• Built as a Next.js application (notice the "page.tsx", Next config, tailwind.config.ts, and other UI components).
• Contains components and libraries dealing with authentication, chat interface, search capabilities, and theme management.
• Infrastructure and Deployment:
• Multiple Dockerfiles (app.dockerfile and backend.dockerfile), and a docker-compose.yaml file imply container-based deployment.
• Documentation in the “docs” directory provides additional architectural, API, and installation insights.
• External Tools/Services:
• SearxNG (configuration in the “searxng” directory) as the metasearch engine is a core component.
• Various API integrations with services like OpenAI, Ollama, Anthropic, and Groq manage the AI and search elements.
Defining Relationships and Interactions Between Components
• Frontend (Next.js UI):
• Acts as the client interface.
• Interacts with backend API endpoints (via REST or WebSocket) to send search queries and receive responses.
• Backend API:
• Orchestrates search functionalities by routing queries through various “agents” based on the selected mode (normal, academic, image, etc.).
• Communicates with the SearxNG metasearch engine to obtain aggregated and re-ranked results.
• Implements real-time updates and notifications through the WebSocket module.
• Handles user configuration and state management.
• Database:
• Stores historical data, user settings, and search indices or schema required by the app.
• External Integrations:
• Providers in src/lib are in charge of interfacing with third-party services (for example, local LLM connections via Ollama, or querying OpenAI’s APIs).
• Deployment Infrastructure:
• Docker, Docker Compose, and associated configuration files ensure the system is containerized and smoothly deployed to various environments.
Important Architectural Patterns and Design Principles
• Modular Design: Separation of concerns between functionalities (agents, routes, DB, websocket, UI).
• Microservices-ish separation: Even if all components are in one repository, having a clear distinction between frontend and backend (and even further, separation of search agents) resembles a microservices architecture.
• Containerization: Use of Docker for isolation and deployment.
• Real-Time Communication: The inclusion of WebSocket modules demonstrates a need for immediate, event-driven data flow (e.g., live chat or dynamic search suggestions).
• Extensible Integration: Interface modules for external providers hint at extensibility and straightforward integration of multiple AI and search services.
• UI (Frontend/Next.js)
• Backend API (with subcomponents such as Agents, Routes, Websocket Manager, DB interface)
• External Services (SearxNG, and individual 3rd party provider integrations like OpenAI, Ollama, Anthropic, etc.)
• Database module
• Infrastructure Layer (Docker, Docker Compose)
• UI to API endpoints (REST/WebSocket calls)
• API to external search services and LLM providers
• API to DB interactions for logging/search history
• Notes on key design patterns (e.g., "modular agents", "real-time WebSocket communication") close to each relevant component.