# akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction architecture

> Architecture diagram of the GitHub repository akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction
- Repository: https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction

## Overview

##### Project type and purpose
- This is a full-stack web application combining a Next.js-based React frontend with a Python microservice backend for ECG (electrocardiogram) arrhythmia prediction using a pre-trained ResNet50 model.
- The frontend handles UI, user input (ECG data or images), and presentation of health tips and prediction results. The backend (ecg-backend/app.py) exposes a REST API, loads the ResNet model, and returns arrhythmia classifications.

##### File structure
- Top-level files: Next.js configuration (next.config.ts, tsconfig.json), Tailwind CSS config, package.json, public assets.
- /public/images: static images served by Next.js.
- /src/app: Next.js App Router directory (Components subfolder, layout.tsx, page.tsx). Components include HealthTips.tsx and PredictionResult.tsx.
- /ecg-backend: a standalone Python service with app.py (likely Flask or FastAPI), requirements.txt, a Jupyter notebook for model training, and the trained_model folder containing resnet50_model2.keras.

##### README
- Confirms that the frontend is a standard Next.js app (bootstrapped with create-next-app).
- No mention of the ECG backend; infer that you need to document it yourself as an external microservice.

##### Main components & relationships
a. Frontend (Next.js + React + Tailwind CSS)
b. Backend microservice (Python + Flask/FastAPI)
c. ML Model (ResNet50 .keras file loaded by the backend)
d. Browser / Client
e. Potential deployment hosts (e.g., Vercel for frontend, AWS/GCP/Docker for backend)

Interactions:
- User (browser) → Next.js UI: uploads ECG data / requests prediction.
- Next.js → Python backend: HTTP POST/GET to /predict endpoint.
- Python backend → ResNet model: run inference, return JSON classification.
- Next.js UI ← receives JSON → renders PredictionResult component.
- HealthTips component reads static data or optional external health-tips service.

##### Architectural patterns & design principles
- Microservices: clear separation of concerns between UI (JavaScript/TypeScript) and compute-heavy ML tasks (Python).
- API-driven design: REST or RPC between front and back.
- Componentized UI: React components under src/app/Components.
- Model serving pattern: backend loads model once on startup and processes each request.
- Static vs. dynamic: public/ folder and Next.js static optimization vs. dynamic backend inference.

##### Essential details to capture
- Clear separation between UI, API, and model inference tiers.
- The fact that the model is loaded from a local file and served in-process.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client
    Browser["User Browser"]:::client

    %% Frontend Layer
    subgraph "Frontend (Next.js v13 App Router)" 
        direction TB
        NextJS["Next.js App<br/>(React, Tailwind CSS)"]:::frontend
        subgraph "UI Components"
            direction TB
            Layout["layout.tsx"]:::frontend
            Page["page.tsx"]:::frontend
            HealthTips["HealthTips.tsx"]:::frontend
            PredictionResult["PredictionResult.tsx"]:::frontend
        end
        StaticAssets["public/images"]:::static
        GlobalsCSS["globals.css"]:::frontend
        NextConfig["next.config.ts"]:::frontend
        TailwindConfig["tailwind.config.ts"]:::frontend
        PostCSSConfig["postcss.config.mjs"]:::frontend
        TSConfig["tsconfig.json"]:::frontend
        PackageJSON["package.json"]:::frontend

        NextJS --> Layout
        NextJS --> Page
        Page --> HealthTips
        Page --> PredictionResult
        NextJS --> StaticAssets
        NextJS --> GlobalsCSS
        NextJS --> NextConfig
        NextJS --> TailwindConfig
        NextJS --> PostCSSConfig
        NextJS --> TSConfig
        NextJS --> PackageJSON
    end

    %% Backend Layer
    subgraph "Backend: ECG Prediction Service (Python 3.x)" 
        direction TB
        API["app.py<br/>(Flask/FastAPI)"]:::backend
        Requirements["requirements.txt"]:::backend
        Notebook["Cardiac_Arrhythmia_ResNet_Train.ipynb"]:::backend
        subgraph "ML Model"
            direction TB
            ModelFile["resnet50_model2.keras"]:::model
        end
        API --> ModelFile
    end

    %% Data Flows
    Browser -->|"HTTP GET/POST"| NextJS
    NextJS -->|"/predict POST"| API
    API -->|"JSON response"| NextJS
    NextJS -->|"Render UI"| Browser

    %% Click Events
    click Layout "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/src/app/layout.tsx"
    click Page "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/src/app/page.tsx"
    click HealthTips "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/src/app/Components/HealthTips.tsx"
    click PredictionResult "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/src/app/Components/PredictionResult.tsx"
    click StaticAssets "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/tree/main/public/images"
    click GlobalsCSS "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/src/app/globals.css"
    click NextConfig "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/next.config.ts"
    click TailwindConfig "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/tailwind.config.ts"
    click PostCSSConfig "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/postcss.config.mjs"
    click TSConfig "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/tsconfig.json"
    click PackageJSON "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/package.json"
    click API "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/ecg-backend/app.py"
    click Requirements "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/ecg-backend/requirements.txt"
    click ModelFile "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/ecg-backend/trained_model/resnet50_model2.keras"
    click Notebook "https://github.com/akash-selvaraj/ecg-based-cardiac-arrhythmia-prediction/blob/main/ecg-backend/Cardiac_Arrhythmia_ResNet_Train.ipynb"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef frontend fill:#DFFFE0,stroke:#228B22,color:#228B22;
    classDef backend fill:#FFE0B2,stroke:#FF8C00,color:#FF8C00;
    classDef model fill:#E0E0E0,stroke:#A9A9A9,color:#000000;
    classDef static fill:#F0F0F0,stroke:#696969,color:#696969;
```
