# sumit-22/social-graph architecture

> Architecture diagram of the GitHub repository sumit-22/social-graph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sumit-22/social-graph
- Repository: https://github.com/sumit-22/social-graph

## Overview

1. **Repository shape**
   - This is a polyglot monorepo with a small **Next.js frontend** at the root (`app/`, `public/`, `lib/`) and a larger **Java/Spring Boot backend** under `backend/socialgraph/`.
   - The backend is split into independently deployable microservices, each with its own `pom.xml`, `Dockerfile`, config, and tests.

2. **Frontend boundary**
   - The root `app/` directory contains the UI shell (`layout.tsx`, `page.tsx`) and a dedicated `app/seed/page.tsx`, which likely serves as a demo or data-seeding entrypoint.
   - The frontend appears to be thin: it presents the app and probably talks to the backend services over HTTP; no heavy client-side domain logic is visible in the tree.

3. **User service**
   - `backend/socialgraph/user-service` owns **authentication, user profiles, and follow relationships**.
   - It persists the social graph in **Neo4j** (`Neo4jConfig`, `FollowNode`, `FollowRepository`) and uses **JWT** for auth (`JwtTokenProvider`, `JwtAuthenticationFilter`, `SecurityConfig`).
   - It also has a **rate limiting filter** and a logging aspect, which are architectural concerns around abuse protection and observability.

4. **Feed ingestor**
   - `backend/socialgraph/feed-ingestor` is the **write path for posts**.
   - It stores posts in a relational database through `PostRepository`/`Post` and publishes a `PostEvent` to **Kafka** via `KafkaProducerConfig`.
   - This service is also JWT-protected, so authenticated users create posts through it rather than directly touching storage or the stream.

5. **Feed ranker**
   - `backend/socialgraph/feed-ranker` is the **asynchronous processing layer**.
   - `FeedRankerConsumer` consumes Kafka post events, resolves follower relationships from **Neo4j**, computes ranking, and writes results into **Redis** as the precomputed read model.
   - `ResilienceConfig` suggests this service is designed for retry/backoff/fault tolerance around downstream dependencies.

6. **Feed API**
   - `backend/socialgraph/feed-api` is the **read path** for personalized feeds.
   - `FeedController` serves feed requests by reading ranked identifiers from **Redis** and enriching them from the post store.
   - This service is separately secured with JWT and includes OpenAPI config, indicating it is the primary client-facing API for feed retrieval.

7. **Core data flow**
   - The main runtime flow is: user authenticates and establishes follows in the user service; a post is created in the ingestor; the ingestor writes the post and emits a Kafka event; the ranker consumes the event, looks up followers, and updates Redis; the feed API then serves a fast ranked feed from Redis-backed state.
   - This is a classic **event-driven split between write amplification and read optimization**.

8. **State and storage boundaries**
   - **Neo4j** is the graph source of truth for social relationships.
   - **PostgreSQL** holds post/user-oriented durable records for transactional access.
   - **Redis** acts as a low-latency serving layer for ranked feeds.
   - **Kafka** is the decoupling mechanism that turns post creation into asynchronous downstream ranking.

9. **Shared security pattern**
   - Each service has its own JWT plumbing rather than a single shared auth gateway.
   - The user service includes the most additional protection, notably **rate limiting**, while the other services focus on verifying authenticated requests before allowing reads/writes.

10. **Operational packaging**
   - The repo is set up for containerized deployment: each backend module has a `Dockerfile`, and there are `docker-compose.yml` and `docker-compose.test.yml` files at the backend root.
   - Helper scripts like `startup.sh` and `health-check.sh` indicate the system is intended to be brought up and validated as a coordinated stack.

11. **Testing and quality**
   - Each service has its own tests in `src/test`, including controller and security tests.
   - `backend/socialgraph/load-tests` contains Scala-based load testing, which aligns with the project’s low-latency feed goal.
   - GitHub Actions workflows cover build/test and code quality, showing CI is part of the architecture, not an afterthought.

12. **Observability and docs**
   - The backend includes `monitoring/prometheus.yml`, so metrics scraping is explicitly supported.
   - OpenAPI configuration exists in at least the user and feed API services, which helps define and expose service contracts.
   - Log artifacts under `logs/` and the logging aspect in the user service suggest production-style operational visibility.

