Skip to content
Collin Lucke edited this page Nov 27, 2024 · 8 revisions

Welcome to the baphomet‐server wiki!

The Baphomet Movie Rating system is a web application that allows its user community to rate the best-itude of movies using a unique methodology. At the moment, the application displays a list of films that show the details of the movie selected in the list. The user can also create new and edit existing movies when authenticated via the login page. This repo concerns the server/backend functionality for authentication and fetching data from a MongoDB


Tech stack

Apollo Server

A server utility used with Node.js/Express to define request and return data through a GraphQL schema connecting to a MongoDB Atlas instance. Apollo Server Docs


MongoDB Altas

A managed NoSQL database that is used to store data for all the things in a JSON-like format from the instance's baphy database. MongoDB Atlas Docs

TODO: Covert to a self-hosted database


JavaScrip and TypeScript

Currently, the project is mostly written in vanilla JavaScript

TODO: Covert all code to TypeScript


JSON Web Tokens (JWT)

JWTs are used for authentication. When an account is created, a JWT is generated from the user's password using bcrypt and stored in the MongoDB user collection as the password value for the new User object as well as the browser's localStorage. Logging in refreshes the token's timer. This token is added to the header of each request and is verified by comparing the passed-in token to the token set in the database. Currently, authentication is required for the following requests: updateMovie, addMovie, deleteMovie, and checkAuth. JWT Docs


Docker Compose & GitHub Actions

Makes it easy to containerize the application and deploy it to the server machine. The GitHub Action workflow pushes the Docker image to Docker Hub. The action runner on the server machine pulls it down, stops the container, rebuilds from the updated image, and restarts it. Docker Compose Docs | GitHub Actions Docs


API Reference

Queries

getAllMovies(limit, searchTerm)

Returns an array of Movie entries

Parameter Type Req. Default Comments
limit Int 100 The number of movies to return per page
serchTerm String empty string Returns movies whose title contains any part of the term. No term will return all movies.

getMovie(id)

Retruns a single Movie entry

Parameter Type Req. Default Comments
id ID none The id of the movie to be fetched

checkAuth(token)

Retrun an CheckAuth object or a 401 (Unauthorized) error

Parameter Type Req. Default Comments
token String none The baphomet-token stored in the browser's localStorage.

Mutations

addMovie(title, rated, releaseDate, fullplot, poster)

Creates a Movie entry

Parameter Type Req. Default Comments
title String undefined The English title of the movie
rated String undefined The MPA (formerly MPAA) content rating.
releaseDate String undefined The date of the movie's release stored in YYYY-MM-DD format. Shows up in MM/DD/YYYY format in the Movie's details page.
fullplot String blank string The complete synopsis of the movie's plot. (there may potentially be an abbreviated version at some point.)
poster String undefined URL to the location of the movie poster.

updateMovie(id, title, releaseDate, rater, poster, fullplot)

Creates a Movie entry

Parameters Type Req. Default Comments
id ID null The id of the movie being updated.
title String null The English title of the movie.
releaseDate String null The date of the movie's release saved in YYYY-MM-DD format. Shows up in MM/DD/YYYY format in the Movie's details page.
rated String null The MPA (formerly MPAA) content rating.
poster String null URL to the location of the movie poster.
fullplot String blank string The complete synopsis of the movie's plot. (there may be an abbreviated version at some point.)

deleteMovie(id)

Deletes an entry from the movies collection. Return a boolean with true for success and false for a failure.

Parameter Type Req. Default Comments
id ID null The id of the movie being updated.

login(id)

Logins in a user if that user exists in th database

Parameter Type Req. Default Comments
email String blank string The email address associated with a users account.
password String blank string The original password used when the account was created. It be encrypted and compared to the token saved as the password in the batabase.

Return Values

Movie

Object that represents all the data for a single movie in the movies database collection

Property Type Comments
id ID The id of the movie object.
title String The English title of the movie
releaseDate String The date of the movie's release saved in YYYY-MM-DD format. Shows up in MM/DD/YYYY format in the Movie's details page.
rated String The MPA (formerly MPAA) content rating.
poster String URL to the location of the movie poster.
fullplot String The complete synopsis of the movie's plot. (there may be an abbreviated version at some point.)

User

Object that contains all the data for a single user in the users database collection

Property Type Comments
id ID The id of the use object.
email String The email address of a user. Used as the login name.
password String The JWT used to compare to the token passed back as part of any query or mutation that requires authentication

AuthToken

Returns validated authentication token

Property Type Comments
token String The token sent back to the client on a login or signUp request

CheckAuth

Return value for isValid or an 401 (Unauthorized) error for any action that requires authentication

Property Type Comments
isValid Boolean Return true if a token is valid. If not, a 401 (Unauthorized) error will return to display an error modal