# openimis/openimis-be-insuree_py architecture

> Architecture diagram of the GitHub repository openimis/openimis-be-insuree_py, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openimis/openimis-be-insuree_py
- Repository: https://github.com/openimis/openimis-be-insuree_py

## Overview

This openIMIS reference module manages insurees, families, and related enrollment data. Its main workflow is GraphQL requests routed through the module schema to query or mutate domain records; mutations delegate persistence and photo handling to services. It also exposes family and enrollment reports. The source excerpts are partial, so some report and schema wiring is documented or indexed rather than directly visible; uncertain links are omitted.

Main entry points: [`insuree/models.py`](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/models.py) (Insuree records), [`insuree/schema.py`](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/schema.py) (GraphQL schema), [`insuree/gql_queries.py`](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/gql_queries.py) (Query fields), [`insuree/gql_mutations.py`](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/gql_mutations.py) (Mutation fields)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["GraphQL API"]
  node_schema["GraphQL schema<br/>[schema.py]"]
  node_queries["Query fields<br/>[gql_queries.py]"]
  node_mutations["Mutation fields<br/>[gql_mutations.py]"]
  node_loaders["Batch loaders<br/>[dataloaders.py]"]
end

subgraph group_domain["Insuree Domain"]
  node_config["Module setup<br/>[apps.py]"]
  node_services["Domain services<br/>[services.py]"]
  node_models["Insuree records<br/>[models.py]"]
end

subgraph group_reports["Reports"]
  node_enrolled["Enrolled families"]
  node_family_report["Family overview"]
  node_missing_photo["Missing photos"]
  node_pending["Pending enrollment"]
end

node_client(("openIMIS client"))
node_database[("openIMIS database")]

node_client -->|"sends GraphQL"| node_schema
node_schema -->|"routes queries"| node_queries
node_schema -->|"routes mutations"| node_mutations
node_config -->|"registers loaders"| node_loaders
node_queries -->|"queries records"| node_models
node_queries -->|"uses loaders"| node_loaders
node_mutations -->|"delegates writes"| node_services
node_mutations -->|"records mutations"| node_models
node_services -->|"updates records"| node_models
node_models -->|"maps tables"| node_database
node_enrolled -->|"reads records"| node_models
node_enrolled -.->|"queries data"| node_database
node_family_report -->|"reads records"| node_models
node_family_report -.->|"queries data"| node_database
node_missing_photo -->|"runs SQL"| node_database
node_pending -->|"runs SQL"| node_database

click node_schema "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/schema.py"
click node_queries "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/gql_queries.py"
click node_mutations "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/gql_mutations.py"
click node_loaders "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/dataloaders.py"
click node_config "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/apps.py"
click node_services "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/services.py"
click node_models "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/models.py"
click node_enrolled "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/enrolled_families.py"
click node_family_report "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/insuree_family_overview.py"
click node_missing_photo "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/insuree_missing_photo.py"
click node_pending "https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/insurees_pending_enrollment.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_schema,node_queries,node_mutations,node_loaders,node_client toneBlue
class node_config,node_services,node_models,node_database toneAmber
class node_enrolled,node_family_report,node_missing_photo,node_pending toneMint
```

## Components

### GraphQL API

- [GraphQL schema](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/schema.py): `insuree/schema.py`
- [Query fields](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/gql_queries.py): `insuree/gql_queries.py`
- [Mutation fields](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/gql_mutations.py): `insuree/gql_mutations.py`
- [Batch loaders](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/dataloaders.py): `insuree/dataloaders.py`

### Insuree Domain

- [Module setup](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/apps.py): `insuree/apps.py`
- [Domain services](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/services.py): `insuree/services.py`
- [Insuree records](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/models.py): `insuree/models.py`

### Reports

- [Enrolled families](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/enrolled_families.py): `insuree/reports/enrolled_families.py`
- [Family overview](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/insuree_family_overview.py): `insuree/reports/insuree_family_overview.py`
- [Missing photos](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/insuree_missing_photo.py): `insuree/reports/insuree_missing_photo.py`
- [Pending enrollment](https://github.com/openimis/openimis-be-insuree_py/blob/develop/insuree/reports/insurees_pending_enrollment.py): `insuree/reports/insurees_pending_enrollment.py`

### Other components

- **openIMIS client**
- **openIMIS database**

## Connections

- openIMIS client → GraphQL schema: sends GraphQL (evidence: `README.md`)
- GraphQL schema → Query fields: routes queries (evidence: `insuree/schema.py`)
- GraphQL schema → Mutation fields: routes mutations (evidence: `insuree/schema.py`)
- Module setup → Batch loaders: registers loaders (evidence: `insuree/apps.py`)
- Query fields → Insuree records: queries records (evidence: `insuree/gql_queries.py`)
- Query fields → Batch loaders: uses loaders (evidence: `insuree/gql_queries.py`)
- Mutation fields → Domain services: delegates writes (evidence: `insuree/gql_mutations.py`)
- Mutation fields → Insuree records: records mutations (evidence: `insuree/gql_mutations.py`)
- Domain services → Insuree records: updates records (evidence: `insuree/services.py`)
- Insuree records → openIMIS database: maps tables (evidence: `README.md`)
- Enrolled families → Insuree records: reads records (evidence: `insuree/reports/enrolled_families.py`)
- Enrolled families → openIMIS database: queries data
- Family overview → Insuree records: reads records (evidence: `insuree/reports/insuree_family_overview.py`)
- Family overview → openIMIS database: queries data
- Missing photos → openIMIS database: runs SQL (evidence: `insuree/reports/insuree_missing_photo.py`)
- Pending enrollment → openIMIS database: runs SQL (evidence: `insuree/reports/insurees_pending_enrollment.py`)
