# ah74n/ism architecture

> Architecture diagram of the GitHub repository ah74n/ism, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ah74n/ism
- Repository: https://github.com/ah74n/ism

## Overview

#### Purpose and Entry Points
IsMalicious is a URL threat-intelligence application: it accepts URLs, gathers network/domain evidence, applies heuristic and ML analysis, optionally executes browser-based sandbox inspection, and returns structured risk findings. The backend FastAPI application starts at `backend/app/main.py`; the Vite/React client starts at `frontend/src/main.jsx` and renders `frontend/src/App.jsx`.

#### API and Request Boundary
HTTP routes form the public control boundary. Scan submission and analysis results are centered on `backend/app/api/routes/scan.py`; retained scan lookup is exposed through `backend/app/api/routes/history.py`. Supporting operational surfaces include authentication, administration, health, and sandbox routes under `backend/app/api/routes/auth.py`, `backend/app/api/routes/admin.py`, `backend/app/api/routes/health.py`, and `backend/app/api/routes/sandbox.py`.

#### Scan Orchestration
The scan route should coordinate analysis rather than embed detection logic. URL validation occurs before service invocation in `backend/app/utils/validators.py`; request/response contracts and scan persistence types live in `backend/app/models/schemas.py` and `backend/app/models/scan_model.py`. The resulting flow is: client URL → validation → enrichment/detection services → normalized threat response → persisted history.

#### Domain and DNS Enrichment
`backend/app/services/dns_service.py` is the external-network intelligence boundary for DNS and likely domain-record collection. Its output feeds the decision pipeline alongside URL characteristics, keeping remote lookup behavior separate from API handlers and response formatting.

#### Detection Pipeline
Two complementary detection stages provide risk signals:
- Rule/indicator analysis in `backend/app/services/heuristic_service.py`, for suspicious URL/domain patterns and deterministic findings.
- Model inference in `backend/app/services/ml_service.py`, backed by extracted URL features from `backend/app/ml/feature_extractor.py` and the committed model artifact `backend/url_model.pkl`.

`backend/app/ml/live_feature_extractor.py` indicates a distinct feature path for runtime/live inspection, which should remain compatible with the trained model’s expected feature schema. Model training is an offline workflow in `backend/train_model.py`, not part of request handling.

#### Sandbox and Automation Boundary
`backend/app/services/sandbox_service.py` encapsulates active target inspection, consistent with the documented Playwright and media-processing capabilities. It is exposed separately at `backend/app/api/routes/sandbox.py`, allowing potentially slower or higher-risk browser automation to remain isolated from lightweight URL scoring. This layer may involve external untrusted pages and must be treated as the strongest execution/network boundary.

#### Persistence, Configuration, and Deployment
Database initialization and session infrastructure are centralized in `backend/app/core/database.py`; the repository includes a local SQLite database at `backend/ismalicious.db`, while the design is described as PostgreSQL-ready. Runtime settings and environment-derived service endpoints belong in `backend/app/core/config.py`; logging is centralized in `backend/app/core/logging.py`. Redis and PostgreSQL are intended optional infrastructure dependencies, configured via environment variables rather than embedded in route logic. Container deployment is represented by `Dockerfile`; backend Python dependencies are declared in `backend/requirements.txt`.

#### Presentation Layer
The frontend is a thin client boundary rather than analysis infrastructure. `frontend/src/App.jsx` presents scan interactions and consumes backend APIs, while `frontend/src/main.jsx` bootstraps the application. Deployment is independently compatible with Vercel for the frontend and Uvicorn/Gunicorn-style Python hosting for the API.

