# raghavmaheshwari2024/android-malware-detection architecture

> Architecture diagram of the GitHub repository raghavmaheshwari2024/android-malware-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raghavmaheshwari2024/android-malware-detection
- Repository: https://github.com/raghavmaheshwari2024/android-malware-detection

## Overview

1. **What this repository actually contains**
   This is primarily a **phishing URL detection system**, despite the top-level PDF/name suggesting an Android malware project. The live code is split into a **Node.js API gateway** and a **Python ML inference service**, with a separate **training pipeline** and a persisted **model artifact**.

2. **Top-level architecture**
   The runtime path is:
   **client → Node.js Express backend on port 3000 → FastAPI ML service on port 8000 → XGBoost model inference → response**.  
   The Node layer is the public API entrypoint; the Python layer owns feature extraction and classification.

3. **Node.js backend boundary**
   `project/backend-node/index.js` is the lightweight Express server. Its role is to accept incoming HTTP requests, handle basic API concerns like CORS, and forward prediction requests to the Python service using an HTTP client. It acts as an **API gateway / adapter**, not the ML engine.

4. **Python ML service boundary**
   `project/ml-service/main.py` is the FastAPI application that exposes the ML endpoints. This service owns the actual scoring logic and is the one that should be diagrammed as the **inference core**. It runs independently of Node and listens on its own port.

5. **Feature extraction subsystem**
   `project/ml-service/features.py` contains the URL feature engineering logic. The important architectural detail is that features are derived **only from the URL string itself**; the README explicitly says there are **no network requests** during extraction. That makes inference fast and self-contained.

6. **Model inference subsystem**
   `project/ml-service/url_model.pkl` is the serialized trained classifier, described as an **XGBoost model**. At startup, the FastAPI service loads this artifact into memory and reuses it for low-latency predictions. This is the main stateful artifact in the inference path.

7. **Training pipeline boundary**
   `project/ml-service/train.py` is separate from serving. It reads phishing URL training data, extracts the same URL features, trains the classifier, evaluates it, and writes `url_model.pkl`. In architecture terms, this is the **offline build/train path**, distinct from the online inference path.

8. **Data flow for prediction**
   A prediction request carries a URL string into the system. The URL is sent from Node to Python, Python extracts structural/protocol/content-based features, the loaded model scores the feature vector, and the service returns a **risk score plus a label** such as benign, suspicious, or malicious.

9. **Outputs and response shape**
   The system returns not just a verdict but also a **confidence/risk score** and the **extracted features**. That means the response is both a classification result and an explainability payload, which is useful for debugging or UI display.

10. **Operational endpoints**
   The Python service exposes at least a **health check** endpoint and the scoring endpoint. The Node service exposes the primary external API endpoint `/predict-url`. This indicates a two-tier operational model: health and inference are owned by the ML service, while client-facing routing is owned by Node.

11. **Local artifacts and persistence**
   There is no database or external storage in the repository. Persistence is limited to the local model file and the local dataset used for training. The architecture is therefore **stateless at request time** except for the in-memory loaded model.

12. **Repo-level tooling and dependencies**
   Python dependencies are managed through `project/requirements.txt`; Node dependencies are defined in `backend-node/package.json`. Runtime-wise, the stack is **FastAPI/Uvicorn on Python** and **Express/Axios on Node.js**. Those technologies mainly matter because they define the service split and HTTP integration boundary.

13. **How to draw the diagram**
   The diagram should show two boxes for the serving path: an **Express gateway** in front and a **FastAPI ML service** behind it. Inside the Python box, separate **feature extraction**, **model loading/inference**, and **response generation**. Off to the side, show an **offline training flow** from dataset to `train.py` to `url_model.pkl`.

14. **Notable architectural constraint**
   The system is designed to classify URLs using **static lexical features only**. It does not crawl websites, call third-party reputation services, or depend on external APIs during prediction. That constraint is a key part of the architecture and explains both the speed and the deployment simplicity.

