Git Product home page Git Product logo

neo4j-movies-template's Introduction

README

This Neo4j-based example app displays movie and person data in a manner similar to IMDB. It is designed to serve as a template for further development projects. There are two versions of the backend - a Python/Flask backend at /flask-api, and a JavaScript/Express backend at /api. The web frontend can be found at /web. Feel encouraged to fork and update this repo!

The Model

image of movie model

Nodes

  • Movie
  • Person
  • Genre

Relationships

  • (:Person)-[:ACTED_IN {role:"some role"}]->(:Movie)
  • (:Person)-[:DIRECTED]->(:Movie)
  • (:Person)-[:WRITER_OF]->(:Movie)
  • (:Person)-[:PRODUCED]->(:Movie)
  • (:MOVIE)-[:HAS_GENRE]->(:Genre)

Database Setup: Sandbox

Go to https://sandbox.neo4j.com/?usecase=recommendations&ref=movie-app-tutorial, pick "Recommendations", and press play to start the database.

Make sure to edit the file flask-api/.env or api/.env and update the MOVIE_DATABASE_USERNAME, MOVIE_DATABASE_PASSWORD, and MOVIE_DATABASE_URL of your chosen backend to connect to your instance.

Node API

First, configure your api/.env file to point to your database.

Then, from the root directory of this project:

Alternative: Flask API

First, configure your flask-api/.env file to point to your database.

Then, from the root directory of this project:

cd flask-api
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
export FLASK_APP=app.py
flask run

Frontend

From the root directory of this project, set up and start the frontend with:

  • cd web
  • nvm use
  • npm install
  • update web/.env file

If you are using the Node API set REACT_APP_API_BASE_URL to http://localhost:3000/api/v0

If you are using the Flask api then set it to http://localhost:5000/api/v0

image of PATH settings for NPM

voilà! IMDB, eat your heart out ;-)

Ratings and Recommendations

User-Centric, User-Based Recommendations

Based on my similarity to other users, user Omar Huffman might be interested in movies rated highly by users with similar ratings as himself.

MATCH (me:User {name:"Omar Huffman"})-[my:RATED]->(m:Movie)
MATCH (other:User)-[their:RATED]->(m)
WHERE me <> other
AND abs(my.rating - their.rating) < 2
WITH other,m
MATCH (other)-[otherRating:RATED]->(movie:Movie)
WHERE movie <> m
WITH avg(otherRating.rating) AS avgRating, movie
RETURN movie
ORDER BY avgRating desc
LIMIT 25

Contributing

Node.js/Express API

The Express API is located in the /api folder.

Create Endpoint

The API itself is created using the Express web framework for Node.js. The API endpoints are documented using Swagger.

To add a new API endpoint there are 3 steps:

  1. Create a new route method in /api/routes directory
  2. Describe the method with swagger specification inside a JSDoc comment to make it visible in swagger
  3. Add the new route method to the list of route methods in /api/app.js.

Flask API

The Flask API is located in the /flask-api folder. The application code is in the app.py file.

Create Endpoint

The API itself is created using the Flask-RESTful library. The API endpoints are documented using Swagger.

To add a new API endpoint there are 3 steps:

  1. Create a new Flask-RESTful resource class
  2. Create an endpoint method including the swagger docs decorator.
  3. Add the new resource to the API at the bottom of the file.

neo4j-movies-template's People

Contributors

chrisportela avatar dependabot[bot] avatar janekk avatar jexp avatar kbastani avatar lenniezelk avatar michael-simons avatar mneedham avatar nossila avatar whatsocks avatar yrong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo4j-movies-template's Issues

developer should be able to copy+paste cURL from swagger

currently there are some line breaks and \ blocking harmonious workflow for some endpoints. For example of a bad one:

$ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
quote>    "username": "Mary Sue", \
quote>    "password": "SuperPassword" \
quote>  }' 'http://localhost:3000/api/v0/register'

