# enterprise-cmcs/macpro-mako architecture

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

- Interactive diagram: https://gitdiagram.com/enterprise-cmcs/macpro-mako
- Repository: https://github.com/enterprise-cmcs/macpro-mako

## Overview

##### Main Components
- Frontend Client: The “react-app” directory shows all the React UI code. This component handles user interfaces for tasks such as form submissions, package tracking, and other interactions.
- Backend API and Serverless Functions: Under “lib/lambda” are many Lambda functions (e.g., submission handling, email processing, index management, and notifications). These functions represent the core business logic.
- Command-Line Interface (CLI): The “bin/cli” directory contains commands (deploy, destroy, logs, test, etc.) that are used to interact with or manage the system.
- Infrastructure and Cloud Resources: The “lib/stacks”, “lib/local-constructs”, and “cdk.json” files show that the infrastructure (e.g., networking, authentication, databases, and storage such as S3) is defined using AWS CDK.
- Shared Libraries and Packages: Directories such as “lib/libs”, “lib/packages/shared-types”, and “lib/packages/shared-utils” represent shared code that likely gets reused in Lambdas and potentially even the frontend.
- External Integrations: The project integrates with systems like Kafka (as seen in “lib/libs/api/kafka.ts”) and OpenSearch (in “lib/libs/opensearch-lib.ts” and shared-types for opensearch), and includes extensive email templating and notification mechanisms.

##### Relationships and Data Flow
- The Frontend (React App) communicates with the backend via API calls. These API calls are likely routed through API Gateway to trigger Lambda functions.
- Lambda functions serve as the business logic layer—processing submissions, generating notifications, managing package workflows, handling file upload URLs, and more.
- Some Lambda functions trigger email flows using shared email libraries (found under “lib/libs/email”) to send notifications back to users or to CMS review teams.
- Infrastructure is managed via CDK stacks (stacks such as “api.ts”, “auth.ts”, “networking.ts”, etc.) that provision AWS resources (e.g., API Gateway, Lambda, S3, OpenSearch, etc.) and define policies.
- The CLI tool (under “bin/cli”) provides deployment, testing, and operational commands to interface with these components.

##### Architectural Patterns and Key Design Principles
- Serverless Architecture: The back-end is composed primarily of AWS Lambda functions orchestrated via a serverless approach, ensuring scalability and agility.
- Infrastructure-as-Code: AWS CDK templates (in “lib/stacks” and “lib/local-constructs”) are used to define the AWS resources and configurations.
- Separation of Concerns: Different folders for Lambdas, shared libraries, and frontend clearly delineate the responsibilities.
- Reusability & Shared Types: The usage of shared-types (common models, events, and utilities) enforces consistency between the front- and back-end.
- Testing & Quality: Extensive tests are visible in directories like “test/e2e”, “vitest.config.ts”, and within source folders for both frontend and backend – emphasizing automated testing.

##### Detail Level
– Capture every essential architectural element down to the logical separation between the CLI, the shared libraries/utilities, and the backend functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        ReactApp["React App (Frontend)"]:::frontend
    end

    %% API/Backend Layer
    subgraph "API/Backend Layer"
        APIGateway["API Gateway"]:::backend
        subgraph "Lambda Functions"
            Submission["Submission Handler"]:::backend
            EmailProcessor["Email Processor"]:::backend
            IndexManager["Index Manager"]:::backend
        end
        SharedLibs["Shared Libraries & Packages"]:::backend
    end

    %% Operations Layer
    subgraph "Operations"
        CLI["CLI Tool"]:::cli
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Infra["CDK Infrastructure"]:::infra
    end

    %% External Services
    subgraph "External Services"
        Kafka["Kafka Integration"]:::external
        EmailService["Email Service"]:::external
        OpenSearch["OpenSearch Integration"]:::external
    end

    %% Data Flow Connections
    ReactApp -->|"HTTP"| APIGateway
    APIGateway -->|"Triggers"| Submission
    APIGateway -->|"Triggers"| EmailProcessor
    APIGateway -->|"Triggers"| IndexManager

    Submission -->|"Publishes"| Kafka
    EmailProcessor -->|"Sends"| EmailService
    IndexManager -->|"Updates"| OpenSearch

    %% Lambda functions using shared libraries
    Submission -.->|"uses"| SharedLibs
    EmailProcessor -.->|"uses"| SharedLibs
    IndexManager -.->|"uses"| SharedLibs

    %% Infrastructure provisioning
    Infra -->|"Provisions"| APIGateway
    Infra -->|"Provisions"| Submission
    Infra -->|"Provisions"| EmailProcessor
    Infra -->|"Provisions"| IndexManager

    %% CLI Interaction with Infrastructure
    CLI -->|"Manages"| Infra

    %% Class Definitions for Colors
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#FDFD96,stroke:#333,stroke-width:2px;
    classDef infra fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef cli fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;

    %% Click Events
    click ReactApp "https://github.com/enterprise-cmcs/macpro-mako/tree/main/react-app/"
    click Submission "https://github.com/enterprise-cmcs/macpro-mako/tree/main/lib/lambda/"
    click EmailProcessor "https://github.com/enterprise-cmcs/macpro-mako/tree/main/lib/lambda/"
    click IndexManager "https://github.com/enterprise-cmcs/macpro-mako/tree/main/lib/lambda/"
    click CLI "https://github.com/enterprise-cmcs/macpro-mako/tree/main/bin/cli/"
    click Infra "https://github.com/enterprise-cmcs/macpro-mako/tree/main/lib/stacks/"
    click SharedLibs "https://github.com/enterprise-cmcs/macpro-mako/tree/main/lib/libs/"
    click Kafka "https://github.com/enterprise-cmcs/macpro-mako/blob/main/lib/libs/api/kafka.ts"
    click OpenSearch "https://github.com/enterprise-cmcs/macpro-mako/blob/main/lib/libs/opensearch-lib.ts"
    click EmailService "https://github.com/enterprise-cmcs/macpro-mako/tree/main/lib/libs/email/"
```
