Skip to content

olael94/spring-boot-banking-rest-api

Repository files navigation

Banking REST API

A full-featured RESTful banking API built with Spring Boot, featuring user management, account operations, transactions, transfers, and loan processing.

Java Spring Boot MySQL License

Features

  • User Management — Registration, authentication, profile updates
  • Account Operations — Create accounts, check balances, deposit, withdraw
  • Fund Transfers — Transfer money between accounts with validation
  • Transaction History — Track all account activity
  • Loan Processing — Apply for loans, track repayments, manage loan status
  • Security — Spring Security with role-based access control

Tech Stack

Layer Technology
Framework Spring Boot 3.4.3
Language Java 21
Database MySQL 8.0
ORM Spring Data JPA / Hibernate
Security Spring Security
Build Maven
Cloud AWS RDS (Production)

Quick Start

Prerequisites

  • Java 21Download
  • DockerDownload (for local MySQL database)
  • Maven — Included via ./mvnw wrapper (no install needed)

1. Clone the Repository

git clone https://github.com/olael94/banking-api.git
cd banking-api

2. Set Up Environment

cp .env.example .env

The default .env is pre-configured for Docker MySQL — no changes needed for local development.

3. Start the Database

docker-compose up -d

This starts a MySQL 8.0 container with the database ready to use.

4. Run the Application

./mvnw spring-boot:run

5. Access the API

The API is now running at: http://localhost:8080

Test it:

curl http://localhost:8080/api/users

Using AWS RDS Instead of Docker

If you prefer to use AWS RDS:

  1. Edit your .env file
  2. Comment out Option 1 (Docker)
  3. Uncomment Option 2 (AWS RDS) and fill in your credentials
# Option 1: Docker MySQL — COMMENT THESE OUT
# SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/banking_application
# SPRING_DATASOURCE_USERNAME=banking_user
# SPRING_DATASOURCE_PASSWORD=banking_password

# Option 2: AWS RDS — UNCOMMENT AND FILL IN
SPRING_DATASOURCE_URL=jdbc:mysql://your-rds-endpoint:3306/banking_application
SPRING_DATASOURCE_USERNAME=admin
SPRING_DATASOURCE_PASSWORD=your-password

See docs/aws-setup.md for detailed AWS RDS setup instructions.


API Endpoints

Users

Method Endpoint Description
POST /api/users/register Register new user
GET /api/users/{id} Get user details
PUT /api/users/{id} Update user
DELETE /api/users/{id} Delete user

Accounts

Method Endpoint Description
POST /api/accounts Create account
GET /api/accounts/{id} Get account details
POST /api/accounts/{id}/deposit Deposit funds
POST /api/accounts/{id}/withdraw Withdraw funds
POST /api/accounts/transfer Transfer between accounts
DELETE /api/accounts/{id} Close account

Transactions

Method Endpoint Description
GET /api/transactions/{accountId} Get transaction history
POST /api/transactions Create transaction

Transfers

Method Endpoint Description
POST /api/transfers Initiate transfer
GET /api/transfers/{id} Get transfer details

Loans

Method Endpoint Description
POST /api/loans/apply Apply for loan
GET /api/loans/{id} Get loan details
POST /api/loans/{id}/repay Make loan payment

Project Structure

banking-api/
│
├── src/main/java/edu/ensign/cs460/banking_api/
│   ├── controller/          # REST API endpoints
│   ├── service/             # Business logic interfaces
│   │   └── impl/            # Service implementations
│   ├── repository/          # Data access layer (JPA)
│   ├── models/              # JPA entities
│   ├── dto/                 # Data transfer objects
│   ├── exception/           # Custom exceptions & global handler
│   ├── config/              # Security & app configuration
│   └── security/            # Authentication components
│
├── src/main/resources/
│   └── application.properties
│
├── src/test/                # Unit & integration tests
├── sql/                     # Database schema scripts
├── docs/                    # Documentation
│   └── aws-setup.md         # AWS RDS setup guide
│
├── .env.example             # Environment variables template
├── docker-compose.yml       # Local MySQL database
├── pom.xml                  # Maven dependencies
└── README.md

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                           Client                                 │
└─────────────────────────────┬───────────────────────────────────┘
                              │ HTTP
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        Controllers                               │
│         REST endpoints for Users, Accounts, Loans, etc.          │
├─────────────────────────────────────────────────────────────────┤
│                         Services                                 │
│              Business logic & validation                         │
├─────────────────────────────────────────────────────────────────┤
│                       Repositories                               │
│                    JPA Data Access Layer                         │
├─────────────────────────────────────────────────────────────────┤
│                      MySQL Database                              │
│           (Docker for local / AWS RDS for production)            │
└─────────────────────────────────────────────────────────────────┘

Database Schema

┌──────────────┐       ┌──────────────┐       ┌──────────────┐
│     USER     │       │   ACCOUNT    │       │ TRANSACTION  │
├──────────────┤       ├──────────────┤       ├──────────────┤
│ user_id (PK) │───┐   │ account_id   │───┐   │ transaction_id│
│ username     │   │   │ user_id (FK) │   │   │ account_id(FK)│
│ password     │   └──►│ account_num  │   └──►│ type         │
│ email        │       │ account_type │       │ amount       │
│ full_name    │       │ balance      │       │ date         │
│ dob          │       │ status       │       │ status       │
│ reg_date     │       └──────────────┘       └──────────────┘
└──────────────┘
        │
        │              ┌──────────────┐       ┌──────────────┐
        │              │   TRANSFER   │       │     LOAN     │
        │              ├──────────────┤       ├──────────────┤
        │              │ transfer_id  │       │ loan_id      │
        │              │ from_acct(FK)│       │ user_id (FK) │
        │              │ to_acct (FK) │       │ loan_type    │
        │              │ amount       │       │ amount       │
        │              │ date         │       │ interest_rate│
        └─────────────►│ status       │       │ status       │
                       └──────────────┘       └──────────────┘

Configuration

Environment variables are loaded automatically from .env via spring-dotenv.

Variable Description Default
SPRING_DATASOURCE_URL JDBC connection URL jdbc:mysql://localhost:3306/banking_application
SPRING_DATASOURCE_USERNAME Database username banking_user
SPRING_DATASOURCE_PASSWORD Database password banking_password
SERVER_PORT Application port 8080
SPRING_JPA_HIBERNATE_DDL_AUTO Schema generation update

Common Commands

# Start MySQL database
docker-compose up -d

# Stop MySQL database (keeps data)
docker-compose down

# Stop MySQL and delete all data
docker-compose down -v

# Run the application
./mvnw spring-boot:run

# Run tests
./mvnw test

# Build JAR file
./mvnw clean package

# Run JAR file
java -jar target/banking-api-0.0.1-SNAPSHOT.jar

Troubleshooting

"Connection refused" error

Make sure MySQL is running:

docker-compose ps

If it's not running:

docker-compose up -d

"Access denied" error

Check your .env file has the correct credentials matching docker-compose.yml:

  • Username: banking_user
  • Password: banking_password

Port 3306 already in use

Stop any existing MySQL service:

# macOS
brew services stop mysql

# Linux
sudo systemctl stop mysql

# Or change the port in docker-compose.yml
ports:
  - "3307:3306"  # Use port 3307 instead

Port 8080 already in use

Change the port in your .env file:

SERVER_PORT=8081

Running Tests

# Run all tests
./mvnw test

# Run a specific test class
./mvnw test -Dtest=UserServiceImplTest

# Run with coverage report
./mvnw test jacoco:report

License

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

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •