# gravitate-health/focusing-manager architecture

> Architecture diagram of the GitHub repository gravitate-health/focusing-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gravitate-health/focusing-manager
- Repository: https://github.com/gravitate-health/focusing-manager

## Overview

Key Components to Include:

##### API Layer
- Main endpoints from the controllers (explanationController, lensesController, preprocessingController)

##### Core Service Components
- Four focusing flows mentioned in the README as sub-components

##### Providers Layer
- FHIR EPI Provider
- FHIR IPS Provider
- Allergies Provider
- Conditions Provider
- Lenses Provider
- Preprocessing Provider
- Profile Provider

##### Infrastructure Components
- Kubernetes components:
- Service Account
- Role
- Role Binding
- Kubernetes API Client

##### External Dependencies
- FHIR Server connection
- Kubernetes Cluster connection

##### Top Level
- [External Clients] → [API Gateway] → [Focusing Manager Core]

##### Middle Level
- [Focusing Manager Core] → [Provider Layer] → [External Services]

##### Bottom Level
- [Kubernetes Infrastructure] ↔ [Service Configuration]

Key Relationships to Show:

##### Four focusing flows as parallel paths within the core component

Important Elements to Include:

##### Configuration Components
- Environment variables (FOCUSING_LABEL_SELECTOR, PREPROCESSING_LABEL_SELECTOR)
- Kubernetes configurations
- Template files (epi.liquid, lenses.css)

##### Security Layer
- Service account and role bindings
- Authentication flow

##### Error Handling
- Error handling components from the error directory
- How errors propagate through the system

Recommendations:

##### The template-based rendering system

Keep the abstraction level focused on the architectural components while maintaining enough detail to understand the system's operation and dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Layer"]
        Client["External Clients"]
        FHIR["FHIR Server"]:::external
        K8S["Kubernetes Cluster"]:::external
    end

    subgraph API["API Layer"]
        Gateway["API Gateway"]:::api
        Controllers["Controllers"]:::api
        Routes["Routes"]:::api
    end

    subgraph Core["Core Service Layer"]
        FocusingManager["Focusing Manager"]:::core
        TemplateEngine["Template Engine"]:::core
        
        subgraph Flows["Focusing Flows"]
            Flow1["Flow 1"]:::core
            Flow2["Flow 2"]:::core
            Flow3["Flow 3"]:::core
            Flow4["Flow 4"]:::core
        end
    end

    subgraph Providers["Providers Layer"]
        FHIR_EPI["FHIR EPI Provider"]:::provider
        FHIR_IPS["FHIR IPS Provider"]:::provider
        Allergies["Allergies Provider"]:::provider
        Conditions["Conditions Provider"]:::provider
        Lenses["Lenses Provider"]:::provider
        Preprocessing["Preprocessing Provider"]:::provider
        Profile["Profile Provider"]:::provider
    end

    subgraph Infrastructure["Infrastructure Layer"]
        ServiceAccount["Service Account"]:::infra
        Role["Role"]:::infra
        RoleBinding["Role Binding"]:::infra
        K8sClient["Kubernetes Client"]:::infra
        ServiceDef["Service Definition"]:::infra
        Deployment["Deployment Config"]:::infra
    end

    subgraph Utils["Utility Layer"]
        Logger["Logger"]:::util
        FHIRClient["FHIR Client"]:::util
        AxiosClient["Axios Client"]:::util
        ErrorHandler["Error Handler"]:::util
    end

    Client --> Gateway
    Gateway --> Controllers
    Controllers --> Routes
    Routes --> FocusingManager
    FocusingManager --> TemplateEngine
    FocusingManager --> Flows
    Flows --> Providers
    Providers --> FHIR
    K8sClient --> K8S
    
    %% Click Events
    click Controllers "https://github.com/Gravitate-Health/focusing-manager/tree/main/src/controllers/"
    click Routes "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/routes/routes.ts"
    click FocusingManager "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/index.ts"
    click TemplateEngine "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/templates/explanationTemplate.ts"
    click FHIR_EPI "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/fhirEpi.provider.ts"
    click FHIR_IPS "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/fhirIps.provider.ts"
    click Allergies "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/allergies.provider.ts"
    click Conditions "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/conditions.provider.ts"
    click Lenses "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/lenses.provider.ts"
    click Preprocessing "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/preprocessing.provider.ts"
    click Profile "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/providers/profile.provider.ts"
    click ServiceAccount "https://github.com/Gravitate-Health/focusing-manager/blob/main/kubernetes/base/001_focusing-manager-service-account.yaml"
    click Role "https://github.com/Gravitate-Health/focusing-manager/blob/main/kubernetes/base/002_focusing-manager-role.yaml"
    click RoleBinding "https://github.com/Gravitate-Health/focusing-manager/blob/main/kubernetes/base/003_focusing-manager-role-binding.yaml"
    click ServiceDef "https://github.com/Gravitate-Health/focusing-manager/blob/main/kubernetes/base/004_focusing-manager-service.yaml"
    click Deployment "https://github.com/Gravitate-Health/focusing-manager/blob/main/kubernetes/base/005_focusing-manager-deployment.yaml"
    click K8sClient "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/utils/k8sClient.ts"
    click ErrorHandler "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/error/CustomError.ts"
    click FHIRClient "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/utils/fhirClient.ts"
    click AxiosClient "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/utils/axios.ts"
    click Logger "https://github.com/Gravitate-Health/focusing-manager/blob/main/src/utils/Logger.ts"

    %% Styling
    classDef external fill:#ff6b6b
    classDef api fill:#4ecdc4
    classDef core fill:#45b7d1
    classDef provider fill:#f7d794
    classDef infra fill:#a8a8a8
    classDef util fill:#96c3eb

    %% Legend
    subgraph Legend
        L1["External Systems"]:::external
        L2["API Components"]:::api
        L3["Core Services"]:::core
        L4["Providers"]:::provider
        L5["Infrastructure"]:::infra
        L6["Utilities"]:::util
    end
```
