# indranil-saha-237/adversarial-ml-defense-systems architecture

> Architecture diagram of the GitHub repository indranil-saha-237/adversarial-ml-defense-systems, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/indranil-saha-237/adversarial-ml-defense-systems
- Repository: https://github.com/indranil-saha-237/adversarial-ml-defense-systems

## Overview

1. **Repository shape**
   - This is a two-service system: a **Node.js/Express authentication web app** in `loginpage/` and a **Python/Flask ML defense API** in `ml/`.
   - The services are tied together by `docker-compose.yml` for local/container deployment and `Jenkinsfile` for CI/CD.

2. **User-facing web app boundary**
   - `loginpage/app.js` is the main server entry point.
   - The UI is **server-rendered EJS** (`views/login.ejs`, `signup.ejs`, `dashboard.ejs`), not a SPA.
   - Static assets are implied to be served by Express, while routes render pages and redirect based on auth state.

3. **Authentication subsystem**
   - `loginpage/routes/auth.js` contains the login/signup/logout and Google OAuth flow.
   - `loginpage/config/passport.js` defines Passport strategies for local credentials and Google OAuth 2.0.
   - `loginpage/models/User.js` is the Mongoose user model backing account creation and lookup.

4. **State and persistence**
   - MongoDB is the persistence layer for both **users** and **sessions**.
   - Sessions are stored server-side through `connect-mongo`, so session state survives restarts and is not kept only in cookies.
   - The app uses bcrypt-based password hashing; OAuth users may have a Google ID and avatar instead of a local password.

5. **ML/defense service boundary**
   - `ml/app.py` is a separate Flask API process, independent from the Node app.
   - It exposes endpoints for health, metadata, model comparison, and adversarial attack simulation.
   - The Node app talks to it over HTTP, typically via Axios, rather than sharing code or memory.

6. **ML model runtime**
   - The Flask service loads pre-trained pickle models from `ml/models/`: baseline and defended Random Forest variants.
   - The API is responsible for selecting model metadata, reporting comparison metrics, and running the attack workflow.
   - The runtime concern is model inference/benchmarking, not training.

7. **Adversarial defense pipeline**
   - The defense story is centered on comparing a **baseline vulnerable model** with a **defended/adversarially trained model**.
   - `ml/scripts/` contains the offline data/ML workflow: preprocessing, baseline training, defended training, and attack simulation.
   - ART (Adversarial Robustness Toolbox) is the key ML security dependency driving attack/defense experimentation.

8. **Cross-service data flow**
   - A browser interacts with the Express app for signup/login and then accesses the protected dashboard.
   - When the dashboard needs ML status or results, the Node app calls the Flask API.
   - Flask returns JSON metrics that the dashboard can render, so the UI is effectively a bridge between auth state and ML defense telemetry.

9. **External integrations**
   - Google OAuth is the only clear third-party identity provider.
   - MongoDB is the only database; there is no separate analytics store or queue.
   - The ML service has no visible external network dependency beyond its HTTP exposure and the local model/data files.

10. **Deployment and orchestration**
   - `docker-compose.yml` is the primary system composition layer, likely running Node app, Flask API, and MongoDB together.
   - Each service has its own Dockerfile, so the app is split by runtime and packaged independently.
   - The architecture depends on environment variables for service URLs, secrets, and database connectivity.

11. **CI/CD boundary**
   - `Jenkinsfile` automates checkout, environment setup, Docker build/deploy, and a health check.
   - The pipeline validates the web app endpoint rather than the ML model directly, so operational success is defined at the system level.

12. **Operational characteristics**
   - The app is mostly synchronous request/response: browser → Express → MongoDB / Flask HTTP call → browser.
   - There is no queue, worker pool, or event bus in the repository.
   - Health endpoints exist for both services, which suggests deployment monitoring is intended to be simple and service-level.

