# hitesh19426/ddinter-main architecture

> Architecture diagram of the GitHub repository hitesh19426/ddinter-main, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hitesh19426/ddinter-main
- Repository: https://github.com/hitesh19426/ddinter-main

## Overview

##### 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).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    subgraph "Browser Layer"
        A1["pages/_app.js"]:::frontend
        A2["pages/_document.js"]:::frontend
        A3["pages/index.js"]:::frontend
        subgraph "components/"
            C1["DrugItem.js"]:::frontend
            C2["Header.js"]:::frontend
            C3["InteractionRow.js"]:::frontend
            C4["InterationTable.js"]:::frontend
            C5["MyLoader.js"]:::frontend
            C6["MyTextInput.js"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer"
        B1["pages/api/getDrugNames.js"]:::backend
        B2["pages/api/getInteraction.js"]:::backend
        B3["lib/mongodb.js"]:::backend
        B4["config/index.js"]:::backend
    end

    %% Database Layer
    subgraph "Database (MongoDB)"
        DB["MongoDB Atlas"]:::db
    end

    %% Offline ETL
    subgraph "Offline ETL"
        E2["ddinterpy/ddinter_downloads_code_*.csv"]:::offline
        E1["ddinterpy/ddinter.py"]:::offline
    end

    %% Connections
    A3 -->|"fetch getDrugNames"| B1
    A3 -->|"fetch getInteraction"| B2
    B1 -->|"query names"| DB
    B2 -->|"query interactions"| DB
    DB -->|"return data"| B1
    DB -->|"return data"| B2
    B4 -->|"env vars"| B3
    B3 -->|"connect"| DB
    E2 -->|"raw CSV input"| E1
    E1 -.->|"ETL load"| DB

    %% Click Events
    click A1 "https://github.com/hitesh19426/ddinter-main/blob/main/pages/_app.js"
    click A2 "https://github.com/hitesh19426/ddinter-main/blob/main/pages/_document.js"
    click A3 "https://github.com/hitesh19426/ddinter-main/blob/main/pages/index.js"
    click C1 "https://github.com/hitesh19426/ddinter-main/blob/main/components/DrugItem.js"
    click C2 "https://github.com/hitesh19426/ddinter-main/blob/main/components/Header.js"
    click C3 "https://github.com/hitesh19426/ddinter-main/blob/main/components/InteractionRow.js"
    click C4 "https://github.com/hitesh19426/ddinter-main/blob/main/components/InterationTable.js"
    click C5 "https://github.com/hitesh19426/ddinter-main/blob/main/components/MyLoader.js"
    click C6 "https://github.com/hitesh19426/ddinter-main/blob/main/components/MyTextInput.js"
    click B1 "https://github.com/hitesh19426/ddinter-main/blob/main/pages/api/getDrugNames.js"
    click B2 "https://github.com/hitesh19426/ddinter-main/blob/main/pages/api/getInteraction.js"
    click B3 "https://github.com/hitesh19426/ddinter-main/blob/main/lib/mongodb.js"
    click B4 "https://github.com/hitesh19426/ddinter-main/blob/main/config/index.js"
    click E1 "https://github.com/hitesh19426/ddinter-main/blob/main/ddinterpy/ddinter.py"
    click E2 "https://github.com/hitesh19426/ddinter-main/blob/main/ddinterpy/ddinter_downloads_code_*.csv"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef db fill:#fff3cd,stroke:#856404,color:#856404;
    classDef offline fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
