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.
- MongoDB / Mongoose
- Express
- Node.js
- GraphQL
- Apollo Server
- Redis
- TypeScript
You can find the live version at https://flix.kimkwanka.io.
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:
The router only contains the routes and applies the corresponding controller middleware - it does not contain any more logic than that.
The controller is responsible for handling the request by utilizing the appropriate services.
The service contains the majority of the business logic and encapsulates calls to the data access layer / models or external APIs.
This layer contains the logic for accessing persistent data (database, Redis server, etc.) - either directly or via an ORM / ODM Model.
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.
After cloning the repository run either
yarn
or npm install
to install all dependencies.
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).
Use yarn start
or npm start
to run the API server.