# ysohaarsh/hospital_management_system architecture

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

- Interactive diagram: https://gitdiagram.com/ysohaarsh/hospital_management_system
- Repository: https://github.com/ysohaarsh/hospital_management_system

## Overview

##### Project Type and Purpose
- This is a web-based hospital management system. Its purpose is to provide functionalities for managing hospital processes such as doctor management, appointment scheduling, chat communication, complaints handling, employee management, user authentication (login, signup, reset/set password), and receipt generation.
- It is a full-stack web application built using Node.js/Express (backend), MySQL (database), and EJS for templating (front-end view rendering). The design also incorporates client-side elements (HTML, CSS, JavaScript) residing mainly under the “public” directory.

##### File Structure
- Key directories:
- controllers: Holds individual route handlers and business logic for features (e.g., add_doctor.js, appointment.js, chat.js, etc.).
- models: Contains database connection logic (db_controller.js) that interfaces with MySQL.
- views: Contains EJS templates used for rendering dynamic HTML pages (e.g., home.ejs, login.ejs, signup.ejs, etc.).
- public: Contains static assets (CSS, fonts, JavaScript, images, and even a separate “182 Medico -DOC” subdirectory that seems to deliver a front-end theme).
- Other important files include app.js (the entry-point that sets up Express, middleware, and routing) and nodelogin.sql (SQL script to create the required database).

##### README for Additional Insights
- The README highlights the system architecture, explaining various features and the overall workflow (sign up, verify, login, book appointments, etc.).
- It details configuration steps for the database and email service.

a. Main Components:
- Client/User Interface: This includes static assets and EJS views served from the “public” and “views” directories.
- Web Server (Backend Application):
- app.js serves as the main entry point.
- Controllers (in the “controllers” directory) handle business logic for various functionalities (doctor, appointment, chat, complaint, etc.).
- Models (in the “models” directory) manage database operations via MySQL.
- Database: MySQL, represented by the nodelogin.sql schema and managed via the models.
- External Services:
- Email service (via nodemailer) for user verification, password reset, etc.
- Static Content Delivery: The “public” directory includes themes, CSS, images, and client-side JavaScript scripts.

b. Relationships and Interactions:
- The user interacts with the front-end (EJS generated views along with static files) rendered by Express.
- HTTP requests hit the server’s routes (defined in app.js) and are then mapped to various controllers.
- Each controller processes business logic, possibly interacting with the database through the model (db_controller.js) and with external services (like an email transporter).
- The controllers then render responses via EJS views, sending back HTML or JSON responses as needed.
- There is a clear data flow: Client → Web Server (Express: middleware, controllers) → Database (and vice versa) → Client.

c. Architectural Patterns and Design Principles:
- MVC Pattern: Although not explicitly separated, controllers (business logic), models (data access), and views (EJS templates) follow a loosely MVC-style pattern.
- Separation of Concerns: Different controllers handle discrete functionality (user authentication, appointment scheduling, chat, etc.).
- Modularity: Files and directories are organized by feature (each controller handles a specific area) and resource type (static assets, SQL file).
- Integration with external services like an email server for verification.

d. Relevant Technologies, Frameworks, and Libraries:
- Node.js and Express for the server and routing.
- MySQL as the database.
- EJS for dynamic HTML generation.
- Nodemailer (as indicated in the signup/readme snippet) for sending verification emails.
- Various front-end libraries and frameworks visible under the “public/assets”, “public/css”, “public/js”, and the “182 Medico -DOC” folder.

- From Controllers to Models (data queries and updates).
- From Controllers to Email Service (for verification or alerts).
- Rectangles for components.
- Circles for external services.
- Important configuration points (such as the database setup in db_controller.js and email settings in the signup controller).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client Layer"
        client["Web Browser/Client"]:::client
        ejs["EJS Views"]:::client
        assets["Static Assets"]:::client
    end

    %% Server Layer
    subgraph "Server Layer"
        app["Entry-Point (app.js)"]:::server
        subgraph "Controllers"
            ctrlLogin["Login (controllers/login.js)"]:::server
            ctrlSignup["Signup (controllers/signup.js)"]:::server
            ctrlDoctor["Add Doctor (controllers/add_doctor.js)"]:::server
            ctrlAppointment["Appointment (controllers/appointment.js)"]:::server
            ctrlChat["Chat (controllers/chat.js)"]:::server
            ctrlVerify["Verify (controllers/verify.js)"]:::server
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        model["DB Controller (models/db_controller.js)"]:::data
        db["MySQL Database"]:::data
        schema["Database Schema (nodelogin.sql)"]:::data
    end

    %% External Services
    subgraph "External Services"
        email["Email Service"]:::external
    end

    %% Connections
    client -->|"HTTP_Request"| app
    app -->|"Routing"| ctrlLogin
    app -->|"Routing"| ctrlSignup
    app -->|"Routing"| ctrlDoctor
    app -->|"Routing"| ctrlAppointment
    app -->|"Routing"| ctrlChat
    app -->|"Routing"| ctrlVerify

    ejs --- client
    assets --- client

    ctrlLogin -->|"DB_Query"| model
    ctrlSignup -->|"DB_Query"| model
    ctrlDoctor -->|"DB_Query"| model
    ctrlAppointment -->|"DB_Query"| model
    ctrlChat -->|"DB_Query"| model
    ctrlVerify -->|"DB_Query"| model

    model -->|"DB_Interaction"| db
    db -->|"DB_Response"| model

    schema -->|"Schema_Setup"| db

    ctrlSignup -->|"Send_Email"| email
    ctrlVerify -->|"Send_Email"| email

    ctrlLogin -->|"HTTP_Response"| client
    ctrlSignup -->|"HTTP_Response"| client
    ctrlDoctor -->|"HTTP_Response"| client
    ctrlAppointment -->|"HTTP_Response"| client
    ctrlChat -->|"HTTP_Response"| client
    ctrlVerify -->|"HTTP_Response"| client

    %% Click Events
    click ejs "https://github.com/ysohaarsh/hospital_management_system/tree/master/views/"
    click assets "https://github.com/ysohaarsh/hospital_management_system/tree/master/public/"
    click app "https://github.com/ysohaarsh/hospital_management_system/blob/master/app.js"
    click ctrlLogin "https://github.com/ysohaarsh/hospital_management_system/blob/master/controllers/login.js"
    click ctrlSignup "https://github.com/ysohaarsh/hospital_management_system/blob/master/controllers/signup.js"
    click ctrlDoctor "https://github.com/ysohaarsh/hospital_management_system/blob/master/controllers/add_doctor.js"
    click ctrlAppointment "https://github.com/ysohaarsh/hospital_management_system/blob/master/controllers/appointment.js"
    click ctrlChat "https://github.com/ysohaarsh/hospital_management_system/blob/master/controllers/chat.js"
    click ctrlVerify "https://github.com/ysohaarsh/hospital_management_system/blob/master/controllers/verify.js"
    click model "https://github.com/ysohaarsh/hospital_management_system/blob/master/models/db_controller.js"
    click schema "https://github.com/ysohaarsh/hospital_management_system/blob/master/nodelogin.sql"

    %% Styles
    classDef client fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef server fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef data fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#333,stroke-width:2px;
```
