# amrkhaledccd/my-moments architecture

> Architecture diagram of the GitHub repository amrkhaledccd/my-moments, 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/amrkhaledccd/my-moments
- Repository: https://github.com/amrkhaledccd/my-moments

## Overview

##### And Map the Main Components
- API Gateway (insta-api-gateway):
– Acts as the entry point for client requests.
– Manages routing, JWT security (using JwtConfig and related filters), and possibly load balancing.
- Service Discovery (insta-discovery):
– Registers and keeps track of all microservices.
– Enables dynamic discovery and fault tolerance for services.
- Microservices:
– Auth Service (auth-service): Responsible for user authentication, registration, and JWT generation.
– Feed Service (insta-feed-service): Handles user news feeds and related operations (e.g., retrieval of posts), backed by Cassandra (as seen in the CassandraConfig).
– Graph Service (insta-graph-service): Manages the social graph (followers/following relationships) and likely interacts with Neo4j.
– Media Service (insta-media-service): Handles media operations like image uploads, file storage, and metadata maintenance (possibly using MongoDB).
– Post Service (insta-post-service): Manages post creation, retrieval, and associated messaging/events.
- Client Application (instagram-clone-client):
– A ReactJS-based frontend that consumes the REST APIs exposed by the backend services.
- Messaging Infrastructure:
– Kafka messaging components appear in several services (provided by “messaging” packages in auth, feed, graph, and post services) for asynchronous event-driven communication.
- Data Stores:

##### Relationships and Interactions
- From the API Gateway, illustrate the routing of requests to the appropriate microservices.
- Registration and lookup interaction between microservices and the Discovery Service.
- How the Auth Service provides JWT tokens that are used by other services (e.g., via common JwtConfig and authentication filters).
- Messaging flows—for example, events sent from the Auth Service (or Post Service) to Kafka, which are consumed by other services (e.g., Graph Service for updating follow relationships).

##### Architectural Patterns & Design Principles
- Microservices Architecture: Emphasize that the system is divided into multiple independent services communicating over well-defined APIs.
- API Gateway Pattern: Demonstrates how a single entry point simplifies client communications.
- Service Discovery Pattern: Shows dynamic lookup of service instances.
- Event-Driven Design: Indicate the use of messaging (Kafka) for inter-service notifications and eventual consistency.
- Security: Indicate the use of JWT-based authentication/authorization as implemented in multiple services.

##### Relevant Technologies and Frameworks
- Spring Boot and Spring Cloud for service implementation.
- Maven for build and dependency management.
- JWT (JSON Web Tokens) for security.
- Kafka for messaging.
- ReactJS along with Ant Design for the frontend.
- Databases: MongoDB, Cassandra, and Neo4j (as per the tech stack described).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        Client["Client Application"]:::frontend
    end

    subgraph "Backend"
        A["API Gateway"]:::infra
        D["Service Discovery"]:::infra
        Auth["Auth Service"]:::service
        Feed["Feed Service"]:::service
        Graph["Graph Service"]:::service
        Media["Media Service"]:::service
        Post["Post Service"]:::service
        Kafka["Kafka Messaging"]:::infra
        Cass["Cassandra"]:::infra
        Mongo["MongoDB"]:::infra
        Neo4j["Neo4j"]:::infra
    end

    %% Client to API Gateway
    Client -->|"HTTP/REST"| A

    %% API Gateway routing to microservices
    A -->|"Route"| Auth
    A -->|"Route"| Feed
    A -->|"Route"| Graph
    A -->|"Route"| Media
    A -->|"Route"| Post

    %% API Gateway registration with Discovery Service
    A -->|"Register/Lookup"| D

    %% Microservices registration with Discovery Service
    Auth -->|"Register"| D
    Feed -->|"Register"| D
    Graph -->|"Register"| D
    Media -->|"Register"| D
    Post -->|"Register"| D

    %% Security interactions (JWT)
    A -.->|"JWT-Validation"| Auth

    %% Event-Driven Messaging flows
    Auth -->|"Publish-Event"| Kafka
    Post -->|"Publish-Event"| Kafka
    Kafka -->|"Consume-Event"| Graph

    %% Data store integrations
    Feed -->|"Stores Data"| Cass
    Media -->|"Stores Media"| Mongo
    Graph -->|"Stores Graph Data"| Neo4j

    %% Click Events for Components
    click A "https://github.com/amrkhaledccd/my-moments/blob/master/insta-api-gateway/src/main/java/com/clone/instagram/instaapigateway/InstaApiGatewayApplication.java"
    click D "https://github.com/amrkhaledccd/my-moments/blob/master/insta-discovery/src/main/java/com/clone/instagram/instadiscovery/InstaDiscoveryApplication.java"
    click Auth "https://github.com/amrkhaledccd/my-moments/blob/master/auth-service/src/main/java/com/clone/instagram/authservice/AuthServiceApplication.java"
    click Feed "https://github.com/amrkhaledccd/my-moments/blob/master/insta-feed-service/src/main/java/com/clone/instagram/instafeedservice/InstaFeedServiceApplication.java"
    click Graph "https://github.com/amrkhaledccd/my-moments/blob/master/insta-graph-service/src/main/java/com/clone/instagram/instagraphservice/InstaGraphServiceApplication.java"
    click Media "https://github.com/amrkhaledccd/my-moments/blob/master/insta-media-service/src/main/java/com/clone/instagram/instamediaservice/InstaMediaServiceApplication.java"
    click Post "https://github.com/amrkhaledccd/my-moments/blob/master/insta-post-service/src/main/java/com/clone/instagram/instapostservice/InstaPostServiceApplication.java"
    click Client "https://github.com/amrkhaledccd/my-moments/blob/master/instagram-clone-client/src/app/App.js"

    %% Style definitions
    classDef frontend fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef infra fill:#ccf2ff,stroke:#333,stroke-width:2px;
    classDef service fill:#d5f5e3,stroke:#333,stroke-width:2px;
```
