# itsmeaksingh/basicawsanguarintegration architecture

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

- Interactive diagram: https://gitdiagram.com/itsmeaksingh/basicawsanguarintegration
- Repository: https://github.com/itsmeaksingh/basicawsanguarintegration

## Overview

##### Project type and purpose
- This is a full-stack demo application integrating an Angular single-page frontend (“demo-app”) with an AWS Serverless backend (“sam-app”).
- The README notes AWS CloudFormation (via SAM), Angular, DynamoDB, API Gateway, S3, etc. The goal is to show how the Angular UI interacts with AWS-hosted Lambdas and a DynamoDB data store.

##### File structure
- Top-level folders:
- demo-app/ – standard Angular project (src/app, environments, angular.json, etc.)
- sam-app/ – AWS SAM project with template.yaml, Lambda handlers under handlers/, local env.json, buildspec.yml for CI, test harness in __tests__/
- Angular client: organized by Services, models, and feature components (users CRUD).
- Serverless backend: individual Lambda functions for create/read/update/delete users, triggered via API Gateway. DynamoDB table defined in template.yaml.
- CI/CD: .github/workflows/main.yml and sam-app/buildspec.yml imply automated build/deploy pipelines.

##### README
- Confirms use of Angular front-end and AWS resources (API Gateway, DynamoDB, S3).

##### Main components
a. Frontend (Angular SPA)
- Users access via browser.
- Hosted (optionally) on S3 + CloudFront or served locally for demo.
- Contains Services (user.service) that call REST APIs.
b. API Layer (Amazon API Gateway)
- Exposes REST endpoints: GET /users, POST /user, GET /user/{id}, PUT /user/{id}, DELETE /user/{id}.
- Routes requests to corresponding Lambda functions.
c. Compute Layer (AWS Lambda functions)
- One function per operation, located under sam-app/handlers/...
- Demo and production handlers coexist (e.g., demo-create-user vs create-user).
- Node.js runtime, each with its own package.json.
d. Data Layer (Amazon DynamoDB)
- Single “Users” table managed via SAM template.yaml.
- Lambda functions perform CRUD on this table.
e. Deployment & CI/CD
- AWS SAM CLI (samconfig.toml) and CloudFormation stack.
- GitHub Actions (.github/workflows/main.yml) or AWS CodeBuild (buildspec.yml).
f. (Optional) S3 & CloudFront for static hosting of Angular build artifacts

##### Relationships and interactions
- Browser → (HTTPS) → S3/CloudFront hosting static Angular assets
- Angular user.service.ts → (HTTPS REST call) → API Gateway endpoint
- API Gateway → invokes appropriate Lambda handler
- Lambda → reads/writes → DynamoDB table
- Lambda → returns HTTP response → API Gateway → propagates to Angular
- CI/CD pipelines push Angular build to S3 and deploy SAM stack (CloudFormation)

