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.
- 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
- 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
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
cd social_network
g++ -std=c++17 -Wall -Wextra -O2 -o social_network main.cpp graph.cpp
./social_networkOn Windows PowerShell:
cd social_network
g++ -std=c++17 -Wall -Wextra -O2 -o social_network.exe main.cpp graph.cpp
.\social_network.exeInside the CLI, run:
seed
help
stats
bfs 1
dfs 1
path 1 8
suggest 1
communities
cd social_network/ui
npm install
npm run build
npm startOpen http://localhost:3000 in a browser.
For development with hot reload, run:
cd social_network/ui
npm run devThe 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.
Edit social_network/ui/.env:
PORT=3000
USE_MEMORY_STORE=false
MONGO_URI=mongodb://localhost:27017/social_networkYou can also use a MongoDB Atlas URI. If MongoDB is unavailable, the server automatically falls back to in-memory storage.
GET /api/graphPOST /api/seedPOST /api/usersDELETE /api/users/:idPOST /api/friendshipsDELETE /api/friendships/:id1/:id2DELETE /api/graphGET /api/bfs/:idGET /api/dfs/:idGET /api/path/:from/:toGET /api/suggest/:idGET /api/communitiesGET /api/stats
The C++ implementation is useful for explaining the data structures and graph algorithms. The web visualizer is useful for demonstration, interaction, and presentation.