This project is a banking application built using Go + PostgreSQL + Docker. I have used Go as the backend language, PostgreSQL as the database, SQLC for generating type-safe SQL queries, and go-playground/validator
for input validation. The project also includes comprehensive unit tests written with testify
and GoMock
for mocking dependencies. The project also includes CI tests written using GitHub workflows and code coverage is also tracked and uploaded to Codecov (find it here). Build automation and commands are managed using Makefile.
β Star us on GitHub β it motivates me a lot!
- Backend Language: Go (Golang)
- Database: PostgreSQL
- ORM/SQL Generator: SQLC
- Validation: go-playground/validator
- Testing: Comprehensive unit tests with GoMock for mocking
- CI Pipeline: GitHub Actions for CI tests and code coverage uploading,
- Code Coverage: Tracking test coverage of the project using Codecov. (find it here)
- Build and Commands: Managed using Makefile
To build the packages, follow these steps:
# Open a terminal (Command Prompt or PowerShell for Windows, Terminal for macOS or Linux)
# Ensure Git and make is installed
# Visit https://git-scm.com to download and install console Git if not already installed
# Clone the repository
git clone https://github.com/1Shubham7/Banking-application.git
# Navigate to the project directory
cd Banking-application
make postgres
make createdb
make start_prod
# If you want to run it through local image:
# Install `go-migrate` with root previliges
sudo go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/[email protected]
make migrateup1
make migrateup
make server
- Create a User/SignIn:
curl -i -X POST http://localhost:8080/users -H "Content-Type: application/json" \
-d '{"username": "Shubham", "password": "secret", "full_name": "Shubham Singh", "email": "[email protected]"}'
- Login User:
curl -i -X POST http://localhost:8080/users/login -H "Content-Type application/json" \
-d '{"username": "Shubham", "password": "secret"}'
This will return you a JWT token:
{
"session_id": "932680d9-a170-4e3d-8f1a-ed9aa090d21b",
"access_token": "v2.local.nqUejIG_-A0-YKfedgDIjfFH9AyLr-idGE5e3QvduogV3hRsO0d1HTu3MoaXjHTfixDPjy7ZImbJZU_6S-LNZG3OqWtNZlQA0ta-UBg5vnnaGjzvahOT4CxwaBXOeZdxMjiZ0eRMB3yf4Kb8X0dYdjk0830h7b6b95gnmWfs85DfUUvh5JxuHaUwdT1SSiAf2r5-hh2d3qX1nFRnyeT0T0P3jOVrFd-Citqgz-ASCGMdtbJ1Dne6xjZ1SXsMlNt5zswiEkfTx5wOBshWV6oj.bnVsbA",
"access_token_expires_at": "2024-12-13T12:15:43.050587204+05:30",
"user": {
"username": "Shubham",
"full_name": "Shubham Singh",
"email": "[email protected]",
"password_changed_at": "0001-01-01T05:53:28+05:53",
"created_at": "2024-12-13T11:36:20.819497+05:30"
},
"refresh_token": "v2.local.aWZ1xqaQ6KZfgwmN-uPrwKgfu2uqzXILAA006JbGvIHdfmpAgWkj_vJ5bjPhUi8KDT1qGyzSYMTG1PD8tOTisGWVz__VYLKzjr7aPBkIB_Nj0yHBInYPXF27G1MK5E_DPi_GOYKiGjITW76CYN-ob7cM8p5ruCwxAB_Mz8Sr4XLlzGGSuRnuEaBVZkBd2rIQil2m5FjidkvyXtwztonC5wT93CxEeVCH7Nnx05zp_tKzUtAZV0vQU4xf_Z0S5ynPvrf0azYrHsyG_Jh2_t9s.bnVsbA",
"refresh_token_expires_at": "2024-12-15T11:45:43.056058261+05:30"
}
- Create an account for the user:
curl -X POST http://localhost:8080/accounts \
-H "Authorization: Bearer <Token> \
-H "Content-Type: application/json" \
-d '{"balance": 10000, "currency": "USD"}'
- Now you can perform actions on the account, for example, get a user account (under authentication):
curl -X GET http://localhost:8080/accounts -H "Authorization: Bearer <Token>"
This will return a response:
{"id":1,"owner":"Shubham","balance":10000,"currency":"USD","created_at":"2024-12-13T12:01:09.869101+05:30"}
- Perform Money Tansfer:
For that we will have to create another user:
curl -i -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{
"username": "Elon",
"password": "secret",
"full_name": "Elon Musk",
"email": "[email protected]"
}'
And then login the new user:
curl -i -X POST http://localhost:8080/users/login \
-H "Content-Type: application/json" \
-d '{
"username": "Elon",
"password": "secret"
}'
This will return this result including the JWT/Paesto Token:
{
"session_id": "0f48c550-16fc-418c-9e99-d5b378fcd53d",
"access_token": "<Token>",
"access_token_expires_at": "2024-12-13T13:23:37.434517608+05:30",
"user": {
"username": "Elon",
"full_name": "Elon Musk",
"email": "[email protected]",
"password_changed_at": "0001-01-01T05:53:28+05:53",
"created_at": "2024-12-13T12:52:38.271222+05:30"
},
"refresh_token": "<Token>",
"refresh_token_expires_at": "2024-12-15T12:53:37.435101986+05:30"
}
Then create new account for this new user:
curl -X POST http://localhost:8080/accounts \
-H "Authorization: Bearer <Token>" \
-H "Content-Type: application/json" \
-d '{
"balance": 100,
"currency": "USD"
}'
And then perform transfer:
curl -X POST http://localhost:8080/transfers \
-H "Authorization: Bearer <Token>" \
-d '{
"from_account_id": 1,
"to_account_id": 2,
"amount": 100,
"currency": "USD"
}'
- For Refreshing Token:
curl -X POST http://localhost:8080/tokens/renew_access \
-H "Authorization: Bearer <Token>" \
-d '{
"refresh_token": "<Token>"
}'
This will return a new access token:
{
"access_token": "<Token>",
"access_token_expires_at": "2024-12-13T13:41:10.668632532+05:30"
}
Whether you have feedback on features, have encountered any bugs, or have suggestions for enhancements, we're eager to hear from you. Your insights help us make our application more robust and user-friendly. Please feel free to contribute by submitting an issue. Each contribution helps us grow and improve. If you would like to contribute to this project, please read the Contribution guidelines and make sure to follow the Code Of Conduct.
We appreciate your support and look forward to making our product even better with your help!
This product is distributed under a Apache License Version 2.0, January 2004. You can review the full license agreement at LICENSE