# nguyenchithannh/loopme-apis architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenchithannh/loopme-apis
- Repository: https://github.com/nguyenchithannh/loopme-apis

## Overview

##### Project Type and Purpose
- LoopMe-apis is a social networking backend platform built with a microservices architecture. Each core capability (authentication, chat, comments, friend management, groups, notifications, posts, post votes, realtime features) has its own service.
- The README and file tree clearly indicate that this is a containerized, Kubernetes-deployed, full-stack backend system that serves as the API layer for a social platform.

##### File Structure
- The “app” directory contains separate folders for each microservice (auth-service, chat-service, comment-service, friend-service, group-service, notification-service, post-service, post-vote-service, realtime-service, and gateway-api). Each service has its own configuration files, Dockerfiles, build scripts, and TypeScript source code (organized in directories like src/controllers, src/routes, and src/services).
- There’s also a “common” directory that contains shared modules (such as configuration, utilities, middlewares, models, error handling, and mail functionalities), which hints at a centralized reusable library across services.
- Command scripts in the “cmd” folder support tasks like image pushing, local run, and Kubernetes deployments.

##### README for Additional Insights
- The README confirms the microservices layout by listing individual services with their assigned ports and describes the role of the API Gateway as the single entry point that manages routing, rate limiting, and WebSocket proxy capabilities.
- It also lists the technologies used (TypeScript, Express, Node.js, MongoDB, RabbitMQ, Redis, etc.), which should be depicted where relevant.
- The provided images and deployment results (dashboard, pods, services, ingress, etc.) are evidence that the design is deployed on Kubernetes and uses Docker for containerization.

a. Main Components:
- API Gateway (Gateway Service): Represent this as the front-door or entry point for all external client requests. Include the designated port (8000) and its functions (reverse proxy, rate limiting, WebSocket proxy).
- Auth Service (Port 8001)
- Chat Service (Port 8002)
- Comment Service (Port 8003)
- Friend Service (Port 8004)
- Service (Port 8005)
- Notification Service (Port 8006)
- Post Service (Port 8007)
- Post Vote Service (Port 8008)
- Realtime Service (Port 8009)
- Shared/Common Module: Represent the common library (inside the “common” directory) that supplies configurations, models, error handling, and utilities across services.
- External Dependencies: Indicate the external systems such as MongoDB (NoSQL database for persistent storage), RabbitMQ (for asynchronous communication/message broker), and Redis (for caching and session management).

b. Relationships and Interactions:
- That each service communicates with MongoDB (and possibly uses Mongoose for ODM) for data storage.
- Intra-service dependencies (like how the Post Service might interact with the Comment or Vote Service through shared business logic or asynchronous events).

c. Architectural Patterns and Design Principles:
- Microservices architecture where each service is independently deployed (as seen in the individual Dockerfiles and Kubernetes YAML configurations).
- Separation of concerns (controllers, services, validations) within individual services as an adherence to standard RESTful API practices.
- That the API Gateway is a central pattern for routing requests, rate limiting, and handling WebSocket connections.

