# 12keerti21/chemxplore architecture

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

- Interactive diagram: https://gitdiagram.com/12keerti21/chemxplore
- Repository: https://github.com/12keerti21/chemxplore

## Overview

##### Project Type and Purpose
- Full-stack Python package with three user interfaces:
a. Command-line tool (`admet_predict`)
b. Python API (`ADMETModel`)
c. Web server (Flask app under `admet_ai/web`)

##### File Structure Analysis
- Top level:
- `admet_ai/` – main Python package
- `scripts/` – data preparation, training, plotting utilities
- `static/`, `templates/` – fallback front-end assets (mirrors web app)
- `Dockerfile`, `setup.py`, `requirements.txt` – build and deploy
- `admet_ai/` layers:
- Core API (`admet_info.py`, `admet_model.py`, `admet_predict.py`)
- Analysis (`analysis/`) – result processing
- Resources (`resources/data`, `resources/models`) – CSV and PyTorch model binaries
- Web (`web/app/`) – Flask MVC structure (config, models, views, templates, static) plus run/wsgi entrypoints
- Utilities (`utils.py`, `storage.py`)

##### README Insights
- Confirms three interfaces and optional extras (`[tdc]`, `[web]` dependencies)
- Mentions Docker support, GPU fallback to CPU, uses TDC datasets, RDKit, Chemprop

a. Main Components
- User Interfaces: CLI tool, Python API, Web UI
- Core Service: ADMETModel service (model loading, prediction logic)
- Data & Models: local CSV data store, pretrained PyTorch models
- Analysis & Plotting: resultanalyzer, plotting scripts
- External Libraries/Services: RDKit, Chemprop, TDC data
- Deployment: Docker container, WSGI server (Gunicorn/Flask)

b. Relationships & Interactions
- CLI/API/Web → call ADMETModel → loads models from `resources/models` → calls Chemprop inference via `admet_predict.py` → returns predictions
- Analysis scripts (`scripts/`) read prediction CSVs → feed `analysis/results_analyzer.py` → output plots
- Web UI (Flask controllers in `views.py`) invoke ADMETModel → render HTML templates with JSME molecule editor → static JS/CSS assets

c. Architectural Patterns & Principles
- Layered architecture:
1. Presentation (CLI / Web)
2. Application core (ADMETModel service)
3. Data (model files, resource CSV)
- MVC in web app: Flask views/models/templates
- Separation of concerns: API vs. web vs. analysis vs. scripts

d. Key Technologies & Frameworks
- Python 3.10+, Flask for web
- PyTorch (Chemprop) for model inference
- RDKit for feature computation
- Pandas for data handling
- Docker for containerization

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        CLI["CLI Tool\n(admet_predict)"]:::ui
        API["Python API Client\n(ADMETModel)"]:::ui
        Browser["Web Browser UI"]:::ui
    end

    %% Core Service Layer
    subgraph "Core Service Layer"
        direction TB
        Service["ADMETModel Service"]:::core
        Info["admet_info.py"]:::core
        PredictCore["admet_predict.py"]:::core
        ModelAPI["admet_model.py"]:::core
        Service -->|uses| Info
        Service -->|uses| PredictCore
        Service -->|exposes| ModelAPI
    end

    %% Data & Model Storage Layer
    subgraph "Data & Model Storage"
        direction TB
        CSVData["CSV Data Store"]:::storage
        ModelStore["Pretrained Model Store"]:::storage
        CSVData -->|loads| Service
        ModelStore -->|loads| Service
    end

    %% External Dependencies
    subgraph "External Libraries"
        direction TB
        RDKit["RDKit"]:::external
        Chemprop["Chemprop (PyTorch)"]:::external
        TDC["TDC Datasets"]:::external
        Service -->|calls| RDKit
        Service -->|calls| Chemprop
        Service -->|optionally uses| TDC
    end

    %% Web MVC Subsystem
    subgraph "Flask Web App" 
        direction TB
        Run["run.py"]:::web
        WSGI["wsgi.py"]:::web
        Config["config.py"]:::web
        WebModels["models.py"]:::web
        Views["views.py"]:::web
        Templates["templates/"]:::web
        StaticAssets["static/"]:::web
        Run -->|starts| WSGI
        WSGI -->|loads| Config
        WSGI -->|routes| Views
        Views -->|renders| Templates
        Views -->|serves| StaticAssets
        Views -->|calls| Service
    end

    %% Output Layer
    subgraph "Output Layer"
        direction TB
        JSONOut["JSON / CSV Output"]:::output
        HTMLOut["Rendered HTML"]:::output
        CLI -->|invokes| Service
        API -->|invokes| Service
        Browser -->|HTTP Requests| Views
        Service -->|returns| JSONOut
        Views -->|renders| HTMLOut
    end

    %% Analysis & Plotting
    subgraph "Analysis & Plotting" 
        direction TB
        Analyzer["results_analyzer.py"]:::analysis
        Plotter["plot.py"]:::analysis
        JSONOut -->|reads| Analyzer
        CSVData -->|reads| Analyzer
        Analyzer -->|generates| Plotter
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        Utils["utils.py"]:::core
        StorageUtil["storage.py"]:::core
        Service -->|uses| Utils
        Views -->|uses| StorageUtil
    end

    %% Deployment Layer
    subgraph "Deployment"
        direction TB
        Docker["Docker Container"]:::deploy
        WSGI -->|deployed in| Docker
        Service -->|runs in| Docker
    end

    %% Click Events
    click CLI "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/admet_predict.py"
    click ModelAPI "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/admet_model.py"
    click PredictCore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/admet_predict.py"
    click Info "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/admet_info.py"
    click CSVData "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/data/admet.csv"
    click CSVData "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/data/drugbank_approved.csv"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_classification/model_0.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_classification/model_1.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_classification/model_2.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_classification/model_3.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_classification/model_4.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_regression/model_0.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_regression/model_1.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_regression/model_2.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_regression/model_3.pt"
    click ModelStore "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/resources/models/admet_regression/model_4.pt"
    click Analyzer "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/analysis/results_analyzer.py"
    click Plotter "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/plot.py"
    click Utils "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/utils.py"
    click StorageUtil "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/storage.py"
    click Run "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/web/run.py"
    click WSGI "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/web/wsgi.py"
    click Config "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/web/app/config.py"
    click WebModels "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/web/app/models.py"
    click Views "https://github.com/12keerti21/chemxplore/blob/main/admet_ai/web/app/views.py"
    click Templates "https://github.com/12keerti21/chemxplore/tree/main/admet_ai/web/app/templates/"
    click StaticAssets "https://github.com/12keerti21/chemxplore/tree/main/admet_ai/web/app/static/"
    click Docker "https://github.com/12keerti21/chemxplore/tree/main/Dockerfile"

    %% Styles
    classDef ui fill:#9f6,stroke:#333,stroke-width:1px
    classDef core fill:#6cf,stroke:#333,stroke-width:1px
    classDef storage fill:#fc6,stroke:#333,stroke-width:1px
    classDef analysis fill:#f96,stroke:#333,stroke-width:1px
    classDef web fill:#6f9,stroke:#333,stroke-width:1px
    classDef output fill:#cff,stroke:#333,stroke-width:1px
    classDef external fill:#ddd,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef deploy fill:#c9c,stroke:#333,stroke-width:1px
```
