# voronalk/ohs_manager_clone architecture

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

- Interactive diagram: https://gitdiagram.com/voronalk/ohs_manager_clone
- Repository: https://github.com/voronalk/ohs_manager_clone

## Overview

##### Project type and purpose
- This is a full-stack CRM web application (“OHS_manager”) designed to help occupational-health specialists manage employees, generate and store document templates, attach scanned documents, and seed large datasets from Excel.
- The README confirms that it features a React/Redux frontend (with React Beautiful DnD, modals, forms) and an Express-based Node.js backend (with file-templating, file storage, Excel parsing, RESTful routes and middleware).

##### File structure
a. Top-level:
- client/ – React UI
- server/ – Node/Express API and business logic
- excelTestSeed/ – sample Excel for bulk seeding
b. client/ breakdown:
- src/index.js, App.js
- src/components/ – feature UI (Login, Dashboard, Workers, Documents, ToDoList)
- src/api/ – HTTP client setup
- src/redux/ – state (actions, reducers), thunks & sagas for side effects
c. server/ breakdown:
- index.js – Express app entry point
- middleware/ (auth, error handling, file upload via multer)
- routes/ – REST endpoints: auth, workers, documents, download, todo
- models/ – data models (company, worker, docs, medical exams) plus a seed script
- xlParcer/ – Excel → JSON
- fileStore/ – persistent storage for uploaded notes/scans
- templater/ – .docx template engine (load .docx templates, fill, error handling)
d. Configuration:
- client/package.json, server/package.json – define dependencies, scripts
- server uses multer, possibly a DB connector (not shown) for models
- No Docker or CI files, but a `yarn dev` script orchestrates both client & server.

##### README for additional insights
- Describes “yarn seed” to pre-populate DB via Excel.
- Shows user flows: Login → Company list → Workers → Documents (standard & DnD) → Upload scans → Medical exams.
- Mentions generating .docx templates server-side, downloadable via API, then re-upload scanned PDFs.

a. Main components
1. Browser / Client UI
- React app, Redux store, Sagas → calls API
2. API Gateway / Backend
- Express server with middleware
- Route controllers for auth, workers, documents, downloads, todo
3. Business Logic Services
- Templater service (.docx generation)
- Excel Parser service (seed)
4. Data Models / Persistence
- A database (e.g., MongoDB or relational DB) for company, worker, docs metadata
- File storage (server/fileStore) for .docx templates and uploaded scans
5. External Dependencies
- Email or storage buckets (optional)
- Excel and docx node modules
b. Relationships & interactions
- User → React UI → Redux Saga → HTTP requests → Express routes
- Routes → middleware(auth, multer) → controllers → service layer → models (DB) or file operations
- Seed process: Excel Parser → model layer → DB & initial .docx template generation
- Document generation: templater loads .docx templates → populates fields → writes to fileStore → serves via download endpoint
- File uploads: multer middleware → writes scans to fileStore → update document status in DB
c. Architectural patterns
- Client: Redux for state, Redux-Saga for side effects (async flows)
- Backend: MVC-like separation (routes → controllers → services → models)
- File-centric micro-services within monolith: templater and parser modules
d. Key technologies/frameworks
- Frontend: React, React Router (implied), Redux, Redux-Saga, react-beautiful-dnd, Sass/CSS modules
- Backend: Node.js, Express, multer, docx templating libraries, xlsx parser, (presumed) Mongoose/Sequelize, file system
- Build tools: Yarn, Babel or Webpack (implied by create-react-app or custom config)

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Client Layer
  subgraph "Client Layer" 
    direction TB
    ReactUI["React UI"]:::client
    IndexJS["Index.js"]:::client
    AppJS["App.js"]:::client
    HTTPClient["HTTP Client"]:::client
    UIComponents["UI Components"]:::client
    ReduxStore["Redux Store"]:::client
    ActionCreators["Action Creators"]:::client
    ActionTypes["Action Types"]:::client
    Reducers["Reducers"]:::client
    Sagas["Sagas"]:::client
    Thunks["Thunks"]:::client
    Utils["Utility Functions"]:::client
  end

  %% API Layer
  subgraph "API Layer" 
    direction TB
    ExpressApp["Express App"]:::server
    AuthMW["Auth Middleware"]:::server
    ErrorMW["Error Handling Middleware"]:::server
    MulterMW["Multer Middleware"]:::server
    subgraph "Routes"
      direction TB
      AuthRoute["Auth Routes"]:::server
      WorkersRoute["Workers Routes"]:::server
      DocumentsRoute["Documents Routes"]:::server
      DownloadRoute["Download Routes"]:::server
      TodoRoute["ToDo Routes"]:::server
    end
  end

  %% Services & Persistence
  subgraph "Services & Persistence"
    direction TB
    subgraph "Services"
      direction TB
      ExcelParser["Excel Parser Service"]:::service
      XLSXLogic["XLSX Parsing Logic"]:::service
      Templater["Templater Service"]:::service
      FillLogic["Template Filling Logic"]:::service
      TemplateErrors["Template Error Handler"]:::service
      ReplaceErrors["Replacement Error Utility"]:::service
      RemoveDir["Directory Removal Utility"]:::service
    end
    DB["Database"]:::database
    FileStore["File Storage"]:::storage
    SeedExcel["Seed Excel"]:::storage
  end

  %% Connections
  ReactUI -->|renders| UIComponents
  ReactUI -->|initializes| ReduxStore
  ReduxStore -->|uses| ActionCreators
  ReduxStore -->|uses| ActionTypes
  ReduxStore -->|handled by| Reducers
  ReduxStore -->|side effects| Sagas
  ReduxStore -->|thunks| Thunks
  ReactUI -->|calls| HTTPClient
  HTTPClient -->|REST/HTTP| ExpressApp

  ExpressApp -->|uses| AuthMW
  ExpressApp -->|uses| ErrorMW
  ExpressApp -->|uses| MulterMW
  ExpressApp -->|routes to| AuthRoute
  ExpressApp -->|routes to| WorkersRoute
  ExpressApp -->|routes to| DocumentsRoute
  ExpressApp -->|routes to| DownloadRoute
  ExpressApp -->|routes to| TodoRoute

  AuthRoute -->|calls| AuthMW
  DocumentsRoute -->|uploads| MulterMW

  AuthRoute -->|db ops| DB
  WorkersRoute -->|db ops| DB
  DocumentsRoute -->|db ops| DB
  TodoRoute -->|db ops| DB
  DownloadRoute -->|reads| FileStore

  DocumentsRoute -->|templating| Templater
  Templater -->|fill| FillLogic
  FillLogic -->|error handling| TemplateErrors
  FillLogic -->|writes| FileStore

  ExcelParser -->|parse| XLSXLogic
  XLSXLogic -->|seed| DB
  ExcelParser -->|trigger| Templater
  SeedExcel -->|offline| ExcelParser

  %% Click Events - Client
  click ReactUI "https://github.com/voronalk/ohs_manager_clone/tree/main/client/"
  click IndexJS "https://github.com/voronalk/ohs_manager_clone/blob/main/client/src/index.js"
  click AppJS "https://github.com/voronalk/ohs_manager_clone/blob/main/client/src/App.js"
  click HTTPClient "https://github.com/voronalk/ohs_manager_clone/blob/main/client/src/api/index.js"
  click UIComponents "https://github.com/voronalk/ohs_manager_clone/tree/main/client/src/components/"
  click ReduxStore "https://github.com/voronalk/ohs_manager_clone/blob/main/client/src/redux/store.js"
  click ActionCreators "https://github.com/voronalk/ohs_manager_clone/blob/main/client/src/redux/actionCreators/ActionCreators.js"
  click ActionTypes "https://github.com/voronalk/ohs_manager_clone/blob/main/client/src/redux/actionTypes/actionTypes.js"
  click Reducers "https://github.com/voronalk/ohs_manager_clone/tree/main/client/src/redux/reducers/"
  click Sagas "https://github.com/voronalk/ohs_manager_clone/tree/main/client/src/redux/sagas/"
  click Thunks "https://github.com/voronalk/ohs_manager_clone/tree/main/client/src/redux/thunks/"
  click Utils "https://github.com/voronalk/ohs_manager_clone/tree/main/client/src/utils/"

  %% Click Events - Server
  click ExpressApp "https://github.com/voronalk/ohs_manager_clone/blob/main/server/index.js"
  click AuthMW "https://github.com/voronalk/ohs_manager_clone/blob/main/server/middleware/auth.js"
  click ErrorMW "https://github.com/voronalk/ohs_manager_clone/blob/main/server/middleware/error.js"
  click MulterMW "https://github.com/voronalk/ohs_manager_clone/blob/main/server/middleware/multer.js"
  click AuthRoute "https://github.com/voronalk/ohs_manager_clone/blob/main/server/routes/auth.js"
  click WorkersRoute "https://github.com/voronalk/ohs_manager_clone/blob/main/server/routes/workers.js"
  click DocumentsRoute "https://github.com/voronalk/ohs_manager_clone/blob/main/server/routes/documents.js"
  click DownloadRoute "https://github.com/voronalk/ohs_manager_clone/blob/main/server/routes/download.js"
  click TodoRoute "https://github.com/voronalk/ohs_manager_clone/blob/main/server/routes/todo.js"
  click DB "https://github.com/voronalk/ohs_manager_clone/blob/main/server/models/companyModel.js"
  click DB "https://github.com/voronalk/ohs_manager_clone/blob/main/server/models/workerModel.js"
  click DB "https://github.com/voronalk/ohs_manager_clone/blob/main/server/models/docTemplatesModel.js"
  click DB "https://github.com/voronalk/ohs_manager_clone/blob/main/server/models/ohsDocModel.js"
  click DB "https://github.com/voronalk/ohs_manager_clone/blob/main/server/models/medicalExamModel.js"
  click ExcelParser "https://github.com/voronalk/ohs_manager_clone/blob/main/server/xlParcer/index.js"
  click XLSXLogic "https://github.com/voronalk/ohs_manager_clone/blob/main/server/xlParcer/parseXlsx.js"
  click Templater "https://github.com/voronalk/ohs_manager_clone/blob/main/server/templater/templater.js"
  click FillLogic "https://github.com/voronalk/ohs_manager_clone/blob/main/server/templater/fillTemplates.js"
  click TemplateErrors "https://github.com/voronalk/ohs_manager_clone/blob/main/server/templater/errorHandler.js"
  click ReplaceErrors "https://github.com/voronalk/ohs_manager_clone/blob/main/server/templater/replaseErrors.js"
  click RemoveDir "https://github.com/voronalk/ohs_manager_clone/blob/main/server/templater/removeDir.js"
  click FileStore "https://github.com/voronalk/ohs_manager_clone/tree/main/server/fileStore/"
  click SeedExcel "https://github.com/voronalk/ohs_manager_clone/blob/main/excelTestSeed/Test.xlsx"

  %% Styles
  classDef client fill:#D6EAF8,stroke:#2980B9,color:#154360;
  classDef server fill:#D5F5E3,stroke:#27AE60,color:#145A32;
  classDef service fill:#FCF3CF,stroke:#F1C40F,color:#7D6608;
  classDef database fill:#FADBD8,stroke:#E74C3C,color:#641E16;
  classDef storage fill:#E8DAEF,stroke:#8E44AD,color:#4A235A;
```
