# tsvtok/machinecaire architecture

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

- Interactive diagram: https://gitdiagram.com/tsvtok/machinecaire
- Repository: https://github.com/tsvtok/machinecaire

## Overview

MachineCare is a REST API for industrial machine maintenance: authenticated users manage machine records and report, track, and resolve incidents. The main flow is HTTP routes through controllers to MongoDB models, with JWT protection on user and maintenance endpoints and centralized error responses. The README documents Swagger/OpenAPI alongside authentication, profiles, machine CRUD/history, and signalement lifecycle. The sampled code supports the main controller/model relationships; service files were only indexed, so their role is not inferred.

Main entry points: [`src/app.js`](https://github.com/tsvtok/machinecaire/blob/main/src/app.js) (Express app), [`src/routes/user.js`](https://github.com/tsvtok/machinecaire/blob/main/src/routes/user.js) (Profile routes), [`src/routes/machine.js`](https://github.com/tsvtok/machinecaire/blob/main/src/routes/machine.js) (Machine routes), [`src/routes/signalement.js`](https://github.com/tsvtok/machinecaire/blob/main/src/routes/signalement.js) (Incident routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry"]
  node_app["Express app<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>[auth.js]"]
  node_user_routes["Profile routes<br/>[user.js]"]
  node_machine_routes["Machine routes<br/>[machine.js]"]
  node_signalement_routes["Incident routes<br/>[signalement.js]"]
end

subgraph group_identity["Identity and access"]
  node_auth_controller["Authentication<br/>[authController.js]"]
  node_user_controller["User profiles<br/>[userController.js]"]
  node_jwt_guard["JWT guard<br/>[auth.middleware.js]"]
end

subgraph group_maintenance["Maintenance domain"]
  node_machine_controller["Machine management"]
  node_signalement_controller["Incident lifecycle"]
end

subgraph group_persistence["MongoDB records"]
  node_user_model[("User records<br/>[User.js]")]
  node_machine_model[("Machine records<br/>[Machine.js]")]
  node_signalement_model[("Incident records<br/>[Signalement.js]")]
  node_mongo[("MongoDB<br/>[db.js]")]
end

subgraph group_support["API support"]
  node_error_handler["Error handling<br/>[errorHandler.js]"]
  node_swagger["API documentation<br/>[swagger.js]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts at auth"| node_auth_routes
node_app -->|"mounts at users"| node_user_routes
node_app -->|"mounts at machines"| node_machine_routes
node_app -->|"mounts at signalements"| node_signalement_routes
node_app -->|"connects"| node_mongo
node_app -->|"checks admin"| node_user_model
node_app -->|"handles errors"| node_error_handler
node_app -->|"serves docs"| node_swagger
node_auth_routes -->|"dispatches"| node_auth_controller
node_user_routes -->|"protects routes"| node_jwt_guard
node_user_routes -->|"dispatches"| node_user_controller
node_machine_routes -->|"protects routes"| node_jwt_guard
node_machine_routes -->|"dispatches"| node_machine_controller
node_signalement_routes -->|"protects routes"| node_jwt_guard
node_signalement_routes -->|"dispatches"| node_signalement_controller
node_auth_controller -->|"creates and checks"| node_user_model
node_user_controller -->|"reads and updates"| node_user_model
node_machine_controller -->|"manages records"| node_machine_model
node_machine_controller -->|"checks incident links"| node_signalement_model
node_signalement_controller -->|"manages lifecycle"| node_signalement_model
node_signalement_controller -->|"validates machine"| node_machine_model
node_client -->|"views API docs"| node_app

click node_app "https://github.com/tsvtok/machinecaire/blob/main/src/app.js"
click node_auth_routes "https://github.com/tsvtok/machinecaire/blob/main/src/routes/auth.js"
click node_user_routes "https://github.com/tsvtok/machinecaire/blob/main/src/routes/user.js"
click node_machine_routes "https://github.com/tsvtok/machinecaire/blob/main/src/routes/machine.js"
click node_signalement_routes "https://github.com/tsvtok/machinecaire/blob/main/src/routes/signalement.js"
click node_auth_controller "https://github.com/tsvtok/machinecaire/blob/main/src/controllers/authController.js"
click node_user_controller "https://github.com/tsvtok/machinecaire/blob/main/src/controllers/userController.js"
click node_jwt_guard "https://github.com/tsvtok/machinecaire/blob/main/src/middlewares/auth.middleware.js"
click node_machine_controller "https://github.com/tsvtok/machinecaire/blob/main/src/controllers/machineController.js"
click node_signalement_controller "https://github.com/tsvtok/machinecaire/blob/main/src/controllers/signalementController.js"
click node_user_model "https://github.com/tsvtok/machinecaire/blob/main/src/models/User.js"
click node_machine_model "https://github.com/tsvtok/machinecaire/blob/main/src/models/Machine.js"
click node_signalement_model "https://github.com/tsvtok/machinecaire/blob/main/src/models/Signalement.js"
click node_mongo "https://github.com/tsvtok/machinecaire/blob/main/src/config/db.js"
click node_error_handler "https://github.com/tsvtok/machinecaire/blob/main/src/middlewares/errorHandler.js"
click node_swagger "https://github.com/tsvtok/machinecaire/blob/main/src/docs/swagger.js"

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_app,node_auth_routes,node_user_routes,node_machine_routes,node_signalement_routes,node_client toneBlue
class node_auth_controller,node_user_controller,node_jwt_guard toneAmber
class node_machine_controller,node_signalement_controller toneMint
class node_user_model,node_machine_model,node_signalement_model,node_mongo toneRose
class node_error_handler,node_swagger toneIndigo
```

## Components

### API entry

- [Express app](https://github.com/tsvtok/machinecaire/blob/main/src/app.js): `src/app.js`
- [Auth routes](https://github.com/tsvtok/machinecaire/blob/main/src/routes/auth.js): `src/routes/auth.js`
- [Profile routes](https://github.com/tsvtok/machinecaire/blob/main/src/routes/user.js): `src/routes/user.js`
- [Machine routes](https://github.com/tsvtok/machinecaire/blob/main/src/routes/machine.js): `src/routes/machine.js`
- [Incident routes](https://github.com/tsvtok/machinecaire/blob/main/src/routes/signalement.js): `src/routes/signalement.js`

### Identity and access

- [Authentication](https://github.com/tsvtok/machinecaire/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [User profiles](https://github.com/tsvtok/machinecaire/blob/main/src/controllers/userController.js): `src/controllers/userController.js`
- [JWT guard](https://github.com/tsvtok/machinecaire/blob/main/src/middlewares/auth.middleware.js): `src/middlewares/auth.middleware.js`

### Maintenance domain

- [Machine management](https://github.com/tsvtok/machinecaire/blob/main/src/controllers/machineController.js): `src/controllers/machineController.js`
- [Incident lifecycle](https://github.com/tsvtok/machinecaire/blob/main/src/controllers/signalementController.js): `src/controllers/signalementController.js`

### MongoDB records

- [User records](https://github.com/tsvtok/machinecaire/blob/main/src/models/User.js): `src/models/User.js`
- [Machine records](https://github.com/tsvtok/machinecaire/blob/main/src/models/Machine.js): `src/models/Machine.js`
- [Incident records](https://github.com/tsvtok/machinecaire/blob/main/src/models/Signalement.js): `src/models/Signalement.js`
- [MongoDB](https://github.com/tsvtok/machinecaire/blob/main/src/config/db.js): `src/config/db.js`

### API support

- [Error handling](https://github.com/tsvtok/machinecaire/blob/main/src/middlewares/errorHandler.js): `src/middlewares/errorHandler.js`
- [API documentation](https://github.com/tsvtok/machinecaire/blob/main/src/docs/swagger.js): `src/docs/swagger.js`

### Other components

- **API client**

## Connections

- API client → Express app: sends requests (evidence: `README.md`)
- Express app → Auth routes: mounts at auth (evidence: `src/app.js`)
- Express app → Profile routes: mounts at users (evidence: `src/app.js`)
- Express app → Machine routes: mounts at machines (evidence: `src/app.js`)
- Express app → Incident routes: mounts at signalements (evidence: `src/app.js`)
- Express app → MongoDB: connects (evidence: `src/app.js`)
- Express app → User records: checks admin (evidence: `src/app.js`)
- Express app → Error handling: handles errors (evidence: `src/app.js`)
- Express app → API documentation: serves docs (evidence: `src/app.js`)
- Auth routes → Authentication: dispatches (evidence: `src/routes/auth.js`)
- Profile routes → JWT guard: protects routes (evidence: `src/routes/user.js`)
- Profile routes → User profiles: dispatches (evidence: `src/routes/user.js`)
- Machine routes → JWT guard: protects routes (evidence: `src/routes/machine.js`)
- Machine routes → Machine management: dispatches (evidence: `src/routes/machine.js`)
- Incident routes → JWT guard: protects routes (evidence: `src/routes/signalement.js`)
- Incident routes → Incident lifecycle: dispatches (evidence: `src/routes/signalement.js`)
- Authentication → User records: creates and checks (evidence: `src/controllers/authController.js`)
- User profiles → User records: reads and updates (evidence: `src/controllers/userController.js`)
- Machine management → Machine records: manages records (evidence: `src/controllers/machineController.js`)
- Machine management → Incident records: checks incident links (evidence: `src/controllers/machineController.js`)
- Incident lifecycle → Incident records: manages lifecycle (evidence: `src/controllers/signalementController.js`)
- Incident lifecycle → Machine records: validates machine (evidence: `src/controllers/signalementController.js`)
- API client → Express app: views API docs (evidence: `README.md`)
