Neo4j microservice for storing User details and their typing biometrics relationships for aldini. This simple flask microservice takes user information as JSON and inserts it into Neo4j. The project is an effort to demonstrate how we can use a graph db like Neo4j for empowering TypingDNA at scale. The demo of entire aldini will presented at TypingDNA hackathon.
Presently we are using Neo4j and Neo4j Browser User Interface, which supports rich and intuitive relationship visualization.
This repostitory is intended as a microservice only, where aldini-backend can send relevant information over HTTP/1.1.
This code primarily uses py2neo as neo4j driver, flask as backend-http framework, uWSGI for production grade WSGI, nginx as reverse-proxy and load-balancer. All thanks to uwsgi-nginx-flask-docker. It was built using Doom Emacs.
→ docker build --rm . -t aldini-graph
→ docker-compose --env-file app/.env up
There are two important endpoints.
Note: replace the IP with your DOCKER IP though. You can find it as inet addr
under docker0
in ifconfig. Also the NGINX_PORT has been purposefully set as 8080 (in the .env) so that aldini-backend can run on default port 80.
/api/add_user
which is used to create a new User node.
useful cURL requests for the same:
ozen: ~/.../aldini_graph/app |main ✓|
→ curl -d '{"uid":"123", "name":"bhavesh"}' -H "Content-Type: application/json" -X POST http://172.19.0.1:8080//api/add_user
{"created":true,"uid":"123"}
ozen: ~/.../aldini_graph/app |main ✓|
→ curl -d '{"uid":"456", "name":"yaswant"}' -H "Content-Type: application/json" -X POST http://172.19.0.1:8080/api/add_user
{"created":true,"uid":"456"}
/api/add_match
which is used to create similarity relationship between two existing User nodes.
useful cURL requests for the same:
ozen: ~/.../aldini_graph/app |main ✓|
→ curl -d '{"from_uid":"456", "to_uid":"123" ,"conf":0.6}' -H "Content-Type: application/json" -X POST http://172.19.0.1:8080/api/add_match
{"conf":0.6,"created":true,"from_uid":"456","to_uid":"123"}
now run to your browser & open http://localhost:7474 to see visualzations using Neo4j Browser User Interface
For demo purposes these commands might be useful:
- show all User nodes and relationships
MATCH (n:User) RETURN n
- delete all nodes and relationships
MATCH (n:User) DETACH DELETE n
- show all Users relationships
MATCH (n:User)-[r:SIMILAR]-(:User) RETURN n
- show all relationships based on property's value
MATCH (n:User)-[r:SIMILAR]-(:User) WHERE r.conf > 0.8 RETURN n