# tech-maniacs/blockchain-phr architecture

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

- Interactive diagram: https://gitdiagram.com/tech-maniacs/blockchain-phr
- Repository: https://github.com/tech-maniacs/blockchain-phr

## Overview

##### Project type and purpose
- From the file tree and README, we see a full-stack web application (“MEDICHAIN”) that manages Personal Health Records (PHRs) on a blockchain.
- Frontend: React (client/ folder), uses Redux for state.
- Backend: Node.js + Express (server.js, routes/, controllers/, models/), persisting data in MongoDB.
- Blockchain integration: a Solidity smart contract deployed on Sepolia, accessed via web3.js (client/src/web3.js and smartcontract/).

##### File structure
- Top-level folders:
- client/ – React app (public/, src/, package.json)
- config/ – database connection (config/db.js)
- controllers/ – Express controllers for admin, doctor, hospital, user
- models/ – Mongoose schemas for patients, doctors, hospitals, PHRs
- routes/ – Express routers for each role
- middlewares/ – auth middleware (JWT or role-based)
- smartcontract/ – Solidity code
- server.js – Express app entry point
- Patterns:
- Backend uses MVC (models/controllers/routes)
- Frontend uses component-based structure, Redux slices (alertSlice, userSlice).
- Integration layer with web3.js for blockchain calls.

