# ghadeer-elsalhawy/cd0157-server-deployment-and-containerization architecture

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

- Interactive diagram: https://gitdiagram.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization
- Repository: https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization

## Overview

##### Project Type and Purpose
- This project is a starter repository focused on containerizing and deploying a simple Flask API. It walks users through building, testing, and deploying a containerized Flask app to a Kubernetes cluster using AWS EKS, CodePipeline, and CodeBuild.
- Key operations include building a Docker container for the Flask API, writing deployment configurations, and guiding the CI/CD process with AWS services alongside Kubernetes for production deployments.

##### File Structure
- Top-Level Files: Notice the presence of key files such as Dockerfile, main.py, requirements.txt, and CI/CD configuration files (buildspec.yml, ci-cd-codepipeline.cfn.yml, simple_jwt_api.yml). These indicate the core functionality (Flask API) and multiple deployment pipelines.
- Directories:
- .github contains CI workflow definitions.
- examples provide multiple deployment and cloudformation templates that illustrate how to deploy using various AWS resources (CloudFormation for EC2, VPN, and pipelines) and also include examples for deploying Flask apps.
- Other configuration files (aws-auth-patch.yml, iam-role-policy.json, trust.json) signal AWS-specific configurations and permission policies.
- The organization hints at a modular design where various deployment examples and CloudFormation templates offer flexibility in infrastructure deployment approaches.

##### Extract Additional Insight from the README
- The README emphasizes the deployment steps—from Docker containerization, local testing, and then full deployment on AWS EKS using CodePipeline and CodeBuild.
- It specifies key endpoints of the Flask API, which reinforces that the app is lightweight and designed for demonstration (health check, authentication, content retrieval).
- It lays out prerequisites and instructions for AWS CLI, eksctl, and kubectl—indicating a production-grade deployment pipeline with a Kubernetes cluster.

a. Main Components to Include:
- Source Code Repository (GitHub): Including CI workflows (.github folder) that trigger on code updates.
- Build and CI/CD Pipeline: This includes CodePipeline and CodeBuild stages. The buildspec.yml and CodePipeline CloudFormation template are central here.
- Docker Build Process: Represents Dockerfile-based container build of the Flask API.
- Container Registry: Though not explicitly shown, assume use of a container repository (like AWS ECR) where the built images are stored.
- Kubernetes Cluster (AWS EKS): The deployment target for the Docker container. This is where the production-ready Gunicorn-based Flask API will run.
- AWS Infrastructure Components: CloudFormation templates, IAM role policies, and other AWS resources (e.g., for secret storage, VPN configuration) are part of the deployment infrastructure.
- Testing: Indicate components for testing the Flask API (locally via main.py and test_main.py).

b. Relationships and Interactions:
- Docker build process as part of CodeBuild, outputting a container image that’s pushed to the container registry.
- Monitoring/health check endpoints as a feedback loop (for example, the “/” endpoint for health checks).

c. Architectural Patterns/Design Principles:
- A clear separation of concerns: the CI/CD pipeline, containerization, and deployment onto a managed Kubernetes service.
- The use of Infrastructure-as-Code (CloudFormation templates and CI/CD definitions) to manage AWS resources.
- Modular design, as shown by the presence of multiple example directories for CloudFormation and deployment scenarios.

d. Relevant Technologies, Frameworks, and Services:
- Flask (for the API)
- Docker (for containerization)
- Gunicorn (as the production server for Flask)
- AWS EKS (for Kubernetes hosting)
- AWS CodePipeline and CodeBuild (for CI/CD)
- CloudFormation (for infrastructure deployment)
- AWS IAM (for role and policy management)

