This repository contains the backend code for a microservices-based application. The backend is built using Node.js, Express, and MongoDB, and includes features for user authentication, business management, notifications, billing, and social media posts.
- Getting Started
- Configuration
- Project Structure
- API Routes
- Middlewares
- Services
- Repositories
- Utils
- Running the Application
To get started with this project, you need to have Node.js and MongoDB installed on your machine.
- Node.js
- MongoDB
- Redis (optional, for caching)
- RabbitMQ (optional, for message brokering)
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
npm install
-
Set up the environment variables. Create a
.envfile in the root directory and add the following variables:PORT=50001 MONGODB_URI=mongodb://127.0.0.1:27017 REDIS_CLIENT_URI=redis://127.0.0.1:6379 MSG_BROKER=amqp://localhost:5672 DB_NAME=microServices ACCESS_TOKEN_SECRET=8ed7c31f17aae378ff9cb32d1274ed0408f4dc5ff5adee6b2ab109add0b139ca REFRESH_TOKEN_SECRET=71f5e973be54c4412f26e53a0b857937ce0540b765151c059ac522042381a9bf NODE_ENV='development' CLOUDINARY_CLOUD_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET= CLOUDINARY_CLOUDINARY_URL=
To start the application, use the following command:
npm startThe server will start on the port specified in the .env file.
Configuration files and environment variables are used to manage different settings for the application.
.env: Environment variables for the application.src/config: Configuration files for Firebase and other services.
src/
│ expressApp.ts
│ server.ts
│
├───config
│ firebaseSdkConfig.ts
│ servicesAccountKey.json
│
├───middlewares
│ firebaseMiddleware.ts
│ multer.ts
│
├───models
│ │ addressModel.ts
│ │ billModel.ts
│ │ billTemplateModel.ts
│ │ businessModel.ts
│ │ notificationModel.ts
│ │ reviewModel.ts
│ │ tokenManagementModels.ts
│ │ userModel.ts
│ │
│ └───socialMedia
│ commentsModel.ts
│ postModel.ts
│
├───repositories
│ │ authRepository.ts
│ │ billsRepository.ts
│ │ billTempletRepository.ts
│ │ businessRepository.ts
│ │ cloudinary-repository.ts
│ │ notificationRepository.ts
│ │ userRepository.ts
│ │
│ └───socialMedia
│ postsRepository.ts
│
├───routes
│ authRoutes.ts
│ billsRoutes.ts
│ businessRoutes.ts
│ notificationsRoutes.ts
│ postsRoutes.ts
│ userRoutes.ts
│
├───services
│ │ authService.ts
│ │ BillServices.ts
│ │ businessServices.ts
│ │ notificationServices.ts
│ │ userServices.ts
│ │
│ └───socialMedia
│ PostServices.ts
│
└───utils
│ convertDateToInvoiceNumber.ts
│ generate_keys.ts
│ init_mongodb.ts
│ init_redis.ts
│ jwt_helper.ts
│ SendApiResponse.ts
│
├───errors
│ app-errors.ts
│
├───message_broker
│ message_broker.ts
│
└───validators
handlers.ts
validators.ts
POST /auth/firebase-singup: Sign up with FirebasePOST /auth/firebase-login: Log in with FirebasePOST /auth/refresh-tokens: Refresh tokensPOST /auth/logout: Log out
GET /users/me: Get current userGET /users/:userId: Get user by IDPUT /users: Update userDELETE /users: Delete userPOST /users/address: Create addressPUT /users/address: Update addressDELETE /users/address: Delete addressGET /users/bills: Get bill history
POST /businesses: Create new business profileGET /businesses/me: Get my businessesGET /businesses: Get all businessesGET /businesses/:businessId: Get business by IDPUT /businesses: Update businessDELETE /businesses: Delete business
POST /bills: Create billGET /bills/me: Get bills for customerGET /bills/business/:businessId: Get bills for businessGET /bills/:billId: Get bill by IDPUT /bills/:billId: Update billPOST /bills/:customerId/send/:billId: Send bill as notification
GET /notifications: Get notificationsPATCH /notifications/:notificationId/read: Mark as readDELETE /notifications/:notificationId: Delete notification
POST /posts: Create postPATCH /posts/:postId/like: Like postPATCH /posts/:postId/unlike: Unlike postGET /posts: Get all postsGET /posts/me: Get my posts
- Firebase Middleware: Middleware for Firebase authentication and validation.
- Multer Middleware: Middleware for handling file uploads.
Services are used to handle business logic and interact with repositories.
- AuthServices: Handles authentication-related operations.
- UserServices: Handles user-related operations.
- BusinessServices: Handles business-related operations.
- BillServices: Handles bill-related operations.
- NotificationServices: Handles notification-related operations.
- PostsService: Handles social media posts-related operations.
Repositories are used to interact with the database.
- AuthRepository: Handles authentication-related database operations.
- UserRepository: Handles user-related database operations.
- BusinessRepository: Handles business-related database operations.
- BillsRepository: Handles bill-related database operations.
- NotificationRepository: Handles notification-related database operations.
- PostsRepository: Handles social media posts-related database operations.
Utility functions and helpers used across the application.
- convertDateToInvoiceNumber.ts: Utility to convert date to invoice number format.
- generate_keys.ts: Utility to generate keys.
- init_mongodb.ts: MongoDB initialization.
- init_redis.ts: Redis initialization.
- jwt_helper.ts: JWT helper functions.
- SendApiResponse.ts: Utility to send API responses.
This project is licensed under the MIT License. See the LICENSE file for details.
docker build -t rental-app-backend.docker run -p 3000:3000 rental-app-backendThis should be correctly formatted and easy to follow.