How hitesh19426/ddinter-main works
Project Type and Purpose
• This is a full-stack web application built with Next.js.
• Purpose: allow users to look up drug–drug interactions by name. Data is stored in MongoDB, and there’s an auxiliary Python script to ingest CSV data into the database.
Key Directories and Architectural Patterns
• components/ : React components for the UI (forms, tables, loaders).
• pages/ : Next.js pages, which include both UI routes (pages/index.js) and serverless API routes under pages/api/ (getDrugNames.js, getInteraction.js).
• lib/mongodb.js : MongoDB connection helper (singleton pattern to avoid multiple connections).
• config/index.js : Reads environment variables (MONGODB_URI, DB_NAME).
• ddinterpy/ : Python scripts and raw CSV files for offline data ingestion (ETL process).
• public/, styles/ : Static assets and CSS modules, served by Next.js.
Architecture Overview
• Client (Browser)
• Renders React components under pages/.
• Sends HTTP requests to the serverless API endpoints.
• Next.js Serverless API
• pages/api/getDrugNames → queries MongoDB for all drug names.
• pages/api/getInteraction → given one or two drug names, returns interaction info.
• Uses lib/mongodb.js and config/index.js to connect.
• Database (MongoDB Atlas or self-hosted)
• Stores collections for drugs and interactions.
• Seeded by ddinterpy Python script reading CSVs and uploading via pymongo.
• Data Ingestion (Offline ETL)
• Python script (ddinter.py) reads ddinterpy/*.csv → transforms → writes to MongoDB.
Main Components and Relationships
a. Frontend (Next.js React UI)
b. API Layer (Next.js serverless functions)
c. Database (MongoDB)
d. Data Ingestion Script (Python ETL)
e. External Services:
• MongoDB hosting (Atlas or on-prem)
• Vercel or similar hosting for Next.js
• External drug-interaction data source used offline
• Data Flow: Browser → API endpoints → DB → API → Browser.
• Offline Flow: Python ETL → DB.
Architectural Patterns and Principles
• Separation of concerns: UI components vs. API routes vs. data layer.
• Serverless API functions: each endpoint is its own unit.
• Reusable DB connection abstraction in lib/mongodb.js.
• Offline ETL decoupled from web service—run as needed to refresh data.
Specific Elements
• Arrowheads to show direction of data flow (e.g., user input → API → DB).