Repository files navigation # 🏦 Go-Bank (Microservices Core Banking)
ระบบธนาคารจำลองแบบ Microservices ด้วย Go + gRPC
## 🏗️ Architecture
```
┌─────────────────────────────────────────────────────────────┐
│ Client │
│ (Web/Mobile App) │
└─────────────────────────┬───────────────────────────────────┘
│ HTTP/REST
▼
┌─────────────────────────────────────────────────────────────┐
│ API Gateway (Fiber) │
│ Port: 8080 │
└──────────┬─────────────────────────────────┬────────────────┘
│ gRPC │ gRPC
▼ ▼
┌──────────────────────┐ ┌──────────────────────────┐
│ Auth Service │ │ Bank Service │
│ Port: 50051 │ │ Port: 50052 │
│ │ │ │
│ - Register │ │ - CreateAccount │
│ - Login │ │ - GetAccount │
│ - Verify Token │ │ - Transfer │
│ │ │ - GetTransfers │
└──────────┬───────────┘ └────────────┬─────────────┘
│ │
▼ ▼
┌──────────────────────┐ ┌──────────────────────────┐
│ PostgreSQL │ │ PostgreSQL │
│ gobank_auth │ │ gobank_core │
└──────────────────────┘ └──────────────────────────┘
```
## 📁 Project Structure
```
Go-Bank/
├── api-gateway/ # HTTP Gateway (Fiber)
│ ├── handlers/ # HTTP Handlers
│ ├── middleware/ # Auth Middleware
│ └── main.go
│
├── auth-service/ # Authentication Service (gRPC)
│ ├── db/
│ │ ├── migration/ # SQL Migrations
│ │ ├── query/ # SQL Queries for sqlc
│ │ └── sqlc/ # Generated Go code
│ ├── pb/ # Generated Protobuf
│ ├── token/ # JWT/PASETO
│ └── main.go
│
├── bank-service/ # Core Banking Service (gRPC)
│ ├── db/
│ │ ├── migration/
│ │ ├── query/
│ │ └── sqlc/
│ ├── pb/
│ └── main.go
│
├── proto/ # Protobuf Definitions (Source of Truth)
│ ├── auth.proto
│ └── bank.proto
│
├── docker-compose.yml
├── Makefile
└── README.md
```
## 🛠️ Tech Stack
- **Language:** Go 1.21+
- **Communication:** gRPC + Protobuf
- **HTTP Framework:** Fiber
- **Database:** PostgreSQL
- **Database Tools:** sqlc, golang-migrate
- **Auth:** JWT / PASETO
- **Deployment:** Docker Compose
- **CI/CD:** GitHub Actions
## 🚀 Quick Start
### Prerequisites
1. **Go 1.21+**
2. **Docker & Docker Compose**
3. **Protocol Buffers Compiler (protoc)**
4. **sqlc**
### Installation
```bash
# Install protoc plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Install sqlc
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Install migrate
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
```
### Run with Docker
```bash
# Start all services
docker-compose up -d
# Run migrations
make migrate-up
# Generate code
make proto
make sqlc
```
## 📋 Makefile Commands
```bash
make proto # Generate Go code from .proto files
make sqlc # Generate Go code from SQL queries
make migrate-up # Run database migrations
make migrate-down # Rollback migrations
make test # Run all tests
make build # Build all services
make docker-up # Start Docker Compose
make docker-down # Stop Docker Compose
```
## 📝 API Endpoints (Gateway)
### Auth
- `POST /api/v1/auth/register` - Register new user
- `POST /api/v1/auth/login` - Login and get token
### Account
- `POST /api/v1/accounts` - Create account
- `GET /api/v1/accounts/:id` - Get account by ID
- `GET /api/v1/accounts` - List accounts
### Transfer
- `POST /api/v1/transfers` - Transfer money
- `GET /api/v1/transfers` - List transfers
## 🔐 Double-Entry Ledger
ระบบใช้หลักการบัญชีคู่ (Double-Entry) เพื่อความถูกต้องของข้อมูล:
```
Transfer: A → B (1000 THB)
entries table:
| account_id | amount |
|------------|---------|
| A | -1000 | (Debit)
| B | +1000 | (Credit)
Sum of entries = 0 (Always balanced!)
```
## 🧪 Testing
```bash
# Run unit tests
make test
# Run with coverage
make test-coverage
```
## 📄 License
MIT License
# Go-Bank
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
You can’t perform that action at this time.