⚙️ Ekub Hub - Backend
Ekub Hub Backend is the server-side component of the Ekub Hub application, designed to modernize the traditional Ethiopian Ekub system.
It handles:
- 🔐 User authentication via Firebase
- 📂 Management of Ekub groups stored in MongoDB
- 🌍 APIs for searching, creating, and joining Ekub groups
- 📍 Geolocation-based search & filtering with MongoDB's geospatial queries
This backend is built using Node.js, Express.js, MongoDB, and Firebase Admin SDK.
- 🔑 Firebase authentication integration
- 📝 CRUD operations for Ekub groups
- 📍 Geolocation-based search with MongoDB 2D sphere indexing
- 🔒 Secure API endpoints with token-based authentication
- ⚙️ Filtering by contribution amount & distance
- ⚡ Node.js (v18+ recommended)
- 🚏 Express.js for API routing
- 🗄️ MongoDB for database
- 🧩 Mongoose for object modeling
- 🔑 Firebase Admin SDK for authentication
- 🛠️ dotenv for environment variable management
- 🌐 CORS for cross-origin requests
Before running the backend, ensure you have:
- ✅ Node.js installed
- ✅ MongoDB running locally or via MongoDB Atlas
- ✅ Firebase project set up with Authentication enabled
- ✅ Firebase service account key JSON downloaded from Firebase console
- Clone the repository
git clone <repository-url> ekub-hub-backend cd ekub-hub-backend
Install dependencies
bash Copy code npm install Configure environment variables Create a .env file in the root directory:
env Copy code MONGO_URI=mongodb://localhost:27017/ekubhub # Replace with your MongoDB connection string PORT=5000 # Optional: default port Add Firebase service account key Place the JSON file inside config/ as:
arduino
Copy code
config/serviceAccountKey.json
bash Copy code mongod Run the backend server
bash Copy code node server.js The server will start on: 👉 http://localhost:5000 (or the port specified in .env)
Test the APIs
Use Postman / cURL
All endpoints require a Firebase ID token in the header:
makefile Copy code Authorization: Bearer 📡 API Endpoints 🔑 Authentication All requests must include a Firebase ID token
👥 Ekub Groups Create Ekub Group POST /api/ekub/create Body:
json Copy code { "name": "My Ekub", "location": { "lat": 9.03, "lng": 38.74 }, "contributionAmount": 500, "maxMembers": 10 } Search Ekub Groups GET /api/ekub/search?lat=9.03&lng=38.74&maxDistance=5000&amount=500
Join an Ekub Group POST /api/ekub/join/:id
🗄️ Database Schema EkubGroup Model js Copy code { name: String, // required location: { // GeoJSON Point type: "Point", coordinates: [lng, lat] }, contributionAmount: Number, // required members: [String], // user IDs maxMembers: Number, // required createdAt: { type: Date, default: Date.now } } Geospatial 2dsphere indexing is enabled on location for efficient proximity searches.
🔒 Security ✅ All API routes protected with Firebase token verification
✅ Input validation recommended (e.g., joi, express-validator)
✅ Use HTTPS in production for secure data transfer
🧪 Testing Run automated tests with Jest or Mocha (add as needed)
Manual testing with Postman:
Authenticate via Firebase
Send ID token in headers
Call protected endpoints
🚀 Deployment Platforms: Heroku, Render, Vercel, AWS
Set environment variables in the hosting platform
Use MongoDB Atlas for production database
Keep Firebase key file secure (never commit to repo!)
🤝 Contributing Contributions are welcome! 🎉
Fork the repo 🍴
Create a feature branch 🌱
Submit a pull request 🚀
👨💻