# b1tw1z/password-manager architecture

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

- Interactive diagram: https://gitdiagram.com/b1tw1z/password-manager
- Repository: https://github.com/b1tw1z/password-manager

## Overview

##### Main Components
- User Interface (UI) Layer: Represented by the Tkinter components—main window, labels, text fields (for website, email, and password), buttons (Generate Password, Add, Search) and a Canvas for the logo.
- Business Logic / Domain Services: This includes the core functionalities such as:
- Password Generation (generatePass): Combines random letters, numbers, and symbols, shuffles them, and uses the pyperclip to copy the result to the clipboard.
- Password Searching (searchPass): Reads from the JSON file, checking if the given website exists and then displays the stored email and password.
- Password Saving (savePass): Validates input, confirms the save operation, and writes the password data into the JSON file.
- Data Persistence Layer: The JSON file (“passwords.json”) which acts as the storage medium for all password entries.

##### Relationships and Interactions
- The UI Layer communicates with the Business Logic Layer by invoking commands when buttons are clicked.
- The Business Logic Layer interacts with the Data Persistence Layer:
- For saving new data (write/update operations on passwords.json),
- For retrieving saved data to support password search.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Even though the entire application is in one file (main.py), conceptually separate the UI components from the business logic (password generation, saving, searching) and the data storage.
- Exception Handling: Identify how the application manages errors (for example, handling FileNotFoundError when the JSON file doesn’t exist).
- Event-Driven Flow: UI actions (button clicks) trigger specific functions (commands) in an event-driven manner.

##### Relevant Technologies and Libraries
- Tkinter: For building the graphical user interface.
- json: For encoding and decoding JSON data.
- random: For generating the various components of the password.
- pyperclip: For copying generated passwords to the clipboard.

##### Putting It All Together
- Sketch the overall flow:
- From here, illustrate how generatePass creates a password and triggers a copy to the clipboard.
- Link searchPass and savePass to the JSON file, showing exception handling if the file is not present.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI["User Interface (Tkinter)"]:::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        GEN["Password Generation Service (generatePass)"]:::logic
        SRCH["Password Search Service (searchPass)"]:::logic
        SAVE["Password Save Service (savePass)"]:::logic
    end

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        DATA["Data Persistence (passwords.json)"]:::data
    end

    %% External Libraries
    EX1["External Library: random"]:::external
    EX2["External Library: pyperclip"]:::external
    EX3["External Library: json"]:::external
    EX4["External Library: tkinter"]:::external

    %% Connections from UI to Business Logic
    UI -->|"callsGeneratePass"| GEN
    UI -->|"callsSearchPass"| SRCH
    UI -->|"callsSavePass"| SAVE

    %% Business Logic interactions with Data Persistence
    SRCH -->|"reads"| DATA
    SAVE -->|"writes"| DATA

    %% Dependencies on External Libraries
    GEN -.->|"dependsOn"| EX1
    GEN -.->|"dependsOn"| EX2
    SRCH -.->|"uses"| EX3
    SAVE -.->|"uses"| EX3
    UI -.->|"builtWith"| EX4

    %% Click Events
    click UI "https://github.com/b1tw1z/password-manager/blob/main/main.py"
    click GEN "https://github.com/b1tw1z/password-manager/blob/main/main.py"
    click SRCH "https://github.com/b1tw1z/password-manager/blob/main/main.py"
    click SAVE "https://github.com/b1tw1z/password-manager/blob/main/main.py"
    click DATA "https://github.com/b1tw1z/password-manager/blob/main/passwords.json"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef logic fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef data fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
