How discovai/discovai-search works
• Frontend (Next.js App):
– Pages, layouts, and various UI components in the src/app and src/components folders.
– This layer handles presentation, user interactions (e.g., search queries, navigation), and state management (stores and hooks exist in src/stores and src/hooks).
– Also includes tailored UI components from libraries like shadcn/ui and Radix UI with styling via Tailwind CSS.
• API / Backend Services:
– API endpoints under src/app/api (e.g., api/chat, api/join-wait) serve as the bridge between the frontend and backend logic.
– These API routes manage chat functionalities, waiting list processing, and perhaps other dynamic responses.
• Data Layer & External Services:
– Supabase and the SQL scripts (src/db/init.sql) indicate that data (like the AI tool database and user information) is housed in a Postgres/Supabase setup.
– Pgvector is used for vector similarity operations.
– Redis (through Upstash integration as seen in src/db/redis.ts and environment variables) handles caching of search results and LLM outputs.
– Integration with third-party services for LLM (gpt-4o-mini/OpenAI APIs) and embeddings (via Jina AI) that are orchestrated through modules in src/lib (e.g., src/lib/chat/embedding.ts, src/lib/chat/llm.ts).
Relationships and interactions
• Calls going from API endpoints to the database layer (Supabase) for fetching AI tool data.
• API interactions with Redis (using Upstash) for caching responses and quick lookups.
• Requests to external services: one path for embedding conversion (Jina AI) and one path for LLM responses (OpenAI’s gpt-4o-mini).
Underlying architectural patterns/design principles
• Separation of concerns – the clear separation between the presentational (frontend UI), API (backend logic), and data (database and caching) layers.
• Modular design – the codebase splits logic into distinct modules (e.g., chat-related functions, database connectors, UI components).