A robust microservices-based system built with Node.js, Prisma, and MongoDB, featuring authentication and post management services. This system demonstrates modern microservices architecture with inter-service communication.
-
🔐 Authentication Service
- User registration and login
- JWT-based authentication
- Password encryption with bcrypt
- User profile management
-
📝 Post Service
- Create and retrieve posts
- User association with posts
- Inter-service communication
- Efficient data fetching strategies
-
🛠️ Technical Features
- MongoDB with Prisma ORM
- Microservices Architecture
- JWT Authentication
- RESTful APIs
- Service Discovery
- Cross-service Data Aggregation
- Node.js (v14 or higher)
- MongoDB
- npm or yarn
- Postman (for testing APIs)
- Clone the repository:
git clone https://github.com/mohd-afnan-shahab/Distributed-Microservices-System.git
cd Distributed-Microservices-System
- Install dependencies for both services:
# Auth Service
cd auth_micro
npm install
# Post Service
cd ../post_micro
npm install
- Set up environment variables:
# For auth_micro/.env
DATABASE_URL="your_mongodb_url"
JWT_SECRET="your_jwt_secret"
PORT=3000
# For post_micro/.env
DATABASE_URL="your_mongodb_url"
JWT_SECRET="your_jwt_secret"
PORT=3001
AUTH_MICRO_URL="http://localhost:3000"
- Run Prisma migrations:
# In each service directory
npx prisma generate
npx prisma db push
- Start the services:
# Run each in separate terminals
npm run dev
POST /api/register - Register new user
POST /api/login - User login
GET /api/user - Get current user
GET /api/getUser/:id - Get user by ID
POST /api/getUsers - Get multiple users
GET /api/posts - Get all posts with user details
POST /api/posts - Create new post
graph LR
Client --> AuthService
Client --> PostService
PostService --> AuthService
AuthService --> MongoDB[(MongoDB)]
PostService --> MongoDB[(MongoDB)]
- User registers/logs in through Auth Service
- JWT token is generated and returned
- Token is used for subsequent requests
- Authenticated request to Post Service
- Post created with user association
- User details fetched from Auth Service
The project implements three methods for data aggregation:
- Individual user fetching
- Batch user fetching
- Optimized lookup with caching
- Node.js - Runtime environment
- Express - Web
- Prisma - ORM
- MongoDB - Database
- JWT - Authentication
- bcrypt - Password hashing
- Axios - HTTP client
- Batch processing for user data
- Efficient data caching
- Optimized database queries
- Connection pooling
Built with ❤️ by Mohd Afnan Shahab