# wilson0406/password-strength architecture

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

- Interactive diagram: https://gitdiagram.com/wilson0406/password-strength
- Repository: https://github.com/wilson0406/password-strength

## Overview

##### Project Type and Purpose
- The project is a web-based application built with Flask that allows users to analyze the strength of their passwords.
- It integrates multiple machine learning models (Naïve Bayes, Random Forest, Logistic Regression, Decision Tree, and Neural Networks) which are stored as serialized joblib files.
- In addition to ML-based analysis, it performs rule-based evaluations and checks passwords against a large compromised database (via Enzoic’s API).

##### File Structure
- At the top level, files like app.py, data.csv, and requirements.txt indicate a lightweight Flask web application.
- The serialized models (e.g., DecisionTree_Model.joblib, LogisticRegression_Model.joblib, etc.) represent the ML backend components.
- The static directory (with assets and css/js folders) contains frontend resources used by the web UI.
- The templates directory holds the HTML files (like index.html and main.html) which render the UI, following an MVC-like pattern with Flask serving as the controller.

##### Establish the Main Components and Their Roles
a. Frontend Component:
- Comprises HTML templates (in templates/) and static assets (in static/).
- Represents the user interface where users input passwords and view evaluation results.

b. Backend Component:
- The Flask application coded in app.py acts as the central controller.
- Manages routing, user input handling, and coordination between different parts of the system.

c. Machine Learning Engine:
- Consists of multiple ML models (Naïve Bayes, Decision Tree, Random Forest, Logistic Regression, Neural Network) loaded from the joblib files.
- Handles processing of inputs and outputs evaluations on password strength.

d. Data Source:
- data.csv could be either a training dataset (if retraining is supported) or used for logging/validation, depending on the implementation.

e. External Service Integration:
- The system interacts with Enzoic’s Live API to check password breaches against a public database.

f. Environment & Dependencies:
- The project relies on Python 3.9, scikit-learn, Flask, and other libraries (as specified in requirements.txt).

##### Relationships and Interactions
- Users interact with the frontend via their browsers, which send HTTP requests to the Flask backend.
- The Flask backend parses the request and invokes the necessary ML model(s) for analysis.
- The backend then gathers results (from one or multiple models) and may combine this with rule-based logic, as well as with data retrieved from the Enzoic API.
- Finally, results are rendered in the HTML views using templates, with static JS and CSS providing interactivity and styling.

##### Architectural Patterns & Design Principles
- MVC or similar pattern:
- Model: The ML models and possibly the datasets.
- View: HTML templates with static assets.
- Controller: The app.py which handles routing and coordinating analyses.
- Separation of concerns is evident where ML logic, web logic, and static content are handled in distinct parts of the project.
- Integration with external services (such as the password breach API) is treated as a separate module integrated into the backend logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    User("User Browser"):::client

    %% Frontend Layer
    subgraph "Frontend Layer"
        T_INDEX("Index Template (index.html)"):::frontend
        T_MAIN("Main Template (main.html)"):::frontend
        STATIC("Static Assets (static/)"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B("Flask App (app.py)"):::backend
        subgraph "Machine Learning Engine"
            ML_NB("Naïve Bayes Model (NaiveBayes_Model.joblib)"):::ml
            ML_DT("Decision Tree Model (DecisionTree_Model.joblib)"):::ml
            ML_RF("Random Forest Model (RandomForest_Model.joblib)"):::ml
            ML_LR("Logistic Regression Model (LogisticRegression_Model.joblib)"):::ml
            ML_NN("Neural Network Model (NeuralNetwork_Model.joblib)"):::ml
        end
        API("Enzoic API Integration"):::ext
        DS("Data Source (data.csv)"):::database
        DEP("Dependencies (requirements.txt)"):::dep
    end

    %% Data Flow
    User -->|"HTTP_Request"| T_INDEX
    T_INDEX -->|"form_submit"| B
    B -->|"calls_ML"| ML_NB
    B -->|"calls_ML"| ML_DT
    B -->|"calls_ML"| ML_RF
    B -->|"calls_ML"| ML_LR
    B -->|"calls_ML"| ML_NN
    B -->|"check_breach"| API
    B -->|"data_lookup"| DS
    B --> T_MAIN
    T_MAIN -->|"renders_output"| User

    %% Click Events
    click T_INDEX "https://github.com/wilson0406/password-strength/blob/main/templates/index.html"
    click T_MAIN "https://github.com/wilson0406/password-strength/blob/main/templates/main.html"
    click STATIC "https://github.com/wilson0406/password-strength/tree/main/static/"
    click B "https://github.com/wilson0406/password-strength/blob/main/app.py"
    click ML_NB "https://github.com/wilson0406/password-strength/blob/main/NaiveBayes_Model.joblib"
    click ML_DT "https://github.com/wilson0406/password-strength/blob/main/DecisionTree_Model.joblib"
    click ML_RF "https://github.com/wilson0406/password-strength/blob/main/RandomForest_Model.joblib"
    click ML_LR "https://github.com/wilson0406/password-strength/blob/main/LogisticRegression_Model.joblib"
    click ML_NN "https://github.com/wilson0406/password-strength/blob/main/NeuralNetwork_Model.joblib"
    click DS "https://github.com/wilson0406/password-strength/blob/main/data.csv"
    click DEP "https://github.com/wilson0406/password-strength/blob/main/requirements.txt"

    %% Styles
    classDef client fill:#ffefba,stroke:#e0a800,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef ml fill:#e2f0d9,stroke:#28a745,stroke-width:2px;
    classDef ext fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef dep fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
