# engineerscodes/amba architecture

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

- Interactive diagram: https://gitdiagram.com/engineerscodes/amba
- Repository: https://github.com/engineerscodes/amba

## Overview

##### Main Components
a. Frontend/Client (even though not in the repository, the README mentions admin pages hosted on localhost:4200, indicating that there is an external client application).
b. API Layer (Controllers): Represented by the controllers under src/main/java/org/amba/app/Controllers (AdminController, AuthenticationController, BatchUploadController, ProjectController, etc.).
c. Service Layer: The business logic components in src/main/java/org/amba/app/Service (AuthenticationService, BatchUploadService, QuestionService, ReportService, UserService).
d. Data Access Layer: The repository classes under src/main/java/org/amba/app/Repo and the associated entities under src/main/java/org/amba/app/Entity.
e. Messaging Component: The RabbitMQ integration represented by RabbitClient and RabbitMQConfig, indicating asynchronous messaging.
f. Scheduled Tasks: The cron jobs located in src/main/java/org/amba/app/Crons (ReportScheduler and its associated DTOs).
g. Database: PostgreSQL (as per the SQL script in the README and configuration in application.properties).
h. Infrastructure/DevOps: Dockerfile, docker-compose.yaml, AWS and Azure workflow configurations, and AWS infra definition indicating container orchestration and CI/CD pipelines.

##### Relationships and Interactions
- The API layer (controllers) receives HTTP requests from the external client (frontend) and passes these requests to the service layer.
- Services encapsulate the business logic, interact with the data repositories to perform CRUD operations on the PostgreSQL database, and utilize messaging for asynchronous tasks.
- The messaging component (RabbitMQ) is used to decouple processes (e.g., handling question uploads or audit events) by sending and receiving messages via queues.
- Cron jobs are set up to periodically run scheduled tasks (such as generating reports) and may interact with both the service and repository layers.
- Security configurations (i.e., JWT-based authentication) ensure that only authenticated users can access certain API endpoints.
- The containerization and CI/CD pipelines indicate that this backend service can be deployed in Docker containers on AWS or Azure.

##### Architectural Patterns and Design Principles
- Layered Architecture (Separation between controllers, services, repositories, and messaging components).
- Use of Data Transfer Objects (DTO) for exposing and transferring data (e.g., AuthenticationResponseDTO, ProjectDto, etc.).
- Asynchronous Communication via RabbitMQ for decoupling.
- Scheduled job execution using Cron jobs.
- Security via JWT with a dedicated filter, configuration, and service.
- Containerization and Infrastructure as Code components for deployment automation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Frontend (Admin UI)"]:::client

    subgraph "API Layer"
        ctrl["Controllers"]:::api
        sec["Security (JWT)"]:::security
    end

    subgraph "Service Layer"
        svc["Services"]:::service
    end

    subgraph "Data Access"
        repo["Repositories"]:::repo
        ent["Entities"]:::entity
    end

    db["PostgreSQL"]:::database

    subgraph "Messaging"
        mqClient["RabbitMQ Client"]:::messaging
        mqConfig["RabbitMQ Config"]:::messaging
    end

    subgraph "Scheduled Tasks"
        cron["Cron Jobs"]:::scheduler
    end

    infra["DevOps & CI/CD"]:::infra

    %% Data Flows
    A -->|"HTTPRequest"| ctrl
    ctrl -->|"Call-Service"| svc
    ctrl -->|"SecuredBy"| sec
    svc -->|"DBOperation"| repo
    repo -->|"UsesEntity"| ent
    svc -->|"DBQuery"| db
    svc -->|"SendMsg"| mqClient
    mqClient -->|"ConfiguredBy"| mqConfig
    cron -->|"RunScheduled"| svc
    infra -->|"DeploysTo"| ctrl
    infra -->|"DeploysTo"| svc
    infra -->|"DeploysTo"| repo
    infra -->|"DeploysTo"| mqClient

    %% Click Events
    click ctrl "https://github.com/engineerscodes/amba/tree/master/src/main/java/org/amba/app/Controllers"
    click svc "https://github.com/engineerscodes/amba/tree/master/src/main/java/org/amba/app/Service"
    click repo "https://github.com/engineerscodes/amba/tree/master/src/main/java/org/amba/app/Repo"
    click ent "https://github.com/engineerscodes/amba/tree/master/src/main/java/org/amba/app/Entity"
    click mqClient "https://github.com/engineerscodes/amba/blob/master/src/main/java/org/amba/app/Messaging/RabbitClient.java"
    click mqConfig "https://github.com/engineerscodes/amba/blob/master/src/main/java/org/amba/app/RabbitMQConfig.java"
    click cron "https://github.com/engineerscodes/amba/blob/master/src/main/java/org/amba/app/Crons/ReportScheduler.java"
    click db "https://github.com/engineerscodes/amba/blob/master/intuserdb.sql"
    click infra "https://github.com/engineerscodes/amba/tree/master/.github/workflows"
    click sec "https://github.com/engineerscodes/amba/tree/master/src/main/java/org/amba/app/Security"

    %% Styling
    classDef client fill:#f4d03f,stroke:#333,stroke-width:2px;
    classDef api fill:#85c1e9,stroke:#333,stroke-width:2px;
    classDef security fill:#bb8fce,stroke:#333,stroke-width:2px;
    classDef service fill:#58d68d,stroke:#333,stroke-width:2px;
    classDef repo fill:#f7dc6f,stroke:#333,stroke-width:2px;
    classDef entity fill:#f0b27a,stroke:#333,stroke-width:2px;
    classDef database fill:#ec7063,stroke:#333,stroke-width:2px;
    classDef messaging fill:#f5b041,stroke:#333,stroke-width:2px;
    classDef scheduler fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef infra fill:#d5dbdb,stroke:#566573,stroke-width:2px;
```
