# nhan295/ci-cd-pipeline-with-aws architecture

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

- Interactive diagram: https://gitdiagram.com/nhan295/ci-cd-pipeline-with-aws
- Repository: https://github.com/nhan295/ci-cd-pipeline-with-aws

## Overview

##### Project Type and Purpose
- The project is a Python application designed to run inside a Docker container and is configured with AWS Continuous Integration (CI) and Continuous Delivery (CD) pipelines.
- The README shows that the system’s purpose is to automate software builds, tests, and deployments using AWS CodeBuild, CodePipeline, and CodeDeploy with GitHub as the source repository.

##### Key Components from the File Structure and README
a. Application Code:
- app.py: The main Python application.
- requirements.txt: Lists the dependencies required to run the application.
- Dockerfile: Used to build the container image.
b. CI/CD Configuration:
- buildspec.yaml: Contains build instructions for AWS CodeBuild.
- appspec.yml: Provides deployment instructions for AWS CodeDeploy.
c. Scripts for Container Management:
- scripts/start_container.sh and scripts/stop_container.sh: Likely used to manage container runtime (starting/stopping).
d. AWS Integration Artifacts (as detailed in the README):
- AWS CodeBuild: Receives the source from GitHub and builds the application container.
- AWS CodePipeline: Orchestrates the CI/CD steps, integrating CodeBuild and CodeDeploy.
- AWS CodeDeploy: Deploys the built application to EC2 instances.
- AWS Systems Manager Parameter Store: Stores configuration parameters (e.g., Docker credentials and image repository URL).

a. Source Code Management:
- GitHub Repository: The starting point where the source code (including all files mentioned) resides.
b. Continuous Integration (CI) Process:
- AWS CodeBuild: Connect to the GitHub repository to fetch the source code. Use buildspec.yaml to build and package the Docker container based on the Dockerfile.
c. Continuous Deployment (CD) Process:
- AWS CodePipeline: Orchestrates the pipeline. It includes stages for source (GitHub), build (CodeBuild), and deployment (CodeDeploy).
d. Deployment and Runtime:
- AWS CodeDeploy: Deploys the built application to an EC2 Instance. Inside the deployment, our app.py runs (within a container started by the scripts).
- EC2 Instance: Receives deployments from CodeDeploy and is tagged appropriately for CodeDeploy to recognize the instance.
e. AWS Systems Manager:
- Parameter Store: Holds configuration parameters (like Docker credentials) that may be injected during deployment or build steps.

##### Architectural Patterns and Design Principles
- Containerization: Highlight the Docker container build process and runtime management as critical parts of the deployment.
- AWS Integration: Emphasize the usage of AWS services to handle these different aspects (build, deployment, configuration management).

##### Elements
- Each Component should be clearly labeled (e.g., “GitHub Repository”, “AWS CodeBuild”, “AWS CodePipeline”, “AWS CodeDeploy”, “EC2 Instance”, “Parameter Store”).
- Instance or container management details (scripts for starting/stopping container) could be depicted as part of the runtime environment in the EC2 block.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Layer
    subgraph "Source Layer"
        A["GitHub Repository"]:::source
    end

    %% Build Layer
    subgraph "Build Layer"
        B["AWS CodeBuild"]:::build
        X1["buildspec.yaml"]:::code
    end

    %% Pipeline Orchestration
    subgraph "Pipeline Orchestration"
        C["AWS CodePipeline"]:::pipeline
    end

    %% Deployment Layer
    subgraph "Deployment Layer"
        D["AWS CodeDeploy"]:::deploy
        X2["appspec.yml"]:::code
    end

    %% Runtime Layer
    subgraph "Runtime Layer"
        E["EC2 Instance"]:::runtime
        %% Deployed components in EC2
        subgraph "Docker Container"
            A1["app.py"]:::code
            A2["requirements.txt"]:::code
            A3["Dockerfile"]:::code
        end
        subgraph "Container Management"
            S1["start_container.sh"]:::scripts
            S2["stop_container.sh"]:::scripts
        end
    end

    %% Relationships between layers
    A -->|"triggers"| B
    B -->|"uses"| X1
    B -->|"sendsArtifact"| C
    C -->|"orchestrates"| D
    D -->|"deploysTo"| E
    D -->|"uses"| X2

    %% Indicate that deployed container is managed by scripts
    A1 -->|"managedBy"| S1
    A1 -->|"managedBy"| S2

    %% Styles
    classDef source fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef build fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#abebc6,stroke:#333,stroke-width:2px;
    classDef deploy fill:#f5cba7,stroke:#333,stroke-width:2px;
    classDef runtime fill:#d5dbdb,stroke:#333,stroke-width:2px;
    classDef code fill:#fadbd8,stroke:#333,stroke-width:2px;
    classDef scripts fill:#fcf3cf,stroke:#333,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/nhan295/ci-cd-pipeline-with-aws/blob/main/app.py"
    click A2 "https://github.com/nhan295/ci-cd-pipeline-with-aws/blob/main/requirements.txt"
    click A3 "https://github.com/nhan295/ci-cd-pipeline-with-aws/tree/main/Dockerfile"
    click X1 "https://github.com/nhan295/ci-cd-pipeline-with-aws/blob/main/buildspec.yaml"
    click X2 "https://github.com/nhan295/ci-cd-pipeline-with-aws/blob/main/appspec.yml"
    click S1 "https://github.com/nhan295/ci-cd-pipeline-with-aws/blob/main/scripts/start_container.sh"
    click S2 "https://github.com/nhan295/ci-cd-pipeline-with-aws/blob/main/scripts/stop_container.sh"
```
