# senk20/ec2connect architecture

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

- Interactive diagram: https://gitdiagram.com/senk20/ec2connect
- Repository: https://github.com/senk20/ec2connect

## Overview

ec2connect is a small Go CLI that selects an EC2 instance, ensures its requested TCP port is reachable from an allowed CIDR, runs the matching local SSH/SFTP/SCP client, and removes any temporary ingress rule afterward. The runtime is concentrated in main.go, so components share that path. The README documents the overall workflow; the excerpt shows config loading, connection execution, and cleanup dispatch, but omits some call sites, so undocumented internal links are not inferred.

Main entry points: [`main.go`](https://github.com/senk20/ec2connect/blob/main/main.go) (Command workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI workflow"]
  node_workflow["Command workflow<br/>[main.go]"]
  node_options["Options and mode<br/>[main.go]"]
end

subgraph group_access["Instance access"]
  node_awsconfig["AWS config loading<br/>[main.go]"]
  node_instance["Instance selection<br/>[main.go]"]
  node_ec2["EC2 API"]
  node_cidr["Allowed CIDR<br/>[main.go]"]
  node_security["Security group rules<br/>[main.go]"]
end

subgraph group_session["Connection session"]
  node_localclient["SSH SFTP SCP"]
end

node_user(("CLI user"))
node_checkip["Public IP service"]

node_user -->|"runs"| node_workflow
node_workflow -->|"parses"| node_options
node_workflow -->|"loads"| node_awsconfig
node_workflow -->|"selects"| node_instance
node_instance -->|"queries"| node_ec2
node_workflow -->|"determines"| node_cidr
node_cidr -->|"requests IP"| node_checkip
node_workflow -->|"checks and updates"| node_security
node_security -->|"reads and changes"| node_ec2
node_workflow -->|"runs session"| node_localclient
node_workflow -->|"cleans up rule"| node_security

click node_workflow "https://github.com/senk20/ec2connect/blob/main/main.go"
click node_options "https://github.com/senk20/ec2connect/blob/main/main.go"
click node_awsconfig "https://github.com/senk20/ec2connect/blob/main/main.go"
click node_instance "https://github.com/senk20/ec2connect/blob/main/main.go"
click node_cidr "https://github.com/senk20/ec2connect/blob/main/main.go"
click node_security "https://github.com/senk20/ec2connect/blob/main/main.go"

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_workflow,node_options,node_user toneBlue
class node_awsconfig,node_instance,node_ec2,node_cidr,node_security toneAmber
class node_localclient toneMint
class node_checkip toneIndigo
```

## Components

### CLI workflow

- [Command workflow](https://github.com/senk20/ec2connect/blob/main/main.go): `main.go`
- [Options and mode](https://github.com/senk20/ec2connect/blob/main/main.go): `main.go`

### Instance access

- [AWS config loading](https://github.com/senk20/ec2connect/blob/main/main.go): `main.go`
- [Instance selection](https://github.com/senk20/ec2connect/blob/main/main.go): `main.go`
- **EC2 API**
- [Allowed CIDR](https://github.com/senk20/ec2connect/blob/main/main.go): `main.go`
- [Security group rules](https://github.com/senk20/ec2connect/blob/main/main.go): `main.go`

### Connection session

- **SSH SFTP SCP**

### Other components

- **CLI user**
- **Public IP service**

## Connections

- CLI user → Command workflow: runs (evidence: `README.md`)
- Command workflow → Options and mode: parses (evidence: `main.go`)
- Command workflow → AWS config loading: loads (evidence: `main.go`)
- Command workflow → Instance selection: selects (evidence: `README.md`)
- Instance selection → EC2 API: queries (evidence: `README.md`)
- Command workflow → Allowed CIDR: determines (evidence: `README.md`)
- Allowed CIDR → Public IP service: requests IP (evidence: `README.md`)
- Command workflow → Security group rules: checks and updates (evidence: `README.md`)
- Security group rules → EC2 API: reads and changes (evidence: `README.md`)
- Command workflow → SSH SFTP SCP: runs session (evidence: `main.go`)
- Command workflow → Security group rules: cleans up rule (evidence: `main.go`)
