How yuconnorl/psychedelics-db works
Main Components
• Client/Frontend – Built on Next.js (see the “app” directory with pages such as “/database”, “/research”, and “/about”) and a variety of reusable UI components in “src/components” and “src/components/ui”.
• Backend API Endpoints – There are two major sets of API routes:
○ Under “app/api”: Legacy endpoints (for example, for OG research data and paper endpoints).
○ Under “app/apiv2”: Newer endpoints handling advanced functions (embedding, research paper extraction, translation, summarization, vector search) which interface with LLM services (e.g., GPT-4/Gemini) and vector databases.
• Content Management – Payload CMS configuration (observable via “src/payload.config.ts” and related files) that provides the data source for the research articles and educational materials.
• External Services & Integrations – The project integrates a vector database for retrieval-augmented generation (PsycheLens) and uses Algolia (client and related components) for search functionalities.
• Utilities and Configuration – Additional support files such as “src/config”, “src/utilities”, and the server entry points (“src/server.ts”, “src/server.default.ts”) that glue the system together.
Relationships and Data Flow
• Browser/Client interacts with the Next.js frontend. The client fetches pages and interacts with API endpoints.
• Frontend Request Flow:
○ Navigation routes (database, research, about) are rendered by Next.js.
• API Layer:
○ Requests from the frontend are routed to the “app/api” and “app/apiv2” endpoints.
○ These endpoints process the requests (data extraction, summarization, embedding, etc.), interfacing with external LLM services and vector databases.
• Payload CMS:
○ The CMS acts as a stored content repository for research papers and educational content.
○ The API queries Payload CMS to fetch/update content as needed.
• External Integrations:
○ APIs for LLM services and vector search are called from the “apiv2” endpoints.
○ Algolia client in “src/utilities” and “src/components/algolia” coordinates search functionality that feeds into the frontend.
Architectural Patterns and Design Principles
• Separation of Concerns – Clear division between frontend rendering (React components, Next.js pages) and backend API logic.
• API Versioning – The “apiv2” folder indicates an evolution of endpoints, hinting at a deliberate design for backward compatibility and incremental improvements.
• Modular & Reusable Components – Extensive use of component-based architecture for UI (in “src/components”) and helper utilities.
• Client–Server Communication – Utilizes API routes to connect the presentation layer to the data and processing layers, often via RESTful or similar protocols.
• Integration of External Services – Both CMS (Payload) and external LLM/vector search services are loosely coupled with designated endpoints handling communication.