This repository contains the code for a Backend Master class written in Golang.
A simple banking system API built with Go, featuring account management, money transfers, and user authentication. This project demonstrates best practices in backend development including database transactions, API design, authentication, and testing.
- User Management: Create users with secure password hashing
- Account Management: Create and manage bank accounts with different currencies
- Money Transfers: Transfer money between accounts with proper transaction handling
- Authentication: JWT and PASETO token-based authentication
- Session Management: Refresh token implementation for secure sessions
- Authorization: Middleware-based route protection
- Database Migrations: Version-controlled database schema changes
- Testing: Comprehensive unit and integration tests
- Language: Go 1.23.1
- Database: PostgreSQL 17
- Framework: Gin (HTTP web framework)
- ORM: SQLC (SQL compiler)
- Authentication: JWT & PASETO tokens
- Testing: Testify, Gomock
- Migrations: golang-migrate
- Containerization: Docker & Docker Compose
- Deployment: AWS EKS
The application uses PostgreSQL with the following main tables:
- users: Store user credentials and profile information
- accounts: Bank accounts with owner, balance, and currency
- entries: Account transaction entries
- transfers: Money transfer records between accounts
- sessions: User session and refresh token management
- Go 1.23.1 or higher
- Docker and Docker Compose
- PostgreSQL 17
- golang-migrate CLI
- SQLC
git clone https://github.com/Mitchxxx/Simple_Bank_Golang.git
cd Simple_Bank_Golangmake postgresmake createdbmake migrateupmake serverThe server will start on http://localhost:8080 (or the address specified in your app.env file).
Create an app.env file in the root directory with the following variables:
DB_DRIVER=postgres
DB_SOURCE=postgresql://root:mysecret@localhost:5432/simple_bank?sslmode=disable
SERVER_ADDRESS=0.0.0.0:8080
TOKEN_SYMMETRIC_KEY=your-32-character-secret-key
ACCESS_TOKEN_DURATION=15m
REFRESH_TOKEN_DURATION=24hmake postgres- Start PostgreSQL containermake createdb- Create databasemake dropdb- Drop databasemake migrateup- Run all migrationsmake migrateup1- Run one migration upmake migratedown- Rollback all migrationsmake migratedown1- Rollback one migrationmake sqlc- Generate SQL codemake test- Run testsmake server- Run the servermake mock- Generate mock database
POST /users- Create a new userPOST /users/login- User loginPOST /tokens/renew_access- Renew access token
POST /accounts- Create a new accountGET /accounts/:id- Get account by IDGET /accounts- List user accounts (paginated)POST /transfers- Create a money transfer
make testThis will run all unit and integration tests with coverage reporting.
docker-compose updocker build -t simplebank:latest ..
├── api/ # HTTP API handlers and routing
├── db/
│ ├── migration/ # Database migration files
│ ├── mock/ # Mock database for testing
│ └── sqlc/ # Generated SQL code
├── doc/ # Database documentation
├── token/ # Token generation and validation
├── util/ # Utility functions and configuration
├── main.go # Application entry point
├── Makefile # Build and task automation
└── README.md # This file
This project is part of a Backend Master Class course.