Main entry points: [`project/ml-service/main.py`](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/main.py) (FastAPI service), [`project/ml-service/url_model.pkl`](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/url_model.pkl) (XGBoost model), [`project/ml-service/train.py`](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/train.py) (Training script), [`project/backend-node/index.js`](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/backend-node/index.js) (Express gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Serving path"]
  node_client(("Client<br/>external caller"))
  node_node_api["Express gateway<br/>Node.js API<br/>[index.js]"]
  node_predict_url{{"Predict URL<br/>endpoint"}}
  node_python_app["FastAPI service<br/>Python API<br/>[main.py]"]
  node_health_check{{"Health check<br/>endpoint"}}
  node_feature_engineering["Feature extraction<br/>URL features<br/>[features.py]"]
  node_feature_vector["Feature vector<br/>inference input"]
  node_xgboost_model[("XGBoost model<br/>serialized artifact<br/>[url_model.pkl]")]
  node_risk_response["Risk result<br/>response payload"]
end

subgraph group_offline["Offline training"]
  node_trainer["Training script<br/>offline ML job<br/>[train.py]"]
  node_train_features["Train features<br/>feature pipeline<br/>[features.py]"]
  node_model_artifact[("Model artifact<br/>trained pickle<br/>[url_model.pkl]")]
end

node_client -->|"HTTP request"| node_node_api
node_node_api -->|"routes to"| node_predict_url
node_predict_url -->|"proxy call"| node_python_app
node_python_app -->|"exposes"| node_health_check
node_python_app -->|"extracts"| node_feature_engineering
node_feature_engineering -->|"builds"| node_feature_vector
node_feature_vector -->|"scored by"| node_xgboost_model
node_xgboost_model -->|"prediction"| node_risk_response
node_python_app -->|"returns"| node_risk_response
node_trainer -->|"reuses"| node_train_features
node_train_features -->|"trains"| node_model_artifact
node_trainer -->|"writes"| node_model_artifact
node_model_artifact -->|"loads at startup"| node_xgboost_model

click node_node_api "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/backend-node/index.js"
click node_python_app "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/main.py"
click node_feature_engineering "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/features.py"
click node_xgboost_model "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/url_model.pkl"
click node_trainer "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/train.py"
click node_train_features "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/features.py"
click node_model_artifact "https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/url_model.pkl"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_node_api,node_predict_url,node_python_app,node_health_check,node_feature_engineering,node_feature_vector,node_xgboost_model,node_risk_response toneBlue
class node_trainer,node_train_features,node_model_artifact toneAmber
```

## Components

### Serving path

Online request flow from client through Node gateway to Python inference.

- **Client**: external caller · Sends URL prediction requests to the public API.
- [Express gateway](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/backend-node/index.js): Node.js API · Public HTTP entrypoint that handles API concerns and forwards scoring requests. · `project/backend-node/index.js`
- **Predict URL**: endpoint · Primary external route for URL classification requests.
- [FastAPI service](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/main.py): Python API · Inference service that owns URL scoring and response assembly. · `project/ml-service/main.py`
- **Health check**: endpoint · Operational endpoint for service readiness and liveness.
- [Feature extraction](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/features.py): URL features · Derives static lexical features directly from the URL string with no network calls. · `project/ml-service/features.py`
- **Feature vector**: inference input · Structured URL features passed into the classifier.
- [XGBoost model](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/url_model.pkl): serialized artifact · Persisted classifier loaded into memory for low-latency predictions. · `project/ml-service/url_model.pkl`
- **Risk result**: response payload · Returns label, confidence/risk score, and extracted features.

### Offline training

Model build path that produces the serialized classifier artifact.

- [Training script](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/train.py): offline ML job · Reads training data, extracts the same URL features, trains and evaluates the model. · `project/ml-service/train.py`
- [Train features](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/features.py): feature pipeline · Shared feature engineering logic reused during model training. · `project/ml-service/features.py`
- [Model artifact](https://github.com/raghavmaheshwari2024/android-malware-detection/blob/main/project/ml-service/url_model.pkl): trained pickle · Output artifact written by training and consumed by the serving service. · `project/ml-service/url_model.pkl`

## Connections

- Client → Express gateway: HTTP request · Client submits a URL for classification.
- Express gateway → Predict URL: routes to · Express exposes the public prediction endpoint.
- Predict URL → FastAPI service: proxy call · Node forwards the request to the Python service.
- FastAPI service → Health check: exposes · FastAPI also serves a health endpoint.
- FastAPI service → Feature extraction: extracts · Scoring begins by deriving URL-only features.
- Feature extraction → Feature vector: builds · Static features are assembled into an inference vector.
- Feature vector → XGBoost model: scored by · The loaded classifier evaluates the feature vector.
- XGBoost model → Risk result: prediction · Model output is converted into label and confidence response data.
- FastAPI service → Risk result: returns · FastAPI sends the final scoring payload back to Node.
- Training script → Train features: reuses · Offline training uses the same feature definitions as serving.
- Train features → Model artifact: trains · Feature extraction feeds the classifier training process.
- Training script → Model artifact: writes · Training persists the serialized model for serving.
- Model artifact → XGBoost model: loads at startup · The inference service loads the artifact into memory.
