File size: 2,547 Bytes
de5ba48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
πŸš— CarPool App Backend - Professional Node.js API
This is a secure, high-performance backend built for a Carpooling application. It handles user authentication, ride management, wallet transactions, and real-time notifications using Node.js, Express, and Firebase.

πŸ›‘οΈ Key Features & Security
The backend is designed with a "Security First" approach, featuring:

Firebase Admin SDK: Secure authentication and Firestore database integration.

Wallet System: A built-in wallet that tracks balances and transactions.

Auto-Commission Logic: Automatically deducts a 10% platform fee from captains upon deal confirmation.

Anti-Spam Rate Limiting: Implemented express-rate-limit to prevent Brute-force and DoS attacks.

Ride Security: Captains must maintain a minimum balance of Rs. 200 to post a ride.

Role-Based Access: Strict middleware to separate 'Captain' and 'Customer' functionalities.

πŸ—οΈ Project Architecture
The project follows a clean MVC (Model-View-Controller) pattern:

src/app.js: Main entry point with security middleware (Helmet, CORS, Morgan).

src/routes/: Route definitions for Auth, Rides, Deals, and Wallet.

src/controllers/: Core business logic (Wallet deductions, ride posting, etc.).

src/middleware/: Authentication guards and rate limiters.

src/config/: Firebase Admin configuration.

πŸ› οΈ API Documentation
πŸ”‘ Authentication
POST /api/auth/sync - Syncs Firebase user data with Firestore.

GET /api/auth/profile - Fetches current user profile.

🚘 Ride Management
POST /api/rides - Create a ride (Requires Captain role + Min Rs. 200 balance).

GET /api/rides - Browse all active rides.

PATCH /api/rides/:rideId/status - Update ride status (Active/Filled/Completed).

🀝 Deals & Bookings
POST /api/deals - Customer requests to join a ride.

PATCH /api/deals/:dealId/confirm - Captain confirms deal (Deducts 10% Platform Fee).

PATCH /api/deals/:dealId/cancel - Refund logic if a confirmed deal is cancelled.

πŸ’³ Wallet System
GET /api/wallet - Check current balance.

GET /api/wallet/transactions - View all credit/debit history.

POST /api/wallet/topup - Manual wallet recharge.

πŸš€ How to Run
Clone the repo

Install dependencies:

Bash
npm install
Setup Environment Variables (.env):

Code snippet
PORT=3000
FIREBASE_PROJECT_ID=your-id
FIREBASE_PRIVATE_KEY="your-key"
FIREBASE_CLIENT_EMAIL=your-email
Start the server:

Bash
node server.js
πŸ“ˆ Current Status
Server Status: βœ… Online & Functional

Security: βœ… Verified (Rate limits & JWT active)

Database: βœ… Firebase Firestore Connected