README
🏢 Arclane Backend Server
This is the backend server for Arclane, a full-stack apartment management web application. It handles authentication, payment, role-based access control, apartment and user management, announcements, coupon verification, and more using Node.js, Express, Firebase Admin SDK, MongoDB, and Stripe.
🌐 Live API URL
https://arc-lane-server.vercel.app
📁 Project Structure
.
├── server.js # Main entry file
├── .env # Environment variables
├── package.json # Project dependencies
└── README.md # This file
🚀 Features
✅ Firebase Admin SDK for secure JWT authentication ✅ Stripe integration for secure rent payments ✅ Role-based access control (Admin, Member, User) ✅ RESTful API for apartments, agreements, coupons, users, payments, and announcements ✅ Admin can:
- Accept or reject agreement requests
- Remove members
- Change coupon statuses ✅ Members can:
- View their assigned apartment
- Pay monthly rent and view history
✅ Secure endpoints with
verifyToken,verifyEmail,verifyAdmin, andverifyMembermiddlewares ✅ Axios interceptor friendly ✅ All private API routes are JWT-protected ✅ Coupon system with status (active/expired) control ✅ MongoDB for data storage
📦 Dependencies
- express
- cors
- dotenv
- mongodb
- firebase-admin
- stripe
🔐 Environment Variables (.env)
Make sure to create a .env file in the root directory with the following variables:
PORT=3000
MONGO_URI=your_mongodb_connection_uri
STRIPE_SECRET_KEY=your_stripe_secret_key
FB_SERVICE_KEY=base64_encoded_firebase_admin_sdk_json
🔐 The
FB_SERVICE_KEYis the base64 encoded version of your Firebase service account JSON file.
To encode it:
base64 firebase-adminsdk.json
🧪 How to Run Locally
- Clone the repository
git clone https://github.com/SayedSheikh/arclane-server.git
cd arclane-server
- Install dependencies
npm install
- Create
.envfile
# .env file
PORT=3000
MONGO_URI=your_mongodb_uri
STRIPE_SECRET_KEY=your_stripe_secret_key
FB_SERVICE_KEY=your_base64_encoded_firebase_admin_json
- Run the server
node server.js
🔐 API Security Middleware
| Middleware | Description |
|---|---|
verifyToken | Validates JWT token via Firebase Admin |
verifyEmail | Compares param email with token email |
verifyAdmin | Restricts access to admin only routes |
verifyMember | Restricts access to member only routes |
📚 Major API Endpoints
👥 Authentication & Users
| Method | Endpoint | Description |
|---|---|---|
| POST | /users | Create or update user info |
| GET | /users/role/:email | Get user role (user, admin, etc.) |
| GET | /users/:email | Get all users (admin only) |
| GET | /countUsers | Get user count |
🏘 Apartments & Agreements
| Method | Endpoint | Description |
|---|---|---|
| GET | /apartments/:page/:size?search=min&max=... | Filtered apartments list |
| GET | /countApartments | Get total apartment count |
| POST | /agreement/:email | Create new agreement |
| PATCH | /updateAgStatus/:email/:agId?actionType=... | Accept/reject agreement |
| GET | /agreements/:email | Get all agreement requests |
💳 Payments
| Method | Endpoint | Description |
|---|---|---|
| POST | /create-payment-intent | Stripe payment intent |
| POST | /paymentInfo/:email | Save payment info |
| GET | /paymentHistory/:email | View payment history (member only) |
| PATCH | /pendingPayments/:email/:agId | Get unpaid months for agreement |
📢 Announcements
| Method | Endpoint | Description |
|---|---|---|
| GET | /countAnnouncements | Total number of posts |
| GET | /announcements/:email | Paginated list (auth) |
| POST | /announcements/:email | Create announcement (admin) |
🧾 Coupons
| Method | Endpoint | Description |
|---|---|---|
| GET | /coupons | Get all coupons |
| POST | /coupon/:email | Create new coupon (admin only) |
| PATCH | /coupon/status/:email/:id | Update status of a coupon (admin) |
| GET | /couponVerify/:couponCode | Verify coupon and get discount |
🧼 Member Management
| Method | Endpoint | Description |
|---|---|---|
| PATCH | /remove/:email/:memId | Admin removes a member |
| GET | /memberApartment/:email | Member’s assigned unit |
📊 Admin Dashboard Stats
| Method | Endpoint | Description |
|---|---|---|
| GET | /dashboardStats/:email | All statistics for admin |
🧠 Additional Notes
- You must pass a JWT token in
Authorization: Bearer <token>header for all protected routes. - Only Flowbite is used for the frontend.
- Built with scalability, modularity, and security in mind.
- All errors are handled with appropriate HTTP status codes and messages.
Let me know if you want the same structure as a downloadable .md file or want to add Postman docs too.