# ai4devsec/minor-project-2 architecture

> Architecture diagram of the GitHub repository ai4devsec/minor-project-2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ai4devsec/minor-project-2
- Repository: https://github.com/ai4devsec/minor-project-2

## Overview

##### Project type and purpose
- This is a full-stack machine-learning web application.
- It provides a web UI (Flask + Jinja2 templates) to serve model predictions, plus a standalone training pipeline (Python scripts + Jupyter notebook).
- It uses Docker for containerization, GitLab CI for build/test, and Kubernetes for deployment.

##### Main components
A. User & UI Layer
– Browser / End-User
– Static assets (Code/static/style.css)
– HTML templates (Code/templates/index.html)
B. Application Server
– Flask app (Code/application.py)
– Business logic / request handling
C. Model & Code Modules
– src/data_processing.py (data cleaning/feature engineering)
– src/model_training.py (model creation, evaluation)
– src/custom_exception.py, src/logger.py (support)
D. Training Pipeline
– pipeline/training_pipeline.py (orchestrates data load → preprocessing → training → model artifact save)
– notebook/iris.ipynb (exploratory analysis)
– DATA/data.csv (raw data source)
E. CI/CD & Build
– .gitlab-ci.yml (defines stages: test, build, train, deploy)
– setup.py, requirements.txt (package metadata)
F. Container & Deployment
– Dockerfile (build image containing app & dependencies)
– Kubernetes deployment manifest (Code/kubernetes-deployment.yaml)
G. Artifact & Model Storage (implicit)
– Docker image registry (e.g., GitLab Registry)
– Model artifacts saved in container filesystem or mounted volume

##### Relationships & Data Flows
1. Developer pushes code → GitLab CI triggers pipeline.
2. CI runs unit tests, training pipeline (produces model.pkl), builds Docker image.
3. Image (with model embedded) is pushed to registry.
4. Kubernetes pulls image, spins up pods (Flask service).
5. End-user’s browser → HTTP → Flask service → loads model → returns prediction.
6. Static files served directly by Flask or via a CDN/Ingress.

##### Architectural patterns & principles
- Separation of concerns: UI / service logic / model logic / pipeline are distinct modules.
- Twelve-factor app: config via environment variables (Docker/K8s), stateless service, logs stdout/stderr.
- CI/CD pipeline automates test → train → build → deploy.
- Microservice style: the ML service is self-contained, containerized, and horizontally scalable in K8s.

– Components: Browser, Static Assets, Templates, Flask App, Model Module, Data Processing Module, Training Pipeline, CI/CD, Docker Registry, K8s Cluster.
– Clear text labels and arrowheads indicating direction of flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    Developer((Developer)):::external
    Browser((End-User Browser)):::external

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI[".gitlab-ci.yml"]:::pipeline
        Setup["setup.py"]:::pipeline
        Reqs["requirements.txt"]:::pipeline
    end

    %% Training Pipeline & Data Science
    subgraph "Training Pipeline & Data Science"
        RawData[(DATA/data.csv)]:::data
        Notebook["iris.ipynb"]:::datasci
        PipelineOrch["training_pipeline.py"]:::pipeline
        ModelArtifact[(model.pkl)]:::data
    end

    %% Container & Deployment
    subgraph "Container Build & Registry"
        Dockerfile["Dockerfile"]:::deployment
        Registry[(Docker Image Registry)]:::storage
    end

    subgraph "Kubernetes Cluster"
        DeployManifest["kubernetes-deployment.yaml"]:::deployment
        Pod["Flask Service Pod"]:::service
    end

    %% Application Service Components
    subgraph "Application Service"
        FlaskApp["Flask App"]:::service
        Static["Static Assets"]:::service
        Templates["HTML Templates"]:::service
        DataProc["Data Processing Module"]:::code
        ModelTrain["Model Training Module"]:::code
        Logger["Logging Utility"]:::code
        Except["Custom Exception Support"]:::code
        ModelArtifact -- loaded by --> FlaskApp
    end

    %% Flows
    Developer -->|push code| CI
    CI -->|uses| Setup
    CI -->|uses| Reqs
    CI -->|triggers| PipelineOrch
    PipelineOrch -->|reads| RawData
    PipelineOrch -->|exploration| Notebook
    PipelineOrch -->|produces| ModelArtifact
    CI -->|builds image via| Dockerfile
    CI -->|pushes image| Registry
    Registry -->|pulled by| DeployManifest
    DeployManifest -->|deploys| Pod

    Browser -->|HTTP Request| Pod
    Pod -->|runs| FlaskApp
    FlaskApp -->|serves CSS/JS| Static
    FlaskApp -->|renders pages| Templates
    FlaskApp -->|calls| DataProc
    FlaskApp -->|calls| ModelTrain
    FlaskApp -->|logs via| Logger
    FlaskApp -->|handles errors via| Except

    %% Click Events
    click Static "https://github.com/ai4devsec/minor-project-2/blob/main/Code/static/style.css"
    click Templates "https://github.com/ai4devsec/minor-project-2/blob/main/Code/templates/index.html"
    click FlaskApp "https://github.com/ai4devsec/minor-project-2/blob/main/Code/application.py"
    click DataProc "https://github.com/ai4devsec/minor-project-2/blob/main/Code/src/data_processing.py"
    click ModelTrain "https://github.com/ai4devsec/minor-project-2/blob/main/Code/src/model_training.py"
    click Logger "https://github.com/ai4devsec/minor-project-2/blob/main/Code/src/logger.py"
    click Except "https://github.com/ai4devsec/minor-project-2/blob/main/Code/src/custom_exception.py"
    click PipelineOrch "https://github.com/ai4devsec/minor-project-2/blob/main/Code/pipeline/training_pipeline.py"
    click Notebook "https://github.com/ai4devsec/minor-project-2/blob/main/Code/notebook/iris.ipynb"
    click RawData "https://github.com/ai4devsec/minor-project-2/blob/main/DATA/data.csv"
    click CI "https://github.com/ai4devsec/minor-project-2/blob/main/Code/.gitlab-ci.yml"
    click Dockerfile "https://github.com/ai4devsec/minor-project-2/tree/main/Code/Dockerfile"
    click DeployManifest "https://github.com/ai4devsec/minor-project-2/blob/main/Code/kubernetes-deployment.yaml"
    click Setup "https://github.com/ai4devsec/minor-project-2/blob/main/Code/setup.py"
    click Reqs "https://github.com/ai4devsec/minor-project-2/blob/main/Code/requirements.txt"

    %% Styles
    classDef external fill:#D6EAF8,stroke:#1F618D,color:#1F618D,stroke-width:1px
    classDef pipeline fill:#FCF3CF,stroke:#B7950B,color:#B7950B,stroke-width:1px
    classDef service fill:#D4E6F1,stroke:#21618C,color:#21618C,stroke-width:1px
    classDef code fill:#FDEBD0,stroke:#D35400,color:#D35400,stroke-width:1px
    classDef data fill:#D5F5E3,stroke:#27AE60,color:#27AE60,stroke-width:1px
    classDef deployment fill:#F5EEF8,stroke:#8E44AD,color:#8E44AD,stroke-width:1px
    classDef storage fill:#EBF5FB,stroke:#5DADE2,color:#5DADE2,stroke-width:1px
```
