A secure and scalable Digital Wallet Backend API built with Go (Golang) using clean architecture principles. This project supports user authentication, wallet management, and financial transactions with role-based access control.
- User Registration & Login (JWT Authentication)
- Secure password hashing with bcrypt
- Create wallet automatically on registration
- Deposit money
- Withdraw money
- Transfer money between wallets
- View wallet balance
- View transaction history
- View all users
- View all wallets
- View all transactions
- Get user details by ID
- Role-based access control (Admin/User)
online-wallet/
│
├── cmd/ # Entry point (main.go)
├── db/
│ └── migrations/ # SQL migrations
│
├── internal/
│ ├── database/ # DB connection (MySQL)
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # Auth & role middleware
│ ├── models/ # Data models
│ ├── repository/ # Database logic
│ ├── service/ # Business logic
│ └── utils/ # Helper functions
│
├── .env # Environment variables
├── go.mod
└── go.sum
This project follows a clean layered architecture:
- Handlers → Handle HTTP requests/responses
- Service → Business logic
- Repository → Database operations
- Middleware → Authentication & authorization
-
Uses JWT (JSON Web Token)
-
Token contains:
user_idrole
-
Secured endpoints require:
Authorization: Bearer <token>
git clone https://github.com/moncef-an/Online-Wallet.git
cd Online-Wallet
go mod tidy
Create .env file:
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=wallet
DB_HOST=localhost
DB_PORT=3306
JWT_SECRET=your_secret_key
go run cmd/main.go
Server will start on:
http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| POST | /register | Register user |
| POST | /login | Login user |
| Method | Endpoint | Description |
|---|---|---|
| POST | /user/deposit | Deposit money |
| POST | /user/withdraw | Withdraw money |
| POST | /user/transfer | Transfer money |
| GET | /user/balance | Get wallet balance |
| GET | /user/transactions | Get user transactions |
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/users | Get all users |
| GET | /admin/wallets | Get all wallets |
| GET | /admin/transactions | Get all transactions |
| GET | /admin/user/{id} | Get user by ID |
-
Uses database transactions (GORM)
-
Ensures:
- Atomic operations
- No money loss
- Consistency
- Password hashing with bcrypt
- JWT authentication
- Role-based authorization
- Input validation (basic)
- Add Swagger API documentation
- Add rate limiting
- Add email verification
- Add pagination for admin endpoints
- Improve validation layer
Moncef Aouina
Give it a star ⭐ on GitHub!