A REST API service for managing customer accounts and financial transactions.
- Language: Go 1.25.3
- Web Framework: chi v5
- Database: PostgreSQL 18.0
- Database Driver: pgx/v5
- Validation: validator/v10
- Containerization: Docker Compose
challenge-money/
├── internal/
│ ├── account/ # Account domain logic
│ │ ├── handler.go
│ │ ├── models.go
│ │ ├── repository.go
│ │ └── handler_test.go
│ ├── transaction/ # Transaction domain logic
│ │ ├── handler.go
│ │ ├── models.go
│ │ ├── repository.go
│ │ └── handler_test.go
│ ├── health/ # Health check handlers
│ ├── database/ # Database connection utilities
│ └── httperrors/ # Custom HTTP error handling
├── main.go # Application entry point
├── init.sql # Database schema and seed data
├── docker-compose.yaml # PostgreSQL container setup
├── Makefile # Build and development tasks
└── run # Quick start script
- Go 1.25.3 or later
- Docker and Docker Compose
- (Optional) Air for live reload during development
- Clone the repository:
git clone https://github.com/rikw22/challenge-money
cd challenge-money- Install dependencies:
go mod download- (Optional) Install Air for live reload:
go install github.com/air-verse/air@latestUse the provided run script:
./runThis will:
- Start PostgreSQL container via docker-compose
- Initialize the database with schema and seed data
- Start the API server with live reload (if Air is installed)
Using Makefile:
make runManual setup:
# Start PostgreSQL
docker compose up -d
# Run the application
go run main.goThe server will start on http://localhost:8080 by default.
https://github.com/rikw22/challenge-money/raw/refs/heads/main/docs/postman_collection.json
https://raw.githubusercontent.com/rikw22/challenge-money/refs/heads/main/docs/requests.http
curl http://localhost:8080/healthResponse (200 OK):
{
"status": "UP"
}curl -X POST http://localhost:8080/accounts \
-H "Content-Type: application/json" \
-d '{
"document_number": "12345678901"
}'Response (201 Created):
{
"account_id": 1,
"document_number": "12345678901"
}curl http://localhost:8080/accounts/1Response (200 OK):
{
"account_id": 1,
"document_number": "12345678901",
"created_at": "2025-10-27T00:18:14Z"
}curl -X POST http://localhost:8080/transactions \
-H "Content-Type: application/json" \
-d '{
"account_id": 1,
"operation_type_id": 4,
"amount": 123.45
}'Operation Types:
1- Normal Purchase (negative amount)2- Purchase with installments (negative amount)3- Withdrawal (negative amount)4- Credit Voucher (positive amount)
Response (201 Created):
{
"id": "019a096b-ad9f-7f0e-88a4-9c93a754b029",
"account_id": 1,
"operation_type_id": 4,
"amount": 123.45
}When using docker compose:
- Host: localhost
- Port: 5432
- Database: postgres
- User: postgres
- Password: postgres
Run all tests:
make test
# or
go test ./...Run tests with coverage:
make test-coverage
# or
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.outmake build
# or
go build# Start PostgreSQL
make docker-up
# Stop PostgreSQL
make docker-down| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 8080 |
DATABASE_URL |
PostgreSQL connection string | postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable |
- Idempotence handling for transactions
- Graceful Shutdown - https://github.com/go-chi/chi/blob/master/_examples/graceful/main.go
- Integration tests
- Database migrations (e.g., golang-migrate, goose)
- API documentation (Swagger/OpenAPI)
- Rate limiting
- Authentication and authorization
- Audit logging
- Transaction rollback mechanisms
- Balance calculation and tracking