Skip to content

REST-API and GraphQL server for the RESTFlix and GraphFlix apps.

Notifications You must be signed in to change notification settings

kimkwanka/flix-backend

Repository files navigation

flix-backend

REST-API and GraphQL server for the RESTFlix and GraphFlix apps.

Movie data is provided via TMDb API and can be retrieved via REST proxy (endpoint /tmdb) or a GraphQL wrapper (endpoint /graphql).

In the same vein, User Management (CRUD) functionality can also be accessed via the corresponding REST endpoints or GraphQL operations.

GraphQL Code Generator is used to generate the base TypeScript typings and GraphQL resolver type signatures directly from flix-backend's GraphQL schema.

For more information, check the API documentation.

Built With

  • MongoDB / Mongoose
  • Express
  • Node.js
  • GraphQL
  • Apollo Server
  • Redis
  • TypeScript

Live Version

You can find the live version at https://flix.kimkwanka.io.

Project Structure

This project is structured 'by components' following the Node.js Best Practices and tries to separate the concerns of the different logic layers as much as possible as outlined in this article by Corey Cleary.

Each feature/component has its own folder containing at least a router, controller and a service file representing the different logic layers:

HTTP Logic Layer

Router

The router only contains the routes and applies the corresponding controller middleware - it does not contain any more logic than that.

Controller

The controller is responsible for handling the request by utilizing the appropriate services.

Business Logic Layer

Service

The service contains the majority of the business logic and encapsulates calls to the data access layer / models or external APIs.

Data Access Layer / Models

This layer contains the logic for accessing persistent data (database, Redis server, etc.) - either directly or via an ORM / ODM Model.

Authentication / Authorization

Authentication and authorization is realized using JWTs and refresh token rotation with silent refresh. As the refresh tokens are provided as http-only, secure cookies it is imperative that the backend uses an encrypted HTTPS connection in production or the cookies can't be set by the server and therefore, auth won't be persistent. This is not an issue in development as most browsers ignore the "secure" setting from "localhost" and cookies can be set regardless.

Getting Started

Install

After cloning the repository run either yarn or npm install to install all dependencies.

Environment Variables

The API depends on the following environment variables:

MONGODB_URI (MongoDB Connection String)

JWT_SECRET (JSON Web Token secret)

TMDB_API_TOKEN (TMDB API key)

REDIS_HOST (Redis server host name or ip)

REDIS_PORT (Redis server port)

REDIS_PASS (Redis server password)

These need to be provided natively in your OS or via a .env in the project root.

Optionally, the PORT variable can be set to change the server's port (default: 8080).

Usage

Use yarn start or npm start to run the API server.

About

REST-API and GraphQL server for the RESTFlix and GraphFlix apps.

Resources

Stars

Watchers

Forks