Skip to content
niloy104Public

About

Secure banking backend built in Go with Gin REST APIs for accounts, transfers and transactions, dual JWT + PASETO authentication, sqlc + pgx with PostgreSQL for type-safe persistence, and Docker Compose for production deployment.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

62 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bank-Pro 🏦

A robust, production-ready backend banking service built with Go, featuring account management, user authentication, secure token handling, and comprehensive database operations.

🌟 Features

  • User Management: Create and manage bank accounts with secure authentication
  • JWT & PASETO Authentication: Dual token generation for enhanced security
  • Account Operations: Core banking functionalities for account management
  • Transfer & Transactions: Secure fund transfer and transaction tracking
  • PostgreSQL Database: Reliable data persistence with connection pooling
  • REST API: Clean, RESTful endpoints powered by Gin framework
  • Input Validation: Comprehensive request validation using go-playground/validator
  • Unit Testing: Full test coverage with mocking support
  • Docker Support: Easy deployment with Docker and Docker Compose
  • Database Migrations: Version-controlled schema management with SQL migrations

πŸ› οΈ Tech Stack

Component Technology Purpose
Language Go 1.25.5 Fast, efficient backend development
Web Framework Gin High-performance HTTP framework
Database PostgreSQL 16 Reliable relational database
DB Driver pgx/v5 Modern PostgreSQL driver
DB Generation sqlc Type-safe SQL queries
Authentication JWT + PASETO Secure token-based auth
Validation go-playground/validator Request validation
Config Management Viper Environment configuration
Containerization Docker & Docker Compose Deployment orchestration
Testing testify + uber/mock Testing & mocking utilities

πŸ“‹ Project Structure

Bank-Pro/
β”œβ”€β”€ main.go                 # Application entry point
β”œβ”€β”€ go.mod & go.sum        # Go dependencies
β”œβ”€β”€ Dockerfile             # Container image definition
β”œβ”€β”€ docker-compose.yaml    # Multi-container setup
β”œβ”€β”€ Makefile              # Common development commands
β”œβ”€β”€ sqlc.yaml             # SQL code generation config
β”œβ”€β”€ app.env               # Environment variables
β”‚
β”œβ”€β”€ api/                  # REST API handlers & server
β”œβ”€β”€ db/                   # Database layer
β”‚   β”œβ”€β”€ migration/        # SQL migration files
β”‚   β”œβ”€β”€ sqlc/            # Generated SQL queries
β”‚   └── mock/            # Mock database for testing
β”œβ”€β”€ token/               # JWT & PASETO token management
└── util/                # Utility functions & helpers

πŸš€ Quick Start

Prerequisites

  • Go 1.25.5 or higher
  • Docker & Docker Compose
  • PostgreSQL client (optional, for local development)

Setup & Run

Option 1: Using Docker Compose (Recommended)

# Clone the repository
git clone https://github.com/niloy104/Bank-Pro.git
cd Bank-Pro

# Start services
docker-compose up --build

# API will be available at http://localhost:8080

Option 2: Local Development

# Clone repository
git clone https://github.com/niloy104/Bank-Pro.git
cd Bank-Pro

# Start PostgreSQL
make postgres

# Create database
make createdb

# Run migrations
make migrateup

# Start server
make server

# API will be running at configured SERVER_ADDRESS

πŸ“¦ Available Make Commands

# Database operations
make postgres              # Start PostgreSQL container
make createdb             # Create 'simple_bank' database
make dropdb               # Drop 'simple_bank' database

# Database migrations
make migrateup            # Run all pending migrations
make migratedown          # Rollback all migrations
make migrateup1           # Run next 1 migration
make migratedown1         # Rollback 1 migration

# Code generation & testing
make sqlc                 # Generate type-safe SQL code
make test                 # Run all tests with coverage
make mock                 # Generate mock database for tests

# Development
make server               # Start the API server

