# onlineu/nhakhotolam architecture

> Architecture diagram of the GitHub repository onlineu/nhakhotolam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/onlineu/nhakhotolam
- Repository: https://github.com/onlineu/nhakhotolam

## Overview

NhaKhoToLam is an inventory web application: staff sign in, search or browse items, and store them; managers can also delete items. The browser calls a Flask server, which handles Cognito authentication and forwards inventory actions to a Lambda handler. The handler validates requests, enforces device and role access, and delegates item operations to DynamoDB helpers; sorting and binary search support listing and lookup. The graph follows the sampled source and README; unsampled infrastructure and deployment wiring are not represented.

Main entry points: [`Source Code/App/Algo/lambda_function.py`](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/lambda_function.py) (Action handler), [`Source Code/App/GUI/app.js`](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/app.js) (Browser UI), [`Source Code/App/GUI/server.py`](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/server.py) (Flask API), [`Source Code/App/Algo/db.py`](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/db.py) (Inventory and security data access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_browser["Browser UI<br/>[app.js]"]
  node_staff_page["Staff page<br/>[staff.html]"]
  node_admin_page["Manager page<br/>[admin.html]"]
  node_web_server["Flask API<br/>[server.py]"]
end

subgraph group_backend["Backend actions"]
  node_lambda["Action handler<br/>[lambda_function.py]"]
  node_validation["Input validation<br/>[validation.py]"]
end

subgraph group_data["Data and algorithms"]
  node_db_helpers["Inventory and security data access<br/>[db.py]"]
  node_dynamodb[("DynamoDB")]
  node_sorting["Sort and search<br/>[sorting.py]"]
end

subgraph group_security["Access control"]
  node_security["Device security<br/>[security.py]"]
end

node_staff(("Staff"))
node_manager(("Manager"))
node_cognito["Cognito"]

node_staff -->|"uses"| node_browser
node_manager -->|"uses"| node_browser
node_staff_page -.->|"loads"| node_browser
node_admin_page -.->|"loads"| node_browser
node_browser -->|"calls API"| node_web_server
node_web_server -->|"authenticates"| node_cognito
node_web_server -->|"invokes actions"| node_lambda
node_lambda -->|"validates with"| node_validation
node_lambda -->|"checks access"| node_security
node_lambda -->|"reads and writes"| node_db_helpers
node_lambda -->|"sorts and searches"| node_sorting
node_security -->|"checks and records"| node_db_helpers
node_db_helpers -->|"reads and writes"| node_dynamodb

click node_browser "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/app.js"
click node_staff_page "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/staff.html"
click node_admin_page "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/admin.html"
click node_web_server "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/server.py"
click node_lambda "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/lambda_function.py"
click node_validation "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/validation.py"
click node_security "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/security.py"
click node_db_helpers "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/db.py"
click node_sorting "https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/sorting.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_staff_page,node_admin_page,node_web_server toneBlue
class node_lambda,node_validation toneAmber
class node_db_helpers,node_dynamodb,node_sorting toneMint
class node_security toneRose
class node_staff,node_manager,node_cognito toneIndigo
```

## Components

### Web application

- [Browser UI](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/app.js): `Source Code/App/GUI/app.js`
- [Staff page](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/staff.html): `Source Code/App/GUI/staff.html`
- [Manager page](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/admin.html): `Source Code/App/GUI/admin.html`
- [Flask API](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/GUI/server.py): `Source Code/App/GUI/server.py`

### Backend actions

- [Action handler](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/lambda_function.py): `Source Code/App/Algo/lambda_function.py`
- [Input validation](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/validation.py): `Source Code/App/Algo/validation.py`

### Data and algorithms

- [Inventory and security data access](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/db.py): `Source Code/App/Algo/db.py`
- **DynamoDB**
- [Sort and search](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/sorting.py): `Source Code/App/Algo/sorting.py`

### Access control

- [Device security](https://github.com/onlineu/nhakhotolam/blob/main/Source%20Code/App/Algo/security.py): `Source Code/App/Algo/security.py`

### Other components

- **Staff**
- **Manager**
- **Cognito**

## Connections

- Staff → Browser UI: uses (evidence: `Source Code/App/GUI/app.js`)
- Manager → Browser UI: uses (evidence: `Source Code/App/GUI/app.js`)
- Staff page → Browser UI: loads
- Manager page → Browser UI: loads
- Browser UI → Flask API: calls API (evidence: `Source Code/App/GUI/app.js`)
- Flask API → Cognito: authenticates (evidence: `Source Code/App/GUI/server.py`)
- Flask API → Action handler: invokes actions (evidence: `Source Code/App/GUI/server.py`)
- Action handler → Input validation: validates with (evidence: `Source Code/App/Algo/lambda_function.py`)
- Action handler → Device security: checks access (evidence: `Source Code/App/Algo/lambda_function.py`)
- Action handler → Inventory and security data access: reads and writes (evidence: `Source Code/App/Algo/lambda_function.py`)
- Action handler → Sort and search: sorts and searches (evidence: `Source Code/App/Algo/lambda_function.py`)
- Device security → Inventory and security data access: checks and records (evidence: `Source Code/App/Algo/security.py`)
- Inventory and security data access → DynamoDB: reads and writes (evidence: `Source Code/App/Algo/db.py`)
