# hariomgupta70427/medical-ai-platform architecture

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

- Interactive diagram: https://gitdiagram.com/hariomgupta70427/medical-ai-platform
- Repository: https://github.com/hariomgupta70427/medical-ai-platform

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“MediAI Discovery Platform”) built with Next.js (React + Node) on the front- and back-end, coupled with a small Python/Flask microservice for RDKit chemistry operations.
- Purpose: provide pharmaceutical researchers with an AI-driven interface for molecular visualization, drug-modification suggestions, retrosynthesis planning, and interactive chat.

##### File Structure
- Top-level folders:
- app/ — Next.js “app router” (pages, server & client components, API routes)
- components/ — shared React UI modules
- lib/ — backend service wrappers (OpenAI, PubChem, IBM RXN, DeepSeek, etc.)
- hooks/ — shared React hooks
- public/, styles/, types/ — static assets, CSS, and TS definitions
- Key API route folders under app/api/:
- chat, drug-modifications, molecule, pubchem, retrosynthesis, explanation, rdkit (with embedded Python service in app/api/rdkit/python/)
- Configuration & deployment files: next.config.mjs, Dockerfile for RDKit service, .env references in README.

##### README for Additional Insights
- Architecture notes: Next.js dev server + optional Dockerized Python RDKit service
- Environment toggles: ENABLE_PYTHON_RDKIT, RDKIT_SERVICE_URL
- External integrations: PubChem, IBM RXN, SwissADME, OpenAI

