# dheer2005/smarthealthcare architecture

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

- Interactive diagram: https://gitdiagram.com/dheer2005/smarthealthcare
- Repository: https://github.com/dheer2005/smarthealthcare

## Overview

##### Project type and purpose
- This is a single‐page application (SPA) front-end built with Angular (version 18), called “SmartHealthCare.”
- It implements a healthcare portal with distinct user roles (Admin, Doctor, Patient), authentication, messaging (chat), appointment management, prescriptions, and lab results views.

##### File structure
- Top-level artifacts:
- angular.json, package.json, tsconfig*.json → Angular CLI configuration
- /public or /src/index.html → host page for the SPA
- Feature modules under src:
- Authentication (login/register)
- Admin (dashboard, manage doctors, manage patients)
- Doctor (dashboard, messages, prescriptions, appointments)
- Patient (appointments, lab results, history, messages, prescriptions)
- Shared cross-cutting pieces:
- /Service → injectable services (authentication.service, doctor.service, patient.service, chat.service)
- /Guards → AuthGuard protecting routes
- /Models → TypeScript interfaces and enums
- Routing is configured in src/app/app.routes.ts, and bootstrapping in src/main.ts.

##### README for additional insights
- Confirms this is purely a front-end Angular project.
- Standard build/test/run commands.
- No back-end code in this repo, so it must rely on external REST/WS services.

##### Main components
a. Client (Web Browser)
b. Angular SPA
– App Module & Router
– Feature Modules (Authentication, Admin, Doctor, Patient)
– Components within each module
– Shared Models
– Guards (AuthGuard)
– Services (AuthService, DoctorService, PatientService, ChatService)
c. External Services
– REST API server (endpoints: /auth, /admin, /doctor, /patient, /appointments, /prescriptions, /lab-results)
– WebSocket (for real-time chat)
d. Persistence Layer (Database) – behind the REST API

##### Relationships and data flow
- User interacts with Browser → loads Angular SPA.
- The Router directs to a feature module (e.g., Patient).
- Components call a Service (e.g., patient.service) → issues HTTP request to REST API.
- ChatService opens a WebSocket connection to a chat server.
- REST API reads/writes to the Database.
- AuthGuard intercepts route activation, calls AuthService → validates JWT via /auth endpoint.

