https://github.com/ankux/auth-wallet-api
A simple Node.js and Express.js backend API for user authentication and financial transactions (credit/debit), built with MongoDB and Dockerized for easy deployment.
https://github.com/ankux/auth-wallet-api
api express mongodb nodejs postman
Last synced: 3 months ago
JSON representation
A simple Node.js and Express.js backend API for user authentication and financial transactions (credit/debit), built with MongoDB and Dockerized for easy deployment.
- Host: GitHub
- URL: https://github.com/ankux/auth-wallet-api
- Owner: ankux
- Created: 2025-06-14T02:22:21.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-06-14T02:53:03.000Z (10 months ago)
- Last Synced: 2025-06-14T03:30:17.056Z (10 months ago)
- Topics: api, express, mongodb, nodejs, postman
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Project Structure
```
affinsys-proj/
├── config/ # MongoDB connection setup
├── controllers/ # Business logic for auth & transactions
├── middleware/ # Basic Auth middleware
├── models/ # Mongoose models
├── routes/ # API endpoints
├── .env # Environment variables
├── server.js # Main server file
└── package.json
```
---
## Project setup
### 1. Clone the Repo
```bash
git clone https://github.com/ankux/auth-wallet-api.git
cd auth-wallet-api
```
### 2. Install Dependencies
```bash
npm install
```
### 3. Setup Environment Variables
Create a `.env` file in the root directory:
```env
PORT=5000
MONGO_URI=mongodb://localhost:27017/walletDB
```
### 4. Start the Server
```bash
node server.js
```
The server will run at: [http://localhost:5000](http://localhost:5000)
---
## API Endpoints
### 🔑 Auth Routes
| Method | Endpoint | Description |
|--------|-------------|---------------------|
| POST | `/register` | Register a new user |
**Sample Request Body:**
```json
{
"username": "your_username",
"password": "your_password"
}
```
---
### 💳 Transaction Routes (Requires Basic Auth)
| Method | Endpoint | Description |
|--------|-----------|--------------------------|
| POST | `/fund` | Credit funds |
| POST | `/pay` | Debit funds |
| GET | `/bal` | Get current balance |
| GET | `/bal?currency=USD` | Get USD conversion |
| GET | `/stmt` | Get transaction history |
#### Authorization:
Use **Basic Auth** in Postman (or any client):
- **Username:** Registered username
- **Password:** Registered password
---
## Example Requests
### Register
```http
POST /register
```
```json
{
"username": "john123",
"password": "pass456"
}
```
### Fund account
```http
POST /fund
Authorization: Basic Auth
```
```json
{
"amt": 100
}
```
### Pay another user
```http
POST /pay
Authorization: Basic Auth
```
```json
{
"to": "dhruv",
"amt": 100
}
```
---
## Notes
- All passwords are hashed using **bcrypt**
- User balances and transactions are stored in MongoDB
- Only authenticated users can access transaction routes
---