Spaces:
Sleeping
Sleeping
|
Download src/middleware/README.md from carpool-team/Carpool: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/spaces/carpool-team/Carpool/resolve/main/src/middleware/README.md
- Command line
-
hf download hf://spaces/carpool-team/Carpool/src/middleware/README.md
-
curl -L -o README.md https://huggingface.co/spaces/carpool-team/Carpool/resolve/main/src/middleware/README.md
2.55 kB
| π 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 |