Skip to content

viswarajramji/budget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Budget Management System

Overview

The Budget Management System is designed to handle budget creation, updates, deletion, and querying operations. The system leverages an event-driven architecture with Kafka for handling expense-related events and integrates with a relational database for persistence.

Sample output:

image

Process Flow Diagram

This diagram illustrates how various events consumed from Kafka are processed by the Budget Service, which subsequently updates the budget data and produces notifications if necessary.

graph TD
    
    KC[Kafka Consumer] -->|Consume 'Create Expense Event'| CEE[Create Expense Event]
    KC -->|Consume 'Delete Expense Event'| DEE[Delete Expense Event]
    KC -->|Consume 'Update Expense Event'| UEE[Update Expense Event]
    KC -->|Consume 'Delete User Event'| DUE[Delete User Event]

    CEE --> BS[Budget Service]
    DEE --> BS
    UEE --> BS
    DUE --> BS

    BS -->|Handle Create Expense Event| UBSC[Update Budget Spend Command Creator]
    BS -->|Handle Delete Expense Event| UBSC
    BS -->|Handle Update Expense Event| UBSC
    BS -->|Handle Delete User Event| DUEE[Delete User Event Executor]

    UBSC -->|Create Command| UBSAC[Update Budget Spend Amount Internal Command]
    UBSAC --> BS[Budget Service]
    
    BS --> UBSAE[Update Budget Spend Amount Executor]

    UBSAE -->|Update in Database| BR[Budget Repository]
    BR --> BE[Budget Entity]
    
    BE -->|Budget Data Updated| DB[(Database)]
    
    UBSAE -.->|Budget Exceeded?| BEE[Budget Exceed Event]

    BEE -->|Publish to 'notificationservice' Topic| KProd[Kafka Producer for Notification Service]
    KProd -->|Handle Notifications| NS[Notification Service]
    DUEE -->|Delete User Data| BR
Loading

Command and Query Handling

This diagram represents how commands and queries are handled by the system. The Budget Command Controller and Budget Query Controller interact with the Budget Service, which dispatches tasks to respective executors that manipulate the Budget Entity via the Budget Repository.

graph TD
    CC[Budget Command Controller] -->|Create| CBC[Create Budget Command]
    CC -->|Update| UBC[Update Budget Command]
    CC -->|Delete| DBC[Delete Budget Command]

    CBC --> BS[Budget Service]
    UBC --> BS
    DBC --> BS

    BS --> CBE[Create Budget Executor]
    BS --> UBE[Update Budget Executor]
    BS --> DBE[Delete Budget Executor]

    CBE -->|Save to| BR[Budget Repository]
    UBE -->|Update in| BR
    DBE -->|Delete from| BR

    BR --> DB[(Budget Database)]

    QC[Budget Query Controller] -->|Get by User ID| GBUI[Get Budget By User ID Query]
    QC -->|Get All| GABQ[Get All Budgets Query]

    GBUI --> BS
    GABQ --> BS

    BS --> GBUIE[Get Budget By User ID Executor]
    BS --> GABQE[Get All Budgets Query Executor]

    GBUIE -->|Fetch from| BR
    GABQE -->|Fetch from| BR

    BR <--> DB[(Budget Database)]

Loading

Key Components

Commands

Commands represent actions that modify the state of the system. Below are the key command classes used in this system:

CreateBudgetCommand

classDiagram
    class CreateBudgetCommand {
        +Long userId
        +Category budgetType
        +Double amount
    }
Loading

Handles the creation of a new budget.

UpdateBudgetCommand

classDiagram
    class UpdateBudgetCommand {
        +Long budgetId
        +Long userId
        +Category budgetType
        +Double amount
    }
Loading

Handles the update of an existing budget.

DeleteBudgetCommand

classDiagram
    class DeleteBudgetCommand {
        +Long budgetId
    }
Loading

Handles the deletion of a budget.

UpdateBudgetSpendAmountInternalCommand

classDiagram
    class UpdateBudgetSpendAmountInternalCommand {
        +RecordType recordType
        +Long expenseId
        +Long userId
        +String expenseName
        +String expenseDescription
        +Category expenseType
        +Double amount
        +Double actualAmount
    }
Loading

Handles the internal update of the budget spend amount, triggered by expense-related events.

Entities

Entities represent the core data models within the system. The primary entity in this system is:

Budget Entity

classDiagram
    class Budget {
        +Long id
        +Long userId
        +Category budgetType
        +Double amount
        +Double spent
    }
Loading

Represents a budget, including attributes such as userId, budgetType, amount, and spent.

Events

Events represent changes or significant occurrences within the system that other components might need to respond to. The key event classes include:

CreateExpenseEvent

classDiagram
    class CreateExpenseEvent {
        +Long expenseId
        +Long userId
        +String expenseName
        +String expenseDescription
        +Category expenseType
        +Double amount
    }
Loading

Triggered when a new expense is created.

DeleteExpenseEvent

classDiagram
    class DeleteExpenseEvent {
        +Long expenseId
        +Long userId
        +String expenseName
        +String expenseDescription
        +Category expenseType
        +Double amount
    }
Loading

Triggered when an expense is deleted.

UpdateExpenseEvent

classDiagram
    class UpdateExpenseEvent {
        +Long expenseId
        +Long userId
        +String expenseName
        +String expenseDescription
        +Category expenseType
        +Double newAmount
        +Double diffAmount
    }
Loading

Triggered when an expense is updated.

DeleteUserEvent

classDiagram
    class DeleteUserEvent {
        +Long userId
    }
Loading

Triggered when a user is deleted, leading to the deletion of associated budgets.

BudgetExceedEvent

classDiagram
    class BudgetExceedEvent {
        +Long expenseId
        +Long userId
        +String expenseName
        +String expenseDescription
        +String expenseType
        +Double amount
        +Double actualAmount
        +String recordType
        +Long budgetId
        +String budgetType
        +Double budgetAmount
        +Double budgetSpent
        +String emailId
    }
Loading

Triggered when the spent amount exceeds the budget, leading to a notification being sent.

Getting Started

To run the service locally:

  1. Clone the repository:

    git clone https://github.com/viswarajramji/budget.git
    cd budget
  2. Build the application:

    ./mvnw clean install
  3. Start the application:

    ./mvnw spring-boot:run
  4. Access the application at http://localhost:8082.

  5. Access the database at http://localhost:8082/h2-console.

Note: Ensure Kafka is running and the topic budgetservice is created.

Swagger Endpoint

Access the Swagger UI to interact with the API:

  • URL: http://localhost:8082/swagger-ui.html

Code Coverage

image

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages