A modern, secure trading platform built with Hono.js and deployed on Cloudflare Workers for lightning-fast serverless performance. This platform provides comprehensive broker management, fraud detection, and real-time trading capabilities with full KYC compliance.
- โจ Features
- ๐ ๏ธ Tech Stack
- ๐ Project Structure
- ๐ Quick Start
- ๐ก API Documentation
- ๐งช Test Cases
- ๐ Security Features
- ๐ Database Schema
- ๐ Deployment
- ๐ฅ Team
- ๐ Secure Authentication - JWT-based login/signup with password hashing
- ๐ KYC Management - Complete Know Your Customer verification system
- ๐ฐ Balance Management - Real-time balance tracking with minimum balance alerts
- ๐ Trading Operations - Buy/sell stocks with real-time portfolio management
- ๐จ Smart Alerts - Low balance notifications and trading alerts
- ๐ Transaction History - Complete audit trail of all financial transactions
- ๐ Portfolio Tracking - Real-time stock holdings and performance metrics
- ๐ก๏ธ Fraud Prevention - Built-in security measures and validation
- Hono.js - Ultra-fast web framework for edge computing
- Cloudflare Workers - Serverless deployment platform
- TypeScript - Type-safe development with full IntelliSense support
- JWT - Secure token-based authentication
- Cloudflare D1 - Serverless SQL database with automatic scaling
- SQLite - Lightweight, reliable database engine
- Wrangler CLI - Cloudflare Workers development and deployment tool
- ESBuild - Fast JavaScript bundler for production builds
sebi-hackathon/
โโโ src/
โ โโโ routes/
โ โ โโโ auth.ts # Authentication endpoints
โ โ โโโ kyc.ts # KYC management
โ โ โโโ balance.ts # Balance and transaction management
โ โ โโโ trading.ts # Trading operations
โ โโโ index.ts # Main application entry point
โโโ schema.sql # Database schema and initial data
โโโ testcase.md # Comprehensive API test cases
โโโ wrangler.toml # Cloudflare Workers configuration
โโโ package.json # Project dependencies and scripts
โโโ README.md # Project documentation
- Node.js 18+
- npm or yarn
- Cloudflare account with Workers enabled
-
Clone the repository
git clone https://github.com/Bhup-GitHUB/sebi-hackathon cd sebi-hackathon -
Install dependencies
npm install
-
Set up Cloudflare D1 Database
# Create D1 database npx wrangler d1 create sebi-trading-db # Apply schema npx wrangler d1 execute sebi-trading-db --file=schema.sql
-
Configure environment
# Update wrangler.toml with your database ID # Add your JWT secret and other environment variables
-
Run development server
npm run dev
-
Deploy to production
npm run deploy
https://sebi-hackathon.bkumar-be23.workers.dev/
POST /auth/signup
Content-Type: application/json
{
"username": "user123",
"email": "[email protected]",
"phone": "9876543210",
"password": "SecurePass123!",
"name": "John Doe"
}POST /auth/login
Content-Type: application/json
{
"username": "user123",
"password": "SecurePass123!"
}POST /kyc/register
Authorization: Bearer <token>
Content-Type: application/json
{
"pan": "ABCDE1234F"
}POST /kyc/validate
Authorization: Bearer <token>
Content-Type: application/json
{
"kycId": 1
}GET /kyc/status
Authorization: Bearer <token>POST /balance/add
Authorization: Bearer <token>
Content-Type: application/json
{
"addBalance": 1000
}GET /balance/check
Authorization: Bearer <token>GET /balance/check-low-balance
Authorization: Bearer <token>GET /balance/transactions?limit=50&offset=0
Authorization: Bearer <token>POST /trading/buy
Authorization: Bearer <token>
Content-Type: application/json
{
"stockName": "RELIANCE",
"price": 2450.50,
"quantity": 10
}POST /trading/sell
Authorization: Bearer <token>
Content-Type: application/json
{
"stockName": "RELIANCE",
"price": 2500.00,
"quantity": 5
}GET /trading/portfolio
Authorization: Bearer <token>-
Health Check
curl -X GET https://sebi-hackathon.bkumar-be23.workers.dev/
-
Register User
curl -X POST https://sebi-hackathon.bkumar-be23.workers.dev/auth/signup \ -H "Content-Type: application/json" \ -d '{ "username": "testuser1", "email": "[email protected]", "phone": "9876543210", "password": "TestPassword123!", "name": "Test User One" }'
-
Login and Get Token
curl -X POST https://sebi-hackathon.bkumar-be23.workers.dev/auth/login \ -H "Content-Type: application/json" \ -d '{ "username": "testuser1", "password": "TestPassword123!" }'
-
Register KYC
curl -X POST https://sebi-hackathon.bkumar-be23.workers.dev/kyc/register \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_JWT_TOKEN_HERE" \ -d '{ "pan": "ABCDE1234F" }'
-
Add Balance
curl -X POST https://sebi-hackathon.bkumar-be23.workers.dev/balance/add \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_JWT_TOKEN_HERE" \ -d '{ "addBalance": 1000 }'
-
Buy Stock
curl -X POST https://sebi-hackathon.bkumar-be23.workers.dev/trading/buy \ -H "Authorization: Bearer YOUR_JWT_TOKEN_HERE" \ -H "Content-Type: application/json" \ -d '{ "stockName": "RELIANCE", "price": 2450.50, "quantity": 10 }'
{
"success": true,
"message": "User created successfully",
"userId": 1
}{
"success": true,
"message": "Login successful",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"username": "testuser1",
"email": "[email protected]",
"name": "Test User One"
}
}{
"success": true,
"message": "Stock purchase successful",
"order": {
"orderId": 1,
"stockName": "RELIANCE",
"orderType": "buy",
"quantity": 10,
"price": 2450.50,
"totalAmount": 24505.00,
"status": "executed",
"executedAt": "2025-08-30T20:30:15.456Z"
},
"balance": {
"previousBalance": 50000,
"amountSpent": 24505.00,
"newBalance": 25495.00,
"currency": "INR"
},
"portfolio": {
"stockName": "RELIANCE",
"quantity": 10,
"averagePrice": 2450.50,
"totalInvestment": 24505.00
}
}The API provides comprehensive error handling with detailed error messages:
{
"success": false,
"error": "Authorization header required"
}{
"success": false,
"error": "Valid balance amount is required (must be a positive number)"
}{
"success": false,
"error": "Insufficient balance for this purchase",
"details": {
"requiredAmount": 24505.00,
"currentBalance": 1000,
"shortfall": 23505.00
}
}For complete test cases, see testcase.md
- JWT Authentication - Secure token-based authentication with expiration
- Password Hashing - Secure password storage using cryptographic hashing
- Input Validation - Comprehensive validation for all API inputs
- Rate Limiting - Built-in protection against API abuse
- CORS Protection - Cross-origin request security
- SQL Injection Prevention - Parameterized queries for database operations
The platform uses a well-structured SQLite database with the following tables:
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
email TEXT UNIQUE NOT NULL,
phone TEXT NOT NULL,
password_hash TEXT NOT NULL,
name TEXT NOT NULL,
kyc_status TEXT DEFAULT 'not_registered',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);CREATE TABLE kyc (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
pan TEXT NOT NULL,
status TEXT DEFAULT 'pending',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
validated_at DATETIME,
FOREIGN KEY (user_id) REFERENCES users(id)
);CREATE TABLE balance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
amount DECIMAL(15,2) DEFAULT 0.00,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);CREATE TABLE balance_transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
type TEXT NOT NULL, -- 'credit' or 'debit'
amount DECIMAL(15,2) NOT NULL,
description TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);# Login to Cloudflare
npx wrangler login
# Deploy to production
npm run deploy
# Deploy to staging
npm run deploy:stagingUpdate your wrangler.toml with the following:
name = "sebi-hackathon"
main = "src/index.ts"
compatibility_date = "2024-01-01"
[[d1_databases]]
binding = "sebi_trading_db"
database_name = "sebi-trading-db"
database_id = "your-database-id"
[vars]
JWT_SECRET = "your-jwt-secret-key"
MINIMUM_BALANCE = "1000"# Development
npm run dev # Start development server
# Deployment
npm run deploy # Deploy to production
npm run cf-typegen # Generate TypeScript typesThe platform includes comprehensive test cases covering:
- โ User registration and authentication
- โ KYC registration and validation
- โ Balance management and transactions
- โ Stock trading operations
- โ Portfolio management
- โ Error handling and edge cases
Run the test cases using the provided curl commands in the Test Cases section.
- Ultra-fast Response Times - Cloudflare Workers edge computing
- Global CDN - Worldwide content delivery
- Auto-scaling - Handles traffic spikes automatically
- 99.9% Uptime - Cloudflare's reliable infrastructure
- Real-time stock price feeds
- Advanced charting and technical analysis
- Mobile app development
- AI-powered trading recommendations
- Multi-currency support
- Advanced fraud detection algorithms
For technical support or questions:
- Create an issue on GitHub
- Contact the development team
- Check the testcase.md for detailed API documentation