##### Final Reminder
- Every AWS and deployment component (e.g., CloudFormation templates, IAM roles, and secret management) is reflected in the architecture.
- The primary goal is to capture the flow from source code management, through CI/CD, containerization, and eventual deployment onto AWS EKS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Code Repository
    Source["Source Code (GitHub)"]:::source

    %% CI/CD Pipeline Subgraph
    subgraph "CI/CD Pipeline"
        Pipeline["CI/CD Pipeline (CodePipeline & CodeBuild)"]:::cicd
        Buildspec["Buildspec (buildspec.yml)"]:::cicd
        CodePipelineCF["CodePipeline Template (ci-cd-codepipeline.cfn.yml)"]:::cicd
        PipelineExample["Pipeline Example (examples/Create_Pipeline)"]:::cicd
    end

    %% Docker Build Process Subgraph
    subgraph "Docker Build Process"
        DockerAgg["Docker Build Process"]:::docker
        subgraph "Docker Build Configurations"
            DockerMain["Dockerfile (Root)"]:::docker
            DockerDeploy["Dockerfile (Deploy_Flask_App)"]:::docker
            DockerFlask["Dockerfile (Flask)"]:::docker
            DockerHello["Dockerfile (Hello)"]:::docker
        end
    end

    %% Container Registry
    ContainerRegistry["Container Registry (ECR)"]:::registry

    %% AWS EKS Cluster Subgraph
    subgraph "AWS EKS Cluster"
        EKS["AWS EKS Cluster"]:::eks
    end

    %% AWS Infrastructure Subgraph
    subgraph "AWS Infrastructure"
        CloudFormationEC2["CloudFormation: EC2 (template_EC2.yml)"]:::infra
        CloudFormationVPN["CloudFormation: VPN (template_VPN.yml)"]:::infra
        IAMPolicy["IAM Policy (iam-role-policy.json)"]:::infra
        TrustFile["Trust Config (trust.json)"]:::infra
        AWSAuthPatch["AWS Auth Patch (aws-auth-patch.yml)"]:::infra
    end

    %% Flask API Application Subgraph
    subgraph "Flask API Application"
        AppMain["App Code (main.py)"]:::app
        AppTest["Tests (test_main.py)"]:::app
        DeployApp["Deploy App (Deploy_Flask_App/app.py)"]:::app
        FlaskApp["Flask App (flask/app.py)"]:::app
    end

    %% Kubernetes Deployment Configuration Subgraph
    subgraph "K8s Deployment Config"
        K8sConfig["K8s Config (simple_jwt_api.yml)"]:::deploy
        K8sDeploy["Deployment YAML (Deploy_Flask_App/deployment.yml)"]:::deploy
    end

    %% Main Flow Connections
    Source -->|"pushesCode"| Pipeline
    Source -->|"containsAppCode"| AppMain
    Source -->|"containsTests"| AppTest
    Pipeline -->|"triggersBuild"| DockerAgg
    Buildspec --- Pipeline
    CodePipelineCF --- Pipeline
    PipelineExample --- Pipeline
    DockerAgg -->|"buildsImage"| ContainerRegistry
    DockerMain --- DockerAgg
    DockerDeploy --- DockerAgg
    DockerFlask --- DockerAgg
    DockerHello --- DockerAgg
    ContainerRegistry -->|"deploysImage"| EKS
    K8sConfig -->|"configuresDeployment"| EKS
    K8sDeploy -->|"appliedTo"| EKS
    Pipeline -->|"provisionsInfra"| CloudFormationEC2
    Pipeline -->|"provisionsInfra"| CloudFormationVPN
    CloudFormationEC2 --> EKS
    CloudFormationVPN --> EKS
    IAMPolicy --> EKS
    TrustFile --> EKS
    AWSAuthPatch --> EKS

    %% Click Events
    click Source "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/.github/workflows/manual.yml"
    click Buildspec "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/buildspec.yml"
    click CodePipelineCF "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/ci-cd-codepipeline.cfn.yml"
    click PipelineExample "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/examples/Create_Pipeline/buildspec.yml"
    click DockerMain "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/tree/master/Dockerfile"
    click DockerDeploy "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/tree/master/examples/Deploy_Flask_App/Dockerfile"
    click DockerFlask "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/tree/master/examples/flask/Dockerfile"
    click DockerHello "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/tree/master/examples/hello/Dockerfile"
    click CloudFormationEC2 "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/examples/Cloudformation/template_EC2.yml"
    click CloudFormationVPN "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/examples/Cloudformation/template_VPN.yml"
    click IAMPolicy "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/iam-role-policy/iam-role-policy.json"
    click TrustFile "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/trust.json"
    click AWSAuthPatch "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/aws-auth-patch.yml"
    click AppMain "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/main.py"
    click AppTest "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/test_main.py"
    click DeployApp "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/examples/Deploy_Flask_App/app.py"
    click FlaskApp "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/examples/flask/app.py"
    click K8sConfig "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/simple_jwt_api.yml"
    click K8sDeploy "https://github.com/ghadeer-elsalhawy/cd0157-server-deployment-and-containerization/blob/master/examples/Deploy_Flask_App/deployment.yml"

    %% Style Definitions
    classDef source fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef cicd fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef docker fill:#98FB98,stroke:#008000,stroke-width:2px;
    classDef registry fill:#FFC0CB,stroke:#FF69B4,stroke-width:2px;
    classDef eks fill:#FFE4B5,stroke:#CD853F,stroke-width:2px;
    classDef infra fill:#AFEEEE,stroke:#20B2AA,stroke-width:2px;
    classDef app fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef deploy fill:#E6E6FA,stroke:#9370DB,stroke-width:2px;
```