##### Important architectural patterns
- Modular, component-based front-end
- Separation of concerns: UI components vs. data services vs. routing vs. models
- SPA with client-side routing
- Guard pattern for route protection
- API-first back-end communication (REST + WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        BR["Web Browser"]:::client
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        SP["Angular SPA"]:::spa
        SP -->|"load SPA"| Router["App Module & Router"]:::module
        Router -->|"route navigation"| AuthGuard["AuthGuard"]:::guard

        subgraph "Authentication Module" 
            direction TB
            Login["Login Component"]:::component
            Register["Register Component"]:::component
        end
        AuthGuard -->|"canActivate"| AuthenticationModule["Authentication Module"]:::module
        AuthenticationModule --> Login
        AuthenticationModule --> Register

        subgraph "Admin Module"
            direction TB
            AdminDash["Admin Dashboard"]:::component
            AdminDocs["Manage Doctors"]:::component
            AdminPats["Manage Patients"]:::component
        end
        AuthGuard -->|"canActivate"| AdminModule["Admin Module"]:::module
        AdminModule --> AdminDash
        AdminModule --> AdminDocs
        AdminModule --> AdminPats

        subgraph "Doctor Module"
            direction TB
            DocDash["Doctor Dashboard"]:::component
            DocMsgs["Messages"]:::component
            DocPresc["Prescriptions"]:::component
            DocAppts["Requested Appointments"]:::component
        end
        AuthGuard -->|"canActivate"| DoctorModule["Doctor Module"]:::module
        DoctorModule --> DocDash
        DoctorModule --> DocMsgs
        DoctorModule --> DocPresc
        DoctorModule --> DocAppts

        subgraph "Patient Module"
            direction TB
            PatAppt["Appointments"]:::component
            PatLab["Lab Results"]:::component
            PatHist["History"]:::component
            PatMsgs["Messages"]:::component
            PatPresc["Prescriptions"]:::component
        end
        AuthGuard -->|"canActivate"| PatientModule["Patient Module"]:::module
        PatientModule --> PatAppt
        PatientModule --> PatLab
        PatientModule --> PatHist
        PatientModule --> PatMsgs
        PatientModule --> PatPresc
    end

    BR -->|"HTTP(S)| load index.html"| SP

    %% Services Layer
    subgraph "Services Layer"
        direction TB
        AuthService["AuthService"]:::service
        DoctorService["DoctorService"]:::service
        PatientService["PatientService"]:::service
        ChatService["ChatService"]:::service
    end

    Login -->|"POST /auth/login"| AuthService
    Register -->|"POST /auth/register"| AuthService
    AdminDash -->|"HTTP GET/POST /admin"| DoctorService
    AdminDocs -->|"HTTP GET/POST /admin/doctors"| DoctorService
    AdminPats -->|"HTTP GET/POST /admin/patients"| PatientService
    DocDash -->|"HTTP GET/POST /doctor"| DoctorService
    DocMsgs -->|"WS CONNECT/SUBSCRIBE"| ChatService
    DocPresc -->|"HTTP GET/POST /doctor/prescriptions"| DoctorService
    DocAppts -->|"HTTP GET/POST /doctor/appointments"| DoctorService
    PatAppt -->|"HTTP GET/POST /patient/appointments"| PatientService
    PatLab -->|"HTTP GET/POST /patient/lab-results"| PatientService
    PatHist -->|"HTTP GET/POST /patient/history"| PatientService
    PatMsgs -->|"WS CONNECT/SUBSCRIBE"| ChatService
    PatPresc -->|"HTTP GET/POST /patient/prescriptions"| PatientService
    AuthGuard -->|"JWT Validation"| AuthService

    %% Integration Layer
    subgraph "Integration Layer"
        direction TB
        REST["REST API Server"]:::external
        WS["WebSocket Chat Server"]:::external
    end

    AuthService -->|"HTTP GET/POST /auth"| REST
    DoctorService -->|"HTTP"| REST
    PatientService -->|"HTTP"| REST
    ChatService -->|"WS"| WS

    %% Data Layer
    subgraph "Data Layer"
        DB["Database"]:::database
    end

    REST -->|"Read/Write"| DB

    %% Click Events
    click Router "https://github.com/dheer2005/smarthealthcare/blob/main/src/app/app.routes.ts"
    click SP "https://github.com/dheer2005/smarthealthcare/blob/main/src/main.ts"
    click Login "https://github.com/dheer2005/smarthealthcare/blob/main/src/Authentication/login/login.component.ts"
    click Register "https://github.com/dheer2005/smarthealthcare/blob/main/src/Authentication/register/register.component.ts"
    click AdminDash "https://github.com/dheer2005/smarthealthcare/blob/main/src/Admin/admin-dashboard/admin-dashboard.component.ts"
    click AdminDocs "https://github.com/dheer2005/smarthealthcare/blob/main/src/Admin/admin-doctors/admin-doctors.component.ts"
    click AdminPats "https://github.com/dheer2005/smarthealthcare/blob/main/src/Admin/admin-patients/admin-patients.component.ts"
    click DocDash "https://github.com/dheer2005/smarthealthcare/blob/main/src/Doctor/dashboard/dashboard.component.ts"
    click DocMsgs "https://github.com/dheer2005/smarthealthcare/blob/main/src/Doctor/messages/messages.component.ts"
    click DocPresc "https://github.com/dheer2005/smarthealthcare/blob/main/src/Doctor/prescriptions/prescriptions.component.ts"
    click DocAppts "https://github.com/dheer2005/smarthealthcare/blob/main/src/Doctor/requested-appointments/requested-appointments.component.ts"
    click PatAppt "https://github.com/dheer2005/smarthealthcare/blob/main/src/Patient/appointment/appointment.component.ts"
    click PatLab "https://github.com/dheer2005/smarthealthcare/blob/main/src/Patient/lab-results/lab-results.component.ts"
    click PatHist "https://github.com/dheer2005/smarthealthcare/blob/main/src/Patient/patient-history/patient-history.component.ts"
    click PatMsgs "https://github.com/dheer2005/smarthealthcare/blob/main/src/Patient/patient-messages/patient-messages.component.ts"
    click PatPresc "https://github.com/dheer2005/smarthealthcare/blob/main/src/Patient/patient-prescription/patient-prescription.component.ts"
    click AuthGuard "https://github.com/dheer2005/smarthealthcare/blob/main/src/Guards/auth.guard.ts"
    click AuthService "https://github.com/dheer2005/smarthealthcare/blob/main/src/Service/authentication.service.ts"
    click DoctorService "https://github.com/dheer2005/smarthealthcare/blob/main/src/Service/doctor.service.ts"
    click PatientService "https://github.com/dheer2005/smarthealthcare/blob/main/src/Service/patient.service.ts"
    click ChatService "https://github.com/dheer2005/smarthealthcare/blob/main/src/Service/chat.service.ts"
    click DB "https://github.com/dheer2005/smarthealthcare/blob/main/src/index.html"

    %% Styles
    classDef client fill:#AEDFF7,stroke:#036B9C,color:#000;
    classDef spa fill:#FCEBB6,stroke:#F0A202,color:#000;
    classDef module fill:#C8FACC,stroke:#3CAEA3,color:#000;
    classDef component fill:#FFDAC1,stroke:#FF9A76,color:#000;
    classDef service fill:#E2F0CB,stroke:#539165,color:#000;
    classDef guard fill:#F4CCCC,stroke:#CC0000,color:#000;
    classDef external fill:#E3E3E3,stroke:#7D7D7D,stroke-dasharray: 5 5,color:#000;
    classDef database fill:#F1D1B5,stroke:#C37B89,color:#000;
```
