# dwb-ehealth/bangladesh-config architecture

> Architecture diagram of the GitHub repository dwb-ehealth/bangladesh-config, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dwb-ehealth/bangladesh-config
- Repository: https://github.com/dwb-ehealth/bangladesh-config

## Overview

##### Project type and purpose
- This is a DevOps/configuration-management repository for deploying the “Bangladesh” implementation of Bahmni (an OpenMRS-based EMR).
- It bundles:
– Ansible playbooks and roles for provisioning servers
– Bahmni installer configuration (in /etc/bahmni-installer)
– OpenMRS modules and offline assets
– Data-warehouse (Bahmni-Mart) ETL scripts and Metabase dumps
– Clinical form definitions and translations

##### File-structure analysis
- Top-level directories:
– playbooks/… : Ansible roles and playbooks (appointment-frontend, openmrs, bahmni-mart, etc.)
– etc/bahmni-installer & etc/bahmni-mart-playbook : installer and mart-ETL config
– openmrs/… & offline/openmrs/… : JSON and Groovy modules, UIs for OpenMRS and offline clients
– bahmni-mart/… : JSON mapping and SQL views for the data-warehouse
– clinical_forms/… : form definitions + translations
– database-snapshots/… : initial DB dumps, anonymization scripts, migration archives
– configuration/… : CSVs for locations, person attributes, appointments definitions
- Key indicators:
– Ansible for orchestration,
– JSON + SQL for metadata & ETL,
– Groovy/.omod for OpenMRS extensions,
– Offline PWA assets for field use,
– Separate inventories for EMR, EMR-DB, reports, reports-DB

##### Insights from README
- Describes step-by-step deployment: install dependencies, fetch configs, run `bahmni -i prod install`, then Ansible playbooks (`playbooks/all.yml`) against an inventory with roles:
– bahmni-emr (Tomcat + OpenMRS)
– bahmni-emr-db (MySQL)
– bahmni-reports (Bahmni-Mart + Metabase)
– bahmni-reports-db (MySQL)

##### Main components and their interactions
a. Ansible Control Machine
– Runs playbooks and roles, pushes configs and packages to all hosts
b. Application Tier – bahmni-emr
– Apache HTTPD / Tomcat
– OpenMRS core + modules (clinical, adt, registration, etc.) loaded from openmrs/apps and offline/openmrs/apps
– Configuration symlinked from /var/www/bahmni_config/configuration
c. Data Tier – bahmni-emr-db
– MySQL storing OpenMRS patient, encounter, concept data
– Initialized via database-snapshots/latest-openmrs_backup.sql
d. Reporting Tier
– Extraction & transformation (“Bahmni-Mart”) using bahmni-mart JSON mappings and SQL views
– Loads into Reporting DB (bahmni-reports-db MySQL)
– Metabase BI server (bahmni-reports) connects to Reporting DB, serves dashboards
e. External actors
– Clinical users via browser (HTTP/HTTPS) to bahmni-emr
– Field/offline clients fetching offline assets from bahmni-emr or dedicated static host
– Operators/DevOps via SSH to Ansible controller and target hosts

##### Architectural patterns and design principles
- Infrastructure as Code (Ansible) – idempotent provisioning
- Multi-tier separation – app, DB, reporting
- Modular config – roles, playbooks, reusable JSON/SQL artifacts
- Offline-first PWA support – pre-bundled assets under offline/

##### Essential details to capture
- Inventory-based host grouping (role assignment)
- SQL dump initialization step for EMR DB
- Symlink of /var/www/bahmni_config/configuration into OpenMRS
- Offline assets provisioning under offline/openmrs/apps
- ETL mapping files in bahmni-mart (JSON + viewSql/*.sql)
- Playbook orchestration flow (all.yml → per-role tasks)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Control Plane
    subgraph "Control Plane"
        AC["Ansible Control Machine"]:::infrastructure
    end

    %% Application Tier
    subgraph "Application Tier"
        EMR["bahmni-emr\nApache HTTPD/Tomcat\nOpenMRS core + modules"]:::app
        WEB["Bahmni Web UI\n(opt/bahmni-web/etc/bahmniapps)"]:::app
    end

    %% Data Tier
    subgraph "Data Tier"
        EMRDB["bahmni-emr-db\nMySQL\nInitialized from latest-openmrs_backup.sql"]:::data
    end

    %% Reporting Tier
    subgraph "Reporting Tier"
        ETL["Bahmni-Mart ETL\nJSON mappings + SQL views"]:::analytics
        REPDB["bahmni-reports-db\nMySQL"]:::data
        MET["Metabase BI Server"]:::analytics
    end

    %% External Actors
    Browser["Clinical Users\n(Browser)"]:::external
    OfflineClient["Field/Offline Clients"]:::external
    Operator["Operators/DevOps\n(SSH)"]:::external

    %% Control-plane arrows
    AC -->|push configs| EMR
    AC -->|push configs| EMRDB
    AC -->|push configs| ETL
    AC -->|push configs| REPDB
    AC -->|push configs| MET

    %% User-plane arrows
    Browser -->|HTTP/HTTPS| EMR
    EMR -->|JDBC| EMRDB
    OfflineClient -->|fetch assets| EMR

    %% ETL-plane arrows
    ETL -->|extract| EMRDB
    ETL -->|load| REPDB
    MET -->|read data| REPDB

    %% Click Events
    click AC "https://github.com/dwb-ehealth/bangladesh-config/blob/master/playbooks/all.yml"
    click AC "https://github.com/dwb-ehealth/bangladesh-config/tree/master/playbooks/roles/"
    click EMR "https://github.com/dwb-ehealth/bangladesh-config/blob/master/playbooks/roles/openmrs/tasks/main.yml"
    click EMR "https://github.com/dwb-ehealth/bangladesh-config/tree/master/openmrs/apps/"
    click OfflineClient "https://github.com/dwb-ehealth/bangladesh-config/tree/master/offline/openmrs/apps/"
    click WEB "https://github.com/dwb-ehealth/bangladesh-config/tree/master/opt/bahmni-web/etc/bahmniapps/"
    click EMRDB "https://github.com/dwb-ehealth/bangladesh-config/blob/master/database-snapshots/latest-openmrs_backup.sql"
    click ETL "https://github.com/dwb-ehealth/bangladesh-config/blob/master/bahmni-mart/bahmni-mart.json"
    click ETL "https://github.com/dwb-ehealth/bangladesh-config/blob/master/etc/bahmni-mart-playbook/setup.yml"
    click ETL "https://github.com/dwb-ehealth/bangladesh-config/blob/master/etc/bahmni-mart-playbook/roles/bahmni-mart/defaults/main.yml"
    click ETL "https://github.com/dwb-ehealth/bangladesh-config/blob/master/playbooks/roles/bahmni-mart/tasks/main.yml"
    click MET "https://github.com/dwb-ehealth/bangladesh-config/blob/master/bahmni-mart/metabase-config.sql"

    %% Styles
    classDef infrastructure fill:#e0f2f1,stroke:#004d40,color:#004d40;
    classDef app fill:#e3f2fd,stroke:#0d47a1,color:#0d47a1;
    classDef data fill:#fff3e0,stroke:#e65100,color:#e65100;
    classDef analytics fill:#f3e5f5,stroke:#4a148c,color:#4a148c;
    classDef external fill:#eceff1,stroke:#607d8b,color:#607d8b;
```
