# gofies/ghms architecture

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

- Interactive diagram: https://gitdiagram.com/gofies/ghms
- Repository: https://github.com/gofies/ghms

## Overview

##### Main Components

A. Client Layer:
- React Frontend (Port 3000)
- Different user interfaces (Patient, Doctor, Admin, Lab Staff)
- Redux state management
- UI component library structure

B. API Gateway/Load Balancer:
- Nginx configuration (nginx.conf)
- SSL/TLS termination
- Routing logic

C. Backend Services:
- Node.js/Express API (Port 5000)
- Authentication/Authorization middleware
- Controller layers for different user types
- Model layer with MongoDB schemas

D. AI Services:
- LLM Service for chat functionality (Port 8000)
- File processing service
- Model inference service

E. Database Layer:
- MongoDB Cluster
- Config servers
- Router servers (Ports 27117, 27118)
- Shard servers
- Data replication and partitioning

F. Monitoring Stack:
- Prometheus for metrics
- Grafana for visualization
- Promtail for log aggregation

##### Connection Flows

- User → Frontend → API Gateway
- API Gateway → Backend Services
- Backend Services → MongoDB Cluster
- Backend Services → AI Services
- All Services → Monitoring Stack

##### Key Elements to Highlight

A. Security Layer:
- JWT authentication flow
- Middleware protection
- SSL/TLS encryption

B. Service Separation:
- Different controller groups (admin, doctor, patient, lab)
- Modular frontend components
- Microservices architecture

C. Data Flow:
- REST API routes
- Database queries
- Real-time updates
- File processing

##### Additional Details

Annotations for:
- Docker container boundaries
- Network isolation
- Environment configurations
- Scaling points
- Backup systems

##### Deployment Information

Show:
- CI/CD pipeline integration
- Container orchestration
- Environment separation (dev/prod)
- Health check endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[React Frontend]:::frontend
        Redux[Redux Store]:::frontend
        UIComp[UI Components]:::frontend
        Pages[Page Components]:::frontend
        
        UI --> Redux
        UI --> UIComp
        UI --> Pages
    end

    subgraph Gateway
        NGINX[API Gateway/Load Balancer]:::gateway
        SSL[SSL/TLS Termination]:::security
        
        NGINX --> SSL
    end

    subgraph Backend
        API[Node.js/Express API]:::backend
        Auth[Authentication]:::security
        Controllers[Controllers]:::backend
        Models[Models]:::backend
        
        API --> Auth
        API --> Controllers
        Controllers --> Models
    end

    subgraph AI
        LLM[LLM Service]:::ai
        FileProc[File Processing]:::ai
        ModelInf[Model Infrastructure]:::ai
        
        LLM --> ModelInf
        FileProc --> ModelInf
    end

    subgraph Database
        Router1[Router Server 27117]:::database
        Router2[Router Server 27118]:::database
        ConfigDB[Config Servers]:::database
        Shards[Shard Servers]:::database
        
        Router1 --> Shards
        Router2 --> Shards
        ConfigDB --> Router1
        ConfigDB --> Router2
    end

    subgraph Monitoring
        Prom[Prometheus]:::monitoring
        Graf[Grafana]:::monitoring
        Logs[Promtail]:::monitoring
        
        Prom --> Graf
        Logs --> Graf
    end

    UI --> NGINX
    NGINX --> API
    API --> LLM
    API --> FileProc
    Models --> Router1
    Models --> Router2
    
    %% Component Monitoring
    API -.-> Prom
    LLM -.-> Prom
    NGINX -.-> Prom

    %% Click Events
    click UI "https://github.com/Gofies/GHMS/tree/main/frontend/src"
    click Redux "https://github.com/Gofies/GHMS/tree/main/frontend/src/redux"
    click UIComp "https://github.com/Gofies/GHMS/tree/main/frontend/src/components/ui"
    click Pages "https://github.com/Gofies/GHMS/tree/main/frontend/src/pages"
    click API "https://github.com/Gofies/GHMS/tree/main/backend"
    click Controllers "https://github.com/Gofies/GHMS/tree/main/backend/controllers"
    click Models "https://github.com/Gofies/GHMS/tree/main/backend/models"
    click Auth "https://github.com/Gofies/GHMS/blob/main/backend/middlewares/auth.middleware.js"
    click LLM "https://github.com/Gofies/GHMS/blob/main/AI/src/services/llm_service.py"
    click FileProc "https://github.com/Gofies/GHMS/blob/main/AI/src/services/file_service.py"
    click ModelInf "https://github.com/Gofies/GHMS/tree/main/AI/src/models"
    click Router1 "https://github.com/Gofies/GHMS/blob/main/database/scripts/init-router.js"
    click ConfigDB "https://github.com/Gofies/GHMS/blob/main/database/scripts/init-configserver.js"
    click Shards "https://github.com/Gofies/GHMS/blob/main/database/scripts/init-shard01.js"
    click Graf "https://github.com/Gofies/GHMS/tree/main/monitoring/grafana"
    click Prom "https://github.com/Gofies/GHMS/blob/main/monitoring/prometheus.yml"
    click Logs "https://github.com/Gofies/GHMS/blob/main/monitoring/promtail-config.yml"
    click NGINX "https://github.com/Gofies/GHMS/blob/main/nginx.conf"
    click SSL "https://github.com/Gofies/GHMS/blob/main/backend/utils/generateJwt.js"

    %% Styling
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef ai fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef database fill:#FFC107,stroke:#FFA000,color:black
    classDef monitoring fill:#FF5722,stroke:#E64A19,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef gateway fill:#607D8B,stroke:#455A64,color:white
```
