# adham011/smart-security-lock- architecture

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

- Interactive diagram: https://gitdiagram.com/adham011/smart-security-lock-
- Repository: https://github.com/adham011/smart-security-lock-

## Overview

##### Main Components
- Hardware Input Devices:
- Four potentiometers for setting each digit of the combination.
- Enter Button: Initiates validation of the entered combination.
- Set Button: Switches the system into “set mode” for entering a new combination.
- Hardware Output Devices:
- LCD Display (managed by the NHD_0216HZ.cpp/h modules) to show the current combination and status messages.
- LED Indicator(s) to provide immediate visual feedback (correct/incorrect combination).
- Servo Motor (handled by Servo.cpp/h) to operate the physical lock mechanism (if applicable).
- Software Core:
- Main Control Logic (found in main.cpp) that ties all the hardware together.
- Supporting Modules:
- The NHD_0216HZ module manages the interface with the LCD.
- The Servo module controls the servo motor, possibly for the actual locking/unlocking mechanism.
- Interrupt and Mode Management:
- The system distinguishes between Validation Mode and Set Mode.
- An ISR (Interrupt Service Routine) is triggered via the Set Button to switch modes and update combination states.

##### Out the Relationships and Interactions
- A central “Smart Lock Controller” block (represented by main.cpp) that acts as the brain.
- “Potentiometer Input Module” indicating that the controller reads the analog inputs.
- “Button Input Module” (for both Enter and Set actions) indicating event-driven mode changes.
- “LCD Interface Module” (NHD_0216HZ) that receives commands from the controller to update display information.
- “LED Control” as an output feedback mechanism.
- “Servo Controller” that triggers physical actuation on successful validation.
- That interrupts (via the Set Button) are used to switch modes for setting a new combination.

##### Architectural and Design Patterns
- Modular Design – The separation into distinct modules (potentiometer reading, display output, servo control) allows reusability and clear separation of concerns.
- Interrupt-Driven Mode Switching – Clearly highlight the mechanism where the Set Button triggers an ISR to change the system state.
- Real-Time Feedback Loop – Show that after input is gathered, the system processes the combination, validates it, and feeds back to both the LCD and LED indicators.

##### Relevant Technologies and Files
- mbed-os: Indicate that the firmware is built atop the mbed platform (using mbed_app.json and mbed-os.lib).
- CMake and build scripts: Note the use of CMake (as shown by CMakeLists.txt) for project compilation, although these are more on the build configuration side than runtime architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Input Layer
    subgraph "Hardware Input Layer"
        POT["Potentiometers"]:::input
        ENTER["Enter Button"]:::input
        SET["Set Button (ISR)"]:::input
    end

    %% Processing Layer
    subgraph "Processing Layer"
        CTRL["Smart Lock Controller"]:::processing
    end

    %% Hardware Output Layer
    subgraph "Hardware Output Layer"
        LCD["LCD Display (NHD_0216HZ)"]:::output
        LED["LED Indicators"]:::output
        SERVO["Servo Controller"]:::output
    end

    %% Build and Config Layer
    subgraph "Build and Config"
        MBED["mbed-os.lib"]:::config
        MBED_APP["mbed_app.json"]:::config
        CMAKE["CMakeLists.txt"]:::config
    end

    %% Connections from Input Layer to Processing Layer
    POT -->|"ReadAnalog"| CTRL
    ENTER -->|"TriggerValidation"| CTRL
    SET -->|"TriggerISR"| CTRL

    %% Connections from Processing Layer to Output Layer
    CTRL -->|"DisplayStatus"| LCD
    CTRL -->|"ActivateLED"| LED
    CTRL -->|"ActivateServo"| SERVO

    %% Styles
    classDef input fill:#FFEBCC,stroke:#D2691E,stroke-width:2px;
    classDef processing fill:#CCF2FF,stroke:#1E90FF,stroke-width:2px;
    classDef output fill:#E6FFCC,stroke:#32CD32,stroke-width:2px;
    classDef config fill:#FFF0F5,stroke:#FF1493,stroke-width:2px;

    %% Click Events
    click CTRL "https://github.com/adham011/smart-security-lock-/blob/main/src/main.cpp"
    click LCD "https://github.com/adham011/smart-security-lock-/blob/main/src/NHD_0216HZ.cpp"
    click SERVO "https://github.com/adham011/smart-security-lock-/blob/main/src/Servo.cpp"
    click MBED "https://github.com/adham011/smart-security-lock-/blob/main/mbed-os.lib"
    click MBED_APP "https://github.com/adham011/smart-security-lock-/blob/main/mbed_app.json"
    click CMAKE "https://github.com/adham011/smart-security-lock-/blob/main/CMakeLists.txt"
```
