# ehoang0106/containerized architecture

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

- Interactive diagram: https://gitdiagram.com/ehoang0106/containerized
- Repository: https://github.com/ehoang0106/containerized

## Overview

##### Project type and purpose
- This is a containerized full-stack web application: a Python Flask “orbwatch” service serving HTML/CSS/JS, running in Docker on AWS ECS, with a MySQL/MariaDB backend on AWS RDS. All AWS resources (VPC, subnets, ECS cluster, RDS, etc.) are provisioned via Terraform (split into `terraform/network` and `terraform/infra`).

##### File structure
- myapp/webapp
– app.py, orbwatch.py: Flask entrypoints and business logic
– static/, templates/: frontend assets and HTML templates
- Dockerfile + requirements.txt: container build instructions
- terraform/network: Terraform code for VPC, subnets, IGW, NAT, security groups
- terraform/infra: Terraform code for ECS cluster/Service/Task Definition, ALB, RDS instance, IAM roles, user-data templates

##### Extract architecture details from README
- Frontend: Flask app in Docker
- Containerization: Docker → AWS ECS (Fargate or EC2)
- Database: AWS RDS (MySQL/MariaDB)
- IaC: Terraform modules for network then application infrastructure
- Environment variables injected at runtime for DB connectivity

##### Main components & their interactions
a. Users & Clients
- Web browser/mobile app → HTTP(S) requests
b. Networking Layer (Terraform “network” module)
- VPC
- Public subnets + Internet Gateway (for ALB)
- Private subnets + NAT Gateway (for ECS tasks, if needed)
- Security Groups
c. Load Balancer
- AWS Application Load Balancer (deployed in public subnets)
- Listens on TCP/HTTP(S) 80/443
d. Container Compute (Terraform “infra” module)
- ECS Cluster
- ECS Service + Task Definition (Docker image “orbwatch”)
- Flows: ALB → ECS Service → Docker container (Flask)
e. Data Layer
- AWS RDS instance (MySQL/MariaDB) in private subnets
- ECS containers connect to RDS over private network
f. Infrastructure as Code
- Terraform drives creation of all above
- Two modules: network first, then infra (depends on network outputs)

##### Architectural patterns & principles
- Layered: Presentation (Flask templates), Application (Flask API), Data (RDS)
- Twelve-factor app: config via environment variables (`DB_HOST`, etc.)
- Immutable infrastructure: containers deployed via ECS with Terraform
- Infrastructure modularization: separate network vs. app modules

## Diagram (Mermaid)

