A modern, production-ready banking backend application built with Go, featuring REST and gRPC APIs, secure authentication, database migrations, and complete CI/CD pipeline.
- π Secure user authentication with JWT and PASETO tokens
- π° Account management with balance tracking
- πΈ Money transfers between accounts with transaction history
- π Database schema migration with golang-migrate
- π Concurrent transaction processing with proper locking
- π£οΈ RESTful API with Gin framework
- π High-performance gRPC API with Protocol Buffers
- π API documentation with Swagger/OpenAPI
- π§ͺ Comprehensive test coverage with testify
- π³ Containerization with Docker and Docker Compose
- π CI/CD with GitHub Actions
- π§ Email verification system with async processing
- π Structured logging with zerolog
- βοΈ Configuration management with Viper
- Language: Go 1.24
- Web Framework: Gin
- Database: PostgreSQL 12
- SQL Generator: SQLC
- API Layer:
- RESTful API with Gin
- gRPC with Protocol Buffers
- gRPC-Gateway
- Authentication:
- Task Queue:
- Validation: validator
- Configuration: Viper
- Logging: zerolog
- Email: jordan-wright/email
- Testing:
- CI/CD: GitHub Actions
- Containerization: Docker, Docker Compose
Before you begin, ensure you have the following installed:
- Go 1.24+
- Docker and Docker Compose
- Make
- golang-migrate CLI
- sqlc
- protoc with Go plugins (for gRPC development)
git clone https://github.com/pawaspy/simple_bank.git
cd simple_bank
The fastest way to get started is using Docker Compose:
# Start all services (PostgreSQL, Redis, API server)
docker compose up
# Run in detached mode
docker compose up -d
Copy the example environment file and configure as needed:
cp app.env.example app.env
# Edit app.env with your preferred editor
# Create a Docker network for the services
docker network create simplebank-net
# Start PostgreSQL container
make postgres
# Create the database
make createdb
# Run all migrations
make migrateup
# Run only one migration forward
make migrateup1
# Roll back all migrations
make migratedown
# Roll back one migration
make migratedown1
# Create a new migration file
make new_migration name=add_users_table
# Generate Go code from SQL queries
make sqlc
make redis
make server
# Run all tests
make test
# Generate mock for testing
make mock
- REST API: http://localhost:8080
- gRPC API: localhost:9090
- Swagger UI: http://localhost:8080/swagger/index.html
# Install Evans (gRPC client)
go install github.com/ktr0731/evans@latest
# Connect to the gRPC server
make evans
# For macOS
brew install golang-migrate
# For Linux
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.18.2/migrate.linux-amd64.tar.gz | tar xvz
sudo mv migrate /usr/bin/migrate
# For macOS
brew install sqlc
# For Linux or other platforms
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
# For macOS
brew install protobuf
# For Linux
apt install -y protobuf-compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
# Generate database schema documentation
make db_docs
# Generate SQL from DBML
make db_schema
# Generate Go code from Protocol Buffer definitions
make proto
Command | Description |
---|---|
make postgres |
Start PostgreSQL container |
make stop |
Stop PostgreSQL container |
make createdb |
Create database inside container |
make dropdb |
Drop the database |
make migrateup |
Apply all migrations |
make migratedown |
Revert all migrations |
make migrateup1 |
Apply single migration |
make migratedown1 |
Revert single migration |
make new_migration name=xyz |
Create new migration files |
make sqlc |
Generate Go code from SQL |
make db_docs |
Generate database documentation |
make db_schema |
Generate SQL from DBML |
make test |
Run all tests |
make server |
Start the API server |
make mock |
Generate mocks for testing |
make proto |
Generate Protocol Buffer code |
make evans |
Start Evans gRPC client |
make redis |
Start Redis container |
The API supports two authentication methods:
- JWT (JSON Web Token) - Industry standard, stateless tokens
- PASETO (Platform-Agnostic Security Tokens) - More secure alternative to JWT
Both methods support:
- Access tokens for short-term authentication
- Refresh tokens for obtaining new access tokens
- Token revocation
- REST API: Available via Swagger UI at
http://localhost:8080/swagger/index.html
- gRPC API: Protocol Buffer definitions in the
proto/
directory
Build and run using Docker:
# Build Docker image
docker build -t simple-bank:latest .
# Run container
docker run -p 8080:8080 -p 9090:9090 simple-bank:latest
Deploy the entire stack:
docker compose up -d
The project includes GitHub Actions workflows for continuous integration:
- Automated testing on push and pull requests
- Database migrations are run before tests
- Tests run against PostgreSQL in a Docker container
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request