# mitre/emasser architecture

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

- Interactive diagram: https://gitdiagram.com/mitre/emasser
- Repository: https://github.com/mitre/emasser

## Overview

##### Project Type and Purpose
- eMASSer is a standalone Ruby Command-Line Interface (CLI) tool.
- Its sole purpose is to automate interactions with the eMASS REST API by leveraging the `emass_client` Ruby gem.

##### File-Structure Analysis
- **exe/**: entry point (`exe/emasser`) that bootstraps the CLI.
- **lib/emasser/**: core Ruby code, including:
- `cli.rb` – orchestrates commands and subcommands
- `options_parser.rb` – parses user flags and arguments
- `configuration.rb` / `configure.rb` – reads `.env` and certificate files
- `input_converters.rb` / `output_converters.rb` – transforms data in/out
- `get.rb`, `post.rb`, `put.rb`, `delete.rb` – business-logic modules that map CLI calls to API calls
- `help/…_mapper.md` – help text and sample payloads for each endpoint
- **Gemfile**, **.env-example**, **Dockerfile** – packaging and deployment
- **.github/** workflows / **Rakefile** – CI/CD pipelines and test orchestration

##### README Insights
- eMASSer delegates all REST interactions to the `emass_client` gem (OpenAPI‐generated).
- Business logic centers on:
a. Parsing CLI input
b. Validating and transforming data
c. Dispatching calls to `emass_client`
d. Formatting and printing responses

a. Main Components
- User Terminal / CLI Executable (`exe/emasser`)
- CLI Core:
– Options Parser
– Command Dispatcher
– Input Converters & Validators
– Business-Logic Modules (get/post/put/delete)
– Output Converters & Formatter
- API Client Layer (`emass_client` gem)
- External eMASS REST API Server
- Environment / Configuration Store (Environment Variables, `.env` file, TLS certificates)
- (Optional) Packaging & CI/CD (Docker, GitHub Actions)

b. Relationships & Data Flows
1. User types `emasser <command> --flags` in terminal.
2. CLI executable loads configuration from `.env` + certs.
3. Options Parser splits command and flags, hands off to Command Dispatcher.
4. Dispatcher routes to the appropriate business-logic module (`get`, `post`, etc.).
5. Module uses Input Converters to build API request objects.
6. Calls the `emass_client` gem methods (OpenAPI-generated stubs).
7. `emass_client` makes HTTPS requests to eMASS REST endpoints.
8. eMASS responds with JSON; the gem returns native Ruby objects.
9. Output Converters format the results, which the CLI prints to STDOUT.

c. Architectural Patterns & Principles
- **Single Responsibility**: separate modules for parsing, conversion, business logic, and API transport.
- **Dependency Injection**: `emass_client` gem is an external dependency injected into business logic.
- **OpenAPI-Driven Client**: decouples CLI logic from protocol details.
- **Extensibility**: help mapper files and modular command files support easy addition of new endpoints.

d. Key Technologies & Libraries
- Ruby 3.x
- emass_client (OpenAPI V3 generated client)
- RubyGems package (`emasser.gemspec`)
- Docker (optional container image)
- GitHub Actions (CI/CD, linting, testing)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    UserTerminal["User Terminal\n(Types emasser command)"]:::external
    UserTerminal -->|runs| CLIExecutable

    %% CLI Executable Entry Point
    CLIExecutable["CLI Executable\n(exe/emasser)"]:::cli
    click CLIExecutable "https://github.com/mitre/emasser/tree/main/exe/emasser"

    %% Configuration Store
    ConfigurationLoader1["Configuration Loader\n(lib/emasser/configuration.rb)"]:::config
    ConfigurationLoader2["Configuration Loader\n(lib/emasser/configure.rb)"]:::config
    click ConfigurationLoader1 "https://github.com/mitre/emasser/blob/main/lib/emasser/configuration.rb"
    click ConfigurationLoader2 "https://github.com/mitre/emasser/blob/main/lib/emasser/configure.rb"
    CLIExecutable --> ConfigurationLoader1
    CLIExecutable --> ConfigurationLoader2

    %% CLI Core Components
    subgraph "CLI Core" 
        style CLI_Core fill:none,stroke:#333,stroke-width:1px
        OptionsParser["Options Parser\n(lib/emasser/options_parser.rb)"]:::cli
        CommandDispatcher["Command Dispatcher\n(lib/emasser/cli.rb)"]:::cli
        Constants["Constants & Versioning\n(lib/emasser/constants.rb,\nlib/emasser/version.rb)"]:::cli
        Errors["Error Definitions\n(lib/emasser/errors.rb)"]:::cli
        HelpMappers["Help Text & Sample Payloads\n(lib/emasser/help/)"]:::cli
        click OptionsParser "https://github.com/mitre/emasser/blob/main/lib/emasser/options_parser.rb"
        click CommandDispatcher "https://github.com/mitre/emasser/blob/main/lib/emasser/cli.rb"
        click Constants "https://github.com/mitre/emasser/blob/main/lib/emasser/constants.rb"
        click Constants "https://github.com/mitre/emasser/blob/main/lib/emasser/version.rb"
        click Errors "https://github.com/mitre/emasser/blob/main/lib/emasser/errors.rb"
        click HelpMappers "https://github.com/mitre/emasser/tree/main/lib/emasser/help/"
        CLIExecutable --> OptionsParser
        OptionsParser --> CommandDispatcher
        CommandDispatcher --> Constants
        CommandDispatcher --> Errors
        CommandDispatcher --> HelpMappers
    end

    %% Business Logic Modules
    subgraph "Business Logic Modules" 
        GetModule["GET Module\n(lib/emasser/get.rb)"]:::business
        PostModule["POST Module\n(lib/emasser/post.rb)"]:::business
        PutModule["PUT Module\n(lib/emasser/put.rb)"]:::business
        DeleteModule["DELETE Module\n(lib/emasser/delete.rb)"]:::business
        click GetModule "https://github.com/mitre/emasser/blob/main/lib/emasser/get.rb"
        click PostModule "https://github.com/mitre/emasser/blob/main/lib/emasser/post.rb"
        click PutModule "https://github.com/mitre/emasser/blob/main/lib/emasser/put.rb"
        click DeleteModule "https://github.com/mitre/emasser/blob/main/lib/emasser/delete.rb"
        CommandDispatcher --> GetModule
        CommandDispatcher --> PostModule
        CommandDispatcher --> PutModule
        CommandDispatcher --> DeleteModule
    end

    %% Converters
    subgraph "Converters" 
        style Converters fill:none,stroke:#333,stroke-width:1px
        InputConverters["Input Converters\n(lib/emasser/input_converters.rb)"]:::converters
        OutputConverters["Output Converters\n(lib/emasser/output_converters.rb)"]:::converters
        click InputConverters "https://github.com/mitre/emasser/blob/main/lib/emasser/input_converters.rb"
        click OutputConverters "https://github.com/mitre/emasser/blob/main/lib/emasser/output_converters.rb"
        GetModule --> InputConverters
        PostModule --> InputConverters
        PutModule --> InputConverters
        DeleteModule --> InputConverters
        InputConverters --> EmassClient
        EmassClient --> OutputConverters
    end

    %% External Dependency and API
    EmassClient["emass_client gem\n(OpenAPI Client)"]:::dependency
    EmassClient -->|HTTPS JSON| EmassAPI
    EmassAPI["eMASS REST API\n(Cylinder)"]:::external
    OutputConverters --> CLIExecutable
    EmassAPI -->|JSON Response| EmassClient

    %% Configuration & Env Example
    EnvExample["Env Example File\n(.env-example)"]:::config
    click EnvExample "https://github.com/mitre/emasser/blob/main/.env-example"
    CLIExecutable --> EnvExample

    %% Packaging & CI/CD
    subgraph "Packaging & CI/CD" 
        DockerfileNode["Dockerfile"]:::ci
        GemfileNode["Gemfile\nGemfile.lock"]:::ci
        GemspecNode["emasser.gemspec"]:::ci
        GitHubActions["GitHub Actions\n(.github/workflows/*.yml)"]:::ci
        RakefileNode["Rakefile"]:::ci
        click DockerfileNode "https://github.com/mitre/emasser/tree/main/Dockerfile"
        click GemfileNode "https://github.com/mitre/emasser/tree/main/Gemfile"
        click GemfileNode "https://github.com/mitre/emasser/blob/main/Gemfile.lock"
        click GemspecNode "https://github.com/mitre/emasser/blob/main/emasser.gemspec"
        click GitHubActions "https://github.com/mitre/emasser/blob/main/.github/workflows/*.yml"
        click RakefileNode "https://github.com/mitre/emasser/tree/main/Rakefile"
        CLIExecutable --> DockerfileNode
        CLIExecutable --> GemfileNode
        CLIExecutable --> GemspecNode
        CLIExecutable --> GitHubActions
        CLIExecutable --> RakefileNode
    end

    %% Styles
    classDef cli fill:#FFDADA,stroke:#D9534F,stroke-width:1px
    classDef config fill:#FFF2CC,stroke:#F0AD4E,stroke-width:1px
    classDef dependency fill:#D0E9C6,stroke:#5CB85C,stroke-width:1px
    classDef external fill:#D9EDF7,stroke:#5BC0DE,stroke-width:1px
    classDef business fill:#FCF8E3,stroke:#8A6D3B,stroke-width:1px
    classDef converters fill:#E2F0D9,stroke:#3C763D,stroke-width:1px
    classDef ci fill:#EBDEF0,stroke:#8E44AD,stroke-width:1px
```