How to change "config.js"

Hi,
Could you provide a config examples of config.js?
I made changes like the following, but it still didn't work.
'neo4j-local': 'http://neo4j@password:localhost:7474', // http://usernama@password:localhost:7474 'neo4j-remote': 'http://neo4j@password:localhost:7474',

Thank you

Request failed with status code 401

Hi
I am new to this and would really appreciate help in solving the error i get when trying to sign up or log in . I am on windows and used flask-api
The error i get is
"Request failed with status code 401"

Thanks
Nawar

Css was not created by the application in build

[17:39:26] STYLES ERROR: { [Error: src/styles/main.scss
Error: File to import not found or unreadable: ../../bower_components/foundation/scss/normalize
Parent style sheet: stdin
on line 2 of stdin

@import '../../bower_components/foundation/scss/normalize';
^
]
status: 1,
file: 'stdin',
line: 2,
column: 1,
message: 'src/styles/main.scss\nError: File to import not found or unreadable: ../../bower_components/foundation/scss/normalize\n Parent style sheet: stdin\n on line 2 of stdin\n>> @import '../../bower_components/foundation/scss/normalize';\n ^\n',
formatted: 'Error: File to import not found or unreadable: ../../bower_components/foundation/scss/normalize\n Parent style sheet: stdin\n on line 2 of stdin\n>> @import '../../bower_components/foundation/scss/normalize';\n ^\n',
messageFormatted: '\u001b[4msrc/styles/main.scss\u001b[24m\nError: File to import not found or unreadable: ../../bower_components/foundation/scss/normalize\n Parent style sheet: stdin\n on line 2 of stdin\n>> @import '../../bower_components/foundation/scss/normalize';\n ^\n',
name: 'Error',
stack: 'Error: src/styles/main.scss\nError: File to import not found or unreadable: ../../bower_components/foundation/scss/normalize\n Parent style sheet: stdin\n on line 2 of stdin\n>> @import '../../bower_components/foundation/scss/normalize';\n ^\n\n at options.error (/home/ubuntu/Documents/neo4j-movies-template-master/web/node_modules/node-sass/lib/index.js:286:26)',
showStack: false,
showProperties: true,
plugin: 'gulp-sass' }

css

{ code: 404, reason: 'genres not found' }

`{ [Error: [object Object]]
stack: [Getter/Setter],
message: { errors: [ [Object] ] },
__frame:
{ name: 'GraphDatabase_prototype_query__20',
line: 710,
file: 'lib/GraphDatabase._coffee',
prev: undefined,
calls: 1,
active: false,
offset: 2,
col: 24 },
rawStack: [Getter] }
{ code: 404, reason: 'genres not found' }

D:\Biswatma\neo4j\neo4j-movies-template-master\api\routes\genres.js:54
if (err || !response.results) throw swe.notFound("genres"); `

I am getting this error while accessing api .

Documentation update for web\dist\assets\js\app.js

First off, I wanted to say how impressed I am with this project. I am new to neo4j this template will be extremely helpful.

In the README.md when we switch from remote to local in the api

in api\config.js we change to this:

