Skip to content

Krishal-Modi/Banking-Application-Rest-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 Banking Application REST API

A comprehensive and secure Banking Application REST API built with Spring Boot 3.4.3, providing complete banking operations including user management, account handling, transactions, and net banking capabilities.

Java Spring Boot PostgreSQL License: MIT

πŸ“‹ Table of Contents

✨ Features

πŸ” Authentication & Authorization

  • JWT-based Authentication - Secure token-based authentication system
  • Spring Security Integration - Role-based access control
  • Custom User Details Service - Personalized user authentication

πŸ‘€ User Management

  • User registration and login
  • Secure password encryption
  • User profile management
  • Admin user search functionality

πŸ’³ Account Management

  • Create and manage bank accounts
  • Link users to accounts
  • View account details
  • Account balance tracking

πŸ’° Transaction Operations

  • Deposit - Add money to accounts
  • Withdrawal - Withdraw money from accounts
  • Net Banking - Transfer money between accounts
  • Balance Inquiry - Check current account balance
  • Real-time transaction processing

πŸ“– Passbook Management

  • View transaction history
  • Complete passbook details
  • Account-wise transaction records
  • Sender and receiver details tracking

πŸ›‘οΈ Security Features

  • JWT token validation
  • Custom exception handling
  • Data validation
  • SQL injection prevention
  • Secure API endpoints

πŸ“Š Admin Features

  • Search and manage users
  • User registration
  • System-wide user overview

πŸ› οΈ Tech Stack

Backend:

  • Java 17
  • Spring Boot 3.4.3
  • Spring Data JPA
  • Spring Security
  • Spring Validation

Database:

  • PostgreSQL

Security:

  • JWT (JSON Web Tokens) - io.jsonwebtoken 0.12.5
  • BCrypt Password Encoder

Tools & Libraries:

  • Lombok - Reduce boilerplate code
  • MapStruct 1.5.5 - Object mapping
  • Apache Commons Text 1.10.0
  • Apache Commons Collections 4.4
  • Maven - Dependency management

Testing:

  • Tested extensively with Postman
  • All endpoints verified and working

πŸ“¦ Prerequisites

Before running this application, make sure you have:

  • Java Development Kit (JDK) 17 or higher
  • PostgreSQL 12 or higher
  • Maven 3.6+ (or use included Maven wrapper)
  • Postman (for API testing)
  • Git (for version control)

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/Krishal-Modi/Banking-Application-Rest-API.git
cd Banking-Application-Rest-API/BankingApplication

2. Configure Database

Create a PostgreSQL database:

CREATE DATABASE BankingApplication;

Update the database credentials in src/main/resources/application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/BankingApplication
spring.datasource.username=your_username
spring.datasource.password=your_password

3. Build the Project

Using Maven wrapper (recommended):

# Windows
mvnw.cmd clean install

# Linux/Mac
./mvnw clean install

Or using Maven:

mvn clean install

4. Run the Application

# Windows
mvnw.cmd spring-boot:run

# Linux/Mac
./mvnw spring-boot:run

The application will start on http://localhost:8086

βš™οΈ Configuration

Application Properties

Key configurations in application.properties:

# Server Port
server.port=8086

# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/BankingApplication
spring.datasource.username=postgres
spring.datasource.password=root

# JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

JWT Configuration

JWT secret key and expiration can be configured in JwtUtil.java

πŸ“‘ API Endpoints

Authentication Endpoints

User Login

POST /user/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

Response: JWT Token


Admin Endpoints

Register New User

POST /admin/signUp
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "secure_password",
  "phoneNumber": "1234567890",
  "roles": "USER"
}

Search Users

GET /admin/search?search=john
Authorization: Bearer {jwt_token}

Account Endpoints

Create Account

POST /userAccount/addingAccount
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
  "accountNumber": 1234567890,
  "accountType": "SAVINGS",
  "balance": 1000.00
}

View Passbook

GET /userAccount/passbook
Authorization: Bearer {jwt_token}

Net Banking (Money Transfer)

PUT /userAccount/netBanking
Authorization: Bearer {jwt_token}
Content-Type: application/x-www-form-urlencoded

senderAccountNumber=1234567890
receiverAccountNumber=0987654321
amount=500

Transaction Endpoints

Deposit Money

PUT /transaction/deposit
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
  "accountNumber": 1234567890,
  "amount": 1000.00
}

Withdraw Money

PUT /transaction/withdrawal
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
  "accountNumber": 1234567890,
  "amount": 500.00
}

Check Balance

GET /transaction/currentBalance/{accountNumber}
Authorization: Bearer {jwt_token}

πŸ§ͺ Testing with Postman

This API has been thoroughly tested with Postman to ensure all endpoints work correctly.

Getting Started with Postman

  1. Download Postman from postman.com

  2. Import Collection (Optional - Create your own)

    • Create a new collection called "Banking API"
    • Add all endpoints mentioned above
  3. Setup Environment Variables

    • Create variables:
      • base_url: http://localhost:8086
      • jwt_token: (Will be set after login)
  4. Testing Flow

    Step 1: Register a User

    POST {{base_url}}/admin/signUp
    

    Step 2: Login

    POST {{base_url}}/user/login
    

    Copy the JWT token from response

    Step 3: Set Authorization

    • Add header: Authorization: Bearer {your_jwt_token}

    Step 4: Create Account

    POST {{base_url}}/userAccount/addingAccount
    

    Step 5: Test Transactions

    • Deposit money
    • Withdraw money
    • Check balance
    • Transfer money (net banking)

    Step 6: View Passbook

    GET {{base_url}}/userAccount/passbook
    