13. **Seed/demo data**
   - `public/data/*.sample.json`, `scripts/generate-seed.ts`, and `lib/seed/generator.ts` indicate a local/demo data generation path.
   - The `app/seed` page likely provides a UI entry for seeding or showcasing sample content, supporting repeatable demos and testing.

14. **How to diagram it**
   - Draw four service boxes: user service, feed ingestor, feed ranker, feed API.
   - Connect user service to Neo4j; feed ingestor to PostgreSQL and Kafka; feed ranker to Kafka, Neo4j, and Redis; feed API to Redis and PostgreSQL.
   - Place the Next.js frontend above them as the client-facing entrypoint, and show Docker/Compose, Prometheus, CI, and load tests as supporting platform layers around the services.

Main entry points: [`backend/socialgraph/feed-api`](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-api) (Feed API), [`backend/socialgraph/docker-compose.yml`](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/docker-compose.yml) (Docker stack), [`backend/socialgraph/user-service`](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service) (User service), [`backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/service/FeedRankerConsumer.java`](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/service/FeedRankerConsumer.java) (Ranker consumer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_nextjs["Next.js app<br/>UI shell<br/>[page.tsx]"]
  node_seed_page["Seed page<br/>demo entry<br/>[page.tsx]"]
end

subgraph group_services["Backend services"]
  node_user_service["User service<br/>Spring service"]
  node_user_auth["Auth layer<br/>JWT security"]
  node_user_graph[("Social graph<br/>Neo4j persistence")]
  node_feed_ingestor["Feed ingestor<br/>write service"]
  node_ingestor_store[("Post store<br/>JPA repository")]
  node_ingestor_kafka["Event producer<br/>Kafka publish"]
  node_feed_ranker["Feed ranker<br/>async worker"]
  node_ranker_consumer["Ranker consumer<br/>Kafka consumer"]
  node_ranker_resilience["Resilience<br/>fault tolerance"]
  node_feed_api["Feed API<br/>read service"]
  node_feed_controller["Feed controller<br/>REST API"]
  node_feed_security["Feed security<br/>JWT security"]
end

subgraph group_platform["Platform"]
  node_neo4j[("Neo4j<br/>graph store")]
  node_postgres[("PostgreSQL<br/>relational store")]
  node_kafka["Kafka<br/>event bus"]
  node_redis[("Redis<br/>serving cache")]
  node_compose["Docker stack<br/>deployment<br/>[docker-compose.yml]"]
  node_monitoring["Prometheus<br/>metrics<br/>[prometheus.yml]"]
  node_ci["CI workflows<br/>automation<br/>[build-and-test.yml]"]
  node_load_tests["Load tests<br/>scala test<br/>[LoadTest.scala]"]
  node_seed_data["Seed data<br/>demo assets<br/>[posts.sample.json]"]
end

node_nextjs -->|"client auth"| node_user_service
node_nextjs -->|"read feed"| node_feed_api
node_seed_page -->|"uses"| node_seed_data
node_user_service -->|"contains"| node_user_auth
node_user_service -->|"contains"| node_user_graph
node_user_graph -->|"stores"| node_neo4j
node_feed_ingestor -->|"contains"| node_ingestor_store
node_feed_ingestor -->|"contains"| node_ingestor_kafka
node_ingestor_store -->|"stores"| node_postgres
node_ingestor_kafka -->|"publishes"| node_kafka
node_feed_ranker -->|"contains"| node_ranker_consumer
node_feed_ranker -->|"contains"| node_ranker_resilience
node_ranker_consumer -->|"consumes"| node_kafka
node_ranker_consumer -->|"reads follows"| node_neo4j
node_ranker_consumer -->|"writes feed"| node_redis
node_feed_api -->|"contains"| node_feed_controller
node_feed_api -->|"contains"| node_feed_security
node_feed_controller -->|"reads"| node_redis
node_feed_controller -->|"enriches"| node_postgres
node_compose -->|"deploys"| node_user_service
node_compose -->|"deploys"| node_feed_ingestor
node_compose -->|"deploys"| node_feed_ranker
node_compose -->|"deploys"| node_feed_api
node_monitoring -->|"scrapes"| node_user_service
node_monitoring -->|"scrapes"| node_feed_api
node_ci -->|"validates"| node_compose
node_load_tests -->|"measures"| node_feed_api

click node_nextjs "https://github.com/sumit-22/social-graph/blob/main/app/page.tsx"
click node_seed_page "https://github.com/sumit-22/social-graph/blob/main/app/seed/page.tsx"
click node_user_service "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service"
click node_user_auth "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service/src/main/java/com/social/user/security"
click node_user_graph "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service/src/main/java/com/social/user/graph"
click node_feed_ingestor "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-ingestor"
click node_ingestor_store "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/repo"
click node_ingestor_kafka "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/config/KafkaProducerConfig.java"
click node_feed_ranker "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-ranker"
click node_ranker_consumer "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/service/FeedRankerConsumer.java"
click node_ranker_resilience "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/config/ResilienceConfig.java"
click node_feed_api "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-api"
click node_feed_controller "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-api/src/main/java/com/social/feed/controller/FeedController.java"
click node_feed_security "https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-api/src/main/java/com/social/feed/security"
click node_compose "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/docker-compose.yml"
click node_monitoring "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/monitoring/prometheus.yml"
click node_ci "https://github.com/sumit-22/social-graph/blob/main/.github/workflows/build-and-test.yml"
click node_load_tests "https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/load-tests/src/test/scala/com/social/LoadTest.scala"
click node_seed_data "https://github.com/sumit-22/social-graph/blob/main/public/data/posts.sample.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_nextjs,node_seed_page toneBlue
class node_user_service,node_user_auth,node_user_graph,node_feed_ingestor,node_ingestor_store,node_ingestor_kafka,node_feed_ranker,node_ranker_consumer,node_ranker_resilience,node_feed_api,node_feed_controller,node_feed_security toneAmber
class node_neo4j,node_postgres,node_kafka,node_redis,node_compose,node_monitoring,node_ci,node_load_tests,node_seed_data toneMint
```

## Components

### Frontend

Next.js UI and local demo seeding entrypoints

- [Next.js app](https://github.com/sumit-22/social-graph/blob/main/app/page.tsx): UI shell · Root Next.js frontend entrypoint and page layout · `app/page.tsx`
- [Seed page](https://github.com/sumit-22/social-graph/blob/main/app/seed/page.tsx): demo entry · UI entrypoint for seeding or showcasing sample data · `app/seed/page.tsx`

### Backend services

Spring Boot microservices for identity, writes, async ranking, and feed reads

- [User service](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service): Spring service · Authentication, profiles, and follow relationships · `backend/socialgraph/user-service`
- [Auth layer](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service/src/main/java/com/social/user/security): JWT security · Login, token issuing, request authentication, and rate limiting · `backend/socialgraph/user-service/src/main/java/com/social/user/security`
- [Social graph](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/user-service/src/main/java/com/social/user/graph): Neo4j persistence · Users and follow edges stored in Neo4j-backed repositories · `backend/socialgraph/user-service/src/main/java/com/social/user/graph`
- [Feed ingestor](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-ingestor): write service · Authenticated post creation and event publication · `backend/socialgraph/feed-ingestor`
- [Post store](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/repo): JPA repository · Transactional post persistence and write-side data access · `backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/repo`
- [Event producer](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/config/KafkaProducerConfig.java): Kafka publish · Emits post events for downstream async processing · `backend/socialgraph/feed-ingestor/src/main/java/com/social/ingestor/config/KafkaProducerConfig.java`
- [Feed ranker](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-ranker): async worker · Consumes post events and builds ranked feed state · `backend/socialgraph/feed-ranker`
- [Ranker consumer](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/service/FeedRankerConsumer.java): Kafka consumer · Consumes post events and computes recipient ranking · `backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/service/FeedRankerConsumer.java`
- [Resilience](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/config/ResilienceConfig.java): fault tolerance · Retry/backoff and downstream protection for ranking flow · `backend/socialgraph/feed-ranker/src/main/java/com/social/ranker/config/ResilienceConfig.java`
- [Feed API](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-api): read service · Serves personalized feeds to clients · `backend/socialgraph/feed-api`
- [Feed controller](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/feed-api/src/main/java/com/social/feed/controller/FeedController.java): REST API · Client-facing feed retrieval endpoint · `backend/socialgraph/feed-api/src/main/java/com/social/feed/controller/FeedController.java`
- [Feed security](https://github.com/sumit-22/social-graph/tree/main/backend/socialgraph/feed-api/src/main/java/com/social/feed/security): JWT security · Request authentication for feed reads · `backend/socialgraph/feed-api/src/main/java/com/social/feed/security`

### Platform

Shared storage, messaging, packaging, observability, and validation

- **Neo4j**: graph store · Source of truth for users and follow relationships
- **PostgreSQL**: relational store · Durable post and transactional records
- **Kafka**: event bus · Decouples post creation from ranking updates
- **Redis**: serving cache · Precomputed ranked feed state for low-latency reads
- [Docker stack](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/docker-compose.yml): deployment · Dockerfiles and compose files for local or staged deployment · `backend/socialgraph/docker-compose.yml`
- [Prometheus](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/monitoring/prometheus.yml): metrics · Metrics scraping and operational monitoring · `backend/socialgraph/monitoring/prometheus.yml`
- [CI workflows](https://github.com/sumit-22/social-graph/blob/main/.github/workflows/build-and-test.yml): automation · Build, test, and code quality pipelines · `.github/workflows/build-and-test.yml`
- [Load tests](https://github.com/sumit-22/social-graph/blob/main/backend/socialgraph/load-tests/src/test/scala/com/social/LoadTest.scala): scala test · Performance validation for feed latency and throughput · `backend/socialgraph/load-tests/src/test/scala/com/social/LoadTest.scala`
- [Seed data](https://github.com/sumit-22/social-graph/blob/main/public/data/posts.sample.json): demo assets · Sample JSON data and seed generation scripts · `public/data/posts.sample.json`

## Connections

- Next.js app → User service: client auth · Frontend interacts with the identity service for sign-in and social actions
- Next.js app → Feed API: read feed · Frontend requests personalized feeds from the API
- Seed page → Seed data: uses · Seed/demo page is backed by sample content and generation assets
- User service → Auth layer: contains · Authentication and rate limiting live inside the user service
- User service → Social graph: contains · Follow graph persistence is part of the user service
- Social graph → Neo4j: stores · User relationships are persisted in Neo4j
- Feed ingestor → Post store: contains · Write-side persistence is handled by the ingestor
- Feed ingestor → Event producer: contains · The ingestor publishes post events after writes
- Post store → PostgreSQL: stores · Posts are written to the relational database
- Event producer → Kafka: publishes · Post creation emits Kafka events
- Feed ranker → Ranker consumer: contains · Ranking is driven by an event consumer
- Feed ranker → Resilience: contains · Fault tolerance is configured in the ranker
- Ranker consumer → Kafka: consumes · Ranking reacts to post events from Kafka
- Ranker consumer → Neo4j: reads follows · Follower relationships are resolved from Neo4j
- Ranker consumer → Redis: writes feed · Computed rankings are stored for fast serving
- Feed API → Feed controller: contains · Feed retrieval is exposed through the controller
- Feed API → Feed security: contains · JWT verification protects feed reads
- Feed controller → Redis: reads · Ranked feed identifiers are loaded from Redis
- Feed controller → PostgreSQL: enriches · Feed items are enriched from durable post records
- Docker stack → User service: deploys · Compose and Docker packaging run the service stack
- Docker stack → Feed ingestor: deploys · Compose and Docker packaging run the service stack
- Docker stack → Feed ranker: deploys · Compose and Docker packaging run the service stack
- Docker stack → Feed API: deploys · Compose and Docker packaging run the service stack
- Prometheus → User service: scrapes · Prometheus supports service-level observability
- Prometheus → Feed API: scrapes · Prometheus supports service-level observability
- CI workflows → Docker stack: validates · CI covers build, test, and quality gates for the stack
- Load tests → Feed API: measures · Load tests target the feed-serving path
