# antoprince001/blockchain_for_ehr architecture

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

- Interactive diagram: https://gitdiagram.com/antoprince001/blockchain_for_ehr
- Repository: https://github.com/antoprince001/blockchain_for_ehr

## Overview

##### Main Components

a) Frontend Layer:
- Web Interface (HTML/CSS/JavaScript)
- User Portals (Patient, Doctor, Admin)
- Static Assets (Bootstrap, Font Awesome)
- Template Engine (Flask Templates)

b) Backend Layer:
- Flask Application Server
- Authentication System
- Blockchain-like Implementation
- Medical Records Manager

c) Database Layer:
- MongoDB Cloud Atlas

d) External Services:
- IPFS (indicated by ipfs.py)
- OCR Service (indicated by ocr.py)
- Email Service (indicated by mail.py)

##### Component Relationships

**[Web Browser] → [Frontend Layer] → [Flask Backend] → [MongoDB]**
- ↘ [External Services]

##### Specific Implementation Details

- Blue: Frontend components
- Green: Backend services
- Yellow: Database
- Gray: External services

- Rectangles: Main components
- Hexagons: External services

##### Detailed Component Breakdown

Frontend Layer (Blue Rectangle):
**┌─ User Interface ─┐**
- Patient Portal │
- Doctor Portal  │
- Admin Portal   │
- Templates      │
- ┘

Backend Layer (Green Rectangle):
**┌─ Flask Backend ──────┐**
- Authentication     │
- Record Management  │
- Blockchain Logic   │
- Access Control     │
- ┘

**┌─ MongoDB ─────┐**
- User Data   │
- Med Records │
- Blocks      │
- ┘

**[Block N-1] → [Block N] → [Block N+1]**
- ↓            ↓            ↓
**[Hash N-1]   [Hash N]    [Hash N+1]**

##### Access Flow Patterns

Different access patterns for:
- Patient Record Access
- Guardian Mode Access
- Doctor Access
- Admin Access

##### Additional Notes

- QR code functionality (shown by qrcode.js)
- Medical record creation flow
- Security layers
- Points where blockchain verification occurs

Remember to:
- Keep components clearly labeled
- Use consistent styling
- Major integration points
- Security boundaries
- Data flow directions
- Authentication checkpoints

This will provide a clear understanding of how the system works while maintaining the necessary level of detail for a principal software engineer to understand the complete architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend["Frontend Layer"]
        UI[Web Interface]
        PP[Patient Portal]:::frontend
        DP[Doctor Portal]:::frontend
        AP[Admin Portal]:::frontend
        SA[Static Assets]:::frontend
        TE[Template Engine]:::frontend
    end

    subgraph Backend["Backend Layer"]
        FAS[Flask App Server]:::backend
        Auth[Authentication]:::backend
        BCI[Blockchain Implementation]:::backend
        MRM[Medical Records Manager]:::backend
        DH[Data Handler]:::backend
        SC[Smart Contracts]:::backend
    end

    subgraph External["External Services"]
        IPFS[IPFS Service]:::external
        OCR[OCR Service]:::external
        Email[Email Service]:::external
        QR[QR Code System]:::external
    end

    subgraph Database["Database Layer"]
        MDB[(MongoDB Atlas)]:::database
    end

    subgraph Blockchain["Blockchain Structure"]
        B1[Block N-1]:::block
        B2[Block N]:::block
        B3[Block N+1]:::block
        H1[Hash N-1]:::hash
        H2[Hash N]:::hash
        H3[Hash N+1]:::hash
    end

    %% Relationships
    UI --> PP & DP & AP
    PP & DP & AP --> FAS
    FAS --> Auth
    Auth --> MRM
    MRM --> BCI
    BCI --> DH
    DH --> SC
    SC --> MDB
    MRM --> IPFS & OCR & Email & QR
    
    %% Blockchain Relationships
    B1 --> B2
    B2 --> B3
    B1 --> H1
    B2 --> H2
    B3 --> H3

    %% Styling
    classDef frontend fill:#3498db
    classDef backend fill:#2ecc71
    classDef database fill:#f1c40f
    classDef external fill:#95a5a6
    classDef block fill:#e74c3c
    classDef hash fill:#9b59b6

    %% Click Events
    click FAS "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/app.py"
    click SA "https://github.com/antoprince001/Blockchain_for_EHR/tree/master/static"
    click PP "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/templates/patdash.html"
    click DP "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/templates/docdash.html"
    click AP "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/templates/admindash.html"
    click IPFS "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/python base/ipfs.py"
    click OCR "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/python base/ocr.py"
    click Email "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/python base/mail.py"
    click QR "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/static/js/qrcode.js"
    click DH "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/python base/data.py"
    click SC "https://github.com/antoprince001/Blockchain_for_EHR/blob/master/python base/smart.py"

    %% Legend
    subgraph Legend
        L1[Frontend Components]:::frontend
        L2[Backend Services]:::backend
        L3[(Database)]:::database
        L4[External Services]:::external
        L5[Blockchain Block]:::block
        L6[Hash]:::hash
    end
```
