A complete REST API for a Digital Wallet platform built with Golang, following Clean Architecture principles.
- User registration with CPF, email, phone validation
- JWT-based authentication with refresh tokens
- Account blocking/unblocking
- Get wallet balance
- Credit wallet
- Debit wallet
- Transfer money between users
- Transaction history with pagination
- Transaction status tracking (pending, confirmed, cancelled)
- Generate Boleto
- PIX payment support
- QR Code payment generation
- Payment processing
- Transaction notifications (console-based, ready for email/SMS integration)
- Language: Go 1.21
- Framework: Gin
- Database: PostgreSQL
- ORM: GORM
- Authentication: JWT with refresh tokens
- Password Hashing: bcrypt
- API Documentation: Swagger/OpenAPI
- Containerization: Docker & Docker Compose
- Migrations: golang-migrate compatible
Wallet/
βββ cmd/
β βββ api/
β βββ main.go # Application entry point
βββ internal/
β βββ config/
β β βββ config.go # Configuration management
β βββ domain/ # Domain models/entities
β β βββ user.go
β β βββ wallet.go
β β βββ transaction.go
β β βββ payment.go
β βββ handler/ # HTTP handlers
β β βββ auth_handler.go
β β βββ user_handler.go
β β βββ wallet_handler.go
β β βββ transaction_handler.go
β β βββ payment_handler.go
β βββ service/ # Business logic
β β βββ auth_service.go
β β βββ user_service.go
β β βββ wallet_service.go
β β βββ transaction_service.go
β β βββ payment_service.go
β β βββ notification_service.go
β βββ repository/ # Data access layer
β β βββ user_repository.go
β β βββ wallet_repository.go
β β βββ transaction_repository.go
β β βββ payment_repository.go
β β βββ refresh_token_repository.go
β βββ middleware/ # HTTP middleware
β β βββ auth.go
β β βββ logging.go
β βββ utils/
β βββ response.go # Response helpers
βββ pkg/
β βββ jwt/
β β βββ jwt.go # JWT utilities
β βββ validator/
β βββ validator.go # CPF, email, phone validators
βββ migrations/ # Database migrations
β βββ 000001_init_schema.up.sql
β βββ 000001_init_schema.down.sql
βββ docs/ # Swagger documentation (generated)
βββ docker-compose.yml
βββ Dockerfile
βββ Makefile
βββ go.mod
βββ go.sum
βββ .env.example
βββ .gitignore
βββ README.md
- Go 1.21 or higher
- Docker and Docker Compose
- PostgreSQL 15 (if running locally without Docker)
- golang-migrate (optional, for manual migrations)
git clone <repository-url>
cd Walletcp .env.example .envEdit .env with your configuration if needed.
docker-compose up -dThis will start:
- PostgreSQL database on port 5432
- API server on port 8080
- API Base URL:
http://localhost:8080 - Swagger Documentation:
http://localhost:8080/swagger/index.html - Health Check:
http://localhost:8080/health
go mod downloaddocker run --name wallet_postgres \
-e POSTGRES_USER=wallet_user \
-e POSTGRES_PASSWORD=wallet_pass \
-e POSTGRES_DB=wallet_db \
-p 5432:5432 \
-d postgres:15-alpinemake migrate-upmake run
# or
go run cmd/api/main.gomake swaggermake testAll protected endpoints require a Bearer token in the Authorization header:
Authorization: Bearer <access_token>
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login userPOST /api/v1/auth/refresh- Refresh access tokenGET /api/v1/auth/me- Get current user profile (protected)
GET /api/v1/users/:id- Get user by ID (protected)POST /api/v1/users/block- Block user account (protected)POST /api/v1/users/unblock- Unblock user account (protected)
GET /api/v1/wallet/balance- Get wallet balance (protected)POST /api/v1/wallet/credit- Credit wallet (protected)POST /api/v1/wallet/debit- Debit wallet (protected)
POST /api/v1/transactions/transfer- Transfer money (protected)GET /api/v1/transactions/history- Get transaction history (protected)GET /api/v1/transactions/:id- Get transaction by ID (protected)
POST /api/v1/payments/boleto- Generate boleto (protected)POST /api/v1/payments/pix- Generate PIX payment (protected)POST /api/v1/payments/qrcode- Generate QR code payment (protected)POST /api/v1/payments/process- Process payment (public - webhook)
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"cpf": "12345678909",
"email": "john@example.com",
"phone": "11987654321",
"password": "password123"
}'curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'curl -X GET http://localhost:8080/api/v1/wallet/balance \
-H "Authorization: Bearer <access_token>"curl -X POST http://localhost:8080/api/v1/transactions/transfer \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"to_user_id": "uuid-here",
"amount": 100.50,
"description": "Payment for services"
}'Run all tests:
make testRun tests with coverage:
go test -v -cover ./...Build and start containers:
make docker-upStop containers:
make docker-downView logs:
docker-compose logs -f api| Variable | Description | Default |
|---|---|---|
| APP_ENV | Application environment | development |
| APP_PORT | Server port | 8080 |
| DB_HOST | Database host | localhost |
| DB_PORT | Database port | 5432 |
| DB_USER | Database user | wallet_user |
| DB_PASSWORD | Database password | wallet_pass |
| DB_NAME | Database name | wallet_db |
| DB_SSLMODE | Database SSL mode | disable |
| JWT_SECRET | JWT secret key | your-secret-key |
| JWT_ACCESS_EXPIRY | Access token expiry | 15m |
| JWT_REFRESH_EXPIRY | Refresh token expiry | 7d |
| BCRYPT_COST | Bcrypt hashing cost | 10 |
This project follows Clean Architecture principles:
- Domain Layer: Core business entities and rules
- Repository Layer: Data access abstraction
- Service Layer: Business logic implementation
- Handler Layer: HTTP request/response handling
- Middleware: Cross-cutting concerns (auth, logging)
- Repository Pattern
- Dependency Injection
- Interface-based design
- Separation of Concerns
- Password hashing with bcrypt
- JWT-based authentication
- Refresh token rotation
- CPF, email, and phone validation
- Account blocking mechanism
- SQL injection prevention (GORM)
- Email/SMS notification integration
- Rate limiting
- API key authentication for webhooks
- Transaction rollback mechanism
- Audit logging
- Multi-currency support
- KYC integration
- 2FA authentication
MIT License
- 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
For support, email support@wallet.com or open an issue in the repository.
Built with β€οΈ using Go and Clean Architecture