This project is a social media application built using a microservices architecture. It leverages RabbitMQ for event-driven communication, MongoDB for data storage, and Redis for caching. The services are containerized using Docker to ensure scalability and easy deployment.
- Node.js (Express)
- MongoDB (Database)
- RabbitMQ (Event-driven messaging)
- Redis (Caching layer)
- Docker (Containerization)
- Mongoose (MongoDB ODM)
- Jest (Testing framework)
- Acts as the entry point for all client requests.
- Routes requests to the appropriate microservices.
- Exposed on port
3000
.
- Handles user authentication and authorization.
- Manages user profiles and sessions.
- Manages posts created by users.
- Publishes events like
post.created
andpost.deleted
to RabbitMQ.
- Handles media uploads and deletions.
- Listens for
post.deleted
events to delete associated media.
- Enables full-text search for posts.
- Utilizes MongoDB text indexes.
- Implements Redis caching for faster search results.
The microservices communicate asynchronously using RabbitMQ. Here are the key events:
Event | Description |
---|---|
post.created |
Triggers search indexing for new posts. |
post.deleted |
Removes associated media and search entries. |
Ensure you have the following installed:
- Docker & Docker Compose
- Node.js (v18 or later)
- Clone the repository:
git clone https://github.com/detayotella/social-app-microservices.git cd social-app-microservices
- Start all services using Docker Compose:
docker-compose up --build
- The services will be available at:
- API Gateway:
http://localhost:3000
- RabbitMQ Management UI:
http://localhost:15672
(username:guest
, password:guest
) - Redis:
redis://localhost:6379
- API Gateway:
- Install dependencies for each service:
cd api-gateway && npm install cd identity-service && npm install cd post-service && npm install cd media-service && npm install cd search-service && npm install
- Start Redis, MongoDB, and RabbitMQ locally.
- Run each service manually:
cd api-gateway && npm start cd identity-service && npm start cd post-service && npm start cd media-service && npm start cd search-service && npm start
GET /
- Health check endpoint.
POST /auth/register
- Register a new user.POST /auth/login
- Authenticate a user.
POST /posts
- Create a new post.DELETE /posts/:id
- Delete a post.
POST /media
- Upload a media file.DELETE /media/:id
- Delete a media file.
GET /search?query=example
- Search for posts.
Each service has its own .env
file. Here are the common variables:
Variable | Description | Example Value |
---|---|---|
PORT |
Port the service runs on | 3000 |
MONGO_URI |
MongoDB connection string | mongodb://localhost:27017 |
REDIS_URL |
Redis connection URL | redis://localhost:6379 |
RABBITMQ_URL |
RabbitMQ connection URL | amqp://localhost:5672 |
The project uses Jest for testing. To run tests:
cd identity-service && npm test
cd post-service && npm test
cd media-service && npm test
cd search-service && npm test
- Fork the repo.
- Create a feature branch (
git checkout -b feature-name
). - Commit changes (
git commit -m "Added new feature"
). - Push to GitHub (
git push origin feature-name
). - Open a Pull Request.
This project is licensed under the MIT License. Feel free to use and modify it.