Skip to content

ChukwuemekaP1/Payvault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

53 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PayVault - Modern Digital Banking Platform

PayVault Banner

A full-stack banking application built with Rust (Axum) and React, featuring real-time transactions, admin panel, and double-entry bookkeeping principles used by real banks.

✨ Features

For Users

  • πŸ” Secure Authentication - JWT-based login/registration
  • πŸ’° Real-time Balance - Instant balance updates with SSE streaming
  • πŸ’Έ Peer-to-Peer Transfers - Send money to any account instantly
  • πŸ“Š Transaction History - Complete payment history with search & filters
  • πŸ“± Mobile-Responsive - Beautiful UI that works on all devices
  • πŸ”” Transaction Notifications - Real-time toast notifications
  • πŸ“„ PDF Export - Download transaction statements as PDF

For Admins

  • πŸ‘₯ User Management - View all users and their wallets
  • πŸ’΅ Manual Credits - Credit user accounts (simulates bank deposits)
  • ❄️ Freeze/Unfreeze - Control wallet access
  • πŸ“‹ Audit Trail - Complete log of all admin actions
  • 🏦 Double-Entry Bookkeeping - Real banking accounting principles

πŸ› οΈ Tech Stack

Backend

  • Rust - Systems programming language for performance & safety
  • Axum 0.8 - Ergonomic web framework
  • PostgreSQL - Primary database via SQLX
  • Redis - Rate limiting & session management
  • JWT - Secure authentication
  • utoipa - OpenAPI/Swagger documentation

Frontend

  • React 18 - UI library
  • TypeScript - Type-safe development
  • Vite - Fast build tool
  • Tailwind CSS - Utility-first styling
  • shadcn/ui - Beautiful components
  • React Query - Data fetching & caching
  • Zustand - State management
  • Sonner - Toast notifications

πŸš€ Quick Start

Prerequisites

Backend Setup

cd backend

# Copy environment template
cp .env.example .env

# Edit .env with your configuration
# DATABASE_URL=postgresql://user:pass@localhost/payvault
# REDIS_URL=redis://localhost:6379
# JWT_SECRET=your-secret-key

# Run database migrations
sqlx migrate run

# Start development server
cargo run

Backend will start on http://localhost:8000 API docs available at http://localhost:8000/docs

Frontend Setup

cd frontend

# Install dependencies
npm install

# Copy environment template
cp .env.example .env

# Set API URL
# VITE_API_URL=http://localhost:8000

# Start development server
npm run dev

Frontend will start on http://localhost:5174

πŸ“š Documentation

API Endpoints

Public Routes

  • POST /auth/register - Create new account
  • POST /auth/login - User login
  • POST /auth/refresh - Refresh JWT token
  • POST /auth/verify-email - Verify email with OTP
  • POST /auth/forgot-password - Request password reset
  • POST /auth/reset-password - Reset password

Protected Routes (Require Auth)

  • GET /wallet/balance - Get wallet balance
  • GET /wallet/balance-stream - SSE balance updates
  • GET /wallet/lookup/{account_number} - Lookup account holder
  • POST /wallet/transfer - Transfer money
  • GET /transactions - List transactions
  • GET /transactions/{id} - Transaction details

Admin Routes (Require Admin Role)

  • GET /admin/users - List all users
  • GET /admin/users/{id} - Get user details
  • POST /admin/wallets/{id}/credit - Credit user wallet
  • POST /admin/wallets/{id}/freeze - Freeze/unfreeze wallet
  • GET /admin/audit-logs - View audit trail

Database Schema

-- Users table
CREATE TABLE users (
    id UUID PRIMARY KEY,
    email VARCHAR UNIQUE NOT NULL,
    password_hash VARCHAR NOT NULL,
    role VARCHAR NOT NULL DEFAULT 'user',
    is_verified BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP
);

-- Wallets table
CREATE TABLE wallets (
    id UUID PRIMARY KEY,
    user_id UUID REFERENCES users(id),
    balance_kobo BIGINT NOT NULL CHECK (balance_kobo >= 0),
    account_number VARCHAR(10) UNIQUE NOT NULL,
    is_frozen BOOLEAN DEFAULT FALSE,
    created_at TIMESTAMP
);

