This repository contains the source code for a user management microservice. The microservice provides endpoints for user authentication and management using Firebase, MongoDB, Redis, and RabbitMQ for message brokering.
You can find postman file in assets folder
- Folder Structure
- Environment Variables
- Installation
- Running the Application
- Available Scripts
- API Endpoints
src/
│ expressApp.ts
│ server.ts
│
├───config
│ firebaseSdkConfig.ts
│ servicesAccountKey.json
│
├───interfaces
├───middlewares
│ firebaseMiddleware.ts
│ multer.js
│
├───models
│ addressModel.ts
│ userModel.ts
│
├───repositories
│ authRepository.ts
│ cloudinary-repository.ts
│ userRepository.ts
│
├───routes
│ authRoutes.ts
│
├───services
│ authService.ts
│
├───types
└───utils
│ 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
To run this project, you will need to add the following environment variables to your .env
file:
PORT=50000
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'
-
Clone the repository:
git clone https://github.com/your-username/user-microservice.git cd user-microservice
-
Install dependencies:
npm install
-
Start the application in development mode:
npm run dev
-
To build the application:
npm run build
-
To run the built application:
npm run run
dev
: Starts the server withnodemon
for development.build
: Compiles TypeScript files into JavaScript.run
: Runs the compiled JavaScript files.
-
POST
/api/firebase-singup
- Middleware:
bearerTokenValidator
,firebaseMiddleware
,checkIfUserAlearyExists
- Service:
authServices.firebaseSignup
- Middleware:
-
POST
/api/firebase-login
- Middleware:
bearerTokenValidator
,firebaseMiddleware
- Service:
authServices.firebaseLogin
- Middleware:
-
POST
/api/refresh-tokens
- Middleware:
refreshTokenValidator
,verifyRefreshToken
- Service:
authServices.refreshTokens
- Middleware:
-
POST
/api/logout
- Middleware:
bearerTokenValidator
,verifyAccessToken
- Service:
authServices.logout
- Middleware:
-
GET
/api/profile
- Middleware:
bearerTokenValidator
,verifyAccessToken
- Returns the user's profile payload
- Middleware:
The entry point for the server, it initializes the Express application, connects to MongoDB and the message broker, and sets up the middleware for error handling.
Contributions are welcome! Please create a pull request or submit an issue if you find any bugs or have suggestions for improvements.
This project is licensed under the ISC License. See the LICENSE
file for more details.