This case study focuses on developing a robust backend for a movie recommendation application. The backend provides APIs for retrieving trending and recommended movies, user authentication, and saving user preferences. It emphasizes performance optimization and comprehensive API documentation.
The primary objectives of the movie recommendation app backend are: -
- API Creation: Develop endpoints for fetching trending and recommended movies.
- User Management: Implement user authentication and the ability to save favorite movies.
- Performance Optimization: Enhance API performance with caching mechanisms.
| Technology | Purpose |
|---|---|
| Django | For backend development. |
| PostgreSQL | Relational database for data storage. |
| Redis | Caching system for performance optimization. |
| JWT | Secure role-based authentication |
| Swagger | API documentation and testing |
-
API for Movie Recommendations:
- Integrate a third-party movie API (e.g., TMDb) to fetch and serve trending and recommended movie data.
- Users can save there favorite movies.
-
User Authentication and Preferences:
- Implement JWT-based user authentication for secure access.
- Create models to allow users to save and retrieve favorite movies.
-
Performance Optimization:
- Use Redis for caching trending and recommended movie data to reduce API call frequency and improve response time.
-
Comprehensive Documentation:
- Use Swagger to document all API endpoints.
- Host Swagger documentation at /api/docs for frontend consumption.
The backend is deployed on Render using PostgreSQL as the database.
- API URL: https://alxprodev-movie-recommendation-backend.onrender.com/api
- Swagger Documentation: https://alxprodev-movie-recommendation-backend.onrender.com/api/docs
USERS
id: Primary Key, UUID, Indexed
first_name: VARCHAR, NOT NULL
last_name: VARCHAR, NOT NULL
email: VARCHAR, UNIQUE, NOT NULL
password: VARCHAR, NOT NULL
created_at: TIMESTAMP, DEFAULT CURRENT_TIMESTAMPFAVORITE
users: Foreign Key, references User(user_id)
movie_id: VARCHAR, NOT NULL
title: VARCHAR, NOT NULL
overview: TEXT, NOT NULL
poster: VARCHAR, NOT NULL
language: VARCHAR, NOT NULL
rating: DECIMAL, NOT NULL
created_at: TIMESTAMP, DEFAULT CURRENT_TIMESTAMP- Endpoint:
POST /api/users/login/ - Description: Authenticates the user and returns a JWT access and refresh token.
- Request Body:
{
"email": "example@gmail.com",
"password": "example_password"
}- Response Body:
{
"access": "jwt_access_token",
"refresh": "jwt_refresh_token"
}- Access Token Lifetime: 15 minute
- Refresh Token Lifetime: 1 day
- Endpoint:
POST /api/users/signup/ - Description: Registers a new user.
- Request Body:
{
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"password": "password123"
}- Response Body:
{
"message": "User created successfully"
}- Endpoint:
POST /users/token/refresh/ - Description: Refresh user access token.
- Request Body:
{
"refresh": "<your_refresh_token>"
}- Response Body:
{
"access": "<new_access_token>"
}- Endpoint:
GET /api/movies/trending/ - Description: Fetches trending movies from TMDb.
- Response Body:
{
"results": [
{
"movie_id": "123",
"title": "Movie Title",
"overview": "Movie description",
"poster": "poster_url",
"language": "en",
"rating": 8.5
}
]
}- Endpoint:
GET /api/movies/recommendations/{movie_id}/ - Description: Fetches recommended movies based on a given movie ID.
- Response Body:
{
"results": [
{
"movie_id": "123",
"title": "Movie Title",
"overview": "Movie description",
"poster": "poster_url",
"language": "en",
"rating": 8.5
}
]
}- Endpoint:
POST /api/favorites/ - Description: Saves a movie to the user's favorites.
- Request Body:
{
"movie_id": "123",
"title": "Movie Title",
"overview": "Movie description",
"poster": "poster_url",
"language": "en",
"rating": 8.5
}
- Response Body:
{
"message": "Movie saved as favorite"
}- Endpoint:
GET /api/favorites/ - Description: Fetches the logged-in user's favorite movies.
- Response Body:
[
{
"movie_id": "123",
"title": "Movie Title",
"overview": "Movie description",
"poster": "poster_url",
"language": "en",
"rating": 8.5
}
]
- Endpoint:
DELETE /api/favorites/{id}/ - Description: delete a movie from the user's favorites.
- Response Body:
{
"message": "Favorite movie deleted successfully"
}
# Database connection
DB_NAME=''
DB_USER=''
DB_PASSWORD=''
DB_HOST=''
DB_PORT=
# Redis Location
REDIS_LOCATION=''
# Django secrete key
SECRET_KEY='
# TMDB API key
TMDB_API_KEY=''
https://image.tmdb.org/t/p/original/<poster>
