Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Graph-Based Social Network Analysis

This project models a social network as an undirected graph. Users are graph nodes, friendships are graph edges, and the project demonstrates common graph operations through both a C++ command-line simulator and a MERN dashboard.

Current Stack

  • MongoDB with Mongoose for optional persistence
  • Express and Node.js for the REST API and production server
  • React with Vite for the modern dashboard UI
  • D3.js inside React for the interactive graph canvas
  • C++17 CLI for the original graph-algorithm demo

Features

  • Add, remove, and list users
  • Add and remove friendships
  • Breadth-first search (BFS)
  • Depth-first search (DFS)
  • Shortest path between two users
  • Friend suggestions using friends-of-friends
  • Community detection using connected components
  • Modern React dashboard with D3.js graph visualization
  • Optional MongoDB persistence, with an in-memory fallback for easy demos

Project Structure

social_network/
  graph.h              C++ graph class declaration
  graph.cpp            C++ graph algorithms and operations
  user.h               User model
  main.cpp             Interactive C++ CLI
  Makefile             C++ build file
  ui/
    server.js          Express API, Mongo storage, and React static server
    index.html         Vite React entry shell
    vite.config.js     React dev server and API proxy config
    src/
      main.jsx         React app and D3 graph workspace
      styles.css       Modern dashboard visual system
    dist/              Production build output after npm run build

Run the C++ CLI

cd social_network
g++ -std=c++17 -Wall -Wextra -O2 -o social_network main.cpp graph.cpp
./social_network

On Windows PowerShell:

cd social_network
g++ -std=c++17 -Wall -Wextra -O2 -o social_network.exe main.cpp graph.cpp
.\social_network.exe

Inside the CLI, run:

seed
help
stats
bfs 1
dfs 1
path 1 8
suggest 1
communities

Run the MERN Dashboard

cd social_network/ui
npm install
npm run build
npm start

Open http://localhost:3000 in a browser.

For development with hot reload, run:

cd social_network/ui
npm run dev

The React app runs on http://localhost:5173 and proxies /api requests to the Express server on http://localhost:3000.

The included local .env and tracked .env.example use USE_MEMORY_STORE=true, so the app runs without MongoDB. Data resets when the server restarts.

Use MongoDB Persistence

Edit social_network/ui/.env:

PORT=3000
USE_MEMORY_STORE=false
MONGO_URI=mongodb://localhost:27017/social_network

You can also use a MongoDB Atlas URI. If MongoDB is unavailable, the server automatically falls back to in-memory storage.

API Endpoints

  • GET /api/graph
  • POST /api/seed
  • POST /api/users
  • DELETE /api/users/:id
  • POST /api/friendships
  • DELETE /api/friendships/:id1/:id2
  • DELETE /api/graph
  • GET /api/bfs/:id
  • GET /api/dfs/:id
  • GET /api/path/:from/:to
  • GET /api/suggest/:id
  • GET /api/communities
  • GET /api/stats

Notes

The C++ implementation is useful for explaining the data structures and graph algorithms. The web visualizer is useful for demonstration, interaction, and presentation.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages