How indranil-saha-237/adversarial-ml-defense-systems works
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: app.js Express App · docker-compose.yml Compose · app.py Flask API · auth.js Auth Routes
Components 17
Client
User interaction and rendering
- Browser · User-facing entrypoint
Web/Auth App
Node.js authentication service
- Express App · Main server entrypoint
loginpage/app.js - Auth Routes · Login, signup, logout, OAuth
loginpage/routes/auth.js - Passport Config · Local and Google strategies
loginpage/config/passport.js - User Model · User account persistence
loginpage/models/User.js - EJS Views · Login, signup, dashboard pages
loginpage/views/dashboard.ejs - Session Store · Server-side session persistence
ML Defense API
Flask model defense service
- Flask API · ML defense HTTP service
ml/app.py - Model Runtime · Loads and serves pickled models
ml/models/baseline_rf.pkl - Baseline Model · Vulnerable reference model
ml/models/baseline_rf.pkl - Defended Model · Adversarially trained model
ml/models/defended_rf.pkl - Attack Pipeline · Compare and simulate attacks
ml/scripts/attack_simulation.py - Prep & Train · Preprocess and train variants
ml/scripts/train_defended_rf.py
Platform
Deployment and CI/CD
- MongoDB · Users and sessions store
- Google OAuth · External social login
- Compose · Local multi-service composition
docker-compose.yml - Jenkins CI · Build, deploy, health check
Jenkinsfile
Connections 21
- 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