# me-as-raki/employee_db_app architecture

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

- Interactive diagram: https://gitdiagram.com/me-as-raki/employee_db_app
- Repository: https://github.com/me-as-raki/employee_db_app

## Overview

##### Project type and purpose
- This is a full-stack CRUD web application (“Dept-Wise Employee Manager”) built with Node.js/Express on the backend, static HTML/CSS/Bootstrap on the frontend, and MySQL as the persistent store.
- Its purpose is to let users add, view, update, and delete employees department-wise through a simple UI.

##### File structure
- Top-level files:
- server.js – the sole Express server entry point and route‐handler module.
- package.json / package-lock.json – dependency management and scripts.
- Directories:
- public/ – all static assets (HTML pages, CSS stylesheets, client-side JS).
- node_modules/ – installed NPM packages.
- .vscode/ – optional local IDE settings.
- No separate “src,” “controllers,” or “models” directories exist; the architecture is consolidated inside server.js.

##### README for additional insights
- The stack: HTML/CSS/Bootstrap/EJS (although only static .html files appear), Express.js, MySQL.
- The DB schema: two tables (department, employee) with a foreign-key relationship.
- Full CRUD is implemented via RESTful endpoints (GET pages, POST form submissions, SQL queries).

a. Main Components
1. Browser (Client UI)
2. Static Asset Server (Express static middleware serving public/)
3. Express Routing & Controllers (server.js)
4. MySQL Database (employee, department tables)
b. Relationships & Data Flow
- The Browser issues HTTP GETs to fetch HTML/CSS/JS.
- User interactions (form submissions) generate HTTP POST/PUT/DELETE to Express routes.
- Express controllers parse requests, build SQL queries, and execute them on MySQL.
- Query results are sent back as redirects or JSON (if AJAX), then rendered as HTML.
c. Architectural Patterns & Design Principles
- Layered web architecture: Presentation layer (static files), Application layer (Express controllers), Data layer (MySQL).
- Simple MVC-like separation:
- Views: public/*.html
- Controllers: route handlers in server.js
- Model: SQL tables accessed via driver
- RESTful resource orientation (employees, departments).
d. Key Technologies
- Express.js (HTTP server, routing, middleware)
- Node.js (runtime)
- MySQL (relational database)
- Bootstrap (UI styling)
- Static HTML/CSS/JS for front end

##### Elements
- Inside “Express Server,” subdivide into “Static File Middleware” and “Route Handlers (Controllers).”
- Browser → Express (GET / POST)
- Express → MySQL (SQL queries)
- MySQL → Express (query results)
- Express → Browser (HTML / redirects)
- Backend components in another (e.g., green)
- Database in a third (e.g., orange)

##### Detail & Clarity
- DB component with table names and key relationships.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    subgraph "Browser (Client UI)"
        B(Browser):::frontend
    end

    %% Express Server Layer
    subgraph "Express Server"
        SM("Static File Middleware"):::backend
        RH("Route Handlers (Controllers)"):::backend
    end

    %% Static Assets
    subgraph "Static Assets (public/)"
        idx["index.html"]:::frontend
        add["add.html"]:::frontend
        addEmp["addEmployee.html"]:::frontend
        update["update.html"]:::frontend
        updateEmp["updateEmployee.html"]:::frontend
        del["delete.html"]:::frontend
        delEmp["deleteEmployee.html"]:::frontend
        dept["department.html"]:::frontend
        emp["employee.html"]:::frontend
        emps["employees.html"]:::frontend
        displayEmps["display_employees.html"]:::frontend
        redirect["redirect.html"]:::frontend
        style1["styles.css"]:::frontend
        style2["styles2.css"]:::frontend
        style3["styles3.css"]:::frontend
        style4["styles4.css"]:::frontend
        script1["scripts.js"]:::frontend
        script2["script2.js"]:::frontend
    end

    %% Database Layer
    DB[(MySQL Database<br/>department ↔ employee)]:::db

    %% Dependency & Tools
    pkg["package.json"]:::misc
    pkglock["package-lock.json"]:::misc
    modules["node_modules/"]:::misc
    ide[".vscode/"]:::misc

    %% Connections: Static Serving
    B -->|"GET /index.html"| SM
    SM -->|"Serves HTML/CSS/JS"| B

    SM -->|serves| idx
    SM -->|serves| add
    SM -->|serves| addEmp
    SM -->|serves| update
    SM -->|serves| updateEmp
    SM -->|serves| del
    SM -->|serves| delEmp
    SM -->|serves| dept
    SM -->|serves| emp
    SM -->|serves| emps
    SM -->|serves| displayEmps
    SM -->|serves| redirect
    SM -->|serves| style1
    SM -->|serves| style2
    SM -->|serves| style3
    SM -->|serves| style4
    SM -->|serves| script1
    SM -->|serves| script2

    %% Form Submissions
    B -->|"POST /add-employee"| RH
    B -->|"PUT /update-employee"| RH
    B -->|"DELETE /delete-employee"| RH

    %% Data Layer Interactions
    RH -->|"SQL Queries"| DB
    DB -->|"Query Results"| RH

    %% Response Back
    RH -->|"Redirect / Display"| B

    %% Dependency Management & Tools
    RH --> pkg
    RH --> pkglock
    RH --> modules
    RH --> ide

    %% Click Events
    click B "https://github.com/me-as-raki/employee_db_app/tree/main/public/"
    click SM "https://github.com/me-as-raki/employee_db_app/blob/main/server.js"
    click RH "https://github.com/me-as-raki/employee_db_app/blob/main/server.js"
    click idx "https://github.com/me-as-raki/employee_db_app/blob/main/public/index.html"
    click add "https://github.com/me-as-raki/employee_db_app/blob/main/public/add.html"
    click addEmp "https://github.com/me-as-raki/employee_db_app/blob/main/public/addEmployee.html"
    click update "https://github.com/me-as-raki/employee_db_app/blob/main/public/update.html"
    click updateEmp "https://github.com/me-as-raki/employee_db_app/blob/main/public/updateEmployee.html"
    click del "https://github.com/me-as-raki/employee_db_app/blob/main/public/delete.html"
    click delEmp "https://github.com/me-as-raki/employee_db_app/blob/main/public/deleteEmployee.html"
    click dept "https://github.com/me-as-raki/employee_db_app/blob/main/public/department.html"
    click emp "https://github.com/me-as-raki/employee_db_app/blob/main/public/employee.html"
    click emps "https://github.com/me-as-raki/employee_db_app/blob/main/public/employees.html"
    click displayEmps "https://github.com/me-as-raki/employee_db_app/blob/main/public/display_employees.html"
    click redirect "https://github.com/me-as-raki/employee_db_app/blob/main/public/redirect.html"
    click style1 "https://github.com/me-as-raki/employee_db_app/blob/main/public/styles.css"
    click style2 "https://github.com/me-as-raki/employee_db_app/blob/main/public/styles2.css"
    click style3 "https://github.com/me-as-raki/employee_db_app/blob/main/public/styles3.css"
    click style4 "https://github.com/me-as-raki/employee_db_app/blob/main/public/styles4.css"
    click script1 "https://github.com/me-as-raki/employee_db_app/blob/main/public/scripts.js"
    click script2 "https://github.com/me-as-raki/employee_db_app/blob/main/public/script2.js"
    click pkg "https://github.com/me-as-raki/employee_db_app/blob/main/package.json"
    click pkglock "https://github.com/me-as-raki/employee_db_app/blob/main/package-lock.json"
    click modules "https://github.com/me-as-raki/employee_db_app/tree/main/node_modules/"
    click ide "https://github.com/me-as-raki/employee_db_app/tree/main/.vscode/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#E6F4EA,stroke:#28a745,color:#28a745;
    classDef db fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00;
    classDef misc fill:#F0F0F0,stroke:#888888,color:#555555;
```
