# siddharthrepo/hackandheal architecture

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

- Interactive diagram: https://gitdiagram.com/siddharthrepo/hackandheal
- Repository: https://github.com/siddharthrepo/hackandheal

## Overview

##### Project Type & Purpose
- Chikitsa360 is a full-stack telehealth web application built on Django. It enables patients to register, book appointments, join HD video calls (WebRTC via Daily.co), and receive live transcriptions (Deepgram). It also supports chat, payments (Razorpay), and post-consultation records.

##### File Structure Analysis
- Top-level Django project:
- manage.py
- chikitsa360/ (ASGI/WSGI entrypoints, settings, main urls)
- Django apps (each implements a core domain/service):
- auth_app (accounts, RBAC, login/registration)
- chat_app (real-time messaging via Django Channels)
- consultation_app (scheduling, video room templates, bookings)
- payment_app (Razorpay integration, receipts)
- transcription_app (Deepgram API wrapper, email summaries)
- Static content: CSS/JS/images under static & staticfiles
- Templates: organized by feature (auth, consultation, payment, transcription, admin)

##### Key Architecture from README
- Web framework: Django (MVC)
- Real-time: Django Channels + ASGI
- Database: PostgreSQL
- Video: Daily.co (WebRTC)
- Transcription: Deepgram API
- Payments: Razorpay (work in progress)
- Deployment: Koyeb (cloud host)

##### Main Components
A. Client Layer
- Browser/mobile (HTML/CSS/JS, video & WebSocket clients)
B. Web/API Layer
- Django (WSGI for HTTP, ASGI for WebSocket)
- URL routing into feature apps
- Frontend assets served via staticfiles & Django’s Static Middleware or CDN
C. Real-Time Layer
- Django Channels
- Redis (or in-memory channel layer) for pub/sub
D. Data Layer
- PostgreSQL database
E. External Services
- Daily.co (WebRTC signaling and media)
- Deepgram (speech-to-text API)
- Razorpay (payment gateway)
- SMTP/email service (appointment & transcript emails)

##### Component Interactions
1. User HTTP ➔ Django WSGI ➔ Auth/App business logic ➔ PostgreSQL
2. User opens video room ➔ WebSocket handshake ➔ Django Channels/ASGI ➔ Redis channel layer
3. Django Channels signals to Daily.co for WebRTC peer negotiation; media streams directly between clients & Daily.co
4. During calls, audio chunks forwarded to Deepgram via transcription_app.services; transcript returned and persisted in DB
5. Payment flow: frontend JS ➔ payment_app endpoint ➔ Razorpay API ➔ callback ➔ receipt generation ➔ DB
6. Notification flow: actions (appointment created, transcript ready) ➔ email service via SMTP or external mail API

##### Architectural Patterns & Principles
- Modular Django apps: feature-based separation (auth, chat, consultation, payment, transcription)
- MVC: models in each app, central template layer, views/controllers handling HTTP & WebSockets
- Asynchronous messaging: Channels + Redis for scaling real-time features
- Service integration layer: dedicated modules wrapping third-party APIs
- Secure design: role-based access, encryption in transit (HTTPS, WSS), environment-driven config

