A REST API for managing users and their social connections using Neo4j & Nodejs.
src/
├── config/ # Database configuration
├── dao/ # Database interaction
├── services/ # Business logics
├── controllers/ # HTTP handlers
├── routes/ # API routes
├── errors/ # Error handling
└── docker/ # Local docker configuration
- Navigate to the project docker directory:
cd social-network-api/docker- Start the services:
docker-compose up -d- Seed the database with sample data:
docker exec social-network-api npm run seed-
The API will be available at
http://localhost:3000/api -
Stop the services and remove all resources:
docker-compose down -v- Check service logs:
docker logs social-network-api The seed script creates 5 users with the following connections:
Connected: alice and bob with relationship (friend)
Connected: alice and charlie with relationship (colleague)
Connected: bob and diana with relationship (friend)
Connected: charlie and diana with relationship (family)
Connected: diana and eve with relationship (friend)
User IDs for testing:
• alice: f73719a1-8cc2-45b3-8d79-151450a633bc
• bob: f077b038-ba9a-47f2-ba7c-b3681e7f77e8
• charlie: 1fc97d98-f66b-4b61-a540-a881f30d2f93
• diana: c576e4da-7167-4dea-baf9-c295a49e4eb5
• eve: a8be6c31-9527-4fec-9416-c7b6e315fb91
GET /api/healthPOST /api/users
Content-Type: application/json
{
"email": "ava@example.com",
"username": "avama",
"firstName": "Ava",
"lastName": "Ma",
"description": "Software engineer"
}GET /api/users/:idPUT /api/users/:id
Content-Type: application/json
{
"firstName": "Ava_update",
"lastName": "Ma_update"
"description": "Updated description"
}DELETE /api/users/:idPOST /api/connections
Content-Type: application/json
{
"userId1": "user-1",
"userId2": "user-2",
"relationshipType": "friend"
}Note: relationshipType defaults to "friend". Valid values: friend, colleague, family, other
DELETE /api/connections
Content-Type: application/json
{
"userId1": "user-1",
"userId2": "user-2"
}GET /api/connections/:userId/degree/:degree?limit=50Returns list of users at with N degrees relationship from the given user (1-3)