a. Main Components
- Client Browser (React pages + components)
- Next.js Frontend / SSR Server (Node.js + TypeScript)
- Next.js API Layer (app/api/* routes)
- Python RDKit Microservice (Flask + RDKit, containerizable)
- External 3rd-party APIs: PubChem, IBM RXN, SwissADME, OpenAI
b. Relationships and Data Flows
1. User → Browser loads React pages (SSR or CSR)
2. Browser → calls Next.js API endpoints (e.g., /api/chat, /api/pubchem)
3. Next.js API route → invokes lib/* service functions
4. Service functions → call external HTTP APIs (PubChem, IBM RXN, OpenAI) or forward to RDKit microservice
5. RDKit Python service ↔ Next.js API (over HTTP at RDKIT_SERVICE_URL)
6. Aggregated response → Next.js API → Browser UI
c. Architectural Patterns & Principles
- “App router” separation of pages vs. API routes in Next.js
- Microservice for chemistry-heavy workloads (RDKit)
- Service-wrapper pattern in lib/ for external integrations
- Environment-driven feature toggles (.env for RDKit, debug, base URLs)
d. Key Technologies
- Frontend: Next.js 13+, React, Tailwind CSS, TypeScript
- Backend: Node.js, TypeScript, Next.js API routes
- Microservice: Python 3.9+, Flask, RDKit, Docker
- External: PubChem PUG-REST, IBM RXN API, OpenAI GPT, SwissADME wrapper

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Browser["Client Browser"]:::frontend
    end

    %% Next.js Server
    subgraph "Next.js SSR Server"
        direction TB
        NextServer["Next.js Server"]:::backend
    end

    %% API Layer
    subgraph "Next.js API Layer"
        direction TB
        ChatAPI["/api/chat"]:::api
        DrugModAPI["/api/drug-modifications"]:::api
        ExplanationAPI["/api/explanation"]:::api
        MoleculeAPI["/api/molecule"]:::api
        PubChemAPI_Route["/api/pubchem"]:::api
        RetrosynthesisAPI["/api/retrosynthesis"]:::api
        RDKitAPI["/api/rdkit"]:::api
    end

    %% Service Wrapper Layer
    subgraph "Service Wrapper Layer (lib/)"
        direction TB
        OpenAILib["lib/openai.ts"]:::service
        PubChemLib["lib/pubchem.ts"]:::service
        IBMRxnLib["lib/ibmRxn.ts"]:::service
        DeepSeekLib["lib/deepseek.ts"]:::service
        DrugModLib["lib/drugModification.ts"]:::service
        LLMServiceLib["lib/llmService.ts"]:::service
        DrugBankLib["lib/drugbank.ts"]:::service
        EnvLib["lib/env.ts"]:::service
        UtilsLib["lib/utils.ts"]:::service
    end

    %% RDKit Microservice
    subgraph "RDKit Microservice"
        direction TB
        RDKitService["Python RDKit Service"]:::micro
    end

    %% External Systems
    subgraph "External APIs"
        direction TB
        PubChemAPI_External["PubChem API"]:::external
        IBMRxnAPI["IBM RXN API"]:::external
        SwissADMEAPI["SwissADME API"]:::external
        OpenAIAPI["OpenAI GPT API"]:::external
    end

    %% Connections
    Browser -->|SSR/CSR| NextServer
    Browser -->|HTTP/JSON| ChatAPI
    Browser -->|HTTP/JSON| DrugModAPI
    Browser -->|HTTP/JSON| ExplanationAPI
    Browser -->|HTTP/JSON| MoleculeAPI
    Browser -->|HTTP/JSON| PubChemAPI_Route
    Browser -->|HTTP/JSON| RetrosynthesisAPI
    Browser -->|HTTP/JSON| RDKitAPI

    ChatAPI -->|uses| OpenAILib
    DrugModAPI -->|uses| DrugModLib
    ExplanationAPI -->|uses| LLMServiceLib
    MoleculeAPI -->|uses| PubChemLib
    PubChemAPI_Route -->|uses| PubChemLib
    RetrosynthesisAPI -->|uses| IBMRxnLib
    RDKitAPI -->|if ENABLE_PYTHON_RDKIT HTTP| RDKitService
    RDKitAPI -->|else uses| UtilsLib

    OpenAILib -->|HTTP| OpenAIAPI
    PubChemLib -->|HTTP| PubChemAPI_External
    IBMRxnLib -->|HTTP| IBMRxnAPI
    DeepSeekLib -->|HTTP| SwissADMEAPI
    DrugModLib -->|orchestrates| OpenAILib
    DrugModLib -->|orchestrates| PubChemLib

    %% Click Events
    click Browser "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/page.tsx"
    click Browser "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/layout.tsx"
    click Browser "https://github.com/hariomgupta70427/medical-ai-platform/tree/main/components/"
    click NextServer "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/_document.tsx"
    click NextServer "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/globals.css"
    click NextServer "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/loading.tsx"
    click NextServer "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/not-found.tsx"
    click NextServer "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/error.tsx"
    click NextServer "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/global-error.tsx"
    click ChatAPI "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/chat/route.ts"
    click DrugModAPI "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/drug-modifications/route.ts"
    click ExplanationAPI "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/explanation/route.ts"
    click MoleculeAPI "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/molecule/route.ts"
    click PubChemAPI_Route "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/pubchem/route.ts"
    click RetrosynthesisAPI "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/retrosynthesis/route.ts"
    click RDKitAPI "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/rdkit/route.ts"
    click RDKitService "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/rdkit/python/app.py"
    click RDKitService "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/app/api/rdkit/python/requirements.txt"
    click RDKitService "https://github.com/hariomgupta70427/medical-ai-platform/tree/main/app/api/rdkit/python/Dockerfile"
    click OpenAILib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/openai.ts"
    click PubChemLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/pubchem.ts"
    click IBMRxnLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/ibmRxn.ts"
    click DeepSeekLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/deepseek.ts"
    click DrugModLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/drugModification.ts"
    click LLMServiceLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/llmService.ts"
    click DrugBankLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/drugbank.ts"
    click EnvLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/env.ts"
    click UtilsLib "https://github.com/hariomgupta70427/medical-ai-platform/blob/main/lib/utils.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#4A90E2,color:#000
    classDef backend fill:#DFF7D8,stroke:#3E8E41,color:#000
    classDef api fill:#E8F4FF,stroke:#2C7EB2,color:#000
    classDef service fill:#FFF4D6,stroke:#D99C00,color:#000
    classDef micro fill:#FFE5D0,stroke:#E07A5F,color:#000
    classDef external fill:#F0F0F0,stroke:#999,color:#000
```