##### Detail
- Django app as its own sub-component.
- Both synchronous (HTTP) and asynchronous (WebSocket, API callbacks) interactions.
- Environmental boundaries (on-prem Django host vs cloud-hosted external services).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Browser["Browser/Mobile\n(HTML/CSS/JS)"]:::client
    end

    %% Application Layer
    subgraph "Django Application"
        direction TB

        %% WSGI Server
        WSGI["Django WSGI Server"]:::django

        %% ASGI Server & Channels
        ASGI["Django ASGI Server\n(Django Channels)"]:::django
    end

    Browser -->|HTTPS| WSGI
    Browser -->|WSS / WebRTC| ASGI

    %% Django Core Files
    subgraph "Django Core" 
        direction TB
        manage["manage.py"]:::django
        asgi_conf["asgi.py"]:::django
        wsgi_conf["wsgi.py"]:::django
        settings["settings.py"]:::django
        urls_conf["urls.py"]:::django
    end

    WSGI --> manage
    WSGI --> settings
    WSGI --> urls_conf
    ASGI --> asgi_conf
    ASGI --> urls_conf

    click manage "https://github.com/siddharthrepo/hackandheal/blob/main/manage.py"
    click asgi_conf "https://github.com/siddharthrepo/hackandheal/blob/main/chikitsa360/asgi.py"
    click wsgi_conf "https://github.com/siddharthrepo/hackandheal/blob/main/chikitsa360/wsgi.py"
    click settings "https://github.com/siddharthrepo/hackandheal/blob/main/chikitsa360/settings.py"
    click urls_conf "https://github.com/siddharthrepo/hackandheal/blob/main/chikitsa360/urls.py"

    %% Feature Apps
    subgraph "Auth Service (auth_app)" 
        direction TB
        auth_models["models.py"]:::django
        auth_views["views.py"]:::django
        auth_urls["urls.py"]:::django
        auth_forms["forms.py"]:::django
        auth_backends["backends.py"]:::django
        auth_mixins["mixins.py"]:::django
    end
    WSGI --> auth_views
    click auth_models "https://github.com/siddharthrepo/hackandheal/blob/main/auth_app/models.py"
    click auth_views "https://github.com/siddharthrepo/hackandheal/blob/main/auth_app/views.py"
    click auth_urls "https://github.com/siddharthrepo/hackandheal/blob/main/auth_app/urls.py"
    click auth_forms "https://github.com/siddharthrepo/hackandheal/blob/main/auth_app/forms.py"
    click auth_backends "https://github.com/siddharthrepo/hackandheal/blob/main/auth_app/backends.py"
    click auth_mixins "https://github.com/siddharthrepo/hackandheal/blob/main/auth_app/mixins.py"

    subgraph "Chat Service (chat_app)" 
        direction TB
        chat_consumers["consumers.py"]:::django
        chat_routing["routing.py"]:::django
        chat_urls["urls.py"]:::django
        chat_models["models.py"]:::django
        chat_views["views.py"]:::django
    end
    ASGI --> chat_consumers
    click chat_consumers "https://github.com/siddharthrepo/hackandheal/blob/main/chat_app/consumers.py"
    click chat_routing "https://github.com/siddharthrepo/hackandheal/blob/main/chat_app/routing.py"
    click chat_urls "https://github.com/siddharthrepo/hackandheal/blob/main/chat_app/urls.py"
    click chat_models "https://github.com/siddharthrepo/hackandheal/blob/main/chat_app/models.py"
    click chat_views "https://github.com/siddharthrepo/hackandheal/blob/main/chat_app/views.py"

    subgraph "Consultation Service (consultation_app)" 
        direction TB
        cons_models["models.py"]:::django
        cons_models_new["models_new.py"]:::django
        cons_views["views.py"]:::django
        cons_forms["forms.py"]:::django
        cons_urls["urls.py"]:::django
        cons_filters["form_filters.py"]:::django
        video_tmpl["video_room.html"]:::django
        appt_tmpl["appointment_detail.html"]:::django
    end
    WSGI --> cons_views
    click cons_models "https://github.com/siddharthrepo/hackandheal/blob/main/consultation_app/models.py"
    click cons_models_new "https://github.com/siddharthrepo/hackandheal/blob/main/consultation_app/models_new.py"
    click cons_views "https://github.com/siddharthrepo/hackandheal/blob/main/consultation_app/views.py"
    click cons_forms "https://github.com/siddharthrepo/hackandheal/blob/main/consultation_app/forms.py"
    click cons_urls "https://github.com/siddharthrepo/hackandheal/blob/main/consultation_app/urls.py"
    click cons_filters "https://github.com/siddharthrepo/hackandheal/blob/main/consultation_app/templatetags/form_filters.py"
    click video_tmpl "https://github.com/siddharthrepo/hackandheal/blob/main/templates/consultation/video_room.html"
    click appt_tmpl "https://github.com/siddharthrepo/hackandheal/blob/main/templates/consultation/appointment_detail.html"

    subgraph "Payment Service (payment_app)" 
        direction TB
        pay_models["models.py"]:::django
        pay_views["views.py"]:::django
        pay_urls["urls.py"]:::django
        checkout_tmpl["checkout.html"]:::django
        receipt_tmpl["receipt.html"]:::django
    end
    WSGI --> pay_views
    click pay_models "https://github.com/siddharthrepo/hackandheal/blob/main/payment_app/models.py"
    click pay_views "https://github.com/siddharthrepo/hackandheal/blob/main/payment_app/views.py"
    click pay_urls "https://github.com/siddharthrepo/hackandheal/blob/main/payment_app/urls.py"
    click checkout_tmpl "https://github.com/siddharthrepo/hackandheal/blob/main/templates/payment/checkout.html"
    click receipt_tmpl "https://github.com/siddharthrepo/hackandheal/blob/main/templates/payment/receipt.html"

    subgraph "Transcription Service (transcription_app)" 
        direction TB
        trans_services["services.py"]:::django
        trans_models["models.py"]:::django
        trans_views["views.py"]:::django
        trans_urls["urls.py"]:::django
        email_doc["email_doctor.html"]:::django
        email_pat["email_patient.html"]:::django
    end
    WSGI --> trans_views
    click trans_services "https://github.com/siddharthrepo/hackandheal/blob/main/transcription_app/services.py"
    click trans_models "https://github.com/siddharthrepo/hackandheal/blob/main/transcription_app/models.py"
    click trans_views "https://github.com/siddharthrepo/hackandheal/blob/main/transcription_app/views.py"
    click trans_urls "https://github.com/siddharthrepo/hackandheal/blob/main/transcription_app/urls.py"
    click email_doc "https://github.com/siddharthrepo/hackandheal/blob/main/templates/transcription/email_doctor.html"
    click email_pat "https://github.com/siddharthrepo/hackandheal/blob/main/templates/transcription/email_patient.html"

    %% Static & Templates
    subgraph "Frontend Assets & Templates"
        direction TB
        css1["custom.css"]:::static
        css2["tailwind.css"]:::static
        js_video["video.js"]:::static
        js_chat["chat.js"]:::static
        js_pay["payment.js"]:::static
        js_main["main.js"]:::static
        base_tmpl["base.html"]:::django
        auth_login["login.html"]:::django
        auth_reg["register.html"]:::django
        auth_prof["profile.html"]:::django
        auth_edit["edit_profile.html"]:::django
        auth_updoc["update_doctor_profile.html"]:::django
        staticfiles["staticfiles/"]:::static
    end
    click css1 "https://github.com/siddharthrepo/hackandheal/blob/main/static/css/custom.css"
    click css2 "https://github.com/siddharthrepo/hackandheal/blob/main/static/css/tailwind.css"
    click js_video "https://github.com/siddharthrepo/hackandheal/blob/main/static/js/video.js"
    click js_chat "https://github.com/siddharthrepo/hackandheal/blob/main/static/js/chat.js"
    click js_pay "https://github.com/siddharthrepo/hackandheal/blob/main/static/js/payment.js"
    click js_main "https://github.com/siddharthrepo/hackandheal/blob/main/static/js/main.js"
    click staticfiles "https://github.com/siddharthrepo/hackandheal/tree/main/staticfiles/"

    WSGI --> base_tmpl
    WSGI --> auth_login
    WSGI --> auth_reg
    WSGI --> auth_prof
    WSGI --> auth_edit
    WSGI --> auth_updoc

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Postgres["PostgreSQL"]:::db
        Redis["Redis (Channels Layer)"]:::db
    end
    WSGI -->|SQL| Postgres
    ASGI -->|Pub/Sub| Redis
    WSGI -->|SQL| Postgres
    trans_services -->|Persist Transcript| Postgres
    pay_views -->|Store Receipt| Postgres

    %% External Services
    subgraph "External Services"
        direction TB
        Dailyco["Daily.co WebRTC"]:::external
        Deepgram["Deepgram API"]:::external
        Razorpay["Razorpay API"]:::external
        EmailSrv["SMTP/Email Service"]:::external
    end
    ASGI -->|Signal| Dailyco
    Browser -->|Media Streams| Dailyco
    trans_services -->|REST| Deepgram
    pay_views -->|REST| Razorpay
    auth_views -->|Email| EmailSrv
    cons_views -->|Email| EmailSrv
    trans_services -->|Email| EmailSrv

    %% Legend
    subgraph "Legend"
        direction TB
        client["Client\n(Gray)"]:::client
        django_["Django\n(Blue)"]:::django
        datastore["Datastore\n(Green)"]:::db
        ext["External API\n(Orange)"]:::external
    end

    %% Styles
    classDef django fill:#D0E6FF,stroke:#4A90E2,stroke-width:1px;
    classDef client fill:#EEEEEE,stroke:#888888,stroke-width:1px;
    classDef db fill:#E6F8E0,stroke:#3C763D,stroke-width:1px;
    classDef external fill:#FFE6CC,stroke:#E08D00,stroke-width:1px;
    classDef static fill:#F5F5F5,stroke:#AAAAAA,stroke-width:1px;
```
