# niranjan017/web-secure architecture

> Architecture diagram of the GitHub repository niranjan017/web-secure, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/niranjan017/web-secure
- Repository: https://github.com/niranjan017/web-secure

## Overview

##### Project Type and Purpose
- This is a full-stack web application named “web-secure” that provides security scanning of web resources.
- The frontend is a static HTML/JS UI for users to log in, configure scans, view dashboards/reports.
- The backend is a Node.js/Express API that manages authentication, scan requests, report persistence, and orchestrates Python‐based scanning modules.
- A database stores user records, scan requests, and scan results.

##### File Structure
- Top level:
- backend/ (Express server, routes, middleware, small Python scanner scripts, db.js)
- frontend/ (static HTML pages, CSS, JS under script/)
- package.json (likely for the entire project or root tooling)
- backend/
- server.js: Express app bootstrap
- routes/: REST endpoints (auth, authcheck, user, scan, repot, savescan)
- middleware/authenticateToken.js: JWT or token‐based auth guard
- scanner/: Python scripts (cs.py, ps.py, si.py, x.py, security_headers.py) – each module handles a specific security test
- db.js: database connection logic (likely MongoDB or similar)
- .env: secrets (DB URI, JWT secret, API keys)
- frontend/
- HTML pages reflect each UI view (login, scan, dash, report, blog, etc.)
- script/: JS controllers for each page that call backend APIs

##### README
- The README only contains the project title. We infer from code that the stack is Node.js + Express + a NoSQL/SQL database + Python scanners + static frontend.

a. Main Components
- User’s Browser (UI) – hosts the frontend HTML/CSS/JS
- Frontend Static Server – can be CDN or web server serving HTML & JS
- API Gateway (Node.js/Express) – handles HTTP(S) requests
- Authentication Module – JWT issuance & verification (middleware)
- Scanner Orchestrator – Express invokes Python scripts via child process or REST calls
- Python Scanner Modules – cs.py, ps.py, security_headers.py, etc.
- Database – stores Users, Scans, Reports
- (Optional) File Storage – if large reports or logs are stored on disk or S3
- External Services – email service, webhook targets, etc., if used
b. Relationships & Interactions
1. User logs in via frontend → POST /auth → Express → db → JWT token
2. Frontend sends scan request → Express /scan route → validates token → writes Scan record to DB → triggers Python scanner modules
3. Scanner modules execute tests and return JSON results → Express collects results → saves to DB (ScanResults) → triggers notify or returns response
4. Frontend polls or fetches /report → Express reads from DB → returns report data → UI renders charts
c. Architectural Patterns & Principles
- Separation of Concerns: frontend UI vs. backend API vs. scanning logic
- Micro-modules for scanning: each Python script is a self-contained test
- Token-based stateless auth (JWT)
- RESTful API design
d. Key Technologies & Frameworks
- Node.js, Express.js, dotenv
- Python for security scanning scripts
- MongoDB or other DB (via db.js)
- JWT for authentication
- Static HTML/CSS/Vanilla JS on frontend

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["User’s Browser"]:::external
        FrontendUI["Frontend UI<br/>(Static HTML/CSS/JS)"]:::frontend
    end

    Browser -->|"HTTPS"| FrontendUI

    click FrontendUI "https://github.com/niranjan017/web-secure/tree/main/frontend/"

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIServer["Express API<br/>(Node.js/Express)"]:::backend
        AuthModule["Authentication Module"]:::backend
        UserRoutes["User Management Routes"]:::backend
        ScanRoutes["Scan Orchestration Routes"]:::backend
    end

    FrontendUI -->|"HTTP Requests"| APIServer
    APIServer -->|"uses"| AuthModule
    APIServer -->|"routes to"| UserRoutes
    APIServer -->|"routes to"| ScanRoutes

    click APIServer "https://github.com/niranjan017/web-secure/blob/main/backend/server.js"
    click AuthModule "https://github.com/niranjan017/web-secure/blob/main/backend/routes/auth.js"
    click AuthModule "https://github.com/niranjan017/web-secure/blob/main/backend/routes/authcheck.js"
    click AuthModule "https://github.com/niranjan017/web-secure/blob/main/backend/middleware/authenticateToken.js"
    click UserRoutes "https://github.com/niranjan017/web-secure/blob/main/backend/routes/user.js"
    click ScanRoutes "https://github.com/niranjan017/web-secure/blob/main/backend/routes/scan.js"
    click ScanRoutes "https://github.com/niranjan017/web-secure/blob/main/backend/routes/savescan.js"
    click ScanRoutes "https://github.com/niranjan017/web-secure/blob/main/backend/routes/repot.js"
    click APIServer "https://github.com/niranjan017/web-secure/blob/main/backend/package.json"
    click APIServer "https://github.com/niranjan017/web-secure/blob/main/backend/package-lock.json"

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        ScannerOrchestrator["Scanner Orchestrator<br/>(child_process)"]:::backend
        subgraph "Python Scanner Modules"
            direction TB
            CS["cs.py"]:::scanner
            PS["ps.py"]:::scanner
            SI["si.py"]:::scanner
            XSS["x.py"]:::scanner
            SecHeaders["security_headers.py"]:::scanner
        end
    end

    ScanRoutes -->|"spawn"| ScannerOrchestrator
    ScannerOrchestrator -->|"executes"| CS
    ScannerOrchestrator -->|"executes"| PS
    ScannerOrchestrator -->|"executes"| SI
    ScannerOrchestrator -->|"executes"| XSS
    ScannerOrchestrator -->|"executes"| SecHeaders
    CS -->|"JSON results"| ScannerOrchestrator
    PS -->|"JSON results"| ScannerOrchestrator
    SI -->|"JSON results"| ScannerOrchestrator
    XSS -->|"JSON results"| ScannerOrchestrator
    SecHeaders -->|"JSON results"| ScannerOrchestrator

    click CS "https://github.com/niranjan017/web-secure/blob/main/backend/scanner/cs.py"
    click PS "https://github.com/niranjan017/web-secure/blob/main/backend/scanner/ps.py"
    click SI "https://github.com/niranjan017/web-secure/blob/main/backend/scanner/si.py"
    click XSS "https://github.com/niranjan017/web-secure/blob/main/backend/scanner/x.py"
    click SecHeaders "https://github.com/niranjan017/web-secure/blob/main/backend/scanner/security_headers.py"

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Database["Database<br/>(MongoDB)"]:::database
        DBLogic["DB Connection Logic"]:::backend
        Env["Environment Config"]:::backend
    end

    AuthModule -->|"user lookup"| DBLogic
    ScanRoutes -->|"insert/update scan"| DBLogic
    ScannerOrchestrator -->|"save results"| DBLogic
    DBLogic -->|"connects to"| Database
    Env -->|"provides URI & secret"| DBLogic

    click DBLogic "https://github.com/niranjan017/web-secure/blob/main/backend/db.js"
    click Env "https://github.com/niranjan017/web-secure/blob/main/backend/.env"

    %% Responses
    APIServer -->|"JSON Responses"| FrontendUI

    classDef frontend fill:#8FBC8F,stroke:#2E8B57,color:#000;
    classDef backend fill:#ADD8E6,stroke:#1E90FF,color:#000;
    classDef scanner fill:#FFD700,stroke:#DAA520,color:#000;
    classDef database fill:#FFA500,stroke:#FF8C00,color:#000;
    classDef external fill:#D3D3D3,stroke:#808080,color:#000;
```