Main entry points: [`backend/app/main.py`](https://github.com/ah74n/ism/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/api/routes/scan.py`](https://github.com/ah74n/ism/blob/main/backend/app/api/routes/scan.py) (Scan API), [`backend/app/utils/validators.py`](https://github.com/ah74n/ism/blob/main/backend/app/utils/validators.py) (URL validation), [`backend/app/core/database.py`](https://github.com/ah74n/ism/blob/main/backend/app/core/database.py) (Database sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_web_bootstrap["React bootstrap<br/>frontend entry<br/>[main.jsx]"]
  node_web_app["Scan UI<br/>React application<br/>[App.jsx]"]
end

subgraph group_api["API boundary"]
  node_api_app["FastAPI application<br/>backend entry<br/>[main.py]"]
  node_scan_route["Scan API<br/>scan controller<br/>[scan.py]"]
  node_history_route["History API<br/>retained scan lookup<br/>[history.py]"]
  node_sandbox_route["Sandbox API<br/>automation controller<br/>[sandbox.py]"]
  node_ops_routes["Operational routes<br/>auth, admin, health<br/>[auth.py]"]
end

subgraph group_analysis["Analysis pipeline"]
  node_validation["URL validation<br/>input validation<br/>[validators.py]"]
  node_contracts["Scan contracts<br/>schemas and persistence types<br/>[schemas.py]"]
  node_scan_model["Scan record<br/>persistence model<br/>[scan_model.py]"]
  node_dns{{"DNS enrichment<br/>network intelligence<br/>[dns_service.py]"}}
  node_heuristics["Heuristic analysis<br/>rule engine"]
  node_ml_inference["ML inference<br/>risk model service<br/>[ml_service.py]"]
  node_url_features["URL features<br/>trained-model features"]
  node_live_features["Live features<br/>runtime feature path"]
  node_model_artifact["Trained URL model<br/>model artifact<br/>[url_model.pkl]"]
  node_sandbox{{"Browser sandbox<br/>active target inspection<br/>[sandbox_service.py]"}}
  node_training["Offline model training<br/>training workflow<br/>[train_model.py]"]
end

subgraph group_platform["Platform &amp; storage"]
  node_database[("Database sessions<br/>persistence infrastructure<br/>[database.py]")]
  node_scan_history[("Scan history store<br/>SQLite / PostgreSQL<br/>[ismalicious.db]")]
  node_settings["Runtime settings<br/>environment configuration<br/>[config.py]"]
end

node_web_bootstrap -->|"renders"| node_web_app
node_web_app -->|"API requests"| node_api_app
node_api_app -->|"mounts"| node_scan_route
node_api_app -->|"mounts"| node_history_route
node_api_app -->|"mounts"| node_sandbox_route
node_api_app -->|"mounts"| node_ops_routes
node_scan_route -->|"validates URL"| node_validation
node_scan_route -->|"uses contracts"| node_contracts
node_validation -->|"valid URL"| node_dns
node_validation -->|"valid URL"| node_heuristics
node_validation -->|"valid URL"| node_ml_inference
node_dns -->|"domain evidence"| node_heuristics
node_url_features -->|"feature vector"| node_ml_inference
node_live_features -->|"live feature vector"| node_ml_inference
node_model_artifact -->|"loaded model"| node_ml_inference
node_scan_route -->|"normalizes result"| node_scan_model
node_scan_model -->|"persists through"| node_database
node_database -->|"stores scans"| node_scan_history
node_history_route -->|"queries"| node_database
node_sandbox_route -->|"starts inspection"| node_sandbox
node_settings -.->|"runtime configuration"| node_api_app
node_settings -.->|"database endpoint"| node_database
node_url_features -->|"training features"| node_training
node_training -->|"produces"| node_model_artifact

click node_web_bootstrap "https://github.com/ah74n/ism/blob/main/frontend/src/main.jsx"
click node_web_app "https://github.com/ah74n/ism/blob/main/frontend/src/App.jsx"
click node_api_app "https://github.com/ah74n/ism/blob/main/backend/app/main.py"
click node_scan_route "https://github.com/ah74n/ism/blob/main/backend/app/api/routes/scan.py"
click node_history_route "https://github.com/ah74n/ism/blob/main/backend/app/api/routes/history.py"
click node_sandbox_route "https://github.com/ah74n/ism/blob/main/backend/app/api/routes/sandbox.py"
click node_ops_routes "https://github.com/ah74n/ism/blob/main/backend/app/api/routes/auth.py"
click node_validation "https://github.com/ah74n/ism/blob/main/backend/app/utils/validators.py"
click node_contracts "https://github.com/ah74n/ism/blob/main/backend/app/models/schemas.py"
click node_scan_model "https://github.com/ah74n/ism/blob/main/backend/app/models/scan_model.py"
click node_dns "https://github.com/ah74n/ism/blob/main/backend/app/services/dns_service.py"
click node_heuristics "https://github.com/ah74n/ism/blob/main/backend/app/services/heuristic_service.py"
click node_ml_inference "https://github.com/ah74n/ism/blob/main/backend/app/services/ml_service.py"
click node_url_features "https://github.com/ah74n/ism/blob/main/backend/app/ml/feature_extractor.py"
click node_live_features "https://github.com/ah74n/ism/blob/main/backend/app/ml/live_feature_extractor.py"
click node_model_artifact "https://github.com/ah74n/ism/blob/main/backend/url_model.pkl"
click node_sandbox "https://github.com/ah74n/ism/blob/main/backend/app/services/sandbox_service.py"
click node_database "https://github.com/ah74n/ism/blob/main/backend/app/core/database.py"
click node_scan_history "https://github.com/ah74n/ism/blob/main/backend/ismalicious.db"
click node_settings "https://github.com/ah74n/ism/blob/main/backend/app/core/config.py"
click node_training "https://github.com/ah74n/ism/blob/main/backend/train_model.py"

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_web_bootstrap,node_web_app toneBlue
class node_api_app,node_scan_route,node_history_route,node_sandbox_route,node_ops_routes toneAmber
class node_validation,node_contracts,node_scan_model,node_dns,node_heuristics,node_ml_inference,node_url_features,node_live_features,node_model_artifact,node_sandbox,node_training toneMint
class node_database,node_scan_history,node_settings toneRose
```

## Components

### Frontend

- [React bootstrap](https://github.com/ah74n/ism/blob/main/frontend/src/main.jsx): frontend entry · `frontend/src/main.jsx`
- [Scan UI](https://github.com/ah74n/ism/blob/main/frontend/src/App.jsx): React application · Collects URLs and displays risk findings. · `frontend/src/App.jsx`

### API boundary

- [FastAPI application](https://github.com/ah74n/ism/blob/main/backend/app/main.py): backend entry · `backend/app/main.py`
- [Scan API](https://github.com/ah74n/ism/blob/main/backend/app/api/routes/scan.py): scan controller · Coordinates synchronous URL analysis and response creation. · `backend/app/api/routes/scan.py`
- [History API](https://github.com/ah74n/ism/blob/main/backend/app/api/routes/history.py): retained scan lookup · `backend/app/api/routes/history.py`
- [Sandbox API](https://github.com/ah74n/ism/blob/main/backend/app/api/routes/sandbox.py): automation controller · Separates active inspection from lightweight scoring. · `backend/app/api/routes/sandbox.py`
- [Operational routes](https://github.com/ah74n/ism/blob/main/backend/app/api/routes/auth.py): auth, admin, health · `backend/app/api/routes/auth.py`

### Analysis pipeline

- [URL validation](https://github.com/ah74n/ism/blob/main/backend/app/utils/validators.py): input validation · `backend/app/utils/validators.py`
- [Scan contracts](https://github.com/ah74n/ism/blob/main/backend/app/models/schemas.py): schemas and persistence types · `backend/app/models/schemas.py`
- [Scan record](https://github.com/ah74n/ism/blob/main/backend/app/models/scan_model.py): persistence model · `backend/app/models/scan_model.py`
- [DNS enrichment](https://github.com/ah74n/ism/blob/main/backend/app/services/dns_service.py): network intelligence · Collects remote DNS and domain-record evidence. · `backend/app/services/dns_service.py`
- [Heuristic analysis](https://github.com/ah74n/ism/blob/main/backend/app/services/heuristic_service.py): rule engine · Produces deterministic URL and domain indicators. · `backend/app/services/heuristic_service.py`
- [ML inference](https://github.com/ah74n/ism/blob/main/backend/app/services/ml_service.py): risk model service · `backend/app/services/ml_service.py`
- [URL features](https://github.com/ah74n/ism/blob/main/backend/app/ml/feature_extractor.py): trained-model features · `backend/app/ml/feature_extractor.py`
- [Live features](https://github.com/ah74n/ism/blob/main/backend/app/ml/live_feature_extractor.py): runtime feature path · Maintains compatibility with the model feature schema. · `backend/app/ml/live_feature_extractor.py`
- [Trained URL model](https://github.com/ah74n/ism/blob/main/backend/url_model.pkl): model artifact · `backend/url_model.pkl`
- [Browser sandbox](https://github.com/ah74n/ism/blob/main/backend/app/services/sandbox_service.py): active target inspection · Executes browser-based inspection against untrusted pages. · `backend/app/services/sandbox_service.py`
- [Offline model training](https://github.com/ah74n/ism/blob/main/backend/train_model.py): training workflow · Builds the committed model outside request handling. · `backend/train_model.py`

### Platform & storage

- [Database sessions](https://github.com/ah74n/ism/blob/main/backend/app/core/database.py): persistence infrastructure · Centralizes initialization and session access. · `backend/app/core/database.py`
- [Scan history store](https://github.com/ah74n/ism/blob/main/backend/ismalicious.db): SQLite / PostgreSQL · Local SQLite is present; PostgreSQL is supported by configuration. · `backend/ismalicious.db`
- [Runtime settings](https://github.com/ah74n/ism/blob/main/backend/app/core/config.py): environment configuration · Configures optional Redis and PostgreSQL endpoints. · `backend/app/core/config.py`

## Connections

- React bootstrap → Scan UI: renders
- Scan UI → FastAPI application: API requests
- FastAPI application → Scan API: mounts
- FastAPI application → History API: mounts
- FastAPI application → Sandbox API: mounts
- FastAPI application → Operational routes: mounts
- Scan API → URL validation: validates URL
- Scan API → Scan contracts: uses contracts
- URL validation → DNS enrichment: valid URL
- URL validation → Heuristic analysis: valid URL
- URL validation → ML inference: valid URL
- DNS enrichment → Heuristic analysis: domain evidence
- URL features → ML inference: feature vector
- Live features → ML inference: live feature vector
- Trained URL model → ML inference: loaded model
- Scan API → Scan record: normalizes result
- Scan record → Database sessions: persists through
- Database sessions → Scan history store: stores scans
- History API → Database sessions: queries
- Sandbox API → Browser sandbox: starts inspection
- Runtime settings → FastAPI application: runtime configuration
- Runtime settings → Database sessions: database endpoint
- URL features → Offline model training: training features
- Offline model training → Trained URL model: produces