```mermaid
graph TD
    developer["Developer Machine"]:::external
    dockerbuild["Docker Build\n(Dockerfile + requirements.txt)"]:::compute
    tf_network["Terraform Network Module"]:::terraform
    tf_infra["Terraform Infra Module"]:::terraform
    aws["AWS Cloud"]:::external

    subgraph "Local Development"
        developer -->|builds image| dockerbuild
        dockerfile["Dockerfile"]:::compute
        requirements["requirements.txt"]:::compute
        dockerbuild --> dockerfile
        dockerbuild --> requirements
        orbwatch_app["Flask App Entry Point\n(app.py)"]:::compute
        orbwatch_logic["Flask Business Logic\n(orbwatch.py)"]:::compute
        static_dir["Static Assets\n(static/)"]:::compute
        css_file["styles.css"]:::compute
        js_file["main.js"]:::compute
        template["HTML Template\n(index.html)"]:::compute
        dockerbuild --> orbwatch_app
        orbwatch_app --> orbwatch_logic
        orbwatch_app --> static_dir
        static_dir --> css_file
        static_dir --> js_file
        orbwatch_app --> template
    end

    subgraph "Infrastructure as Code"
        tf_network --> tf_net_provider["_provider.tf"]:::terraform
        tf_network --> tf_net_vars["_vars.tf"]:::terraform
        tf_network --> tf_net_main["main.tf"]:::terraform
        tf_infra --> tf_inf_provider["_provider.tf"]:::terraform
        tf_infra --> tf_inf_vars["_vars.tf"]:::terraform
        tf_infra --> tf_inf_data["_data.tf"]:::terraform
        tf_infra --> tf_inf_main["main.tf"]:::terraform
        tf_infra --> tf_userdata["userdata.tftpl"]:::terraform
    end

    subgraph "AWS Cloud"
        subgraph "VPC" 
            vpc
            subgraph "Public Subnets"
                public
                alb["Application Load Balancer\n(HTTP/HTTPS)"]:::network
            end
            subgraph "Private Subnets"
                private
                ecs["ECS Cluster & Service"]:::compute
                container["Docker Container\n(Flask)"]:::compute
                rds["RDS Instance\n(MySQL/MariaDB)"]:::data
            end
        end
    end

    developer -->|runs Terraform| tf_network
    developer -->|runs Terraform| tf_infra
    tf_network -->|provisions| vpc
    tf_network -->|creates| public
    tf_network -->|creates| private
    tf_infra -->|deploys| alb
    tf_infra -->|deploys| ecs
    tf_infra -->|provisions| rds

    public --> alb
    alb -->|HTTP| ecs
    ecs --> container
    container -->|TCP/MySQL| rds

    readme["README.md"]:::external
    diagram_file["diagram.drawio"]:::external

    classDef compute fill:#D1E8FF,stroke:#0366D6,color:#0366D6;
    classDef network fill:#FFE5B4,stroke:#D2691E,color:#D2691E;
    classDef data fill:#E2F0CB,stroke:#6AA121,color:#6AA121;
    classDef terraform fill:#EAD1DC,stroke:#C00081,color:#C00081;
    classDef external fill:#EDEDED,stroke:#666666,color:#333333;

    click orbwatch_app "https://github.com/ehoang0106/containerized/blob/master/myapp/webapp/app.py"
    click orbwatch_logic "https://github.com/ehoang0106/containerized/blob/master/myapp/webapp/orbwatch.py"
    click static_dir "https://github.com/ehoang0106/containerized/tree/master/myapp/webapp/static/"
    click css_file "https://github.com/ehoang0106/containerized/blob/master/myapp/webapp/static/css/styles.css"
    click js_file "https://github.com/ehoang0106/containerized/blob/master/myapp/webapp/static/js/main.js"
    click template "https://github.com/ehoang0106/containerized/blob/master/myapp/webapp/templates/index.html"
    click dockerfile "https://github.com/ehoang0106/containerized/tree/master/Dockerfile"
    click requirements "https://github.com/ehoang0106/containerized/blob/master/requirements.txt"
    click tf_network "https://github.com/ehoang0106/containerized/tree/master/terraform/network/"
    click tf_net_provider "https://github.com/ehoang0106/containerized/blob/master/terraform/network/_provider.tf"
    click tf_net_vars "https://github.com/ehoang0106/containerized/blob/master/terraform/network/_vars.tf"
    click tf_net_main "https://github.com/ehoang0106/containerized/blob/master/terraform/network/main.tf"
    click tf_infra "https://github.com/ehoang0106/containerized/tree/master/terraform/infra/"
    click tf_inf_provider "https://github.com/ehoang0106/containerized/blob/master/terraform/infra/_provider.tf"
    click tf_inf_vars "https://github.com/ehoang0106/containerized/blob/master/terraform/infra/_vars.tf"
    click tf_inf_data "https://github.com/ehoang0106/containerized/blob/master/terraform/infra/_data.tf"
    click tf_inf_main "https://github.com/ehoang0106/containerized/blob/master/terraform/infra/main.tf"
    click tf_userdata "https://github.com/ehoang0106/containerized/blob/master/terraform/infra/userdata.tftpl"
    click readme "https://github.com/ehoang0106/containerized/blob/master/README.md"
    click diagram_file "https://github.com/ehoang0106/containerized/blob/master/media/diagram.drawio"
```
