# code-sans/hospital-management-system architecture

> Architecture diagram of the GitHub repository code-sans/hospital-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/code-sans/hospital-management-system
- Repository: https://github.com/code-sans/hospital-management-system

## Overview

##### Project Type and Purpose
- This is a full-stack, server-rendered web application built with Python and Flask, serving as a Hospital Management System.
- It supports three user roles—Admin, Doctor, Patient—and provides functionality for registration, authentication, appointment management, and user-specific dashboards.

##### File Structure Analysis
- Entry point: app.py
- Application package (app/):
- __init__.py — initializes Flask app and extensions
- auth.py — login, logout, register routes
- admin.py — admin routes for managing doctors, patients, appointments
- doctor.py — doctor-specific routes (availability, appointments, patient history)
- patient.py — patient-specific routes (search, book appointments, history)
- database.py — ORM initialization (SQLAlchemy) and session setup
- models.py — data models (User, Doctor, Patient, Appointment, etc.)
- Configuration: config.py
- Templates: templates/ organized by role (admin, doctor, patient) plus shared base.html, login.html, register.html
- Requirements: requirements.txt lists Flask, SQLAlchemy, and other dependencies

a. Clients
- Web Browser (Patient, Doctor, Admin)
b. Web Server / Application Layer
- Flask Application (app.py + app package)
- Blueprint Modules (auth, admin, doctor, patient)
- Templating Engine (Jinja2)
c. Data Layer
- Relational Database (e.g., PostgreSQL, SQLite)
- ORM (SQLAlchemy)
d. Configuration
- config.py (environment, database URI, secret key)
e. External Services (optional)
- Email/SMS gateway for notifications (if implemented later)

##### Relationships and Data Flow
1) Browser sends HTTP(S) request to Flask server.
2) app.py routes request to appropriate Blueprint (auth, admin, doctor, patient).
3) Controller accesses models via SQLAlchemy (database.py + models.py).
4) Data fetched/updated in the database.
5) Controller renders templates (templates/**) or returns JSON (if APIs exist).
6) Jinja2 template renders HTML, response sent back to browser.

##### Architectural Patterns and Design Principles
- MVC-style separation:
- Models: app/models.py
- Views: Jinja2 templates in templates/
- Controllers: Blueprints in app/*.py
- Modularization by user role via Flask Blueprints.
- Configuration abstraction (config.py).
- Single codebase but clear role-based routing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        PatientBrowser["Patient Browser"]:::presentation
        DoctorBrowser["Doctor Browser"]:::presentation
        AdminBrowser["Admin Browser"]:::presentation
    end

    %% Application Layer
    subgraph "Flask Application" 
        direction TB
        AppEntry["app.py"]:::application
        Init["__init__.py"]:::application
        Config["config.py"]:::config
        Auth["Authentication Module (auth.py)"]:::application
        AdminMod["Admin Module (admin.py)"]:::application
        DoctorMod["Doctor Module (doctor.py)"]:::application
        PatientMod["Patient Module (patient.py)"]:::application
        TemplEng["Jinja2 Templating Engine"]:::application
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        ORM["ORM Initialization (database.py)"]:::data
        Models["Data Models (models.py)"]:::data
        Database[(Relational Database)]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Notify["Email/SMS Gateway"]:::external
    end

    %% Views Layer
    subgraph "Templates"
        direction TB
        SharedTemplates["Base, Login, Register Templates"]:::presentation
        AdminViews["Admin Views Templates"]:::presentation
        DoctorViews["Doctor Views Templates"]:::presentation
        PatientViews["Patient Views Templates"]:::presentation
    end

    %% Connections
    PatientBrowser -->|"HTTP request"| AppEntry
    DoctorBrowser -->|"HTTP request"| AppEntry
    AdminBrowser -->|"HTTP request"| AppEntry

    AppEntry --> Init
    Init --> Config
    Init --> Auth
    Init --> AdminMod
    Init --> DoctorMod
    Init --> PatientMod

    Auth --> ORM
    AdminMod --> ORM
    DoctorMod --> ORM
    PatientMod --> ORM

    ORM --> Models
    Models --> Database

    AdminMod -->|uses| SharedTemplates
    DoctorMod -->|uses| SharedTemplates
    PatientMod -->|uses| SharedTemplates

    AdminMod -->|renders| AdminViews
    DoctorMod -->|renders| DoctorViews
    PatientMod -->|renders| PatientViews

    AdminMod -->|notification| Notify
    DoctorMod -->|notification| Notify
    PatientMod -->|notification| Notify

    Models --> TemplEng
    TemplEng --> PatientBrowser
    TemplEng --> DoctorBrowser
    TemplEng --> AdminBrowser

    %% Click Events
    click AppEntry "https://github.com/code-sans/hospital-management-system/blob/main/app.py"
    click Init "https://github.com/code-sans/hospital-management-system/blob/main/app/__init__.py"
    click Auth "https://github.com/code-sans/hospital-management-system/blob/main/app/auth.py"
    click AdminMod "https://github.com/code-sans/hospital-management-system/blob/main/app/admin.py"
    click DoctorMod "https://github.com/code-sans/hospital-management-system/blob/main/app/doctor.py"
    click PatientMod "https://github.com/code-sans/hospital-management-system/blob/main/app/patient.py"
    click ORM "https://github.com/code-sans/hospital-management-system/blob/main/app/database.py"
    click Models "https://github.com/code-sans/hospital-management-system/blob/main/app/models.py"
    click Config "https://github.com/code-sans/hospital-management-system/blob/main/config.py"
    click SharedTemplates "https://github.com/code-sans/hospital-management-system/blob/main/templates/base.html"
    click SharedTemplates "https://github.com/code-sans/hospital-management-system/blob/main/templates/login.html"
    click SharedTemplates "https://github.com/code-sans/hospital-management-system/blob/main/templates/register.html"
    click AdminViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/admin/dashboard.html"
    click AdminViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/admin/manage_doctors.html"
    click AdminViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/admin/manage_patients.html"
    click AdminViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/admin/view_appointments.html"
    click DoctorViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/doctor/dashboard.html"
    click DoctorViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/doctor/appointments.html"
    click DoctorViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/doctor/availability.html"
    click DoctorViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/doctor/patient_history.html"
    click PatientViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/patient/dashboard.html"
    click PatientViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/patient/search_doctors.html"
    click PatientViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/patient/book_appointment.html"
    click PatientViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/patient/appointments.html"
    click PatientViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/patient/appointment_history.html"
    click PatientViews "https://github.com/code-sans/hospital-management-system/blob/main/templates/patient/profile.html"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef application fill:#A9DFBF,stroke:#145A32,color:#0B5345
    classDef data fill:#F9E79F,stroke:#7D6608,color:#784212
    classDef config fill:#D5DBDB,stroke:#566573,color:#1C2833
    classDef external fill:#F5B7B1,stroke:#641E16,color:#78281F
```