-- Transactions table
CREATE TABLE transactions (
    id UUID PRIMARY KEY,
    reference VARCHAR UNIQUE NOT NULL,
    sender_id UUID REFERENCES users(id),
    receiver_id UUID REFERENCES users(id),
    amount_kobo BIGINT NOT NULL,
    type VARCHAR NOT NULL,
    status VARCHAR NOT NULL,
    metadata JSONB,
    created_at TIMESTAMP
);

-- Audit log table
CREATE TABLE audit_log (
    id UUID PRIMARY KEY,
    actor_id UUID REFERENCES users(id),
    action VARCHAR NOT NULL,
    target_type VARCHAR NOT NULL,
    target_id UUID,
    details JSONB,
    created_at TIMESTAMP
);

🎯 Demo Credentials

Admin Panel

Access at: http://localhost:5174/admin/login

Email: admin@payvault.com
Password: Admin123!

User Accounts

Register new accounts at: http://localhost:5174/auth/register

Or use demo accounts (if pre-created):

πŸ§ͺ Testing

Backend Tests

cd backend
cargo test

Frontend Tests

cd frontend
npm test

πŸ“ Project Structure

Rust_Bank/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ middleware/      # Auth, rate limiting, idempotency
β”‚   β”‚   β”œβ”€β”€ modules/         # Feature modules (auth, wallet, etc.)
β”‚   β”‚   β”œβ”€β”€ utils/           # Helper functions
β”‚   β”‚   β”œβ”€β”€ config.rs        # Configuration
β”‚   β”‚   β”œβ”€β”€ error.rs         # Error handling
β”‚   β”‚   β”œβ”€β”€ router.rs        # Route definitions
β”‚   β”‚   └── main.rs          # Entry point
β”‚   β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ db/migrations/       # SQL migrations
β”‚   └── Cargo.toml
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom hooks
β”‚   β”‚   β”œβ”€β”€ lib/             # Utilities & API client
β”‚   β”‚   β”œβ”€β”€ pages/           # Page components
β”‚   β”‚   β”œβ”€β”€ store/           # Zustand stores
β”‚   β”‚   β”œβ”€β”€ types/           # TypeScript types
β”‚   β”‚   └── App.tsx
β”‚   β”œβ”€β”€ public/
β”‚   └── package.json
β”‚
└── README.md

πŸ”’ Security Features

  • βœ… JWT authentication with refresh tokens
  • βœ… Password hashing with bcrypt
  • βœ… Rate limiting on sensitive endpoints
  • βœ… Idempotency keys for transfers
  • βœ… Input validation with validator crate
  • βœ… SQL injection prevention via SQLX
  • βœ… XSS protection via React escaping
  • βœ… CORS configuration
  • βœ… Audit logging for admin actions

🏦 Banking Principles Implemented

This isn't just another demo app - it implements real banking principles:

1. Double-Entry Bookkeeping

Every transaction affects at least 2 accounts:

User A sends ₦5,000 to User B:
DEBIT:  User A Wallet (₦5,000)
CREDIT: User B Wallet (₦5,000)

2. Ledger System

  • Assets: Bank's reserves (operations account)
  • Liabilities: Customer deposits (user wallets)
  • Equity: Bank's capital

3. Audit Trail

Every admin action is logged:

  • Who performed the action
  • What action was taken
  • Which entity was affected
  • Details of the change

4. ACID Transactions

All money movements use database transactions:

  • Atomicity: All or nothing
  • Consistency: Database stays valid
  • Isolation: Concurrent operations don't interfere
  • Durability: Committed data persists

🌍 Deployment

See DEPLOYMENT.md for production deployment guides:

  • VPS deployment (DigitalOcean, Linode)
  • PaaS deployment (Railway, Render)
  • Docker deployment
  • Frontend deployment (Vercel, Netlify)

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines first.

πŸ“„ License

MIT License - See LICENSE file for details

πŸ‘¨β€πŸ’» Author Chukwuemeka Paul Nwokolo

Built with ❀️ using Rust and React


PayVault - Banking infrastructure for the modern web.

About

This is a backend bank app that was built to show the powers of rust backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors