# nathanmendis/secure-qr-code-generator-web-application-using-flask architecture

> Architecture diagram of the GitHub repository nathanmendis/secure-qr-code-generator-web-application-using-flask, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nathanmendis/secure-qr-code-generator-web-application-using-flask
- Repository: https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask

## Overview

##### Main Components
- Frontend Components:
- Templates: The HTML files (index.html and decrypt.html) act as the user interface for the encryption and decryption workflows.
- Static Assets: Files such as encrypted_qr.png (and any other static resources) that are used to display or store the generated QR code images.
- Backend Components:
- Flask Application: The main web server logic is encapsulated in app.py, handling routes, encryption, decryption, and QR code generation.
- Encryption/Decryption Logic: Implemented using the cryptography.fernet library to encrypt and decrypt URL data.
- QR Code Generation and Scanning: Uses libraries like qrcode for generating QR codes and OpenCV for scanning/decrypting QR codes from user uploads.
- Data Storage:
- File storage for static QR code images and uploads for image files.
- Temporary data storage in memory when handling requests and responses.

##### Relationships and Interactions
- The client visits the homepage (index.html) provided via Flask routes and submits a URL for encryption.
- The app processes the request by:
- Encrypting the URL.
- Generating a QR code based on the encrypted data.
- Displaying and providing an option to download the generated QR code along with the unique encryption key.
- For decryption:
- The user navigates to the decryption page (decrypt.html) and uploads an image of the QR code.
- The app uses OpenCV to decode the QR code and then applies the decryption function (using the provided key) to reveal the original URL.

##### Architectural Patterns and Design Principles
- Views are the HTML templates.
- The Controller is represented by Flask routing and app.py's logic.
- The Model, in this case, is minimal (mainly handling the encryption/decryption and QR code binary data manipulation).
- Separation of Concerns: Isolate the encryption/decryption logic, QR code generation, and scanning into distinct functional blocks within the app.
- Security: Emphasize secure key management and safe file upload practices.

##### Relevant Technologies, Frameworks, or Libraries
- Flask for backend routing and HTTP request handling.
- Cryptography (Fernet) for secure encryption/decryption.
- qrcode for QR code generation.
- OpenCV for scanning and decoding QR codes from images.
- HTML/CSS (within templates) for the frontend UI.
- Python (app.py) for orchestrating the entire process.

##### Detailed Component Breakdown
- Client Layer:
- Web Browser: Direct interaction with the index and decrypt pages.
- Application Layer (Flask - app.py):
- Routing: Handle routes for home (encryption) and decryption endpoints.
- Business Logic: Process input data, invoke encryption/decryption functions, interact with QR code generation/scanner.
- Service Layer:
- Encryption Service: Provided by the cryptography library, which securely handles URL encryption.
- QR Code Service: Uses the qrcode library for generating QR codes from encrypted data, and OpenCV for decoding them.
- Data/Storage Layer:
- Static File Storage: Holds generated QR images referenced by the frontend.
- Upload Directory: (Not shown in file_tree but mentioned in README) Where user-uploaded QR code images are stored.
- Integration Points:
- Key generation and handling between encryption and decryption functionalities.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["Encryption UI"]:::frontend
        FE2["Decryption UI"]:::frontend
    end

    %% Backend Application
    FL["Flask Application (app.py)"]:::backend

    %% Services Layer
    subgraph "Services Layer"
        S1["Encryption/Decryption Service (Fernet)"]:::service
        S2["QR Code Service (qrcode/OpenCV)"]:::service
    end

    %% Data/Storage Layer
    SF["Static File Storage"]:::storage

    %% Connections from Frontend to Flask Application
    FE1 -->|"send_URL"| FL
    FE2 -->|"send_QRImage&Key"| FL

    %% Flask Application interactions with Services
    FL -->|"invoke_encrypt/decrypt"| S1
    S1 -->|"return_result"| FL
    
    FL -->|"invoke_QR_process"| S2
    S2 -->|"return_QR_data"| FL

    %% Interaction with Data Storage
    S2 -->|"store/serve_QR"| SF

    %% Responses from Flask Application back to Frontend
    FL -->|"render_encryption_result"| FE1
    FL -->|"render_decryption_result"| FE2

    %% Click Events
    click FE1 "https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask/blob/main/Templates/index.html"
    click FE2 "https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask/blob/main/Templates/decrypt.html"
    click FL "https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask/blob/main/app.py"
    click S1 "https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask/blob/main/app.py"
    click S2 "https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask/blob/main/app.py"
    click SF "https://github.com/nathanmendis/secure-qr-code-generator-web-application-using-flask/tree/main/static"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1E88E5,stroke-width:2px;
    classDef backend fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
    classDef service fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef storage fill:#FFF9C4,stroke:#FDD835,stroke-width:2px;
```
