# edcance/workcells architecture

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

- Interactive diagram: https://gitdiagram.com/edcance/workcells
- Repository: https://github.com/edcance/workcells

## Overview

##### Main Components
a. Client/UI Layer:
- Views: Represented by the “views” folder which contains EJS templates. These are used for web pages like login, calendars, employee management, absence requests, and other recruitment-related forms.
b. Application Layer (Backend/Server):
- app.js: The main entry point of the application.
- Controllers: Found in the “controllers” directory, handling various domain logic for absences, authentication, calendar events, departments, employees, faults, holidays, one-to-one meetings, reports, users, and vacations.
- Routes: Located in the “routes” folder, mapping HTTP endpoints to the corresponding controller functions.
- Util: Provides helper functions for privileges, date formatting, authentication, and session management.
c. Data Layer:
- Models: The “models” directory, which defines the data schemas/structures for entities such as absences, employees, faults, holidays, one-to-one records, reports, vacations, and more.
- SQL Scripts: The “sql” folder contains scripts for creating the database, inserting dummy data, and handling migrations, indicating the use of a relational database.
d. Supporting Artifacts:
- Avances (Progress): Directories “avances/avance2”, “avances/avance3”, “avances/avance4”, containing documentation (PDF) and SQL scripts, which provide historical context and evolution of the project.

##### Establishing Relationships and Interactions
- The Client/UI initiates requests (typically via forms and interactive pages) that are routed through the “routes” files to the appropriate Controllers.
- Controllers act as an intermediary between the UI and Models. They process the HTTP requests, perform business logic by invoking utility functions (located in the “util” folder), and interact with the Models to query or update the database.
- Once the Models perform data operations (using SQL scripts to initialize and manage the underlying database), the processed data is handed back to Controllers which then render an appropriate EJS view response.
- Utility functions, such as those managing authentication (util/google-auth.js) or specific privileges (e.g., for absences, vacations), provide middleware and specialized logic that integrates with Controllers and Routes.

##### Highlighting Architectural Patterns and Design Principles
- MVC Structure: Clearly separate the concerns among Models, Views, and Controllers.
- Layered Architecture: The application layer (routing and controllers) is distinct from the data layer (models and SQL scripts) and presentation layer (views and public assets).
- Modularity: The “util” folder demonstrates modular handling of business-specific functionalities (privileges and authentication) which can be plugged into routes/controllers as middleware.

##### Final Recommendations
- Component has a clear label and describe its role briefly (e.g., “Employee Controller: manages employee CRUD operations”).
- Dependency directions – for example, controllers depend on models and utility functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/UI Layer
    subgraph "Client/UI Layer"
        VIEWS["Views (EJS Templates)"]:::ui
        PUBLIC["Public Assets (Static Files)"]:::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        APP["app.js (Main Entry)"]:::app
        subgraph "Backend Modules"
            ROUTES["Routes"]:::app
            CONTROLLERS["Controllers"]:::app
            UTIL["Utility Functions"]:::app
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        MODELS["Models"]:::db
        SQL["SQL Scripts"]:::db
    end

    %% Supporting Artifacts
    subgraph "Supporting Artifacts"
        DIAGRAMS["Diagrams (PlantUML)"]:::support
        AVANCES["Avances/Progress Docs"]:::support
    end

    %% Relationships
    VIEWS -->|"HTTPRequest"| ROUTES
    APP -->|"Initializes"| ROUTES
    ROUTES -->|"MapsTo"| CONTROLLERS
    ROUTES -->|"Uses"| UTIL
    CONTROLLERS -->|"ExecutesLogic"| UTIL
    CONTROLLERS -->|"PerformsDBOperations"| MODELS
    MODELS -->|"RunsSQL"| SQL
    CONTROLLERS -->|"RendersView"| VIEWS
    DIAGRAMS ---|"SupportingDesign"| AVANCES

    %% Click Events
    click VIEWS "https://github.com/edcance/workcells/tree/main/views/"
    click PUBLIC "https://github.com/edcance/workcells/tree/main/public/"
    click APP "https://github.com/edcance/workcells/blob/main/app.js"
    click CONTROLLERS "https://github.com/edcance/workcells/tree/main/controllers/"
    click ROUTES "https://github.com/edcance/workcells/tree/main/routes/"
    click UTIL "https://github.com/edcance/workcells/tree/main/util/"
    click MODELS "https://github.com/edcance/workcells/tree/main/models/"
    click SQL "https://github.com/edcance/workcells/tree/main/sql/"
    click DIAGRAMS "https://github.com/edcance/workcells/tree/main/diagrams/"
    click AVANCES "https://github.com/edcance/workcells/tree/main/avances/"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef app fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef db fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef support fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
```