##### Readme insights
- Points out blockchain network (Sepolia), smart contract deployed on Remix, web3.js integration.
- No built-in backend-to-contract communication: client handles contract calls.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        WebClient["Web Client (React + Redux)"]:::frontend
        subgraph "UI Components & Pages"
            direction TB
            Pages["Pages & Components"]:::frontend
        end
        subgraph "State Management"
            direction TB
            ReduxStore["Redux Store"]:::frontend
            AlertSlice["alertSlice"]:::frontend
            UserSlice["userSlice"]:::frontend
        end
        Web3Module["Blockchain Integration (web3.js)"]:::frontend
        Tailwind["Styling (Tailwind)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        APIServer["API Server (Express)"]:::backend
        DBConfig["DB Config (config/db.js)"]:::backend
        subgraph "Controllers"
            direction TB
            AdminCtrl["adminCtrl"]:::backend
            DoctorCtrl["doctorCtrl"]:::backend
            HospitalCtrl["hospitalCtrl"]:::backend
            UserCtrl["userCtrl"]:::backend
            DemoCtrl["demo"]:::backend
        end
        subgraph "Routes"
            direction TB
            AdminRoutes["adminRoutes"]:::backend
            DoctorRoutes["doctorRoutes"]:::backend
            HospitalRoutes["hospitalRoutes"]:::backend
            UserRoutes["userRoutes"]:::backend
        end
        AuthMiddleware["Auth Middleware"]:::backend
        subgraph "Models"
            direction TB
            AbhaModel["abhaModel"]:::backend
            DoctorModel["doctorModel"]:::backend
            EncryptPhrModel["encryptPhrModel"]:::backend
            HealthFacilityModel["healthFacilityModel"]:::backend
            HealthInfoProviderModel["healthInfoProviderModel"]:::backend
            HospitalModel["hospitalModel"]:::backend
            PatientModel["patientModel"]:::backend
            UserModels["userModels"]:::backend
        end
    end

    %% Database
    MongoDB[(MongoDB)]:::db

    %% Blockchain
    subgraph "Blockchain"
        direction TB
        Sepolia["Ethereum Sepolia TestNet"]:::blockchain
        SmartContract[(Smart Contract)]:::blockchain
    end

    %% Connections
    User["User/Browser"] -->|"interacts with"| WebClient
    WebClient -->|"REST API calls"| APIServer
    APIServer -->|"reads/writes"| MongoDB
    APIServer -->|"uses"| DBConfig
    APIServer -->|"calls"| AdminCtrl
    APIServer -->|"calls"| DoctorCtrl
    APIServer -->|"calls"| HospitalCtrl
    APIServer -->|"calls"| UserCtrl
    APIServer -->|"calls"| DemoCtrl
    AdminCtrl -->|uses| AbhaModel
    DoctorCtrl -->|uses| DoctorModel
    HospitalCtrl -->|uses| HospitalModel
    UserCtrl -->|uses| UserModels
    UserCtrl -->|uses| EncryptPhrModel
    AdminCtrl -->|uses| HealthFacilityModel
    DoctorCtrl -->|uses| HealthInfoProviderModel
    APIServer -->|"routes via"| AdminRoutes
    APIServer -->|"routes via"| DoctorRoutes
    APIServer -->|"routes via"| HospitalRoutes
    APIServer -->|"routes via"| UserRoutes
    APIServer -->|"auth checks"| AuthMiddleware
    WebClient -->|"dispatches"| ReduxStore
    ReduxStore -->|"includes"| AlertSlice
    ReduxStore -->|"includes"| UserSlice
    WebClient -->|"calls"| Web3Module
    Web3Module -->|"connects to"| Sepolia
    Sepolia -->|"deploys/contracts"| SmartContract
    WebClient -->|"imports styles"| Tailwind

    %% Click Events
    click WebClient "https://github.com/tech-maniacs/blockchain-phr/tree/main/client/src/"
    click Pages "https://github.com/tech-maniacs/blockchain-phr/tree/main/client/src/pages/"
    click ReduxStore "https://github.com/tech-maniacs/blockchain-phr/blob/main/client/src/redux/store.js"
    click AlertSlice "https://github.com/tech-maniacs/blockchain-phr/blob/main/client/src/redux/features/alertSlice.js"
    click UserSlice "https://github.com/tech-maniacs/blockchain-phr/blob/main/client/src/redux/features/userSlice.js"
    click Web3Module "https://github.com/tech-maniacs/blockchain-phr/blob/main/client/src/web3.js"
    click Tailwind "https://github.com/tech-maniacs/blockchain-phr/blob/main/client/tailwind.config.js"
    click APIServer "https://github.com/tech-maniacs/blockchain-phr/blob/main/server.js"
    click DBConfig "https://github.com/tech-maniacs/blockchain-phr/blob/main/config/db.js"
    click AdminCtrl "https://github.com/tech-maniacs/blockchain-phr/blob/main/controllers/adminCtrl.js"
    click DoctorCtrl "https://github.com/tech-maniacs/blockchain-phr/blob/main/controllers/doctorCtrl.js"
    click HospitalCtrl "https://github.com/tech-maniacs/blockchain-phr/blob/main/controllers/hospitalCtrl.js"
    click UserCtrl "https://github.com/tech-maniacs/blockchain-phr/blob/main/controllers/userCtrl.js"
    click DemoCtrl "https://github.com/tech-maniacs/blockchain-phr/blob/main/controllers/demo.js"
    click AdminRoutes "https://github.com/tech-maniacs/blockchain-phr/blob/main/routes/adminRoutes.js"
    click DoctorRoutes "https://github.com/tech-maniacs/blockchain-phr/blob/main/routes/doctorRoutes.js"
    click HospitalRoutes "https://github.com/tech-maniacs/blockchain-phr/blob/main/routes/hospitalRoutes.js"
    click UserRoutes "https://github.com/tech-maniacs/blockchain-phr/blob/main/routes/userRoutes.js"
    click AuthMiddleware "https://github.com/tech-maniacs/blockchain-phr/blob/main/middlewares/authMiddleware.js"
    click AbhaModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/abhaModel.js"
    click DoctorModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/doctorModel.js"
    click EncryptPhrModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/encryptPhrModel.js"
    click HealthFacilityModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/healthFacilityModel.js"
    click HealthInfoProviderModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/healthInfoProviderModel.js"
    click HospitalModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/hospitalModel.js"
    click PatientModel "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/patientModel.js"
    click UserModels "https://github.com/tech-maniacs/blockchain-phr/blob/main/models/userModels.js"
    click SmartContract "https://github.com/tech-maniacs/blockchain-phr/tree/main/smartcontract/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef db fill:#FFA500,stroke:#000,stroke-width:1px
    classDef blockchain fill:#DDA0DD,stroke:#000,stroke-width:1px
```