##### Architectural patterns & design principles
- Separation of concerns: UI vs API vs data store
- Microservices-style: one Lambda function per business operation
- Infrastructure as code: AWS SAM template.yaml and CI configurations
- Clear layering for testability (unit tests under demo-app and __tests__ in sam-app)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    Browser["User Browser"]:::external
    Browser -->|"HTTP GET static assets"| StaticHost

    %% Static Hosting
    StaticHost["S3 & CloudFront\n(Static Hosting)"]:::aws
    StaticHost -->|"Serves Angular SPA"| AngularSPA

    %% Frontend Layer
    subgraph "Angular SPA (demo-app)" 
        direction TB
        AngularSPA["Angular SPA\n(Angular 12)"]:::ui
        Env["environment.ts"]:::config
        EnvDev["environment.development.ts"]:::config
        UserService["user.service.ts"]:::service
        UserServiceSpec["user.service.spec.ts"]:::test
        UserModel["User.ts"]:::model
        RoleModel["Role.ts"]:::model
        UsersUI["Users CRUD Components"]:::component

        AngularSPA --> Env
        AngularSPA --> EnvDev
        AngularSPA --> UserService
        AngularSPA --> UsersUI
        AngularSPA --> UserModel
        AngularSPA --> RoleModel
        UserService --> UserServiceSpec
    end

    AngularSPA -->|"REST API calls\n(GET/POST/PUT/DELETE)"| APIGateway

    %% Backend CloudFormation Stack
    subgraph "AWS SAM Stack" 
        direction TB
        APIGateway["API Gateway\n(REST API)"]:::aws

        subgraph "Lambda Functions" 
            direction TB
            DemoGetAll["demo-get-all-users\nLambda"]:::lambda
            DemoGetOne["demo-get-user\nLambda"]:::lambda
            DemoCreate["demo-create-user\nLambda"]:::lambda
            DemoUpdate["demo-update-user\nLambda"]:::lambda
            DemoDelete["demo-delete-user\nLambda"]:::lambda
            ProdGetAll["get-all-users\nLambda"]:::lambda
        end

        DynamoDB["DynamoDB Users Table"]:::aws

        APIGateway -->|"GET /users"| DemoGetAll
        APIGateway -->|"GET /user/{id}"| DemoGetOne
        APIGateway -->|"POST /user"| DemoCreate
        APIGateway -->|"PUT /user/{id}"| DemoUpdate
        APIGateway -->|"DELETE /user/{id}"| DemoDelete
        APIGateway -->|"GET /users (prod)"| ProdGetAll

        DemoGetAll -->|"CRUD operations"| DynamoDB
        DemoGetOne --> DynamoDB
        DemoCreate --> DynamoDB
        DemoUpdate --> DynamoDB
        DemoDelete --> DynamoDB
        ProdGetAll --> DynamoDB
    end

    %% CI/CD Pipeline
    subgraph "CI/CD" 
        direction TB
        GHWorkflow["GitHub Actions\n(.github/workflows/main.yml)"]:::ci
        CodeBuild["AWS CodeBuild\n(buildspec.yml)"]:::ci
        SAMCLI["SAM CLI\ndeploy (samconfig.toml)"]:::tools
        EnvJSON["Local Lambda Config\n(env.json)"]:::config
        LambdaTests["Lambda Unit Tests"]:::test

        GHWorkflow -->|"CI triggers"| CodeBuild
        CodeBuild -->|"build & test"| LambdaTests
        CodeBuild -->|"deploy SAM stack"| SAMCLI
        CodeBuild -->|"sync SPA to S3"| StaticHost
        LambdaTests -->|"uses config"| EnvJSON
    end

    %% Click Events
    click AngularSPA "https://github.com/itsmeaksingh/basicawsanguarintegration/tree/main/demo-app/"
    click Env "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/demo-app/src/environments/environment.ts"
    click EnvDev "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/demo-app/src/environments/environment.development.ts"
    click UserService "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/demo-app/src/app/Services/user.service.ts"
    click UserServiceSpec "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/demo-app/src/app/Services/user.service.spec.ts"
    click UserModel "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/demo-app/src/app/_models/User.ts"
    click RoleModel "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/demo-app/src/app/_models/Role.ts"
    click UsersUI "https://github.com/itsmeaksingh/basicawsanguarintegration/tree/main/demo-app/src/app/users/"
    click Template "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/template.yaml"
    click DemoCreate "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/handlers/demo-create-user/index.js"
    click DemoDelete "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/handlers/demo-delete-user/index.js"
    click DemoGetAll "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/handlers/demo-get-all-users/index.js"
    click DemoGetOne "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/handlers/demo-get-user/index.js"
    click DemoUpdate "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/handlers/demo-update-user/index.js"
    click ProdGetAll "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/handlers/get-all-users/index.js"
    click EnvJSON "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/env.json"
    click SAMCLI "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/samconfig.toml"
    click LambdaTests "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/__tests__/unit/handlers/get-all-items.test.js"
    click GHWorkflow "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/.github/workflows/main.yml"
    click CodeBuild "https://github.com/itsmeaksingh/basicawsanguarintegration/blob/main/sam-app/buildspec.yml"

    %% Styles
    classDef aws fill:#cce5ff,stroke:#3399ff,color:#000
    classDef lambda fill:#d4edda,stroke:#28a745,color:#000
    classDef ui fill:#ffe5cc,stroke:#ff9900,color:#000
    classDef service fill:#fff2cc,stroke:#ffcc00,color:#000
    classDef model fill:#f0f0f0,stroke:#999,color:#000
    classDef component fill:#f9e5f7,stroke:#d63384,color:#000
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#000
    classDef test fill:#f8d7da,stroke:#dc3545,color:#000
    classDef external fill:#e2f0d9,stroke:#28a745,color:#000
    classDef ci fill:#e8eaf6,stroke:#3f51b5,color:#000
    classDef tools fill:#f0f4c3,stroke:#afb42b,color:#000
```