d. Relevant Technologies:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client("Client Applications (Web/Mobile)"):::client

    %% API Gateway Layer
    APIGW("API Gateway [Port:8000]\n(Reverse Proxy, Rate Limiting, WebSocket Proxy)"):::gateway

    %% Microservices
    subgraph "Microservices"
        Auth("Auth Service [Port:8001]"):::service
        Chat("Chat Service [Port:8002]"):::service
        Comment("Comment Service [Port:8003]"):::service
        Friend("Friend Service [Port:8004]"):::service
        Group("Group Service [Port:8005]"):::service
        Notification("Notification Service [Port:8006]"):::service
        Post("Post Service [Port:8007]"):::service
        PostVote("Post Vote Service [Port:8008]"):::service
        Realtime("Realtime Service [Port:8009]"):::service
    end

    %% Common Modules
    Common("Shared/Common Modules"):::common

    %% External Dependencies
    subgraph "External Dependencies"
        Mongo("MongoDB\n(NoSQL Database)"):::external
        Rabbit("RabbitMQ\n(Message Broker)"):::external
        Redis("Redis\n(Caching/Session)"):::external
    end

    %% Deployment Infrastructure
    subgraph "Deployment Infrastructure"
        K8s("Kubernetes Cluster"):::k8s
        Docker("Docker Containers"):::docker
        Cmd("Deployment Commands"):::cmd
    end

    %% Connections
    Client -->|"sends requests"| APIGW

    APIGW -->|"routes to"| Auth
    APIGW -->|"routes to"| Chat
    APIGW -->|"routes to"| Comment
    APIGW -->|"routes to"| Friend
    APIGW -->|"routes to"| Group
    APIGW -->|"routes to"| Notification
    APIGW -->|"routes to"| Post
    APIGW -->|"routes to"| PostVote
    APIGW -->|"routes to"| Realtime

    %% Microservices interactions with external dependencies
    Auth -->|"queries"| Mongo
    Chat -->|"queries"| Mongo
    Comment -->|"queries"| Mongo
    Friend -->|"queries"| Mongo
    Group -->|"queries"| Mongo
    Notification -->|"queries"| Mongo
    Post -->|"queries"| Mongo
    PostVote -->|"queries"| Mongo
    Realtime -->|"queries"| Mongo

    Auth -->|"publishes"| Rabbit
    Chat -->|"publishes"| Rabbit
    Comment -->|"publishes"| Rabbit
    Friend -->|"publishes"| Rabbit
    Group -->|"publishes"| Rabbit
    Notification -->|"publishes"| Rabbit
    Post -->|"publishes"| Rabbit
    PostVote -->|"publishes"| Rabbit
    Realtime -->|"publishes"| Rabbit

    Auth -->|"caches"| Redis
    Chat -->|"caches"| Redis
    Comment -->|"caches"| Redis
    Friend -->|"caches"| Redis
    Group -->|"caches"| Redis
    Notification -->|"caches"| Redis
    Post -->|"caches"| Redis
    PostVote -->|"caches"| Redis
    Realtime -->|"caches"| Redis

    %% Microservices using common modules
    Auth ---|"uses"| Common
    Chat ---|"uses"| Common
    Comment ---|"uses"| Common
    Friend ---|"uses"| Common
    Group ---|"uses"| Common
    Notification ---|"uses"| Common
    Post ---|"uses"| Common
    PostVote ---|"uses"| Common
    Realtime ---|"uses"| Common

    %% Containerization and orchestration
    APIGW ---|"containerized"| Docker
    Auth ---|"containerized"| Docker
    Chat ---|"containerized"| Docker
    Comment ---|"containerized"| Docker
    Friend ---|"containerized"| Docker
    Group ---|"containerized"| Docker
    Notification ---|"containerized"| Docker
    Post ---|"containerized"| Docker
    PostVote ---|"containerized"| Docker
    Realtime ---|"containerized"| Docker

    Docker -->|"managed by"| K8s
    Cmd ---|"triggers deployments"| K8s

    %% Click Events
    click APIGW "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/gateway-api"
    click Auth "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/auth-service"
    click Chat "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/chat-service"
    click Comment "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/comment-service"
    click Friend "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/friend-service"
    click Group "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/group-service"
    click Notification "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/notification-service"
    click Post "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/post-service"
    click PostVote "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/post-vote-service"
    click Realtime "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/realtime-service"
    click Common "https://github.com/nguyenchithannh/loopme-apis/tree/main/app/common"
    click K8s "https://github.com/nguyenchithannh/loopme-apis/tree/main/k8s"
    click Cmd "https://github.com/nguyenchithannh/loopme-apis/tree/main/cmd"

    %% Styles
    classDef client fill:#FFEBCD,stroke:#000,stroke-width:2px;
    classDef gateway fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef common fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef k8s fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef docker fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef cmd fill:#AFEEEE,stroke:#000,stroke-width:2px;
```
