An open API service indexing awesome lists of open source software.

https://github.com/youhad08/e-bank-backend-springboot

Digital banking system backend developed with Spring Boot. Includes customer and account management, operations, and REST APIs.
https://github.com/youhad08/e-bank-backend-springboot

api hibernate java java21 lombok maven mysql openapi rest-api restful-api spring-boot spring-data-jpa spring-framework spring-web swagger

Last synced: about 2 months ago
JSON representation

Digital banking system backend developed with Spring Boot. Includes customer and account management, operations, and REST APIs.

Awesome Lists containing this project

README

          

# ๐Ÿ’ณ E-BANK Backend Application

A robust and modular backend banking system built with **Spring Boot**, **Spring Data JPA**, and **MariaDB/MySQL**.

This backend powers core banking features such as customer management, bank account operations (debit, credit, transfer), and full transaction history. The application is structured with clean architectural separation (DTOs, services, mappers, exception handling) and JWT-based security.

> โš ๏ธ This repository contains the **backend only**. The **Angular frontend** is implemented in this [repository](https://github.com/YOUHAD08/e-bank-frontend-angular.git).

---

## ๐Ÿš€ Features

### โœ… Customer Management

- Create, update, retrieve, and delete customers.
- Search customers by keyword or exact name.

### โœ… Bank Account Management

- Supports Current Accounts (with overdraft) and Saving Accounts (with interest rate).
- Create, update, delete, and retrieve bank accounts.
- Retrieve accounts by customer.

### โœ… Account Operations

- Debit, credit, and transfer between accounts.
- Track full transaction history with pagination and summaries.

### โœ… Advanced History API
- Structured account history using `AccountHistoryDTO`.
- Access latest operation summaries.

### โœ… Security & Authentication

-JWT-based authentication with role-based access control (USER and ADMIN scopes).
Password encryption using BCrypt.

### โœ… Exception Handling
Handles common banking errors:
- `CustomerNotFoundException`
- `BankAccountNotFoundException`
- `InsufficientBalanceException`

### โœ… API Documentation

Interactive Swagger UI at:

http://localhost:8085/swagger-ui/index.html

---

## ๐Ÿ“‚ Project Structure

![Backend Project Structure](images/project-structure.png)

- **Entities:** `Customer`, `BankAccount`, `CurrentAccount`, `SavingAccount`, `AccountOperation`
- **DTOs:** Transfer objects for API communication
- **Repositories:** Spring Data JPA Repositories
- **Services:** Business logic with interfaces and implementations
- **Controllers:** REST API endpoints secured by JWT scopes
- **Mappers:** Entity โ†” DTO transformation
- **Exceptions:** Custom exceptions for domain errors
- **Security**: JWT generation and validation, password encoding

---

## ๐Ÿงฉ MySQL Database Structure

This backend currently uses a **relational MySQL** database to persist customer, account, and transaction data.

![MySQL Database Schema](images/mysql-db.png)

### ๐Ÿ”— Relationships

- **1๏ธโƒฃ Customer โ‡จ N BankAccounts**
- **1๏ธโƒฃ BankAccount โ‡จ N AccountOperations**

---

## ๐Ÿ› ๏ธ Technologies Used

| Technology | Version |
|-------------------|-------------------|
| Java | 21 |
| Spring Boot | 3.5.3 |
| Spring Data JPA | Included |
| MySQL | 8+ |
| Lombok | 1.18.34 |
| Swagger / OpenAPI | 2.5.0 |
| Maven | Build Tool |
| H2 (optional) | For testing |
| JWT (Nimbus JOSE) | included |
| BCrypt | Password Encoding |

---

## ๐Ÿ’ป Getting Started

### Prerequisites

- Java 21+
- Maven
- MySQL running (DB name: `E-BANK`)
- (Optional) phpMyAdmin or MySQL client

---

### โš™๏ธ Setup & Run

1. Clone this repository:
```bash
git clone https://github.com/YOUHAD08/e-bank-backend-springboot.git
cd e-bank-backend-springboot

2. Configure database in `src/main/resources/application.properties`:
```bash
spring.datasource.url=jdbc:mysql://localhost:3306/E-BANK?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=

3. Build & Run
```bash
mvn clean install
mvn spring-boot:run

4. Access the APIs:

- Swagger UI: http://localhost:8085/swagger-ui/index.html
- MySQL Database via phpMyAdmin: http://localhost/phpmyadmin/index.php?route=/database/structure&db=e-bank

---

## ๐Ÿ“„ API Overview

### Customer API (`/auth`)

- `POST /auth/login` โ€” Login with username and password, returns JWT token.
- `POST /auth/signup` โ€” Register a new customer (role USER by default).
- `GET /auth/profile` โ€” Get current authenticated user details.

### Customer API (`/customer, /customers`)

- `GET /customers` โ€” List all customers.
- `GET /customer/{id}` โ€” Get customer by ID.
- `GET /customers/search?keyword=` โ€” Search customers by keyword.
- `GET /customer/search?name=` โ€” Search customer by exact name.
- `POST /customer` โ€” Create customer (ADMIN only).
- `PUT /customer/{id}` โ€” Update customer (ADMIN only).
- `DELETE /customer/{id}` โ€” Delete customer (ADMIN only)

### Bank Account API (`/account`, `/accounts`, `/currentAccount`, `/savingAccount`)

- `GET /account/{accountId}`โ€” Get bank account by ID.
- `GET /accounts` โ€” List all accounts.
- `GET /accounts/{customerId}` โ€” List all accounts of a customer.
- `POST /currentAccount/{customerId}` โ€” Create current account (ADMIN only).
- `POST /savingAccount/{customerId}` โ€” Create saving account (ADMIN only).
- `PUT /currentAccount/{accountId}` โ€” Update current account (ADMIN only).
- `PUT /savingAccount/{accountId}` โ€” Update saving account (ADMIN only).
- `DELETE /account/{accountId}` โ€” Delete account (ADMIN only).

### Account Operations API (`/account/{accountId}/operations`)

- `GET /account/{accountId}/operations` โ€” List all operations for an account.
- `GET /account/{accountId}/pageOperations?page=&size=` โ€” Paginated operations list.
- `POST /account/{accountId}/debit?amount=&description=` โ€” Debit an account.
- `POST /account/{accountId}/credit?amount=&description=` โ€” Credit an account (ADMIN only).
- `POST /account/{accountId}/transfer?toAccountId=&amount=` โ€” Transfer money (ADMIN only).
- `GET /operations` โ€” List all account operations.

---

## ๐Ÿ“š Exception Handling

- `CustomerNotFoundException` - Thrown when a customer is not found.
- `BankAccountNotFoundException` - Thrown when a bank account is not found.
- `InsufficientBalanceException` - Thrown when an account has insufficient funds for a debit or transfer.

---

## ๐Ÿงช Database Initialization

On startup, the application seeds the database with:

- 10 customers with realistic names, cities, and emails.
- 3 to 5 random accounts per customer (mix of current and saving).
- 10 to 20 random debit and credit operations per account.

---

## ๐Ÿค Contribution

Contributions are welcome! Feel free to open issues or pull requests so we grow together.

---

## ๐Ÿ–ฅ๏ธ Next Steps: Agentic AI & Future Database Migration

This project currently implements the **backend RESTful API** using **Spring Boot** and a relational **MySQL** database.

### ๐Ÿ”œ Upcoming Plans

#### ๐Ÿ› ๏ธ Frontend (Done):

The frontend is currently under development using Angular and is structured to provide a clean and interactive UI for:

- Customer and account management
- Performing debit/credit/transfer operations
- Viewing paginated account operation history
- ... and more features to come

#### ๐Ÿค– Agentic AI Integration (In Progress):
In future development, I plan to build an **agentic AI component** to work alongside this backend. While the full scope is yet to be defined, potential features might include:

- Intelligent customer support and chatbot integration
- Automated transaction analysis and fraud detection
- Personalized financial advice and account management
- Dynamic task automation within the banking system

This agentic AI will aim to enhance user experience, improve operational efficiency, and provide smart automation capabilities.

#### ๐Ÿ” Future Migration to MongoDB:
Although this version uses **MySQL**, a future version of this backend will be migrated to **MongoDB** to take advantage of:

- Flexible document-based schema
- Easier scalability
- Faster iterations in development

Stay tuned for the **agentic AI enhancements**, and the **MongoDB-backed backend**!

---

> Developed by **Youhad**
> ยฉ 2025