Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💰 Online Wallet API

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.


🚀 Features

👤 User Features

  • 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

👑 Admin Features

  • View all users
  • View all wallets
  • View all transactions
  • Get user details by ID
  • Role-based access control (Admin/User)

🏗️ Project Structure

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

🧠 Architecture

This project follows a clean layered architecture:

  • Handlers → Handle HTTP requests/responses
  • Service → Business logic
  • Repository → Database operations
  • Middleware → Authentication & authorization

🔐 Authentication

  • Uses JWT (JSON Web Token)

  • Token contains:

    • user_id
    • role
  • Secured endpoints require:

Authorization: Bearer <token>

⚙️ Installation

1️⃣ Clone the repository

git clone https://github.com/moncef-an/Online-Wallet.git
cd Online-Wallet

2️⃣ Install dependencies

go mod tidy

3️⃣ Setup environment variables

Create .env file:

DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=wallet
DB_HOST=localhost
DB_PORT=3306

JWT_SECRET=your_secret_key

▶️ Run the project

go run cmd/main.go

Server will start on:

http://localhost:8080

📡 API Endpoints

🔓 Public

Method Endpoint Description
POST /register Register user
POST /login Login user

🔐 User Routes

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

👑 Admin Routes

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

🔄 Transactions

  • Uses database transactions (GORM)

  • Ensures:

    • Atomic operations
    • No money loss
    • Consistency

🛡️ Security

  • Password hashing with bcrypt
  • JWT authentication
  • Role-based authorization
  • Input validation (basic)

📈 Future Improvements

  • Add Swagger API documentation
  • Add rate limiting
  • Add email verification
  • Add pagination for admin endpoints
  • Improve validation layer

👨‍💻 Author

Moncef Aouina


⭐ If you like this project

Give it a star ⭐ on GitHub!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages