Exploring a Neo4j-Based Movie Database App

Aug 13, 2021 | Programming

Welcome to our guide on how to create a movie database application similar to IMDB using Neo4j! This application leverages a combination of Python Flask and JavaScript Express backends. Not only is this an excellent template for your upcoming development projects, but it also showcases user-centric movie ratings and recommendations.

Understanding the Model

Before we dive into the setup and implementation, let’s understand the entity relationship model that powers our application. Picture this model as a social web of movie goers and creators:

  • 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)

You can think of it as a movie industry ecosystem where each person plays various roles, and every movie belongs to particular genres.

Setting Up the Database

For a smooth experience, let’s start by setting up the database. We will use Neo4j’s Sandbox.

  1. Go to the Neo4j Sandbox.
  2. Choose “Recommendations” and hit the play button to initialize your database.
  3. Edit the flask-api.env or api.env file to update the MOVIE_DATABASE_USERNAME, MOVIE_DATABASE_PASSWORD, and MOVIE_DATABASE_URL for your backend.

API Setup

Now let’s set up the Node API or the Flask API depending on your choice of backend.

Node API

  1. Configure the api.env file to connect to your database.
  2. From the root directory, run the following commands:
    cd api
    nvm use
    npm install
    node app.js
  3. Access the API documentation at http://localhost:3000/docs.

Flask API

  1. Edit the flask-api.env file with your database details.
  2. From the root directory, execute the following commands:
    cd flask-api
    python3 -m venv venv
    source venv/bin/activate
    pip3 install -r requirements.txt
    export FLASK_APP=app.py
    flask run
  3. Check the API documentation at http://localhost:5000/docs.

Frontend Setup

Let’s not forget the user interface!

  1. Navigate to the web folder by running:
    cd web
  2. Activate the environment:
    nvm use
  3. Install dependencies:
    npm install
  4. Update the web.env file:
  5. Start the app with:
    npm start
  6. Your application should now be up and running at http://localhost:3000!

Ratings and Recommendations

The application allows for user-centric recommendations based on similarities between users. For instance, if a user named Omar Huffman has rated several movies, the app finds other users with similar ratings to recommend films to Omar based on their ratings.

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

Creating New Endpoints

You can easily create new API endpoints, whether you’re using the Node.js Express API or the Flask API. Here’s a simplified analogy for each:

  • In Node.js: Consider it like building extra shops in a mall. You first construct the ground structure (create a route in the apiroutes directory), then put up shop signs (write Swagger documentation), and finally, welcome customers by joining it with the main entrance (add the route method in api/app.js).
  • In Flask: It’s like adding a new dish to a restaurant menu. You develop a new recipe (create your Flask-RESTful resource), write down how to prepare it (document the endpoint), and then add it to your menu card (include the resource at the bottom of the file).

Troubleshooting

If you encounter issues during setup, here are a few troubleshooting tips:

  • Double-check your environment configuration files for correct credentials.
  • Ensure that your Neo4j database is up and running before starting the applications.
  • Check for any port conflicts in your local setup.
  • If using virtual environments, make sure they are activated before running any commands.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Final Thoughts

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox