# sneh1604/mylabverse--mern-version- architecture

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

- Interactive diagram: https://gitdiagram.com/sneh1604/mylabverse--mern-version-
- Repository: https://github.com/sneh1604/mylabverse--mern-version-

## Overview

##### Main Components
- Frontend: The client directory (React-based) that handles the UI, routing, and interactions. Key sub-components are the various React components (e.g., Login, Signup, Dashboard, Home) that facilitate user interactions.
- Backend: The server directory (Node.js/Express) that handles API endpoints, authentication, JWT generation/verification, and business logic. This directory also holds the models (e.g., User, Administrator, BloodSugar, HemogramReport, etc.) which represent the database entities.
- Database: Although not directly visible in the file tree, the README indicates a MongoDB connection. This should be represented as an external database component interfacing with the backend.
- External Services/Utilities: Highlight the utility scripts (e.g., Tesseract integration scripts for OCR) and configuration files that are used for tasks like generating templates or migrating users.

##### Relationships and Interactions
- The Frontend interacts with the Backend via RESTful API calls (e.g., /register, /login, /dashboard).
- The Backend performs authentication, role verification (using JWT), and authorization, then communicates with the MongoDB database to retrieve and update persistent data.
- Utility scripts and modules (like generateTemplates.js or install_tesseract.js) support the backend processes.
- The system follows separation of concerns: frontend handles presentation and user experience, and the backend manages data processing and security.

##### Architectural Patterns and Key Technologies
- MVC (or similar separation): While the client code is component-based (following React’s component-driven architecture), the backend follows a modular structure with models and scripts.
- JWT Authentication & Role-Based Authorization: Clearly demonstrate how the verification middleware (e.g., verifyUser) protects routes like /dashboard.
- RESTful API Design: Endpoints for login, registration, and dashboard access, with expected HTTP methods and data flows.
- Configuration Management: Environment variables (notably the MongoDB connection URI and JWT secret) enhance security and flexibility.

##### Specific Elements
- Use clearly labeled blocks or nodes for each major component:
- "Client (React)" – including subcomponents such as Login, Signup, Dashboard, Home, and any Admin-specific components.
- "Server (Express/Node.js)" – including models (User, Administrator, etc.), API endpoints (e.g., /login, /register, /dashboard), and middleware (JWT verification).
- "Database (MongoDB)" – represented as an external data store.
- From Client components to Server endpoints to represent API calls.
- Within the server component, show middleware interactions before requests hit protected routes.
- From Server to Database showing data queries and updates.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend (React)"
        F1["Login Component"]:::frontend
        F2["Signup Component"]:::frontend
        F3["Dashboard Component"]:::frontend
        F5["User Dashboard Component"]:::frontend
        F4["Home Component"]:::frontend
    end

    subgraph "Backend (Express/Node.js)"
        B1["Server Entry (index.js)"]:::backend
        B2["API Endpoints (/login, /register, /dashboard)"]:::backend
        B3["JWT Middleware"]:::backend
        B4["Models (User, Administrator, etc.)"]:::backend
        subgraph "Utilities"
            U1["Tesseract OCR & Integration"]:::utility
            U2["Template Generation"]:::utility
            U3["User Migration Script"]:::utility
            U4["Token Fix Script"]:::utility
        end
    end

    D1["MongoDB Database"]:::database

    F1 -->|"calls"| B2
    F2 -->|"calls"| B2
    F3 -->|"calls"| B2
    F5 -->|"calls"| B2
    F4 -->|"calls"| B2

    B1 --> B2
    B2 --> B3
    B3 --> B4
    B4 -->|"query/update"| D1

    B1 --> U1
    B1 --> U2
    B1 --> U3
    B1 --> U4

    click F1 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/client/src/components/Login.jsx"
    click F2 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/client/src/components/SignUp.jsx"
    click F3 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/client/src/components/Dashboard.jsx"
    click F5 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/client/src/components/UserDashboard.jsx"
    click F4 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/client/src/components/Home.jsx"
    click B1 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/server/index.js"
    click B4 "https://github.com/sneh1604/mylabverse--mern-version-/tree/main/server/models/"
    click U1 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/server/install_tesseract.js"
    click U2 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/server/utils/generateTemplates.js"
    click U3 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/server/scripts/migrateUsers.js"
    click U4 "https://github.com/sneh1604/mylabverse--mern-version-/blob/main/server/scripts/fixTokenIds.js"

    classDef frontend fill:#cfe2f3,stroke:#0b5394,stroke-width:2px;
    classDef backend fill:#ead1dc,stroke:#953734,stroke-width:2px;
    classDef database fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef utility fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
```
