# cms-enterprise/ztmf architecture

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

- Interactive diagram: https://gitdiagram.com/cms-enterprise/ztmf
- Repository: https://github.com/cms-enterprise/ztmf

## Overview

##### Main Components

A. Client Layer:
- React SPA (in separate repository)
- CloudFront Distribution (primary entry point)

B. Security Layer:
- AWS Verified Access
- Okta IDM Integration
- Authentication/Authorization Components

C. Backend Services:
- REST API (Go-based)
- ETL Process (Go-based)
- ECS Fargate Containers

D. Data Layer:
- Aurora Serverless PostgreSQL (RDS)
- S3 Bucket (for static assets)

**┌─ Client Tier ─────┐    ┌─ Security Tier ──┐    ┌─ Application Tier ─┐    ┌─ Data Tier ────┐**
- React SPA       │    │ - CloudFront     │    │ - ECS Fargate      │    │ - Aurora RDS   │
- >│ - Verified Access │───>│   - REST API       │───>│ - S3 Bucket    │
- Okta IDM       │    │   - ETL Process    │    │                │
- ┘    └─────────────────┘     └──────────────────┘     └───────────────┘

##### Key Elements to Highlight

a. API Structure (from backend/cmd/api):
- Auth Module
- Controllers
- Models
- Router
- Migrations

b. Infrastructure Components (from infrastructure/):
- Load Balancers (ALB)
- VPC Configuration
- ECS/ECR Setup
- RDS Configuration

##### Important Flows

a. Authentication Flow:
**User -> CloudFront -> Verified Access -> Okta IDM -> API**

b. Data Flow:
**API -> RDS (for data operations)**
**ETL -> RDS (for data loading)**

##### Additional Details

Architectural elements:
- GitHub Actions workflows for CI/CD
- Internal ALB vs Public ALB
- VPC networking zones
- Security group relationships

##### Specific Implementation Notes

- The microservices architecture (API and ETL as separate services)
- The security-first approach (Zero Trust implementation)
- The cloud-native AWS infrastructure
- The separation of concerns between components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        SPA[React SPA]
    end

    subgraph Security["Security Layer"]
        CF["CloudFront Distribution"]:::security
        VA["AWS Verified Access"]:::security
        OKTA["Okta IDM"]:::security
        Auth["Authentication Module"]:::security
    end

    subgraph Application["Application Layer"]
        subgraph ECS["ECS Fargate Cluster"]
            API["REST API Service"]:::app
            ETL["ETL Service"]:::app
            Router["API Router"]:::app
            Controllers["Controllers"]:::app
            Models["Models"]:::app
        end
    end

    subgraph Data["Data Layer"]
        RDS[(Aurora Serverless PostgreSQL)]:::data
        S3[("S3 Bucket")]:::data
    end

    subgraph Infrastructure["Infrastructure Components"]
        VPC["VPC Configuration"]:::infra
        ALB_INT["Internal ALB"]:::infra
        ALB_PUB["Public ALB"]:::infra
        ECR["ECR Registry"]:::infra
    end

    subgraph CICD["CI/CD Pipeline"]
        GHA["GitHub Actions"]:::cicd
        CFG["Configuration Management"]:::cicd
        SEC["Secrets Management"]:::cicd
    end

    %% Relationships
    SPA --> CF
    CF --> VA
    VA --> OKTA
    OKTA --> Auth
    Auth --> API
    API --> Router
    Router --> Controllers
    Controllers --> Models
    Models --> RDS
    ETL --> RDS
    API --> S3
    ALB_INT --> API
    ALB_PUB --> ETL
    ECR --> ECS
    GHA --> ECR

    %% Click Events
    click Auth "https://github.com/CMS-Enterprise/ztmf/tree/main/backend/cmd/api/internal/auth/"
    click VA "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/verified-access.tf"
    click Controllers "https://github.com/CMS-Enterprise/ztmf/tree/main/backend/cmd/api/internal/controller/"
    click Models "https://github.com/CMS-Enterprise/ztmf/tree/main/backend/cmd/api/internal/model/"
    click Router "https://github.com/CMS-Enterprise/ztmf/tree/main/backend/cmd/api/internal/router/"
    click ETL "https://github.com/CMS-Enterprise/ztmf/blob/main/backend/cmd/etl/main.go"
    click ALB_INT "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/alb-internal.tf"
    click ALB_PUB "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/alb-public.tf"
    click CF "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/cloudfront.tf"
    click VPC "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/vpc.tf"
    click ECR "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/ecr.tf"
    click ECS "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/ecs.tf"
    click RDS "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/rds.tf"
    click S3 "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/s3.tf"
    click GHA "https://github.com/CMS-Enterprise/ztmf/tree/main/.github/workflows"
    click CFG "https://github.com/CMS-Enterprise/ztmf/tree/main/infrastructure/config"
    click SEC "https://github.com/CMS-Enterprise/ztmf/blob/main/infrastructure/secrets.tf"

    %% Styles
    classDef security fill:#a8e6cf
    classDef app fill:#ffd3b6
    classDef data fill:#ff8b94
    classDef infra fill:#dcedc1
    classDef cicd fill:#a8d1d1

    %% Legend
    subgraph Legend
        L1[Security Component]:::security
        L2[Application Component]:::app
        L3[Data Store]:::data
        L4[Infrastructure]:::infra
        L5[CI/CD Component]:::cicd
    end
```
