apexkv / facebook-clone

This is a clone project of facebook platform in microservies architecture

Repository from Github https://github.comapexkv/facebook-cloneRepository from Github https://github.comapexkv/facebook-clone

Facebook-Clone Project

Table of Contents

  1. Overview
  2. High-Level Architecture
  3. Folder Structure
  4. Key Features
  5. System Architecture
  6. Technologies Used
  7. Advantages of the Architecture
  8. Getting Started
  9. References
  10. License
  11. Finally

Overview

This Facebook Clone project is a fully functional social media platform built with a microservices architecture. It features user authentication, posts, comments, likes, chat functionality, friend connections, and a modern frontend interface. The project emphasizes scalability, data consistency, and performance.


High-Level Architecture

  1. Microservices
  1. Frontend

    • Built with Next.js, the frontend offers a seamless user experience with modern UI/UX principles and server-side rendering.
  2. Databases

    • PostgreSQL: Used for structured data in the Chat, Posts, and Users microservices.
    • Neo4j: Used in the Friends microservice to handle graph-based relationships like friendships and friend suggestions.
  3. Messaging and Caching

    • RabbitMQ: Ensures data consistency across microservices by facilitating event-driven communication.
    • Redis:
      • Used for caching frequently accessed data.
      • Functions as the event store for channels in the Chat microservice to support real-time communication.
  4. Containerization

    • All microservices and the frontend are fully containerized using Docker.
    • A Docker Compose file orchestrates the services, ensuring seamless development and deployment.

Folder Structure

facebook-clone/
│
├── users/              # Users Microservice
├── posts/              # Posts Microservice
├── friends/            # Friends Microservice
├── chat/               # Chat Microservice
├── frontend/           # Frontend Service
├── docker-compose.yml  # Docker Compose configuration
├── README.md           # Main Project Documentation

Key Features

  • Authentication and Authorization:

    • User registration, login, and session management via the Users microservice.
  • Posts Management:

    • Users can create, delete and view posts.
    • Features like commenting and liking posts are supported.
  • Friendship Management:

    • Users can send and accept friend requests.
    • Friend suggestions are generated using graph-based algorithms in Neo4j.
  • Real-time Chat:

    • Secure, scalable real-time messaging using Django Channels and Redis.
  • Modern Frontend:

    • Built with Next.js for optimized performance and modern design.
  • Scalability and Consistency:

    • Event-driven communication ensures data consistency across microservices using RabbitMQ.
    • Redis caching improves response times for high-demand endpoints.
  • Containerization:

    • All components are containerized for consistent deployment across different environments.

System Architecture

High-Level System Architecture

Technologies Used

  • Backend Framework: Django with Django Rest Framework
  • Frontend Framework: Next.js
  • Databases: PostgreSQL, Neo4j
  • Message Broker: RabbitMQ
  • Cache: Redis
  • Containerization: Docker
  • Orchestration: Docker Compose

Advantages of the Architecture

  1. Scalability: Each microservice can be scaled independently to handle growing user demands.
  2. Modularity: Clear separation of concerns between different services simplifies maintenance and development.
  3. Data Consistency: RabbitMQ ensures event-driven synchronization between services.
  4. Performance: Redis caching improves the speed of frequently accessed data.
  5. Modern Development Practices: The use of Docker and Docker Compose enables seamless deployment and development.

Getting Started

1. Clone the repository

git clone https://github.com/apexkv/facebook-clone.git
cd facebook-clone

2. Configure environment variables for each service

  • These environment variables configure the necessary services like the database, message broker (RabbitMQ), and other service dependencies. Please make sure to fill in the appropriate values based on your environment.

Users .env

# ./users/.env

SECRET_KEY=ILKQ1giDu=

POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_ROOT_PASSWORD=
POSTGRES_PORT=

RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_HOST=

CURRENT_QUEUE=users
QUEUE_LIST=friends,posts,chat

Chat .env

# ./chat/.env

# this secret key need to be same scret key in Users service secret key
SECRET_KEY=ILKQ1giDu=

POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_ROOT_PASSWORD=
POSTGRES_PORT=

RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_HOST=

CURRENT_QUEUE=chat
QUEUE_LIST=friends,posts,users

USERS_SERVICE=http://users:8000

Posts .env

# ./posts/.env

SECRET_KEY=ILKQ1giDu=

POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_ROOT_PASSWORD=
POSTGRES_PORT=

RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_HOST=

CURRENT_QUEUE=posts
QUEUE_LIST=friends,chats,users

USERS_SERVICE=http://users:8000

Friends .env

# ./friends/.env

SECRET_KEY=ILKQ1giDu=

NEO4J_AUTH=
NEO4j_HOST=

RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_HOST=

QUEUE_LIST=chat,posts,users
CURRENT_QUEUE=friends

USERS_SERVICE=http://users:8000

3. Start Service Using Docker

docker compose up --build

4. Now you can explorer the project in these endpoints

http://localhost:3000/ # nextjs frontend

http://localhost:888/api/users/ # users microservice

http://localhost:888/api/posts/ # posts microservice

http://localhost:888/api/friends/ # friends microservice

http://localhost:888/api/chat/ # chat microservice

References

For more information on Docker and Docker Compose, visit their official documentation:

License

This project is licensed under the MIT License. See the LICENSE file for details.

Finally

Thank you for exploring this Facebook Clone project. If you have any feedback, feel free to create an issue or contribute to the repository. Happy coding! 😊

About

This is a clone project of facebook platform in microservies architecture

License:MIT License


Languages

Language:Python 47.0%Language:TypeScript 45.1%Language:Shell 6.9%Language:CSS 0.5%Language:Dockerfile 0.4%Language:JavaScript 0.0%