How raghavmaheshwari2024/android-malware-detection works
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: main.py FastAPI service · url_model.pkl XGBoost model · train.py Training script · index.js Express gateway
Components 12
Serving path
Online request flow from client through Node gateway to Python inference.
- Client · Sends URL prediction requests to the public API.
- Express gateway · Public HTTP entrypoint that handles API concerns and forwards scoring requests.
project/backend-node/index.js - Predict URL · Primary external route for URL classification requests.
- FastAPI service · Inference service that owns URL scoring and response assembly.
project/ml-service/main.py - Health check · Operational endpoint for service readiness and liveness.
- Feature extraction · Derives static lexical features directly from the URL string with no network calls.
project/ml-service/features.py - Feature vector · Structured URL features passed into the classifier.
- XGBoost model · Persisted classifier loaded into memory for low-latency predictions.
project/ml-service/url_model.pkl - Risk result · Returns label, confidence/risk score, and extracted features.
Offline training
Model build path that produces the serialized classifier artifact.
- Training script · Reads training data, extracts the same URL features, trains and evaluates the model.
project/ml-service/train.py - Train features · Shared feature engineering logic reused during model training.
project/ml-service/features.py - Model artifact · Output artifact written by training and consumed by the serving service.
project/ml-service/url_model.pkl
Connections 13
- 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.