# charan-143/medical architecture

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

- Interactive diagram: https://gitdiagram.com/charan-143/medical
- Repository: https://github.com/charan-143/medical

## Overview

##### Project type and purpose
- This is a full‑stack web application (“Medical Dashboard”) built with Flask.
- Purpose: manage and organize medical records, real‑time chat, PDF report generation, folder hierarchies, and AI‑powered features.

##### File structure
- Top‑level:
- app.py – Flask application entry point
- config.py – environment configurations
- extensions.py – initialization of Flask extensions (SQLAlchemy, SocketIO, WTForms, etc.)
- models.py – central SQLAlchemy model definitions
- migrations/ – database migration scripts
- requirements.txt – Python dependencies
- README.md
- Modular “blueprints/” directory with subpackages:
- auth/ – forms.py, models.py, routes.py for login, registration, profile
- chat/ – routes.py handling real‑time chat via Flask‑SocketIO
- dashboard/ – routes.py for record views, uploads, AI, PDF
- Static assets (JS, CSS, images, uploads) and Jinja2 HTML templates mirror blueprint modules.

##### README for additional insights
- Uses Flask‑Login, bcrypt, Flask‑WTF for security/forms.
- Real‑time comm via Flask‑SocketIO.
- File storage on local “static/uploads” and optional AWS S3 (boto3).
- PDF generation via pdfkit.
- AI integration with Google Generative AI API.
- Deployment under Gunicorn.

##### Elements
- Labels for each component (e.g., “Auth Blueprint”, “Chat Blueprint”, “SQLite DB”, “S3 Bucket”, “Google AI API”)
- HTTP request/response
- WebSocket events
- Database reads/writes
- External API calls
- Blue for backend components
- Green for external services
- Orange for database/storage
- Yellow for real‑time communication

##### Detail
- Break the Flask app into subcomponents (extensions, blueprints, models).
- For each blueprint, show key routes and their interactions with models and services.
- Which components talk to AWS S3 (uploads) vs. local storage.
- PDF generation flow from request to wkhtmltopdf engine to user download.
- AI integration call flow: dashboard controller → Google AI → response merged into view.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["User's Web Browser"]:::frontend
    Browser -- HTTP/HTTPS --> WebServer["Gunicorn/WSGI Server"]:::backend
    Browser -- WebSocket --> SocketIO["Flask-SocketIO"]:::realtime

    WebServer --> FlaskApp["Flask Application"]:::backend
    SocketIO --> FlaskApp

    subgraph "Flask App Components"
        direction TB
        AppEntry["app.py"]:::backend
        Config["config.py"]:::backend
        Extensions["extensions.py"]:::backend
        Models["models.py"]:::backend
        subgraph "Blueprints"
            direction TB
            subgraph "Auth Blueprint"
                direction TB
                AuthForms["forms.py"]:::backend
                AuthModels["models.py"]:::backend
                AuthRoutes["routes.py"]:::backend
            end
            subgraph "Chat Blueprint"
                direction TB
                ChatRoutes["routes.py"]:::backend
                ChatClient["static/js/chat.js"]:::frontend
            end
            subgraph "Dashboard Blueprint"
                direction TB
                DashRoutes["routes.py"]:::backend
            end
        end
    end

    FlaskApp --> AppEntry
    FlaskApp --> Config
    FlaskApp --> Extensions
    FlaskApp --> Models

    AuthRoutes --> AuthForms
    AuthRoutes --> AuthModels
    AuthRoutes --> Models

    ChatRoutes --> Extensions
    ChatClient --> ChatRoutes

    DashRoutes --> Extensions
    DashRoutes --> Models

    subgraph "Persistence & Storage"
        direction TB
        DB["SQLite Database"]:::db
        Migrations["migrations/"]:::backend
        Uploads["Local Uploads (static/uploads)"]:::db
        S3["AWS S3 Bucket"]:::external
    end

    Extensions --> DB
    Extensions --> Migrations
    DashRoutes --> Uploads
    DashRoutes --> S3

    subgraph "External Services"
        direction TB
        GoogleAI["Google Generative AI API"]:::external
        PDFEngine["wkhtmltopdf/pdfkit"]:::external
    end

    DashRoutes --> GoogleAI
    DashRoutes --> PDFEngine

    classDef backend fill:#D6EAF8,stroke:#1F618D,color:#1B4F72;
    classDef external fill:#D5F5E3,stroke:#27AE60,color:#145A32;
    classDef db fill:#FCF3CF,stroke:#F1C40F,color:#7D6608;
    classDef realtime fill:#FDEDEC,stroke:#E74C3C,color:#641E16;
    classDef frontend fill:#EBDEF0,stroke:#8E44AD,color:#512E5F;

    click AppEntry "https://github.com/charan-143/medical/blob/main/app.py"
    click Config "https://github.com/charan-143/medical/blob/main/config.py"
    click Extensions "https://github.com/charan-143/medical/blob/main/extensions.py"
    click Models "https://github.com/charan-143/medical/blob/main/models.py"
    click Migrations "https://github.com/charan-143/medical/tree/main/migrations/"
    click AuthForms "https://github.com/charan-143/medical/blob/main/blueprints/auth/forms.py"
    click AuthModels "https://github.com/charan-143/medical/blob/main/blueprints/auth/models.py"
    click AuthRoutes "https://github.com/charan-143/medical/blob/main/blueprints/auth/routes.py"
    click ChatRoutes "https://github.com/charan-143/medical/blob/main/blueprints/chat/routes.py"
    click ChatClient "https://github.com/charan-143/medical/blob/main/static/js/chat.js"
    click DashRoutes "https://github.com/charan-143/medical/blob/main/blueprints/dashboard/routes.py"
    click Uploads "https://github.com/charan-143/medical/tree/main/static/uploads/"
```
