Skip to content

detayotella/social-app-microservices

Repository files navigation

Social App Microservices

Overview

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.


Tech Stack

  • Node.js (Express)
  • MongoDB (Database)
  • RabbitMQ (Event-driven messaging)
  • Redis (Caching layer)
  • Docker (Containerization)
  • Mongoose (MongoDB ODM)
  • Jest (Testing framework)

Microservices

1. API Gateway

  • Acts as the entry point for all client requests.
  • Routes requests to the appropriate microservices.
  • Exposed on port 3000.

2. Identity Service

  • Handles user authentication and authorization.
  • Manages user profiles and sessions.

3. Post Service

  • Manages posts created by users.
  • Publishes events like post.created and post.deleted to RabbitMQ.

4. Media Service

  • Handles media uploads and deletions.
  • Listens for post.deleted events to delete associated media.

5. Search Service

  • Enables full-text search for posts.
  • Utilizes MongoDB text indexes.
  • Implements Redis caching for faster search results.

Event-Driven Architecture

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.

Setup & Installation

Prerequisites

Ensure you have the following installed:

  • Docker & Docker Compose
  • Node.js (v18 or later)

Running the Project (Docker)

  1. Clone the repository:
    git clone https://github.com/detayotella/social-app-microservices.git
    cd social-app-microservices
  2. Start all services using Docker Compose:
    docker-compose up --build
  3. 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

Running Without Docker (Manual Setup)

  1. 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
  2. Start Redis, MongoDB, and RabbitMQ locally.
  3. 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

API Endpoints

API Gateway

  • GET / - Health check endpoint.

Identity Service

  • POST /auth/register - Register a new user.
  • POST /auth/login - Authenticate a user.

Post Service

  • POST /posts - Create a new post.
  • DELETE /posts/:id - Delete a post.

Media Service

  • POST /media - Upload a media file.
  • DELETE /media/:id - Delete a media file.

Search Service

  • GET /search?query=example - Search for posts.

Environment Variables

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

Testing

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

Contributing

  1. Fork the repo.
  2. Create a feature branch (git checkout -b feature-name).
  3. Commit changes (git commit -m "Added new feature").
  4. Push to GitHub (git push origin feature-name).
  5. Open a Pull Request.

License

This project is licensed under the MIT License. Feel free to use and modify it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published