# techtyphoon/cyber-threat-detection-machine-learning-project architecture

> Architecture diagram of the GitHub repository techtyphoon/cyber-threat-detection-machine-learning-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/techtyphoon/cyber-threat-detection-machine-learning-project
- Repository: https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project

## Overview

##### Project Type and Purpose
- This is a full-stack web application for cyber threat detection.
- Frontend: React.js/Vite single-page app for user input and displaying predictions.
- Backend: Python/Flask API serving a pre-trained machine learning model (scikit-learn) to classify network traffic as Normal or malicious.

##### File Structure
- Top-level:
- Pipfile/Pipfile.lock: root environment for running scripts or orchestration
- README.md: project overview and setup instructions
- backend/: contains model code, data, API definitions, Dockerfile
- frontend/: contains React app, config files (package.json, vite.config.js, tailwind.config.js)
- backend/:
- data/: raw dataset (cyberfeddefender_dataset.csv)
- model artifacts: model.pkl, scaler.pkl, label_encoder.pkl
- notebook.py: training and EDA pipeline
- model.py: model-building logic
- predict.py: Flask server exposing /predict endpoint
- Dockerfile: containerizes Flask app
- frontend/:
- src/: React entrypoint (main.jsx), components (InputForm.jsx, ResultCard.jsx, ResultsTable.jsx), styling (App.css, index.css)
- public/index.html
- package.json & lock: npm dependencies (React, Axios, Tailwind)
- vite.config.js, postcss.config.js, tailwind.config.js, eslint.config.js

##### README for Insights
- Workflow: data preprocessing → model training → export .pkl files → containerize Flask API → React UI calls API
- Deployment: Docker build and run for backend; npm run dev for frontend
- External interactions: user’s browser communicates with backend via REST over HTTP (JSON payloads)

##### Main Components and Their Relationships
a. Frontend Client (React/Vite)
- Renders forms for single/batch inputs
- Sends HTTP POST requests with feature vectors or CSV file to /predict
- Displays prediction labels & probabilities
b. Backend API (Flask)
- Receives requests, loads model artifacts (scaler.pkl, label_encoder.pkl, model.pkl)
- Applies preprocessing steps, runs inference
- Returns JSON response with label and probabilities
c. Data & Model Artifacts
- Stored on backend filesystem under backend/data and root of backend
d. Containerization & Deployment
- Dockerfile builds a “flask-predict-app” image exposing port 5002
- Frontend and backend can be deployed independently (microservices-style)
e. Development Tooling
- Pipenv for Python virtual environments
- npm/Yarn and Vite for frontend bundling
- ESLint, Tailwind for code quality and styling

##### Architectural Patterns and Design Principles
- Layered architecture:
- Presentation layer (React UI)
- Service layer (Flask REST API)
- Data layer (model files + dataset)
- Separation of concerns: UI vs. inference logic vs. data preprocessing/training
- Containerization for portability and scaling
- Stateless API design: each request reloads model or reuses in-memory global

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    A["User / Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        FE1["frontend/public/index.html"]:::frontend
        FE2["frontend/src/main.jsx"]:::frontend
        FE3["frontend/src/App.jsx"]:::frontend
        FE4["frontend/src/App.css"]:::frontend
        subgraph "Components"
            direction TB
            FE5["frontend/src/components/InputForm.jsx"]:::frontend
            FE6["frontend/src/components/ResultCard.jsx"]:::frontend
            FE7["frontend/src/ResultsTable.jsx"]:::frontend
        end
        subgraph "Config & Tooling"
            direction TB
            FE8["frontend/package.json"]:::tool
            FE9["frontend/vite.config.js"]:::tool
            FE10["frontend/postcss.config.js"]:::tool
            FE11["frontend/tailwind.config.js"]:::tool
            FE12["frontend/eslint.config.js"]:::tool
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        BE1["backend/predict.py\n(Flask API)"]:::backend
        BE2["backend/model.py\n(Model Logic)"]:::backend
        BE3["backend/notebook.py\n(Training & EDA)"]:::backend
        subgraph "Env & Docs"
            direction TB
            BE4["backend/Pipfile"]:::tool
            BE5["backend/Pipfile.lock"]:::tool
            BE6["backend/requirements.txt"]:::tool
            BE7["backend/README.md"]:::tool
            BE8["backend/Notes.txt"]:::tool
        end
        subgraph "Model Store"
            direction TB
            BE9["backend/data/cyberfeddefender_dataset.csv"]:::data
            BE10["backend/model.pkl"]:::data
            BE11["backend/scaler.pkl"]:::data
            BE12["backend/label_encoder.pkl"]:::data
        end
        BE13["backend/Dockerfile"]:::tool
    end

    %% Root-level Orchestration
    RL1["Pipfile"]:::tool
    RL2["Pipfile.lock"]:::tool
    RL3["README.md"]:::tool

    %% Connections
    A -->|"HTTP/JSON POST"| FE2
    FE2 -->|"renders UI"| FE3
    FE3 --> FE5
    FE3 --> FE6
    FE3 --> FE7
    FE2 -->|"Axios POST /predict\nHTTP/JSON"| BE1
    BE1 -->|"loads artifacts"| BE10
    BE1 --> BE11
    BE1 --> BE12
    BE1 --> BE2
    BE1 -->|"file I/O dataset"| BE9
    BE1 -->|"returns JSON"| FE2
    BE3 -->|"generates artifacts"| BE10
    BE3 --> BE11
    BE3 --> BE12
    BE13 -.-> BE1
    RL1 -.-> BE4
    RL2 -.-> BE5

    %% Class Definitions
    classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000;
    classDef backend fill:#d4edda,stroke:#28a745,color:#000;
    classDef data fill:#f0f0f0,stroke:#666,color:#000;
    classDef tool fill:#fff3cd,stroke:#ffcc00,color:#000;
    classDef external fill:#ece2f0,stroke:#884d9e,color:#000;

    %% Click Events
    click FE1 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/public/index.html"
    click FE2 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/src/main.jsx"
    click FE3 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/src/App.jsx"
    click FE4 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/src/App.css"
    click FE5 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/src/components/InputForm.jsx"
    click FE6 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/src/components/ResultCard.jsx"
    click FE7 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/src/ResultsTable.jsx"
    click FE8 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/package.json"
    click FE9 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/vite.config.js"
    click FE10 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/postcss.config.js"
    click FE11 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/tailwind.config.js"
    click FE12 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/frontend/eslint.config.js"
    click BE1 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/predict.py"
    click BE2 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/model.py"
    click BE3 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/notebook.py"
    click BE4 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/tree/main/backend/Pipfile"
    click BE5 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/Pipfile.lock"
    click BE6 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/requirements.txt"
    click BE7 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/README.md"
    click BE8 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/Notes.txt"
    click BE9 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/data/cyberfeddefender_dataset.csv"
    click BE10 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/model.pkl"
    click BE11 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/scaler.pkl"
    click BE12 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/backend/label_encoder.pkl"
    click BE13 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/tree/main/backend/Dockerfile"
    click RL1 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/tree/main/Pipfile"
    click RL2 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/Pipfile.lock"
    click RL3 "https://github.com/techtyphoon/cyber-threat-detection-machine-learning-project/blob/main/README.md"
```
