# shantanu200/ds_social-app architecture

> Architecture diagram of the GitHub repository shantanu200/ds_social-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shantanu200/ds_social-app
- Repository: https://github.com/shantanu200/ds_social-app

## Overview

##### Project Type and Purpose
- The project is a distributed microservices social media application, similar to Twitter.
- The README emphasizes a multi-service architecture where each service (User, Tweet, Timeline, Notification, and User Relation) is an independent Golang microservice.
- The tech stack spans a modern client (React, NodeJs, Tailwind CSS) to Golang services leveraging Postgres, Redis, RabbitMQ, and WebSocket, with orchestration via Docker Compose and Kubernetes.

##### File Structure
- The file tree reveals separate directories for each microservice (e.g., user-service, tweet-service, timeline-service, notification-service, user-relation-service). Each service is organized with its own API entrypoints, controllers, handlers, models, and support modules (database connections, caches, RabbitMQ interactions, and even socket handling in the Notification service).
- Every service contains its Dockerfile, indicating containerization and independent deployment.
- There are shared patterns across services such as the “cmd/api” structure following standard MVC-like organization where controllers handle the API logic, and auxiliary layers are dedicated to caching, database connectivity, or messaging.

##### README for Additional Insights
- The README outlines the different API endpoints and operations for each service, providing clarity on service responsibilities:
- User Service: registration, login, and user detail management.
- Tweet Service: handling tweets, replies, likes/favorites, and media storage through S3.
- Timeline Service: generating user timelines including home feed, following feeds, and timeline management.
- User Relation Service: managing follow and unfollow operations, plus recommendations.
- Notification Service: using WebSocket to trigger real-time notifications upon events like posting a tweet, liking a tweet, or following users.

a. Main Components:
- Client Application: React-driven interface that interacts via HTTP/WebSocket with the backend.
- API Microservices:
- User Service: handles authentication, user CRUD, and JWT token management.
- Tweet Service: manages tweet posting, reply threads, like/dislike actions, and S3 integrations.
- Timeline Service: aggregates and serves timeline data using database queries, cache, and RabbitMQ.
- User Relation Service: controls follow/unfollow mechanics and user recommendations.
- Notification Service: implements real-time communication via WebSocket to deliver notifications.
- Infrastructure Components:
- Database: Postgres (for persisting relational data across services).
- Cache: Redis (for caching and fast data access).
- Message Broker: RabbitMQ (for inter-service communication and event handling).
- Containerization and orchestration (Docker Compose and Kubernetes).

b. Relationships and Interactions:
- The Client initiates REST/API calls to the individual microservices (or through an optional API Gateway if available).
- Each service communicates with its own database instance in Postgres.
- Redis is used in multiple services to cache frequently accessed data (e.g., in the tweet and timeline services).
- RabbitMQ acts as the central messaging backbone, facilitating event-driven communication between services (e.g., notifying the timeline service on new tweets, updating caches, or triggering WebSocket notifications).
- The Notification Service listens for specific events (tweet posted, like, follow) and then pushes updates via WebSocket to active clients.

c. Architectural Patterns and Design Principles:
- Microservices Architecture: Independent services with dedicated responsibilities.
- Event-Driven Communication: Usage of RabbitMQ to decouple services.
- API Layer: Each microservice exposes REST endpoints to serve client requests.
- Caching Strategy: Redis is incorporated to improve response times.
- Containerization: Dockerfiles for each service indicate isolated, containerized deployments.
- Real-Time Data Flow: Notification service via WebSocket ensures immediate client updates.

d. Technologies and Libraries:
- Server-side: Golang, RabbitMQ (messaging), Redis (caching), Postgres (database).
- Client-side: React, Axios, and modern React libraries (React Query, React Hook Form).
- Deployment: Docker Compose (locally), Kubernetes (production).
- S3 Storage: Used by the Tweet Service for handling media.

##### Final Touch
- The goal is to capture every crucial architectural element – every service, its internal modules, and its interactions – to give a comprehensive view of the overall architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Interface
    subgraph "Client Interface"
        C["Client Application (React)"]:::client
    end

    %% Microservices Layer
    subgraph "Microservices"
        US["User Service"]:::service
        TS["Tweet Service"]:::service
        TLS["Timeline Service"]:::service
        NS["Notification Service"]:::service
        URS["User Relation Service"]:::service
    end

    %% Infrastructure & Orchestration
    subgraph "Infrastructure & Orchestration"
        DB["Postgres Database"]:::infra
        RD["Redis Cache"]:::infra
        MQ["RabbitMQ Message Broker"]:::infra
        S3["S3 Storage (Media)"]:::infra
        DOCKER["Docker Compose & Kubernetes"]:::infra
    end

    %% Client to Microservices interactions
    C -->|"RESTAPI"| US
    C -->|"RESTAPI"| TS
    C -->|"RESTAPI"| TLS
    C -->|"RESTAPI"| URS
    NS -- "WebSocketNotification" --> C

    %% Microservices to Infrastructure interactions
    US -->|"Database"| DB
    US -->|"RabbitMQ"| MQ

    TS -->|"Database"| DB
    TS -->|"Cache"| RD
    TS -->|"RabbitMQ"| MQ
    TS -->|"S3"| S3

    TLS -->|"Database"| DB
    TLS -->|"Cache"| RD
    TLS -->|"RabbitMQ"| MQ

    URS -->|"Database"| DB
    URS -->|"Cache"| RD
    URS -->|"RabbitMQ"| MQ

    NS -->|"Database"| DB
    NS -->|"Cache"| RD
    NS -->|"RabbitMQ"| MQ

    %% Event-Driven Communications via RabbitMQ
    TS -->|"TweetEvent"| MQ
    MQ -->|"UpdateTimeline"| TLS
    MQ -->|"NotifyEvent"| NS

    %% Orchestration arrows from Docker Compose & Kubernetes
    DOCKER ---|"Deploys"| US
    DOCKER ---|"Deploys"| TS
    DOCKER ---|"Deploys"| TLS
    DOCKER ---|"Deploys"| NS
    DOCKER ---|"Deploys"| URS

    %% Click Events
    click C "https://github.com/shantanu200/ds_social-app/tree/main/project"
    click US "https://github.com/shantanu200/ds_social-app/tree/main/user-service"
    click TS "https://github.com/shantanu200/ds_social-app/tree/main/tweet-service"
    click TLS "https://github.com/shantanu200/ds_social-app/tree/main/timeline-service"
    click NS "https://github.com/shantanu200/ds_social-app/tree/main/notification-service"
    click URS "https://github.com/shantanu200/ds_social-app/tree/main/user-relation-service"
    click DOCKER "https://github.com/shantanu200/ds_social-app/blob/main/project/docker-compose.yml"

    %% Styles
    classDef client fill:#ffeb3b,stroke:#f57f17,stroke-width:2px;
    classDef service fill:#90caf9,stroke:#0d47a1,stroke-width:2px;
    classDef infra fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