βš™οΈ Configuration

Configuration is managed via environment variables. Create an app.env file:

# Server Configuration
SERVER_ADDRESS=0.0.0.0:8080

# Database Configuration
DB_SOURCE=postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable

# JWT/PASETO Configuration
TOKEN_SYMMETRIC_KEY=<your-32-character-key>
ACCESS_TOKEN_DURATION=15m
REFRESH_TOKEN_DURATION=24h

πŸ”Œ API Endpoints

Authentication

  • POST /auth/login - User login (returns JWT/PASETO token)
  • POST /auth/refresh - Refresh authentication token

Accounts

  • POST /accounts - Create new account
  • GET /accounts/:id - Get account details
  • GET /accounts - List user accounts

Transfers

  • POST /transfers - Create fund transfer
  • GET /transfers/:id - Get transfer details

Transactions

  • GET /transactions - List account transactions

Detailed API documentation available in /api endpoint

πŸ§ͺ Testing

# Run all tests
make test

# Run specific test
go test -v ./api

# Run with coverage report
go test -cover ./...

Tests use mock databases and dependency injection for isolated, reliable testing.

πŸ“¦ Build & Deployment

Build Docker Image

# Build image
docker build -t bank-pro:latest .

# Run container
docker run -p 8080:8080 \
  -e DB_SOURCE=postgresql://root:secret@postgres:5432/simple_bank \
  bank-pro:latest

Deploy with Docker Compose

docker-compose up -d

πŸ” Security Features

  • Token-Based Authentication: JWT and PASETO tokens
  • Password Encryption: Secure hashing with golang.org/x/crypto
  • SQL Injection Prevention: Type-safe queries via sqlc
  • Input Validation: Comprehensive request validation
  • Environment-Based Config: Sensitive data in environment variables
  • Connection Pooling: Secure database connection management via pgxpool

πŸ“š Dependencies

Key external dependencies:

  • github.com/gin-gonic/gin - Web framework
  • github.com/golang-jwt/jwt/v5 - JWT token generation
  • github.com/o1egl/paseto - PASETO token generation
  • github.com/jackc/pgx/v5 - PostgreSQL driver
  • golang.org/x/crypto - Cryptographic functions
  • github.com/google/uuid - UUID generation
  • github.com/spf13/viper - Configuration management

See go.mod for complete dependency list.

🀝 Development Workflow

  1. Create Feature Branch: git checkout -b feature/your-feature
  2. Make Changes: Implement your feature
  3. Run Tests: make test - ensure all tests pass
  4. Generate Code: make sqlc - if database changes
  5. Commit: Commit with meaningful messages
  6. Push & PR: Create pull request for review

πŸ“Š Code Quality

  • Type Safety: Full static typing with Go
  • Testing: Comprehensive unit tests with mocking
  • Linting: Go standard conventions followed
  • Documentation: Inline comments for complex logic

πŸ› Troubleshooting

Port Already in Use

# Change SERVER_ADDRESS in app.env
SERVER_ADDRESS=0.0.0.0:8081

Database Connection Error

# Verify PostgreSQL is running
docker ps | grep postgres

# Check DB_SOURCE connection string

Migration Issues

# Reset migrations
make migratedown
make migrateup

πŸ“„ License

This project is licensed under the terms specified in the LICENSE file.

πŸ‘€ Author

niloy104 - GitHub Profile


πŸ“ˆ Language Composition

  • Go: 92% (Core application)
  • Shell: 5.8% (Deployment scripts)
  • Makefile: 1.5% (Build automation)
  • Dockerfile: 0.7% (Container setup)

🌐 Resources


Built with ❀️ for secure, scalable banking backend systems

About

Secure banking backend built in Go with Gin REST APIs for accounts, transfers and transactions, dual JWT + PASETO authentication, sqlc + pgx with PostgreSQL for type-safe persistence, and Docker Compose for production deployment.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages