# adarshh9/taxocapsnets architecture

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

- Interactive diagram: https://gitdiagram.com/adarshh9/taxocapsnets
- Repository: https://github.com/adarshh9/taxocapsnets

## Overview

##### Project type and purpose
- This is a full-stack machine-learning application (“TaxoCapsNets”) for predicting Autism Spectrum Disorder from gut microbiome data.
- It combines a data-processing & training pipeline (Python + Keras), a Flask-based model-serving backend, and a JavaScript-based frontend for interactive visualization (SHAP explainability outputs).

##### File structure
- Top-level folders:
- dataset/ (CSV input data)
- model/ (trained model files & pickles)
- taxoshap-backend/ (Flask server notebook)
- taxoshap-frontend/ (UI code)
- training_metrics/ (training logs & plots)
- Key files: test.py (CLI inference), demo.webm (demo video), README.md
- Patterns: clear separation of data, training, serving, and presentation layers.

##### README for additional insights
- “End-to-end pipeline: preprocessing → training → evaluation → explainability”
- Uses taxonomy-aware Capsule Networks + SHAP.
- Interactive frontend + backend integration.

##### Main components & their relationships
a. Data Layer
- Source: dataset/*.csv
- Processed by: preprocessing scripts (inside model/ or separate notebook)
b. Training Pipeline
- Input: preprocessed data
- Core: Capsule Network architecture (Keras)
- Output: capsule_model.keras, taxonomy_map.pkl, test_data.pkl
- Artifacts stored in model/
- Training logs written to training_metrics/
c. Model Serving / Backend
- Flask server (taxoshap-backend/flask_server.ipynb)
- Loads model artifacts from model/
- Exposes REST endpoints for:
- Inference (test.py can call these or use direct load)
- SHAP explainability generation
d. Frontend
- Runs in browser (taxoshap-frontend/)
- Calls backend APIs to:
- Submit sample data → get ASD prediction
- Retrieve SHAP results for interactive plots
e. CLI Test Script
- test.py: standalone inference using saved model artifacts

##### Architectural patterns and design principles
- Layered architecture: Data → Training → Serving → Presentation
- Separation of concerns: model artifacts are decoupled from serving and visualization
- Micro-component design: Preprocessing, Model, Explainability, Frontend all separate
- Use of standard ML ops flow (train→store→serve), with explainability integrated at serving time.

##### Putting it all together
- Top row (Batch Training):
[dataset CSVs] → [Preprocessing] → [Capsule Network Trainer] → [Model & Pickle Artifacts] & [Training Metrics]
- Middle row (Serving):
[Model & Pickle Artifacts] → [Flask API + SHAP Engine]
- Bottom row (Clients):
[taxoshap-frontend UI] ←→ [Flask API] ←→ [test.py CLI]

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Batch Training Layer
    subgraph "Batch Training Layer"
        DataStore["Dataset: 16S rRNA CSVs"]:::dataStore
        Preprocessor["Preprocessor\n(Python)"]:::compute
        Trainer["Capsule Network Trainer\n(Keras)"]:::compute
        ModelStore["Model Artifacts\n(capsule_model.keras,\n taxonomy_map.pkl,\n test_data.pkl)"]:::dataStore
        TrainingMetrics["Training Metrics\n(logs & plots)"]:::dataStore
    end

    %% Model Serving Layer
    subgraph "Model Serving Layer"
        FlaskAPI["Flask API + SHAP Engine\n(Flask, SHAP)"]:::serving
    end

    %% Client Layer
    subgraph "Client Layer"
        FrontendUI["Frontend UI\n(JavaScript, SHAP Visuals)"]:::presentation
        CLITester["CLI Tester\n(test.py)"]:::presentation
        Overview["Project Overview\nREADME.md"]:::presentation
        Demo["Demo Video\ndemo.webm"]:::presentation
    end

    %% Data and Control Flows
    DataStore -->|"batch data"| Preprocessor
    Preprocessor -->|"preprocessed data"| Trainer
    Trainer -->|"model artifacts"| ModelStore
    Trainer -->|"logs & plots"| TrainingMetrics
    ModelStore -->|"load model"| FlaskAPI
    FlaskAPI -->|"serve predictions & SHAP"| FrontendUI
    FrontendUI -->|"API calls"| FlaskAPI
    CLITester -->|"direct inference"| ModelStore
    CLITester -->|"optionally APIs"| FlaskAPI

    %% Click Events
    click DataStore "https://github.com/adarshh9/taxocapsnets/tree/main/dataset/"
    click ModelStore "https://github.com/adarshh9/taxocapsnets/tree/main/model/"
    click TrainingMetrics "https://github.com/adarshh9/taxocapsnets/tree/main/training_metrics/"
    click FlaskAPI "https://github.com/adarshh9/taxocapsnets/blob/main/taxoshap-backend/flask_server.ipynb"
    click FrontendUI "https://github.com/adarshh9/taxocapsnets/tree/main/taxoshap-frontend/"
    click CLITester "https://github.com/adarshh9/taxocapsnets/blob/main/test.py"
    click Overview "https://github.com/adarshh9/taxocapsnets/blob/main/README.md"
    click Demo "https://github.com/adarshh9/taxocapsnets/blob/main/demo.webm"

    %% Styles
    classDef dataStore fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef compute fill:#98FB98,stroke:#333,stroke-width:1px
    classDef serving fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef presentation fill:#FFDAB9,stroke:#333,stroke-width:1px
```
