# ayush-030/medsafe_drug-drug-interaction architecture

> Architecture diagram of the GitHub repository ayush-030/medsafe_drug-drug-interaction, 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/ayush-030/medsafe_drug-drug-interaction
- Repository: https://github.com/ayush-030/medsafe_drug-drug-interaction

## Overview

##### Project type and purpose
- MedSafe is a full-stack Python/Flask web application that provides an AI-driven drug-drug interaction (DDI) prediction service.
- It combines:
- A web front end (HTML/CSS/JS under `templates/` and `static/`)
- A Flask back end (`app.py`, Form and SIMPLE modules)
- A machine-learning pipeline that loads molecular data (`Drug_data/`) and runs similarity/clustering using RDKit, scikit-learn, pandas, etc.
- Optional integration with an external service (PubChem API) for real-time SMILES retrieval.

##### File structure
- Top level:
- `app.py` – application entry point
- `templates/` and `static/` – shared UI assets (index, login, signup, contact, main pages)
- `Form/` – Flask “blueprint” or module managing the main DDI prediction form and results
- `SIMPLE/` – alternate interface (CLI or simple web form) with its own templates and static files
- `Drug_data/` – CSV data (drug lists, similarity matrices) and a README describing the data • Other assets: `SAME_DRUG.csv`, `drug_names_ids.csv`, and a Jupyter notebook for exploration.
- Key patterns:
- MVC-style separation: Flask routes & controllers in `app.py` and blueprints, Models are the ML pipeline, Views are Jinja2 templates + static assets.
- Configuration/dependencies declared in `requirements.txt`.
- Data files live in a dedicated folder, loaded at runtime by the back end.

##### README for additional insights
- Confirms tech stack: Python, Flask, RDKit, scikit-learn, pandas, optional PubChemPy.
- Describes the high-level model flow: SMILES → Morgan fingerprints → similarity matrix → clustering → risk prediction.
- Mentions both a web interface (Flask) and a CLI fallback.

##### Final advice
- Every module: root `app.py`, the two blueprints, the static/template directories, the ML code paths, and the data files.
- Do not omit the optional Jupyter notebook and PubChem integration—they illustrate extensibility.
- Provide enough detail to guide new engineers through the full request life cycle—from form submission to risk result display.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Tier
    subgraph "Presentation Tier"
        Browser["Browser"]:::ui
        subgraph "Templates"
            Index["index.html"]:::ui
            Login["login.html"]:::ui
            Signup["signup.html"]:::ui
            Contact["contact.html"]:::ui
            MainPage["main.html"]:::ui
        end
        subgraph "Static Assets"
            CSS["CSS Files"]:::ui
            JS["JS Files"]:::ui
            Resources["Resources"]:::ui
        end
    end

    Browser -->|"GET pages/assets"| FlaskApp

    %% Application Tier
    subgraph "Application Tier"
        FlaskApp["Flask Application (app.py)"]:::backend
        subgraph "Form Blueprint"
            FormCtrl["form.py"]:::backend
            FormTemplate["form.html"]:::ui
            FormResults["results.html"]:::ui
            FormCSS["form.css"]:::ui
            FormJS["form.js"]:::ui
        end
        subgraph "SIMPLE Module"
            SimpleCtrl["simpleChecker.py"]:::backend
            SimpleTemplate["simpleChecker.html"]:::ui
            SimpleCSS["form.css"]:::ui
            SimpleJS["form.js"]:::ui
        end
        subgraph "ML Pipeline"
            Fingerprint["Fingerprint (RDKit)"]:::pipeline
            Similarity["Similarity Matrix"]:::pipeline
            Clustering["Clustering"]:::pipeline
            Classification["Classification"]:::pipeline
        end
    end

    Browser -->|"POST /predict"| FlaskApp
    FlaskApp -->|uses| FormCtrl
    FlaskApp -->|uses| SimpleCtrl
    FormCtrl --> Fingerprint
    SimpleCtrl --> Fingerprint
    Fingerprint --> Similarity
    Similarity --> Clustering
    Clustering --> Classification
    Classification -->|returns risk| FormCtrl
    Classification -->|returns risk| SimpleCtrl
    FormCtrl -->|responds| Browser

    %% Data Tier
    subgraph "Data Tier"
        subgraph "Local Data Store"
            DrugList["DrugID_List.csv"]:::data
            SimMatrix["reduced_drug_similarity_matrix.csv"]:::data
            Metadata["drug_names_ids.csv"]:::data
            SameDrug["SAME_DRUG.csv"]:::data
            DataReadme["README.txt"]:::data
        end
        Requirements["requirements.txt"]:::data
        ProjectReadme["README.md"]:::data
        PubChem["PubChem API"]:::external
        Notebook["progress_work.ipynb"]:::external
    end

    DataReadme -->|describes data| Fingerprint
    DrugList --> Fingerprint
    SimMatrix --> Similarity
    Metadata --> Fingerprint
    SameDrug --> Classification
    FormCtrl -.->|optional SMILES fetch| PubChem

    %% Click Events
    click FlaskApp "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/app.py"
    click Index "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/templates/index.html"
    click Login "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/templates/login.html"
    click Signup "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/templates/signup.html"
    click Contact "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/templates/contact.html"
    click MainPage "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/templates/main.html"
    click CSS "https://github.com/ayush-030/medsafe_drug-drug-interaction/tree/main1/static/css/"
    click JS "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/static/script/script.js"
    click Resources "https://github.com/ayush-030/medsafe_drug-drug-interaction/tree/main1/static/resources/"
    click FormCtrl "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Form/form.py"
    click FormTemplate "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Form/templates/form.html"
    click FormResults "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Form/templates/results.html"
    click FormCSS "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Form/static/css/form.css"
    click FormJS "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Form/static/script/form.js"
    click SimpleCtrl "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/SIMPLE/simpleChecker.py"
    click SimpleTemplate "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/SIMPLE/templates/simpleChecker.html"
    click SimpleCSS "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/SIMPLE/static/css/form.css"
    click SimpleJS "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/SIMPLE/static/script/form.js"
    click DrugList "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Drug_data/DrugID_List.csv"
    click SimMatrix "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Drug_data/reduced_drug_similarity_matrix.csv"
    click Metadata "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/drug_names_ids.csv"
    click SameDrug "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/SAME_DRUG.csv"
    click DataReadme "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/Drug_data/README.txt"
    click Requirements "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/requirements.txt"
    click ProjectReadme "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/README.md"
    click Notebook "https://github.com/ayush-030/medsafe_drug-drug-interaction/blob/main1/progress_work.ipynb"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef pipeline fill:#FFE4B5,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
