# arjunhg/servicemeshx architecture

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

- Interactive diagram: https://gitdiagram.com/arjunhg/servicemeshx
- Repository: https://github.com/arjunhg/servicemeshx

## Overview

##### Project type and purpose
- This is a full-blown Node.js microservices application.
- It implements a microservices architecture with an API Gateway at the front, four independent services (Identity, Post, Media, Search), and shared infrastructure (MongoDB, Redis, RabbitMQ).
- Purpose: handle authentication, content creation, media management, and full-text search in a scalable, event-driven manner.

##### File structure
- Top-level:
- api-gateway/
- identity-service/
- post-service/
- media-service/
- search-service/
- docker-compose.yml
- Each service:
- Dockerfile + Readme + package.json
- src/
– controllers, routes, middleware, models (where applicable), utils, server.js
– Event handlers in media and search for RabbitMQ integration
- Shared infra inferred by docker-compose.yml: MongoDB, Redis, RabbitMQ.

##### README for additional insights
- Tech stack: Node.js, Express, MongoDB, Redis, RabbitMQ, Docker, Winston, Cloudinary.
- Architecture patterns: API Gateway, event-driven communication via RabbitMQ, caching via Redis, JWT auth via Identity service.

##### Detail without overthinking
- Every microservice component, its data store, and its event/HTTP interactions
- Middleware roles (auth, error-handling) in the gateway and services

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients and Gateway
    Client["Client"]:::external
    Client -->|"HTTP Requests"| APIGateway

    APIGateway["API Gateway<br/>(3000)"]:::service
    click APIGateway "https://github.com/arjunhg/servicemeshx/blob/master/api-gateway/src/server.js"

    %% Services
    subgraph Services
        Identity["Identity Service<br/>(3001)"]:::service
        Post["Post Service<br/>(3002)"]:::service
        Media["Media Service<br/>(3003)"]:::service
        Search["Search Service<br/>(3004)"]:::service
    end

    click Identity "https://github.com/arjunhg/servicemeshx/blob/master/identity-service/src/server.js"
    click Post "https://github.com/arjunhg/servicemeshx/blob/master/post-service/src/server.js"
    click Media "https://github.com/arjunhg/servicemeshx/blob/master/media-service/src/server.js"
    click Search "https://github.com/arjunhg/servicemeshx/blob/master/search-service/src/server.js"

    %% HTTP Routing
    APIGateway -->|"HTTP /auth, JWT"| Identity
    APIGateway -->|"HTTP /posts"| Post
    APIGateway -->|"HTTP /media"| Media
    APIGateway -->|"HTTP /search"| Search

    %% Datastores
    subgraph Databases & Cache
        MongoID["MongoDB (Identity)"]:::db
        MongoPost["MongoDB (Post)"]:::db
        MongoMedia["MongoDB (Media)"]:::db
        MongoSearch["MongoDB (Search)"]:::db
        Redis["Redis Cache"]:::cache
    end

    Identity -->|"Reads/Writes"| MongoID
    Post -->|"Reads/Writes"| MongoPost
    Post -->|"Cache Read/Invalidate"| Redis
    Media -->|"Reads/Writes"| MongoMedia
    Search -->|"Reads/Writes"| MongoSearch

    click Redis "https://github.com/arjunhg/servicemeshx/blob/master/post-service/src/utils/invalidateCache.js"

    %% Message Broker
    RabbitMQ["RabbitMQ Broker"]:::broker
    subgraph MessageQueue
        RabbitMQ
    end

    Post -->|"post.created, post.deleted"| RabbitMQ
    Media -->|"media.uploaded"| RabbitMQ
    Search -->|"Consumes post.created"| RabbitMQ
    Media -->|"Consumes post.created"| RabbitMQ

    click RabbitMQ "https://github.com/arjunhg/servicemeshx/blob/master/docker-compose.yml"

    %% External Services
    Cloudinary["Cloudinary"]:::external
    Media -->|"Uploads to"| Cloudinary
    click Cloudinary "https://github.com/arjunhg/servicemeshx/blob/master/media-service/src/utils/cloudinary.js"

    %% Styles
    classDef service fill:#D6E9FE,stroke:#4A90E2,color:#000
    classDef db fill:#FEF3D6,stroke:#E2A700,color:#000
    classDef cache fill:#F0F5D8,stroke:#8DAE32,color:#000
    classDef broker fill:#FDE2E2,stroke:#D94A4A,color:#000
    classDef external fill:#E8F6F3,stroke:#17A398,color:#000
```
