# rocketseat-content/pulumi-aws-nodejs architecture

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

- Interactive diagram: https://gitdiagram.com/rocketseat-content/pulumi-aws-nodejs
- Repository: https://github.com/rocketseat-content/pulumi-aws-nodejs

## Overview

##### Project Type and Purpose
- This is a workshop project focused on deploying an API to AWS.
- The primary components include a backend API code (in src/server.ts), containerization with Docker (using the Dockerfile and associated build instructions), and infrastructure-as-code for AWS deployment using Pulumi (located in the infra directory).
- There’s also an automated CI/CD aspect provided via the GitHub Actions workflow (in .github/workflows/deploy-api.yml), which likely triggers the deployment process.

##### File Structure
- Top-level project files:
- Dockerfile: Defines how to package the API into a Docker container.
- README.md: Provides instructions for building and running the Docker image.
- package.json, tsconfig.json, tsup.config.ts: These files suggest a Node.js/TypeScript environment for the API.
- The src directory contains the actual server code (server.ts).
- The infra directory includes Pulumi configuration files (Pulumi.yaml, Pulumi.dev.yaml, index.ts, etc.), indicating how the AWS infrastructure is defined and deployed.
- The .github/workflows folder holds a deploy pipeline configuration that automates deployment of the API.

a. Main Components:
- API Server: Represent the service implemented in src/server.ts, which is the core application logic exposed as an API on port 3333.
- Docker Container: Show that the API server is packaged inside a Docker image built using the Dockerfile.
- CI/CD Pipeline: Include GitHub Actions (deploy-api.yml) that automates the build and deployment processes.
- Infrastructure-as-Code (Pulumi): Highlight the infra directory where Pulumi scripts define AWS resources (such as compute resources, networking, etc.) to host the API container.
- AWS Environment: Although not explicitly listed in files, represent the target AWS environment where the container runs.

b. Relationships & Data Flow:
- The API code is containerized by Docker (Dockerfile → Docker build process).
- GitHub Actions (CI/CD) triggers the build process and then runs deployment tasks using Pulumi, which provisions and configures AWS resources.
- The API container, once deployed, listens on port 3333, serving requests.
- Pulumi interacts with AWS services to deploy and manage the infrastructure required to host the container.

##### Architectural Patterns and Design Principles
- Modular separation of concerns:
- Application Code (src) is separated from Infrastructure Code (infra).
- The Dockerfile encapsulates the build environment, ensuring portability.
- CI/CD (GitHub Actions) decouples manual intervention from deployments.
- Infrastructure-as-Code:
- Use of Pulumi for defining AWS infrastructure resources clearly distinguishes configuration management from application logic.
- Containerization:
- Emphasizes portability and consistency between development and production environments.

##### Final Reminders
- Be very detailed: Ensure every element from the file structure is represented.
- Essential interdependencies: Each transition (code to container, container to deployment, etc.) should be clearly marked.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Source & Code"
        API["API Server (src/server.ts)"]:::api
    end

    subgraph "CI/CD Pipeline"
        CI["CI/CD Pipeline (GitHub Actions)"]:::ci
    end

    subgraph "Containerization"
        DOCKER["Docker Container Build (Dockerfile)"]:::container
    end

    subgraph "Infrastructure"
        IAC["Infrastructure as Code (Pulumi)"]:::iac
        AWS["AWS Environment"]:::aws
    end

    API -->|"push_code"| CI
    CI -->|"trigger_build"| DOCKER
    DOCKER -->|"build_success"| CI
    CI -->|"deploy_using"| IAC
    IAC -->|"provision_container"| AWS

    click API "https://github.com/rocketseat-content/pulumi-aws-nodejs/blob/main/src/server.ts"
    click DOCKER "https://github.com/rocketseat-content/pulumi-aws-nodejs/tree/main/Dockerfile"
    click CI "https://github.com/rocketseat-content/pulumi-aws-nodejs/blob/main/.github/workflows/deploy-api.yml"
    click IAC "https://github.com/rocketseat-content/pulumi-aws-nodejs/tree/main/infra/"

    classDef api fill:#aee1f9,stroke:#0a74da,stroke-width:2px;
    classDef ci fill:#fde2a3,stroke:#f4a261,stroke-width:2px;
    classDef container fill:#c7f9cc,stroke:#2f5233,stroke-width:2px;
    classDef iac fill:#d3c0eb,stroke:#8e44ad,stroke-width:2px;
    classDef aws fill:#f7c59f,stroke:#d35400,stroke-width:2px;
```