13. **What to draw in an architecture diagram**
   - Show three main boxes: **Web/Auth App**, **MongoDB**, and **ML Defense API**.
   - Connect the browser to the web app; connect the web app to MongoDB for users/sessions; connect the web app to the ML API via HTTP; connect the ML API to local model files and training artifacts.
   - Add Google OAuth as an external identity provider and Docker/Jenkins as deployment/automation boundaries.

Main entry points: [`loginpage/app.js`](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/app.js) (Express App), [`docker-compose.yml`](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/docker-compose.yml) (Compose), [`ml/app.py`](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/app.py) (Flask API), [`loginpage/routes/auth.js`](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/routes/auth.js) (Auth Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_browser(("Browser<br/>client"))
end

subgraph group_web["Web/Auth App"]
  node_express_app["Express App<br/>node server<br/>[app.js]"]
  node_auth_routes["Auth Routes<br/>auth flow<br/>[auth.js]"]
  node_passport_cfg["Passport Config<br/>auth config<br/>[passport.js]"]
  node_user_model["User Model<br/>mongoose model<br/>[User.js]"]
  node_views["EJS Views<br/>server render<br/>[dashboard.ejs]"]
  node_session_store[("Session Store<br/>connect-mongo")]
end

subgraph group_ml["ML Defense API"]
  node_flask_api["Flask API<br/>python api<br/>[app.py]"]
  node_ml_runtime["Model Runtime<br/>inference<br/>[baseline_rf.pkl]"]
  node_baseline_model["Baseline Model<br/>rf pickle<br/>[baseline_rf.pkl]"]
  node_defended_model["Defended Model<br/>rf pickle<br/>[defended_rf.pkl]"]
  node_attack_pipeline["Attack Pipeline<br/>analysis workflow"]
  node_prep_train["Prep & Train<br/>ml scripts"]
end

subgraph group_infra["Platform"]
  node_mongo[("MongoDB<br/>database")]
  node_google_oauth(("Google OAuth<br/>identity provider"))
  node_docker_compose["Compose<br/>orchestration<br/>[docker-compose.yml]"]
  node_jenkins["Jenkins CI<br/>pipeline"]
end

node_browser -->|"HTTPS"| node_express_app
node_express_app -->|"renders"| node_views
node_views -->|"HTML"| node_browser
node_express_app -->|"routes"| node_auth_routes
node_auth_routes -->|"uses"| node_passport_cfg
node_passport_cfg -->|"loads"| node_user_model
node_user_model -->|"CRUD"| node_mongo
node_express_app -->|"sessions"| node_session_store
node_session_store -->|"stores"| node_mongo
node_auth_routes -->|"OAuth"| node_google_oauth
node_express_app -->|"HTTP/JSON"| node_flask_api
node_flask_api -->|"serves"| node_ml_runtime
node_ml_runtime -->|"loads"| node_baseline_model
node_ml_runtime -->|"loads"| node_defended_model
node_flask_api -->|"reports"| node_attack_pipeline
node_attack_pipeline -->|"depends on"| node_prep_train
node_docker_compose -->|"runs"| node_express_app
node_docker_compose -->|"runs"| node_flask_api
node_docker_compose -->|"runs"| node_mongo
node_jenkins -->|"builds"| node_docker_compose
node_jenkins -->|"checks"| node_express_app

click node_express_app "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/app.js"
click node_auth_routes "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/routes/auth.js"
click node_passport_cfg "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/config/passport.js"
click node_user_model "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/models/User.js"
click node_views "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/views/dashboard.ejs"
click node_flask_api "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/app.py"
click node_ml_runtime "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/models/baseline_rf.pkl"
click node_baseline_model "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/models/baseline_rf.pkl"
click node_defended_model "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/models/defended_rf.pkl"
click node_attack_pipeline "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/scripts/attack_simulation.py"
click node_prep_train "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/scripts/train_defended_rf.py"
click node_docker_compose "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/docker-compose.yml"
click node_jenkins "https://github.com/indranil-saha-237/adversarial-ml-defense-systems/tree/main/Jenkinsfile"

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_browser toneBlue
class node_express_app,node_auth_routes,node_passport_cfg,node_user_model,node_views,node_session_store toneAmber
class node_flask_api,node_ml_runtime,node_baseline_model,node_defended_model,node_attack_pipeline,node_prep_train toneMint
class node_mongo,node_google_oauth,node_docker_compose,node_jenkins toneRose
```

## Components

### Client

User interaction and rendering

- **Browser**: client · User-facing entrypoint

### Web/Auth App

Node.js authentication service

- [Express App](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/app.js): node server · Main server entrypoint · `loginpage/app.js`
- [Auth Routes](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/routes/auth.js): auth flow · Login, signup, logout, OAuth · `loginpage/routes/auth.js`
- [Passport Config](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/config/passport.js): auth config · Local and Google strategies · `loginpage/config/passport.js`
- [User Model](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/models/User.js): mongoose model · User account persistence · `loginpage/models/User.js`
- [EJS Views](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/loginpage/views/dashboard.ejs): server render · Login, signup, dashboard pages · `loginpage/views/dashboard.ejs`
- **Session Store**: connect-mongo · Server-side session persistence

### ML Defense API

Flask model defense service

- [Flask API](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/app.py): python api · ML defense HTTP service · `ml/app.py`
- [Model Runtime](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/models/baseline_rf.pkl): inference · Loads and serves pickled models · `ml/models/baseline_rf.pkl`
- [Baseline Model](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/models/baseline_rf.pkl): rf pickle · Vulnerable reference model · `ml/models/baseline_rf.pkl`
- [Defended Model](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/models/defended_rf.pkl): rf pickle · Adversarially trained model · `ml/models/defended_rf.pkl`
- [Attack Pipeline](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/scripts/attack_simulation.py): analysis workflow · Compare and simulate attacks · `ml/scripts/attack_simulation.py`
- [Prep & Train](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/ml/scripts/train_defended_rf.py): ml scripts · Preprocess and train variants · `ml/scripts/train_defended_rf.py`

### Platform

Deployment and CI/CD

- **MongoDB**: database · Users and sessions store
- **Google OAuth**: identity provider · External social login
- [Compose](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/blob/main/docker-compose.yml): orchestration · Local multi-service composition · `docker-compose.yml`
- [Jenkins CI](https://github.com/indranil-saha-237/adversarial-ml-defense-systems/tree/main/Jenkinsfile): pipeline · Build, deploy, health check · `Jenkinsfile`

## Connections

- Browser → Express App: HTTPS · User interacts with the web app
- Express App → EJS Views: renders · Server-side page rendering
- EJS Views → Browser: HTML · Login, signup, dashboard pages
- Express App → Auth Routes: routes · Auth and dashboard requests
- Auth Routes → Passport Config: uses · Authentication strategies
- Passport Config → User Model: loads · User lookup and creation
- User Model → MongoDB: CRUD · Account persistence
- Express App → Session Store: sessions · Server-side session handling
- Session Store → MongoDB: stores · Persistent session backing
- Auth Routes → Google OAuth: OAuth · Third-party identity login
- Express App → Flask API: HTTP/JSON · Fetches ML status and results
- Flask API → Model Runtime: serves · Runs model comparison and inference
- Model Runtime → Baseline Model: loads · Baseline model artifact
- Model Runtime → Defended Model: loads · Defended model artifact
- Flask API → Attack Pipeline: reports · Attack metrics and comparisons
- Attack Pipeline → Prep & Train: depends on · Offline preprocessing and training workflow
- Compose → Express App: runs · Web service container
- Compose → Flask API: runs · ML service container
- Compose → MongoDB: runs · Database container
- Jenkins CI → Compose: builds · Automated deploy orchestration
- Jenkins CI → Express App: checks · System health validation