Postman Testing Tips

  • Use Environment Variables for base URL and tokens
  • Enable Auto-Refresh Tokens if tokens expire
  • Save Example Responses for documentation
  • Use Tests Tab to add assertions
  • Create Collection Runner for automated testing

Common Postman Test Scripts

// Save JWT token automatically after login
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

var jsonData = pm.response.text();
pm.environment.set("jwt_token", jsonData);

πŸ“ Project Structure

BankingApplication/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/com/example/BankingApplication/
β”‚   β”‚   β”‚   β”œβ”€β”€ BankingApplication.java          # Main application class
β”‚   β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   β”‚   └── SpringSecurity.java          # Security configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ controller/                      # REST controllers
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AccountController.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AdminController.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ TransactionalController.java
β”‚   β”‚   β”‚   β”‚   └── UserController.java
β”‚   β”‚   β”‚   β”œβ”€β”€ entity/                          # JPA entities
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Account.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Passbook.java
β”‚   β”‚   β”‚   β”‚   └── User.java
β”‚   β”‚   β”‚   β”œβ”€β”€ exceptions/                      # Custom exceptions
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DataNotFoundException.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DataValidationException.java
β”‚   β”‚   β”‚   β”‚   └── handler/
β”‚   β”‚   β”‚   β”‚       └── GlobalExceptionHandler.java
β”‚   β”‚   β”‚   β”œβ”€β”€ filter/                          # Security filters
β”‚   β”‚   β”‚   β”‚   └── JwtFilter.java
β”‚   β”‚   β”‚   β”œβ”€β”€ mapper/                          # MapStruct mappers
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AccountMapper.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PassbookMapper.java
β”‚   β”‚   β”‚   β”‚   └── UserMapper.java
β”‚   β”‚   β”‚   β”œβ”€β”€ model/                           # DTOs
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AccountModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoanModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ NetBankingModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PassbookAccountModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PassbookModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ReceiverModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SenderModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ TransactionalModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ UserAccountModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ UserModel.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ UserPassbookModel.java
β”‚   β”‚   β”‚   β”‚   └── error/
β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ ErrorResponse.java
β”‚   β”‚   β”‚   β”‚       └── ErrorType.java
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/                      # JPA repositories
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AccountRepository.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PassbookRepository.java
β”‚   β”‚   β”‚   β”‚   └── UserRepository.java
β”‚   β”‚   β”‚   β”œβ”€β”€ service/                         # Business logic
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AccountService.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AdminService.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CustomUserDetailsService.java
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ TransactionalService.java
β”‚   β”‚   β”‚   β”‚   └── UserService.java
β”‚   β”‚   β”‚   └── utils/                           # Utility classes
β”‚   β”‚   β”‚       └── JwtUtil.java
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.properties           # Application configuration
β”‚   └── test/                                    # Test files
β”œβ”€β”€ mvnw                                         # Maven wrapper (Unix)
β”œβ”€β”€ mvnw.cmd                                     # Maven wrapper (Windows)
└── pom.xml                                      # Maven dependencies

πŸ”’ Security

Authentication Flow

  1. User sends credentials to /user/login
  2. Server validates credentials
  3. JWT token is generated and returned
  4. Client includes token in Authorization header for subsequent requests
  5. Server validates token using JwtFilter

Security Measures

  • Password Encryption: BCrypt encoding for password storage
  • JWT Tokens: Stateless authentication
  • Request Filtering: JWT validation on protected endpoints
  • Custom Exception Handling: Secure error messages
  • Input Validation: Bean validation on all inputs
  • SQL Injection Prevention: JPA/Hibernate parameterized queries

Best Practices Implemented

βœ… Token-based authentication
βœ… Password hashing
βœ… Role-based access control
βœ… Global exception handling
βœ… Input validation
βœ… Secure headers
βœ… Database connection pooling

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/AmazingFeature
  3. Commit your changes
    git commit -m 'Add some AmazingFeature'
  4. Push to the branch
    git push origin feature/AmazingFeature
  5. Open a Pull Request

Contribution Guidelines

  • Follow Java coding conventions
  • Write meaningful commit messages
  • Add comments for complex logic
  • Update documentation if needed
  • Test your changes thoroughly with Postman

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“§ Contact

Krishal Modi

πŸ™ Acknowledgments

  • Spring Boot Documentation
  • PostgreSQL Community
  • JWT.io for JWT implementation guidance
  • Postman for excellent API testing tools
  • Open source community

πŸ“ˆ Future Enhancements

  • Add interest calculation for savings accounts
  • Implement loan management system
  • Add email notifications for transactions
  • Create admin dashboard
  • Implement transaction limits
  • Add two-factor authentication
  • Create mobile app integration
  • Add support for multiple currencies
  • Implement account statements PDF generation
  • Add GraphQL support

⭐️ Star this repo if you find it helpful! ⭐️

Made with ❀️ by Krishal Modi

About

A backend banking application developed with Spring Boot and PostgreSQL. It includes RESTful APIs for user authentication using JWT(token), profile management, login/signup, passbook functionality (credit/debit), and net banking transfers. Designed to simulate real-world banking workflows with secure and scalable architecture.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages