Skip to content

Banking operations backend using Go, PostgreSQL, and REST APIs

Notifications You must be signed in to change notification settings

timjtchang/banking-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏦 Banking System Backend

This is a robust, modular, and scalable banking system backend built with Go (Golang). It uses the gorilla/mux router for request handling and follows a clean separation of concerns.


✨ Features

  • User Management: Create, retrieve, update, and delete user accounts.
  • Transaction Handling: Perform transfers, withdrawals, and deposits. Handle race condition using row-level locking.
  • Modular Design: Clear separation between handlers, internal logic (database/transaction), and data models.
  • Environment Configuration: Uses a .env file for sensitive configuration.

Demo

Demo


🛠️ Project Structure

The key components of the application are organized as follows:

Directory/File Purpose
handlers/ HTTP request controllers for User and Transaction actions.
internal/db/ Database connection and specific data access methods.
internal/transaction/ Core business logic for handling funds and transfers.
internal/user/ Core business logic for managing user accounts.
internal/models/ Structs defining application data (e.g., User, Transaction).
main.go Application entry point, configuration loading, and route definition.
schema.sql SQL script for creating necessary database tables.
.env.example Template for required environment variables.

🚀 Getting Started

Prerequisites

  • Go (version 1.24+ recommended)
  • A running PostgreSQL or equivalent database instance.
  • Docker (optional, for containerized deployment)

Local Setup

  1. Clone the repository:

    git clone [repo-link]
    cd banking
  2. Set up environment variables: Create a file named .env by copying the example and filling in your database credentials and secrets.

    cp .env.example .env
  3. Install dependencies:

    go mod tidy
  4. Initialize the database: Run the setup script or manually execute the SQL from schema.sql to create tables.

    ./setup.sh
    # OR manually run the contents of schema.sql
  5. Run the application:

    go run main.go

    The server will start on http://localhost:8080.


🌎 API Endpoints

The API is accessible on port 8080 and handles the following routes:

User Management

Method Path Description
POST /user Creates a new user account.
GET /user/{id} Retrieves a specific user by ID.
GET /user Retrieves a list of users.
PUT /user/{id} Updates user details (e.g., name).
DELETE /user/{id} Deletes a user account.

Transaction Handling

Method Path Description
PUT /transaction/transfer Transfers funds between two accounts.
PUT /transaction/withdraw Withdraws funds from an account.
PUT /transaction/deposit Deposits funds into an account.

About

Banking operations backend using Go, PostgreSQL, and REST APIs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published