# manvirheer/shift_logger_api architecture

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

- Interactive diagram: https://gitdiagram.com/manvirheer/shift_logger_api
- Repository: https://github.com/manvirheer/shift_logger_api

## Overview

##### Main Components
- API Gateway / Entry Point:
- Represented by the NestJS application’s main entry point (src/main.ts). This acts as the interface to the outside world.
- User Management Module:
- Includes components such as User, Admin, and Staff.
- Involves authentication (using JWT strategies, local strategies) and role-based authorization (guards and decorators).
- Plant Module:
- Manages plant details and is associated with users.
- Record Modules:
- Multiple sub-modules exist under “record”, such as steam generation, ash, shipment, inventory, and core record management.
- Each record module contains controllers, services, DTOs, and entities which encapsulate business logic for data logging.
- Shift Modules:
- Cover aspects like shift schedules, shift assignments, shift templates, and shift end entries.
- Data Entry Period:
- A module dedicated to managing the period during which data entries are valid.
- External Systems / Database:
- MySQL is used as the relational database, along with TypeORM for ORM support.

##### Understand Relationships and Interactions
- The API endpoints (represented by controllers) handle incoming HTTP requests, pass them to services that encapsulate business logic, and then interact with the database via repositories (ORM) by managing entities.
- User entities are associated with various records and plant entries (illustrating many-to-many and many-to-one relationships).
- The various “record” modules, such as steam generation records, interact with both the Plant module and User module (to log who made which data entry).

##### Architectural Patterns & Technologies
- Follow an MVC-like pattern (Controllers for handling HTTP, Services for business logic, and Entities/Repositories for data access).
- Important frameworks and libraries include:
- NestJS – for the overall application structure.
- TypeORM – for interacting with the MySQL database.
- Passport.js and JWT – for implementing authentication and role-based security.

##### Detailed Recommendations
- Authentication workflow:
- Middleware/Guard intercepting the request, checking the JWT token, and then permitting access if the user’s role qualifies.
- Under the User module, show separation into authentication (JWT strategy, local strategy), authorization (row-based access using roles.decorator and roles.guard), and CRUD operations.
- For the Record section (including steam generation, ash, shipment, inventory):
- Detail that each record type has its own sub-module with corresponding controllers, services, and entities tied together.
- Use notes to illustrate that interactions between modules may occur through service calls or shared database relationships.

Key Note for the Principal Software Engineer:

## Diagram (Mermaid)

```mermaid
flowchart TD
    HTTP["HTTP Request"]:::external
    API["API Gateway (NestJS Main)"]:::api
    Auth["Auth Middleware/Guard (JWT,RBAC)"]:::auth
    Router["Router"]:::router

    HTTP --> API
    API --> Auth
    Auth --> Router

    %% User Management Module
    subgraph "User Management Module"
        UM["User Management Module"]:::module
        uctrl["User Controller"]:::controller
        uservice["User Service"]:::service
        udto["User DTO"]:::dto
        uentity["User Entity"]:::entity
        uauth["Auth & RBAC"]:::auth
        UM --> uctrl
        uctrl --> uservice
        uservice --> udto
        uservice --> uentity
        uservice --> DB
    end
    click UM "https://github.com/manvirheer/shift_logger_api/tree/main/src/user"

    %% Plant Module
    subgraph "Plant Module"
        PM["Plant Module"]:::module
        pctrl["Plant Controller"]:::controller
        pserv["Plant Service"]:::service
        pdto["Plant DTO"]:::dto
        pentity["Plant Entity"]:::entity
        PM --> pctrl
        pctrl --> pserv
        pserv --> pdto
        pserv --> pentity
        pserv --> DB
    end
    click PM "https://github.com/manvirheer/shift_logger_api/tree/main/src/plant"

    %% Record Modules
    subgraph "Record Modules"
        %% Steam Generation Record Module
        subgraph "Steam Generation Record Module"
            SG["Steam Generation Module"]:::module
            sg_ctrl["Controller"]:::controller
            sg_serv["Service"]:::service
            sg_dto["DTO"]:::dto
            sg_entity["Entity"]:::entity
            SG --> sg_ctrl
            sg_ctrl --> sg_serv
            sg_serv --> sg_dto
            sg_serv --> sg_entity
            sg_serv --> DB
        end
        click SG "https://github.com/manvirheer/shift_logger_api/tree/main/src/record/steam-generation"

        %% Ash Record Module
        subgraph "Ash Record Module"
            AR["Ash Module"]:::module
            ar_ctrl["Controller"]:::controller
            ar_serv["Service"]:::service
            ar_dto["DTO"]:::dto
            ar_entity["Entity"]:::entity
            AR --> ar_ctrl
            ar_ctrl --> ar_serv
            ar_serv --> ar_dto
            ar_serv --> ar_entity
            ar_serv --> DB
        end
        click AR "https://github.com/manvirheer/shift_logger_api/tree/main/src/record/ash"

        %% Shipment Record Module
        subgraph "Shipment Record Module"
            SR["Shipment Module"]:::module
            sr_ctrl["Controller"]:::controller
            sr_serv["Service"]:::service
            sr_dto["DTO"]:::dto
            sr_entity["Entity"]:::entity
            SR --> sr_ctrl
            sr_ctrl --> sr_serv
            sr_serv --> sr_dto
            sr_serv --> sr_entity
            sr_serv --> DB
        end
        click SR "https://github.com/manvirheer/shift_logger_api/tree/main/src/record/shipment"

        %% Inventory Record Module
        subgraph "Inventory Record Module"
            IR["Inventory Module"]:::module
            ir_ctrl["Controller"]:::controller
            ir_serv["Service"]:::service
            ir_dto["DTO"]:::dto
            ir_entity["Entity"]:::entity
            IR --> ir_ctrl
            ir_ctrl --> ir_serv
            ir_serv --> ir_dto
            ir_serv --> ir_entity
            ir_serv --> DB
        end
        click IR "https://github.com/manvirheer/shift_logger_api/tree/main/src/record/inventory"

        %% Activity Record Module
        subgraph "Activity Record Module"
            ActR["Activity Module"]:::module
            actr_ctrl["Controller"]:::controller
            actr_serv["Service"]:::service
            actr_dto["DTO"]:::dto
            actr_entity["Entity"]:::entity
            ActR --> actr_ctrl
            actr_ctrl --> actr_serv
            actr_serv --> actr_dto
            actr_serv --> actr_entity
            actr_serv --> DB
        end
        click ActR "https://github.com/manvirheer/shift_logger_api/tree/main/src/record/activity"

        %% Steam Parameters Module
        subgraph "Steam Parameters Module"
            SP["Steam Parameters Module"]:::module
            sp_ctrl["Controller"]:::controller
            sp_serv["Service"]:::service
            sp_dto["DTO"]:::dto
            sp_entity["Entity"]:::entity
            SP --> sp_ctrl
            sp_ctrl --> sp_serv
            sp_serv --> sp_dto
            sp_serv --> sp_entity
            sp_serv --> DB
        end
        click SP "https://github.com/manvirheer/shift_logger_api/tree/main/src/record/steam-parameters"

        %% Core Record Management Module
        subgraph "Core Record Management Module"
            CRM["Core Record Management Module"]:::module
            crm_ctrl["Controller"]:::controller
            crm_serv["Service"]:::service
            crm_dto["DTO"]:::dto
            crm_entity["Entity"]:::entity
            CRM --> crm_ctrl
            crm_ctrl --> crm_serv
            crm_serv --> crm_dto
            crm_serv --> crm_entity
            crm_serv --> DB
        end
        click CRM "https://github.com/manvirheer/shift_logger_api/blob/main/src/record/record.module.ts"
    end

    %% Shift Modules
    subgraph "Shift Modules"
        %% Shift Assignment Module
        subgraph "Shift Assignment Module"
            SA["Shift Assignment Module"]:::module
            sa_ctrl["Controller"]:::controller
            sa_serv["Service"]:::service
            sa_dto["DTO"]:::dto
            sa_entity["Entity"]:::entity
            SA --> sa_ctrl
            sa_ctrl --> sa_serv
            sa_serv --> sa_dto
            sa_serv --> sa_entity
            sa_serv --> DB
        end
        click SA "https://github.com/manvirheer/shift_logger_api/tree/main/src/shift/shift-assignment"

        %% Shift End Module
        subgraph "Shift End Module"
            SE["Shift End Module"]:::module
            se_ctrl["Controller"]:::controller
            se_serv["Service"]:::service
            se_dto["DTO"]:::dto
            se_entity["Entity"]:::entity
            SE --> se_ctrl
            se_ctrl --> se_serv
            se_serv --> se_dto
            se_serv --> se_entity
            se_serv --> DB
        end
        click SE "https://github.com/manvirheer/shift_logger_api/tree/main/src/shift/shift-end"

        %% Shift Schedule Module
        subgraph "Shift Schedule Module"
            SS["Shift Schedule Module"]:::module
            ss_ctrl["Controller"]:::controller
            ss_serv["Service"]:::service
            ss_dto["DTO"]:::dto
            ss_entity["Entity"]:::entity
            SS --> ss_ctrl
            ss_ctrl --> ss_serv
            ss_serv --> ss_dto
            ss_serv --> ss_entity
            ss_serv --> DB
        end
        click SS "https://github.com/manvirheer/shift_logger_api/tree/main/src/shift/shift-schedule"

        %% Shift Template Module
        subgraph "Shift Template Module"
            ST["Shift Template Module"]:::module
            st_ctrl["Controller"]:::controller
            st_serv["Service"]:::service
            st_dto["DTO"]:::dto
            st_entity["Entity"]:::entity
            ST --> st_ctrl
            st_ctrl --> st_serv
            st_serv --> st_dto
            st_serv --> st_entity
            st_serv --> DB
        end
        click ST "https://github.com/manvirheer/shift_logger_api/tree/main/src/shift/shift-template"

        %% Aggregated Shift Module
        subgraph "Aggregated Shift Module"
            AS["Aggregated Shift Module"]:::module
            as_ctrl["Controller"]:::controller
            as_serv["Service"]:::service
            as_dto["DTO"]:::dto
            as_entity["Entity"]:::entity
            AS --> as_ctrl
            as_ctrl --> as_serv
            as_serv --> as_dto
            as_serv --> as_entity
            as_serv --> DB
        end
        click AS "https://github.com/manvirheer/shift_logger_api/blob/main/src/shift/shift.module.ts"
    end

    %% Data Entry Period Module
    subgraph "Data Entry Period Module"
        DEP["Data Entry Period Module"]:::module
        dep_ctrl["Controller"]:::controller
        dep_serv["Service"]:::service
        dep_dto["DTO"]:::dto
        dep_entity["Entity"]:::entity
        DEP --> dep_ctrl
        dep_ctrl --> dep_serv
        dep_serv --> dep_dto
        dep_serv --> dep_entity
        dep_serv --> DB
    end
    click DEP "https://github.com/manvirheer/shift_logger_api/tree/main/src/data-entry-period"

    %% Database
    DB["MySQL Database"]:::database

    %% Routing connections from Router to modules
    Router --> UM
    Router --> PM
    Router --> SG
    Router --> AR
    Router --> SR
    Router --> IR
    Router --> ActR
    Router --> SP
    Router --> CRM
    Router --> SA
    Router --> SE
    Router --> SS
    Router --> ST
    Router --> AS
    Router --> DEP

    %% Class definitions
    classDef external fill:#f4cccc,stroke:#a64d79,stroke-width:2px;
    classDef api fill:#c9daf8,stroke:#6d9eeb,stroke-width:2px;
    classDef auth fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef router fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef module fill:#ead1dc,stroke:#c27ba0,stroke-width:2px;
    classDef controller fill:#d9d2e9,stroke:#8e7cc3,stroke-width:2px;
    classDef service fill:#cfe2f3,stroke:#3c78d8,stroke-width:2px;
    classDef dto fill:#fce5cd,stroke:#e69138,stroke-width:2px;
    classDef entity fill:#f4cccc,stroke:#e06666,stroke-width:2px;
    classDef database fill:#d9d9d9,stroke:#666666,stroke-width:2px;
```
