# sayan706/sahihealth-backend architecture

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

- Interactive diagram: https://gitdiagram.com/sayan706/sahihealth-backend
- Repository: https://github.com/sayan706/sahihealth-backend

## Overview

##### Project Type and Purpose
- This is a Django-based backend service (“SahiHealth-Backend”) exposing a RESTful API for a healthcare application.
- It handles user management, appointments, cases, prescriptions, and related domain entities via versioned endpoints under `/api/v1/…`.

##### File Structure Analysis
- Top-level:
- `manage.py` – Django management entrypoint
- `project/` – Django settings, URL routing (ASGI/WGSI)
- `app/` – Core application logic: models, serializers, views, migrations, middlewares, signals
- `app/v1/…` – Version-1 API modules, each resource as its own Django app folder with `views.py`
- `utils/` – Cross-cutting exception and response handlers
- `media/` & `static/` – Static assets, admin and DRF UI, uploaded files
- `templates/` – HTML templates (e.g., prescription printing)
- `requirements.txt`, `.env-template`, `.gitignore`, `LICENSE`, `README.md`
- Architectural patterns:
- Layered MVC (Views → Serializers → Models → DB)
- Versioned API structure under `app/v1/`
- Custom middleware and signal hooks for cross-cutting concerns

##### README Insights
- Confirms this is strictly the backend for SahiHealth, using Django/DRF.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Clients["Web/Mobile Clients"]:::external

    %% Gateway Layer
    NGINX["Nginx API Gateway/Load Balancer"]:::gateway

    %% App Server
    Gunicorn["Gunicorn/Daphne App Server"]:::compute

    %% Django Application
    subgraph "Django Application"
        direction TB
        Router["URL Router (project/urls.py)"]:::app
        click Router "https://github.com/sayan706/sahihealth-backend/blob/main/project/urls.py"

        subgraph "View Layer"
            direction TB
            GlobalViews["Global Views (app/views.py)"]:::app
            click GlobalViews "https://github.com/sayan706/sahihealth-backend/blob/main/app/views.py"
            APIV1Router["API v1 Router (app/v1/urls.py)"]:::app
            click APIV1Router "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/urls.py"
        end

        subgraph "API v1 Endpoints"
            direction TB
            AuthView["Auth Views"]:::app
            click AuthView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/auth/views.py"
            PatientView["Patient Views"]:::app
            click PatientView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/patient/views.py"
            DoctorView["Doctor Views"]:::app
            click DoctorView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/doctor/views.py"
            AppointmentView["Appointment Views"]:::app
            click AppointmentView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/appointment/views.py"
            CaseView["Case Views"]:::app
            click CaseView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/case/views.py"
            PrescriptionView["Prescription Views"]:::app
            click PrescriptionView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/prescription/views.py"
            ProfileView["Profile Views"]:::app
            click ProfileView "https://github.com/sayan706/sahihealth-backend/blob/main/app/v1/profile/views.py"
            %% additional v1 views omitted for brevity
        end

        subgraph "Serialization Layer"
            direction TB
            UserSer["user.py"]:::app
            click UserSer "https://github.com/sayan706/sahihealth-backend/blob/main/app/serializers/user.py"
            PatientSer["patient.py"]:::app
            click PatientSer "https://github.com/sayan706/sahihealth-backend/blob/main/app/serializers/patient.py"
            CaseSer["case.py"]:::app
            click CaseSer "https://github.com/sayan706/sahihealth-backend/blob/main/app/serializers/case.py"
            PrescriptionSer["prescription.py"]:::app
            click PrescriptionSer "https://github.com/sayan706/sahihealth-backend/blob/main/app/serializers/prescription.py"
            %% additional serializers omitted for brevity
        end

        subgraph "Domain Layer"
            direction TB
            Models["Models (app/models.py)"]:::app
            click Models "https://github.com/sayan706/sahihealth-backend/blob/main/app/models.py"
            ModelMgr["Model Manager (app/model_manager.py)"]:::app
            click ModelMgr "https://github.com/sayan706/sahihealth-backend/blob/main/app/model_manager.py"
        end

        subgraph "Cross-Cutting"
            direction TB
            Middleware["Middleware (app/middlewares.py)"]:::util
            click Middleware "https://github.com/sayan706/sahihealth-backend/blob/main/app/middlewares.py"
            Signals["Signals (app/signals.py)"]:::util
            click Signals "https://github.com/sayan706/sahihealth-backend/blob/main/app/signals.py"
            ExceptionUtils["Exception Handler (utils/exception_handler.py)"]:::util
            click ExceptionUtils "https://github.com/sayan706/sahihealth-backend/blob/main/utils/exception_handler.py"
            ResponseUtils["Response Handler (utils/response_handler.py)"]:::util
            click ResponseUtils "https://github.com/sayan706/sahihealth-backend/blob/main/utils/response_handler.py"
        end
    end

    %% Persistence & Storage
    subgraph "Persistence & Storage"
        direction TB
        Database[(PostgreSQL/MySQL)]:::data
        Migrations["Migrations (app/migrations/)"]:::data
        MediaStorage[(Media Storage)]:::data
        StaticAssets[(Static Assets)]:::data
        Templates["HTML Templates"]:::data
        click Templates "https://github.com/sayan706/sahihealth-backend/blob/main/templates/prescription.html"
    end

    %% External Services
    subgraph "External Services"
        EmailSMS["Email/SMS Service"]:::external
        Monitoring["Monitoring/Logging"]:::external
    end

    %% Dependencies & Env
    Requirements["requirements.txt"]:::util
    GIT[".gitignore/README.md/LICENSE"]:::util

    %% Connections
    Clients -->|HTTPS Request| NGINX
    NGINX -->|Reverse Proxy| Gunicorn
    Gunicorn -->|WSGI/ASGI| Router

    Router -->|route to view| GlobalViews
    Router -->|route to v1| APIV1Router

    APIV1Router -->|dispatch| AuthView
    APIV1Router --> PatientView
    APIV1Router --> DoctorView
    APIV1Router --> AppointmentView
    APIV1Router --> CaseView
    APIV1Router --> PrescriptionView
    APIV1Router --> ProfileView

    GlobalViews --> ExceptionUtils
    AuthView --> UserSer
    PatientView --> PatientSer
    CaseView --> CaseSer
    PrescriptionView --> PrescriptionSer

    UserSer --> Models
    PatientSer --> Models
    CaseSer --> Models
    PrescriptionSer --> Models

    Models -->|ORM Query| Database
    ModelMgr -->|custom queries| Database
    Migrations --> Database

    AuthView --> MediaStorage
    GlobalViews --> StaticAssets
    GlobalViews --> Templates

    AuthView -->|signals| Signals -.-> Models
    Middleware --> Router
    ExceptionUtils --> GlobalViews

    Database -->|events| Monitoring
    EmailSMS -->|notifications| Clients

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef gateway fill:#87CEEB,stroke:#333,stroke-width:1px
    classDef app fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef util fill:#FFDAB9,stroke:#333,stroke-width:1px
```
