# mahesh100/micronaut-with-aws-lambda architecture

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

- Interactive diagram: https://gitdiagram.com/mahesh100/micronaut-with-aws-lambda
- Repository: https://github.com/mahesh100/micronaut-with-aws-lambda

## Overview

##### Project Type and Purpose
- This is a serverless microservice/demo application built on Micronaut (Java), intended to run as AWS Lambda functions.
- It demonstrates handling HTTP requests (GreetingHandler, RedisController), processing DynamoDB Streams events (DynamoDBStreamhandler), and encapsulates business logic in a service class (MyService).

##### File‐Structure Analysis
- src/main/java/com/example/demo/Application.java — Micronaut entry point, bootstraps the Lambda environment or embedded HTTP server.
- Handlers/controllers:
- GreetingHandler.java — HTTP Lambda endpoint (e.g., GET /greet).
- RedisController.java — HTTP endpoint interacting with Redis (ElastiCache).
- DynamoDBStreamhandler.java — AWS Lambda event handler for DynamoDB Streams.
- MyService.java — Shared business logic, invoked by controllers/handlers.
- application.yml — Configuration for AWS credentials, DynamoDB table names, Redis URL, logging levels.
- build.gradle + Shadow plugin — Bundles the application into a fat JAR for deployment.

##### Key Components
a. API Gateway (or HTTP Trigger)
- Triggers GreetingHandler and RedisController Lambdas on HTTP calls.
b. AWS Lambda Functions
- GreetingHandler
- RedisController
- DynamoDBStreamhandler (triggered by DynamoDB Streams).
c. Business Layer
- MyService (shared component invoked by all handlers).
d. External Systems
- DynamoDB (source table + Streams)
- Redis (ElastiCache cluster or Redis instance)
- Any outbound HTTP services called by MyService (if applicable).
e. Build & Deployment
- Gradle/Shadow: builds a single executable JAR.
- CI/CD (optional): pipeline pushing JAR to AWS Lambda.

##### Relationships & Data Flows
- HTTP Request → API Gateway → Lambda (GreetingHandler or RedisController) → MyService → DynamoDB or Redis → Response back to caller.
- DynamoDB Table Update → DynamoDB Streams → DynamoDBStreamhandler → MyService → downstream processing or external HTTP call.
- MyService may also call external REST APIs using Micronaut HTTP client (if implemented).

##### Architectural Patterns & Principles
- Serverless functions for event-driven and HTTP workloads.
- Single‐jar microservice via Shadow plugin.
- Dependency injection via Micronaut’s IoC container.
- Configuration externalized in application.yml.
- Separation of concerns:
- Handlers/controllers handle transport (HTTP, Streams)
- MyService contains domain logic

- Clear labels: component names, ports/endpoints (e.g., /greet, /redis).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Subgraphs and modules
    subgraph "AWS Serverless"
        API["API Gateway"]:::compute
        APP["Application Entry Point"]:::compute
        GH["GreetingHandler"]:::compute
        RC["RedisController"]:::compute
        DBH["DynamoDBStreamhandler"]:::compute
        MS["MyService"]:::compute
    end

    subgraph "External Systems"
        DDB["DynamoDB Table"]:::store
        DDBS["DynamoDB Streams"]:::store
        REDIS["Redis (ElastiCache)"]:::store
        EXT["External REST API"]:::external
    end

    subgraph "Build & Deployment"
        CFG["application.yml"]:::deploy
        LOG["logback.xml"]:::deploy
        BUILD["build.gradle + Shadow"]:::deploy
        TEST["LambdaDemoAppTest"]:::deploy
    end

    %% Connections: HTTP triggers
    API -->|"/greet (HTTP GET)"| GH
    API -->|"/redis (HTTP)"| RC

    %% Lambda to service
    GH -->|"invoke"| MS
    RC -->|"invoke"| MS
    DBH -->|"invoke"| MS

    %% Service to data stores and external
    MS -->|"Read/Write"| DDB
    MS -->|"Cache"| REDIS
    MS -->|"HTTP Call"| EXT

    %% DynamoDB Streams flow
    DDB -->|"Stream Event"| DDBS
    DDBS -->|"trigger"| DBH

    %% Entry point and configuration
    APP -->|"bootstraps"| GH
    APP -->|"bootstraps"| RC
    APP -->|"bootstraps"| DBH
    APP -->|"injects"| MS

    CFG -.-> GH
    CFG -.-> RC
    CFG -.-> DBH
    CFG -.-> MS
    LOG -.-> GH
    LOG -.-> RC
    LOG -.-> DBH
    LOG -.-> MS

    BUILD -->|"packages JAR"| GH
    BUILD -->|"packages JAR"| RC
    BUILD -->|"packages JAR"| DBH

    TEST -->|"validates"| GH
    TEST -->|"validates"| RC
    TEST -->|"validates"| DBH

    %% Click Events
    click APP "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/java/com/example/demo/Application.java"
    click GH "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/java/com/example/demo/GreetingHandler.java"
    click RC "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/java/com/example/demo/RedisController.java"
    click DBH "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/java/com/example/demo/DynamoDBStreamhandler.java"
    click MS "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/java/com/example/demo/MyService.java"
    click CFG "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/resources/application.yml"
    click LOG "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/main/resources/logback.xml"
    click BUILD "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/build.gradle"
    click TEST "https://github.com/mahesh100/micronaut-with-aws-lambda/blob/main/src/test/java/com/example/demo/LambdaDemoAppTest.java"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef store fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef deploy fill:#FFD700,stroke:#333,stroke-width:1px
```
