# shivamsingh163248/health_privacy_app architecture

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

- Interactive diagram: https://gitdiagram.com/shivamsingh163248/health_privacy_app
- Repository: https://github.com/shivamsingh163248/health_privacy_app

## Overview

##### Project Type and Purpose
- This is a full-stack, monolithic web application built with Flask (Python).
- It provides a web UI (HTML templates) for health-data anonymization, backed by a relational database and supporting utilities.
- It is containerized with Docker, deployed to an Ubuntu EC2 instance via Terraform, and uses GitHub Actions for CI/CD.

##### Key Directories and Files
- app.py, config.py: Flask application entry point and configuration.
- models/database.py, db/schema.sql: Data layer, ORM setup and schema.
- utils/anonymizer.py: Core anonymization logic.
- templates/*.html: View layer (Jinja2 templates).
- docker-compose.yml, Dockerfile: Local multi-container setup vs. single-service container build.
- terraform/*.tf: Infrastructure-as-code provisioning (EC2 instance, security group).
- .github/workflows: CI/CD pipelines (build, push image, deploy).

##### Main Components
a. Client & Browser
- End user’s web browser issuing HTTP(S) requests.
b. AWS Infrastructure
- Terraform Provisioner: creates EC2 instance and security group.
- EC2 Instance: Docker host.
c. Containerized Application
- Docker Engine running a single container from the built health_privacy_app image.
- Flask App (app.py):
- Controller layer handling routes (/login, /dashboard, /anonymize).
- Model layer (models/database.py + SQLAlchemy) interacting with the RDBMS.
- Utility layer (utils/anonymizer.py) performing data anonymization.
- View layer serving templates/*.html.
d. Database
- Relational database (e.g., PostgreSQL) defined either in docker-compose or external service.
- Holds donor data before anonymization and possibly audit logs.
e. Outputs
- File storage (outputs/*.csv) where anonymized data is written.
f. CI/CD & Container Registry
- GitHub Actions workflows:
- build.yml: runs tests, builds Docker image.
- DockerHubImagePush.yml: tags & pushes to Docker Hub.
- deploy-image.yml: triggers remote deploy (SSH/Ansible/Terraform apply).
- Docker Hub: stores versioned container images.

##### Relationships and Data Flows
- Browser → (HTTP/HTTPS) → EC2 Security Group → EC2 Docker Host → Docker Container → Flask Routing →
– If reading data: Flask → ORM → Database → Flask → Browser.
– If anonymizing: Flask → receives file or DB data → utils.anonymizer → writes CSV to outputs → Flask → Browser triggers download.
- CI/CD Flow: GitHub push → Actions → build & test → push image to Docker Hub → trigger Terraform/apply or SSH to EC2 → Docker pull & run new image.

##### Architectural Patterns & Principles
- MVC-style separation within a monolithic Flask app.
- Container-first deployment (Docker + Docker Compose).
- Infrastructure-as-code (Terraform) for reproducible environments.
- Automated CI/CD (GitHub Actions) for continuous delivery.
- Single responsibility modules (models, utils, templates).

##### Essential Elements Checklist
- Arrowheads showing direction of HTTP, data, file system, and CI/CD flows.
- Callouts for critical ports (e.g., 80:6000 mapping) and security group rules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    Browser["Browser"]:::external

    %% Security and Infrastructure
    SG["Security Group"]:::compute
    Browser -->|"HTTPS"| SG
    SG --> EC2

    EC2["EC2 Instance<br>(Ubuntu, Docker Engine)"]:::compute
    EC2 --> DockerEngine

    DockerEngine["Docker Engine"]:::compute
    DockerEngine --> Container

    subgraph "Docker Container (health_privacy_app)" 
        direction TB
        Controller["Controller<br>(routes in app.py)"]:::compute
        Config["Configuration Module<br>(config.py)"]:::compute
        Model["Model Layer<br>(models/database.py)"]:::compute
        Schema["Schema Definition<br>(db/schema.sql)"]:::storage
        Utils["Anonymization Utility<br>(utils/anonymizer.py)"]:::compute
        subgraph "View Layer (Jinja2 Templates)"
            direction TB
            ViewHome["home.html"]:::compute
            ViewLogin["login.html"]:::compute
            ViewDashboard["dashboard.html"]:::compute
            ViewForm["donor_form.html"]:::compute
            ViewPreview["preview.html"]:::compute
        end
    end

    %% Storage
    DB(("PostgreSQL")):::storage
    Outputs["Anonymized CSVs<br>(outputs/)"]:::storage

    %% CI/CD Pipeline
    subgraph "CI/CD (GitHub Actions)" 
        direction TB
        Build["build.yml"]:::external
        Push["DockerHubImagePush.yml"]:::external
        Deploy["deploy-image.yml"]:::external
    end

    %% Terraform IaC
    subgraph "Terraform IaC" 
        direction TB
        TerraformProv["Terraform Provisioner"]:::external
        TFMain["main.tf"]:::external
        TFVars["variables.tf"]:::external
    end

    %% Docker Compose & Dockerfile
    Compose["docker-compose.yml"]:::compute
    Dockerfile["Dockerfile"]:::compute

    %% Data Flows
    Container --> Controller
    Controller -->|reads/writes| Model
    Model -->|SQL queries| DB
    Controller -->|invokes| Utils
    Utils -->|writes CSV| Outputs
    Controller -->|renders| ViewHome
    Controller -->|renders| ViewLogin
    Controller -->|renders| ViewDashboard
    Controller -->|renders| ViewForm
    Controller -->|renders| ViewPreview
    DB -->|data| Controller

    %% CI/CD Flows
    Build --> Push
    Push --> DockerHub["Docker Hub"]:::external
    Push -->|push image| DockerHub
    Deploy -->|deploy| EC2

    %% Terraform Flow
    TFMain --> TerraformProv
    TFVars --> TerraformProv
    TerraformProv --> EC2

    %% Click Events
    click Controller "https://github.com/shivamsingh163248/health_privacy_app/blob/main/app.py"
    click Config "https://github.com/shivamsingh163248/health_privacy_app/blob/main/config.py"
    click Model "https://github.com/shivamsingh163248/health_privacy_app/blob/main/models/database.py"
    click Schema "https://github.com/shivamsingh163248/health_privacy_app/blob/main/db/schema.sql"
    click Utils "https://github.com/shivamsingh163248/health_privacy_app/blob/main/utils/anonymizer.py"
    click ViewHome "https://github.com/shivamsingh163248/health_privacy_app/blob/main/templates/home.html"
    click ViewLogin "https://github.com/shivamsingh163248/health_privacy_app/blob/main/templates/login.html"
    click ViewDashboard "https://github.com/shivamsingh163248/health_privacy_app/blob/main/templates/dashboard.html"
    click ViewForm "https://github.com/shivamsingh163248/health_privacy_app/blob/main/templates/donor_form.html"
    click ViewPreview "https://github.com/shivamsingh163248/health_privacy_app/blob/main/templates/preview.html"
    click Outputs "https://github.com/shivamsingh163248/health_privacy_app/tree/main/outputs/"
    click Compose "https://github.com/shivamsingh163248/health_privacy_app/blob/main/docker-compose.yml"
    click Dockerfile "https://github.com/shivamsingh163248/health_privacy_app/tree/main/Dockerfile"
    click TFMain "https://github.com/shivamsingh163248/health_privacy_app/blob/main/terraform/main.tf"
    click TFVars "https://github.com/shivamsingh163248/health_privacy_app/blob/main/terraform/variables.tf"
    click Build "https://github.com/shivamsingh163248/health_privacy_app/blob/main/.github/workflows/build.yml"
    click Push "https://github.com/shivamsingh163248/health_privacy_app/blob/main/.github/workflows/DockerHubImagePush.yml"
    click Deploy "https://github.com/shivamsingh163248/health_privacy_app/blob/main/.github/workflows/deploy-image.yml"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef storage fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
```