nconf.defaults({
'neo4j': 'local'

I had to also set this up in the application

in web\dist\assets\js\app.js I changed to this:

var PATH_TO_API = 'http://localhost:3000/api/v0/'

Also, the PATH_TO_API above works but 'http://localhost:3000/docs' did not seem to work. /docs was there but commented out.

Was there a step I missed anywhere?

Thanks!

The Frontend pages has nothing, only 'Featured Movies'

I deployed all of this project, the api link localhost:3000 is right and has many GET requests, but the Frontend page has nothing , only a big size and bold 'Featured Movies', such as #Featured Movies# , and on this page, the F12--console has nothing red (WARN or ERROR) . PLEASE HELP ME!

Neo4jError: Client network socket disconnected before secure TLS connection was established

Steps to reproduce:

  1. load all csv files
  2. npm install in /api
  3. node api.js
Neo4jError: Client network socket disconnected before secure TLS connection was established

    at captureStacktrace (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/neo4j-driver/lib/v1/result.js:199:15)
    at new Result (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/neo4j-driver/lib/v1/result.js:65:19)
    at Session._run (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/neo4j-driver/lib/v1/session.js:152:14)
    at Session.run (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/neo4j-driver/lib/v1/session.js:130:19)
    at Object.getAll (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/models/genres.js:5:18)
    at exports.list (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/routes/genres.js:36:10)
    at Layer.handle [as handle_request] (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/krs/Documents/Krishna/TryCode/neo4j-movies-template/api/node_modules/express/lib/router/layer.js:95:5)

Content at PORT 3000 failed to load

After having failed to get this example to speak on windows 10 (as bootstrap was not compatible with it) I decided to give it a try on a Ubuntu14 VM.
Somehow I got to the end (I had problems with the middleware, but I I think I installed all the necessary npm modules and that this is fine now).
So finally I got to the point where the system listens on port 3000, and I actually see all the GETS. But when I look for content it is EMPTY.

Also on port 5000 I can see the frame, but not content.

What do you think the problem is? What can I do?

graphDB upgrade

Hi, I got to the step of wanting to open the moviesDB with Neo, but it tells me: please set configuration parameter "allow_store_upgrade=true".

I already have this flag to true, so I was wondering if you could just provide an upgraded moviesDB for Neo 2.3.0. It would be nice...

Create a new section for scenario-based learning (Bacon Path)

Show readers how to modify the Swagger REST API by adding a new method for solving the bacon path. The bacon path tells you how people are connected through mutual acquaintances.

The method should take 2 parameters. Person 1 and Person 2. If Person 1 is Kevin Bacon and Person 2 is Tom Hanks, a return result would be an ordered array of people between Kevin Bacon and Tom Hanks.

Front end user experience will be 2 portrait boxes, one on the left of the screen and one to the right. In between the two portraits will be smaller portrait boxes that will be populated from the return response of the new REST API method.

How can I run the project in a closed web environ?

When I set up the flask app, I got the following output. Maybe I should deploy a neo4j DB locally?

Traceback (most recent call last):
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/bin/flask", line 11, in <module>
    sys.exit(main())
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 848, in run_command
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 305, in __init__
    self._load_unlocked()
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 330, in _load_unlocked
    self._app = rv = self.loader()
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 388, in load_app
    app = locate_app(self, import_name, name)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/app.py", line 57, in <module>
    driver = GraphDatabase.driver(DATABASE_URL, auth=basic_auth(DATABASE_USERNAME, str(DATABASE_PASSWORD)))
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/__init__.py", line 183, in driver
    return cls.bolt_driver(parsed.netloc, auth=auth, **config)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/__init__.py", line 196, in bolt_driver
    return BoltDriver.open(target, auth=auth, **config)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/__init__.py", line 359, in open
    pool = BoltPool.open(address, auth=auth, pool_config=pool_config, workspace_config=default_workspace_config)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 531, in open
    seeds = [pool.acquire() for _ in range(pool_config.init_size)]
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 531, in <listcomp>
    seeds = [pool.acquire() for _ in range(pool_config.init_size)]
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 545, in acquire
    return self._acquire(self.address, timeout)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 409, in _acquire
    connection = self.opener(address, timeout)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 528, in opener
    return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 198, in open
    keep_alive=pool_config.keep_alive,
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 1049, in connect
    raise last_error
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 1039, in connect
    s = _connect(resolved_address, timeout, keep_alive)
  File "/root/pjr/web_projects/flask_playground/neo4j-movies-template-master/flask-api/venv/lib/python3.6/site-packages/neo4j/io/__init__.py", line 943, in _connect
    raise ServiceUnavailable("Failed to establish connection to {!r} (reason {})".format(resolved_address, error))
neo4j.exceptions.ServiceUnavailable: Failed to establish connection to IPv4Address(('127.0.1.1', 7687)) (reason [Errno 111] Connection refused)

updated for Neo4j 3.0.3

Can this project be updated for Neo4j 3.0.3? Also it would be good to have TDD examples include in the template.

build fails in /web on OS X 10.13 using node 9.4

The /api part installs without any problem.
The /web part doesn't work as expected.
First I had to 'brew install libsass' to make 'npm install' run in the /web subdirectory.

But there still seems to be some incompatibility.
In the > [email protected] postinstall section, the build fails like that:
../src/sass_types/list.cpp:28:19: error: no matching function for call to 'sass_make_list'
return out = sass_make_list(length, comma ? SASS_COMMA : SASS_SPACE);
^~~~~~~~~~~~~~
/usr/local/include/sass/values.h:53:34: note: candidate function not viable: requires 3 arguments, but 2 were provided
ADDAPI union Sass_Value
ADDCALL sass_make_list (size_t len, enum Sass_Separator sep, bool is_bracketed);

use environment variables in web api

Currently all urls seem to be hardcoded to use http://movieapi-neo4j.herokuapp.com/api/v0/. The app should be easily pointable to a local database/endpoints.

Pages sometimes take a minute or more to load

Hi there,

First off, thanks for this app. I wanted to learn React and got more than I bargained for here -- cool to see how Redux works, too. I've been customizing the app, and started to notice that some percentage of requests (maybe 15-20%) take an incredibly long time to resolve. The response payload is 369B, so that shouldn't be an issue. I'm not sure how to debug this. Things I've tried:

  • Stripping out all the code from the render function that required information from the database. Still slow.
  • Using a profiler from Werkzeug, which apparently Flask runs on. This didn't work because the middleware that wrapped the app wasn't compatible with all the Swagger stuff.
  • Disabling IPv6 on my localhost -- apparently this can be a problem with Werkzeug. No dice there, either.

Anyone have suggestions on how to figure this out? Thanks in advance!

The code doesn't match the schema

The readme suggests to use this database: Go to https://sandbox.neo4j.com/?usecase=recommendations&ref=movie-app-tutorial, pick "Recommendations", and press play to start the database.

The recommendations database has relationships: DIRECTED, ACTED_IN, RATED, IN_GENRE
However the code expects these relationships: DIRECTED, ACTED_IN, RATED, IN_GENRE, PRODUCED, WRITER_OF

Also the code has looks for "tmdbId" in the below cypher. tmdbId should be imdbId:

MATCH (movie:Movie {tmdbId: $movieId})
OPTIONAL MATCH (movie)<-[my_rated:RATED]-(me:User {id: null})
OPTIONAL MATCH (movie)<-[r:ACTED_IN]-(a:Person)
OPTIONAL MATCH (related:Movie)<--(a:Person) WHERE related <> movie
OPTIONAL MATCH (movie)-[:IN_GENRE]->(genre:Genre)
OPTIONAL MATCH (movie)<-[:DIRECTED]-(d:Person)
OPTIONAL MATCH (movie)<-[:PRODUCED]-(p:Person)
OPTIONAL MATCH (movie)<-[:WRITER_OF]-(w:Person)
WITH DISTINCT movie,
my_rated,
genre, d, p, w, a, r, related, count(related) AS countRelated
ORDER BY countRelated DESC
RETURN DISTINCT movie,
my_rated.rating AS my_rating,
collect(DISTINCT d) AS directors,
collect(DISTINCT p) AS producers,
collect(DISTINCT w) AS writers,
collect(DISTINCT{ name:a.name, id:a.tmdbId, poster_image:a.poster, role:r.role}) AS actors,
collect(DISTINCT related) AS related,
collect(DISTINCT genre) AS genres

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.