# zzhustc2016/raremed architecture

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

- Interactive diagram: https://gitdiagram.com/zzhustc2016/raremed
- Repository: https://github.com/zzhustc2016/raremed

## Overview

##### Main Components
- Data Layer:
- Files under the data folder (data/input and data/process.py) indicate a dedicated component for data ingestion, pre-processing, and preparation.
- External dependencies include MIMIC-III and MIMIC-IV datasets along with supplementary files from DrugBank.
- Model Components:
- src/models: Contains implementations of the RAREMed model and baseline models (e.g., COGNet, GAMENet, GBert, LEAP, MICRON, MoleRec, RETAIN, SafeDrug).
- The models sub-directory is further organized to encapsulate submodules such as gnn components (like GNNConv, GNNs) which hint at a graph neural network usage.
- Baselines Module:
- src/Baselines contains separate executable scripts to run experiments for each baseline—this is key to showing alternatives and comparisons with the primary RAREMed method.
- Utility and Support Functions:
- src/utils: Contains utility functions for beam search, data loading, layer definitions, and overall helper functions that support model training and evaluation.
- Experimentation & Visualization:
- Notebooks (e.g., src/figs.ipynb) and figs directory supply visualizations and potentially in-depth analysis artifacts.
- Deployment and Installation:
- Files like install.sh, .gitignore, and LICENSE represent environment setup and legal documentation aspects.

##### Relationships and Interactions
- The Data Layer processes raw input files from the specified directories, likely feeding preprocessed data into the models.
- The Models (including the central RAREMed model as well as baselines) ingest processed data via functions defined in the utils module (like data_loader.py) and use various neural network components (including transformer encoders and GNN layers) to generate medication recommendations.
- Baseline scripts interact with the same utility modules and hence share dependencies with the main RAREMed pipeline.
- There’s an integration layer between the experimental setup (command-line driven via main_RAREMed.py and similar scripts) and the actual deep learning models.
- Visual outputs are generated both during training (logs, tensorboard which might be created via logging utilities) and then visualizations are stored in the figs folder or Jupyter notebooks.

##### Architectural Patterns and Design Principles
- Modular design: Separation of concerns into data processing, model definitions, utility functions, and experiment execution.
- Extensibility: Separate directories for Baselines and models indicate a design that supports plugging in or comparing additional models.
- Use of standard deep learning practices using PyTorch, configuration through command-line arguments (as seen in main_RAREMed.py).
- If following best practices, dependency injection for datasets and logging should be visible though the file organization supports clear integration.

##### Relevant Technologies, Frameworks, and Libraries
- PyTorch as the deep learning framework.
- Likely use of Python libraries for data manipulation (e.g., pandas, numpy) as indicated by the processing scripts.
- Graph neural network components (potential GNN frameworks integrated into PyTorch) for handling relational data modeling in medication recommendations.
- Possibly Jupyter Notebook for visualization and experiment tracking.

##### Elements
- Clear Labels: Each major component (Data Layer, Models, Baselines, Utilities, Experiment Scripts) should be explicitly labeled.
- Blue blocks for data ingestion and pre-processing.
- Green blocks for model implementations.
- Subdivision for “model internals” if further detail is desired: Indicate parts such as transformer encoder layers, adapter layers, GNN components as used in RAREMed.

##### Putting It Together
- Link these inputs to the “Data Processing” module (represented by process.py in the data folder).
- Processed data feeding into the core "Model Training and Evaluation" module (main_RAREMed.py in the src folder).
- Split out the “Models” architecture – with a node for RAREMed and nodes for each baseline (perhaps clustering baseline models together under the Baselines directory).
- Connections between the primary model binaries (using modules from src/models and src/models/gnn) and their supporting utilities (src/utils) demonstrating dependency.
- Finally, optionally include a section for “Results & Visualization” linking to the figs directory and Jupyter notebooks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Data (MIMIC-III, MIMIC-IV, DrugBank)"]:::external
    A -->|"raw-data"| D["Data Processing (process.py)"]:::data
    D -->|"preprocessed"| E["Processed Data"]:::data
    E -->|"feeds into"| F["Model Training & Evaluation (main_RAREMed)"]
    
    subgraph "Models"
        F1["RAREMed Model"]:::model
        F2["GNN Components"]:::model
    end
    F -->|"trains"| F1
    F -->|"integrates"| F2

    F -->|"supports"| U["Utilities (data_loader, beam, layers, recommend, util)"]:::utils
    B["Baseline Experiments"]:::baseline
    B -->|"utilizes"| U

    F -->|"generates"| V["Visualization & Analysis (figs & notebooks)"]:::viz
    B -->|"produces"| V

    V -->|"reports"| Dep["Deployment & Installation"]:::deployment

    %% Click Events
    click D "https://github.com/zzhustc2016/raremed/blob/main/data/process.py"
    click F1 "https://github.com/zzhustc2016/raremed/tree/main/src/models/"
    click F2 "https://github.com/zzhustc2016/raremed/tree/main/src/models/gnn"
    click B "https://github.com/zzhustc2016/raremed/tree/main/src/Baselines/"
    click U "https://github.com/zzhustc2016/raremed/tree/main/src/utils/"
    click V "https://github.com/zzhustc2016/raremed/blob/main/src/figs.ipynb"
    click Dep "https://github.com/zzhustc2016/raremed/blob/main/install.sh"

    %% Styles
    classDef external fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef data fill:#b8daff,stroke:#004085,stroke-width:2px;
    classDef model fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef baseline fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef utils fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef viz fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef deployment fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
