Skip to content

Rahmasamy/Musliem-Community-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŒ™ Muslim Community Server

A comprehensive backend solution for building connected Muslim communities with real-time messaging, event management, and service sharing.

Node.js Express MongoDB Socket.io License

πŸ“‹ Table of Contents


✨ Features

Core Features

  • πŸ‘€ User Authentication - Secure JWT-based authentication with refresh tokens
  • πŸ’¬ Real-time Messaging - Group chats and private messaging with Socket.io
  • πŸ“… Event Management - Create, manage, and join community events
  • πŸ‘₯ Group Management - Build and manage community groups
  • πŸ›οΈ Marketplace - Share products and services within the community
  • πŸ’³ Payment Integration - PayPal integration for transactions
  • πŸ“Š Dashboard Analytics - Community insights and statistics
  • πŸ“Έ Media Management - Cloudinary integration for image/video storage
  • πŸ“§ Email Services - Automated email notifications and communications
  • πŸ” Security - Password reset, email verification, role-based access control

Advanced Features

  • πŸ”„ Automatic Cleanup - Cron jobs for ad removal and data maintenance
  • πŸ“± RESTful API - Fully documented REST endpoints
  • πŸ‘€ Profile Management - User profiles with skills and business information
  • πŸ” Search Functionality - Search across products, services, and users
  • ⭐ Contact System - User contact and inquiry management

πŸ›  Tech Stack

Backend

  • Runtime: Node.js v22
  • Framework: Express.js 5.1
  • Database: MongoDB with Mongoose ODM
  • Real-time: Socket.io 4.8
  • Authentication: JWT (JSON Web Tokens)
  • File Storage: Cloudinary
  • Payment: PayPal SDK

Utilities & Middleware

  • Validation: Express Validator
  • File Upload: Multer + Multer Storage Cloudinary
  • Task Scheduling: Node-cron
  • Email: Nodemailer & Resend
  • Encryption: Bcryptjs, Crypto
  • API Documentation: RESTful endpoints
  • Development: Nodemon

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v22 or higher)
  • npm or yarn
  • MongoDB Atlas account
  • Cloudinary account (for media uploads)
  • PayPal Developer account (for payments)
  • Gmail Account (for email service)

πŸ“¦ Installation

Step 1: Clone the Repository

git clone https://github.com/Rahmasamy/Musliem-Community-Server.git
cd Musliem-Community-Server

Step 2: Install Dependencies

npm install

πŸ”§ Environment Setup

Create a .env file in the root directory and add the following variables:

# Server Configuration
PORT=5000
NODE_ENV=development

# Database
MONGO_URI=mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0

# JWT Secrets
JWT_SECRET=your_jwt_secret_here
JWT_REFRESH_SECRET=your_refresh_secret_here
JWT_EXPIRES_IN=1h

# Client URLs
CLIENT_URL=http://localhost:5173
CLIENT_URL_PROD=https://yourdomain.com

# Email Configuration
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password
EMAIL_PORT_PROD=465

# Email Service (Resend)
RESEND_API_KEY=your_resend_api_key

# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

# PayPal Configuration (Optional)
# PAYMENT_BASE_URL=https://api-m.sandbox.paypal.com

Important Notes:

  • ⚠️ Never commit .env file to version control
  • For Gmail: Use App Passwords instead of your regular password
  • Ensure your MongoDB Atlas IP Whitelist includes your current IP address or use 0.0.0.0/0 for development

πŸš€ Getting Started

Development Mode

Start the development server with hot reload:

npm run dev

The server will start on http://localhost:5000

Production Mode

npm start

πŸ“š API Documentation

Authentication Routes

POST   /api/auth/register          - Register new user
POST   /api/auth/login             - Login user
POST   /api/auth/refresh-token     - Refresh access token
POST   /api/auth/forgot-password   - Request password reset
POST   /api/auth/verify-reset-code - Verify reset code
POST   /api/auth/reset-password    - Reset password

Service Routes

GET    /api/services               - Get all services
POST   /api/services               - Create service
GET    /api/services/:id           - Get service details
PUT    /api/services/:id           - Update service
DELETE /api/services/:id           - Delete service

Event Routes

GET    /api/events                 - Get all events
POST   /api/events                 - Create event
GET    /api/events/:id             - Get event details
PUT    /api/events/:id             - Update event
DELETE /api/events/:id             - Delete event
POST   /api/events/:id/join        - Join event

Group Routes

GET    /api/groups                 - Get all groups
POST   /api/groups                 - Create group
GET    /api/groups/:id             - Get group details
PUT    /api/groups/:id             - Update group
DELETE /api/groups/:id             - Delete group
POST   /api/groups/:id/join        - Join group

Messaging Routes

GET    /api/messages               - Get messages
POST   /api/messages               - Send message
DELETE /api/messages/:id           - Delete message

Product Routes

GET    /api/products               - Get all products
POST   /api/products               - Create product
GET    /api/products/:id           - Get product details
PUT    /api/products/:id           - Update product
DELETE /api/products/:id           - Delete product

Payment Routes

POST   /api/payments/create        - Create payment
GET    /api/payments/:id           - Get payment details

Search Routes

GET    /api/search?q=query         - Search products/services/users

Dashboard Routes

GET    /api/dashboard/stats        - Get dashboard statistics
GET    /api/dashboard/analytics    - Get analytics data

πŸ“ Project Structure

src/
β”œβ”€β”€ config/                    # Configuration files
β”‚   β”œβ”€β”€ db.js                 # MongoDB connection
β”‚   β”œβ”€β”€ basicSetupCloudinary.js
β”‚   β”œβ”€β”€ eventCloudinary.js
β”‚   └── ...
β”‚
β”œβ”€β”€ controllers/              # Business logic
β”‚   β”œβ”€β”€ authController/
β”‚   β”œβ”€β”€ serviceController/
β”‚   β”œβ”€β”€ eventController/
β”‚   β”œβ”€β”€ groupController/
β”‚   β”œβ”€β”€ messageController/
β”‚   β”œβ”€β”€ privateChatController/
β”‚   β”œβ”€β”€ productController/
β”‚   └── ...
β”‚
β”œβ”€β”€ models/                   # Database schemas
β”‚   β”œβ”€β”€ User/
β”‚   β”œβ”€β”€ Service/
β”‚   β”œβ”€β”€ Event/
β”‚   β”œβ”€β”€ Group/
β”‚   β”œβ”€β”€ Product/
β”‚   β”œβ”€β”€ Message/
β”‚   └── ...
β”‚
β”œβ”€β”€ routes/                   # API endpoints
β”‚   β”œβ”€β”€ authRoutes/
β”‚   β”œβ”€β”€ serviceRoutes/
β”‚   β”œβ”€β”€ eventRoutes/
β”‚   β”œβ”€β”€ groupRoutes/
β”‚   └── ...
β”‚
β”œβ”€β”€ middlewares/              # Custom middlewares
β”‚   β”œβ”€β”€ auth/
β”‚   β”œβ”€β”€ errorHandleMiddleware/
β”‚   └── upload/
β”‚
β”œβ”€β”€ services/                 # Utility services
β”‚   β”œβ”€β”€ Email/
β”‚   β”œβ”€β”€ payment/
β”‚   β”œβ”€β”€ cron-job/
β”‚   └── dashboard-anayltics/
β”‚
β”œβ”€β”€ utils/                    # Helper utilities
β”‚   └── asyncHandler.js
β”‚
└── index.js                  # Application entry point

πŸ”„ Real-time Features

The application uses Socket.io for real-time communication:

Events Handled

  • User Connection - connection, disconnect
  • Messaging - sendMessage, receiveMessage, messageDelete
  • Notifications - Real-time updates for events, groups, and messages
  • Status Updates - User online/offline status

Usage Example

// Client-side (Frontend)
const socket = io('http://localhost:5000');

socket.on('connect', () => {
  console.log('Connected to server');
});

socket.emit('sendMessage', { message: 'Hello!' });

socket.on('receiveMessage', (data) => {
  console.log('New message:', data);
});

πŸ—„οΈ Database Models

Main Collections

  • Users - User profiles, authentication data, business info
  • Services - Community services listing
  • Events - Community events and activities
  • Groups - Community groups and forums
  • Products - Product listings
  • Messages - Group messages
  • PrivateMessages - Direct messages between users
  • PrivateChats - Chat sessions
  • Payments - Payment transactions
  • ContactUs - Contact inquiries

πŸ” Security Features

  • βœ… JWT-based authentication
  • βœ… Password hashing with bcryptjs
  • βœ… Refresh token rotation
  • βœ… Password reset with temporary tokens
  • βœ… Role-based access control (RBAC)
  • βœ… Email verification
  • βœ… CORS protection
  • βœ… Input validation with Express Validator

πŸ“§ Email Service Configuration

Gmail Setup

  1. Enable 2-factor authentication on Gmail
  2. Generate an App Password
  3. Use the App Password in EMAIL_PASS environment variable

Alternative: Resend Service

Configure RESEND_API_KEY for alternative email delivery


🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the ISC License - see the LICENSE file for details.


πŸ’¬ Support

For support, email: rahmasamy949@gmail.com or open an issue on GitHub.


πŸ™ Acknowledgments

  • MongoDB for database hosting
  • Cloudinary for media management
  • Socket.io for real-time features
  • PayPal for payment processing
  • All contributors and the community

Made with ❀️ for the Muslim Community

About

A comprehensive backend solution for building connected Muslim communities with real-time messaging, event management, and service sharing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors