DEV Community

Cover image for Here is the Java Backend to my IMDb Clone!
Niklas Tiede
Niklas Tiede

Posted on • Updated on

Here is the Java Backend to my IMDb Clone!

Heya fellows!

As someone who graduated in chemistry and had never any contact with software development in an professional environment I had to grasp all knowledge I could get from open-source projects on Github to become a professional developer.

And for me it was not that easy to find projects from which I could learn. People often suggest building a movie database app but I was not able to find a good real-world example on Github. So here I present a nice IMDb Clone!

What does this project differentiate from other real-world example apps? It comes with the original IMDb dataset of ~9 million movies shipped!

Contents

  1. What Functionality does this Backend provide?
  2. How to Rebuild this Project
  3. Testing some Endpoints
  4. What's the Data Model under the Hood?
  5. Topics to learn from this Project

1. What Functionality does this Backend provide?

  • user can search for movies from the original IMDb dataset (with Elasticsearch as Search Engine and images saved with MinIO!)
  • user registration with email confirmation and JWT security
  • user can rate movies (CRUD by MySQL)
  • user can add movies to their watchlist
  • user can comment movies and have conversations

2. How to Rebuild this Project

The best way to learn is to get our hands on. Firstly, we just have to download and build the repository:

git clone https://github.com/NiklasTiede/imdb-clone.git
Enter fullscreen mode Exit fullscreen mode

Before we can run the application we have to pull and run the docker image of the data base. This saves us the extra effort of adding credentials to config files, creating database schemes, importing the dataset and indexing the table.

cd infrastructure/deployment/development
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Be aware: the docker containers need 5-20 min before you can connect to it, because the MySQL container has to import the data from the .csv file first! You can also remove the -d (detach) flag to see when the container is ready. Then we can load our gradle project, let it download dependencies if not already done and run it!


3. Testing some Endpoints

I added .http-files which make it very simple to execute requests against the endpoints! Here's an example if we want to search for a movie (substring search).

Movie Search request

We get a paged reponse back.

{
  "content": [
    {
      "id": 2872718,
      "primaryTitle": "Nightcrawler",
      "originalTitle": "Nightcrawler",
      "startYear": 2014,
      "endYear": null,
      "runtimeMinutes": 117,
      "movieGenre": [
        "THRILLER",
        "DRAMA",
        "CRIME"
      ],
      "movieType": "MOVIE",
      "imdbRating": 7.8,
      "imdbRatingCount": 528339,
      "adult": false,
      "rating": null,
      "ratingCount": 0
    }
  ],
  "page": 0,
  "size": 1,
  "totalElements": 30,
  "totalPages": 30,
  "last": false
}
Enter fullscreen mode Exit fullscreen mode

If we want to access secured endpoints we have to create an account. The first account created will automatically have Admin role permissions.

registration request

Email confirmation is not necessary, it is turned off by default. But you can activate it by setting the following property from false to true.

spring.mail.properties.mail.smtp.starttls.enable=false
Enter fullscreen mode Exit fullscreen mode

Now we can login.

login request

A Json Web Token will be returned which we then use to authenticate if necessary.

{
  "accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNjY2NTQxNTEyLCJleHAiOjE2NjkxMzm1MTJ9.HKlIagNPjHH-GITb_hMzcS4bH0jSMZGrjolw_buneIpm7MIYiN-42nLMqkj7ulRYqXv4LFfWwsNEMGFIJim30w",
  "tokenType": "Bearer"
}
Enter fullscreen mode Exit fullscreen mode

Now lets make a request to a secured endpoint. Only users can rate movies. So lets rate a movie.

movie rating request

The rating of the movie is stored in database.

DB entry screenshot

You can go on and check out also some other endpoints!


4. What's the Data Model under the Hood?

Here's an UML diagram of the underlying data model.

Data Model

The two most important tables of the data model are the account- and movie-table. The watchlist and rating tables are using a composite primary key: each user can rate or put a movie an his watchlist only once. For the email confirmation and the password reset we need a verification token which is persisted in the verification_token table.


5. Topics to Learn from this Project

I learned a lot by writing this project. Here are some interesting topics you can find in this project.

...and many more! Feel free to fork/clone the repository and discover it!


I put a lot of effort into this project and will continue working on it. I would really appreciate if you give my Github repository a star! 😃

I wish you all a nice day!

Top comments (0)