Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Database Design

Since movies are fetched from an external API like TMDb and not stored locally, we don't need to
create a movie table. Instead, we'll have tables for users, their history, and their watchlist.

1. Users Table:
- user_id (Primary Key)
- username
- email
- password (hashed)
- created_at
- updated_at

2. User History Table:


- history_id (Primary Key)
- user_id (Foreign Key to Users Table)
- movie_id (ID of the movie from the external API)
- date_watched

3. User Watchlist Table:


- watchlist_id (Primary Key)
- user_id (Foreign Key to Users Table)
- movie_id (ID of the movie from the external API)
- added_at

4 . movie API schema:


 adult: Indicates whether the movie is suitable for adults.
 backdrop_path: The path to the backdrop image for the movie.
 genre_ids: An array of genre IDs associated with the movie.
 id: The unique identifier of the movie.
 original_language: The original language of the movie.
 original_title: The original title of the movie.
 overview: A brief overview or summary of the movie's plot.
 popularity: A measure of the movie's popularity.
 poster_path: The path to the poster image for the movie.
 release_date: The release date of the movie.
 title: The title of the movie.
 video: Indicates whether the movie has video content.
 vote_average: The average rating of the movie.
 vote_count: The number of votes/ratings the movie has received.

With this schema, users can have their own history of watched movies and a watchlist. Here's
how each feature maps to the database:

- Stream Movie:
- Fetch movie details from the external API.
- Update user history upon watching.

- History Management:
- View, clear, search, and remove movies from the history based on the user_id.

- Watchlist Management:
- View, clear, search, and remove movies from the watchlist based on the user_id.
- Login and Logout:
- Authenticate users based on username/email and password from the Users table.

- Update Account:
- Update user details in the Users table.

- Browse for Movies:


- Fetch movies from the external API.

- Search for Movies:


- Utilize search functionality of the external API.

- Home Page:
- Display personalized recommendations based on user history and watchlist.

- Movie Info:
- Fetch detailed information about a selected movie from the external API.

Database
Here's a list of necessary database interactions based on the functionalities you provided:

1. User Registration:
- Insert new user data into the Users table.

2. User Login:
- Retrieve user data based on username/email and password from the Users table for
authentication.

3. User Logout:
- No direct interaction with the database, typically handled in the application's session
management.

4. Update Account:
- Update user details (username, email, password) in the Users table.

5. Stream Movie:
- Fetch movie details from the external API.
- Insert a new record into the User History table indicating the movie the user watched and the
date they watched it.

6. View History:
- Retrieve movie history records based on the user_id from the User History table.

7. Clear History:
- Delete history records based on the user_id from the User History table.

8. Search History:
- Retrieve history records based on search criteria and user_id from the User History table.

9. Remove Movie from History:


- Delete a specific history record based on the movie_id and user_id from the User History
table.

10. View Watchlist:


- Retrieve watchlist records based on the user_id from the User Watchlist table.

11. Clear Watchlist:


- Delete watchlist records based on the user_id from the User Watchlist table.

12. Search Watchlist:


- Retrieve watchlist records based on search criteria and user_id from the User Watchlist table.

13. Remove Movie from Watchlist:


- Delete a specific watchlist record based on the movie_id and user_id from the User Watchlist
table.

14. Fetch Movies:


- Fetch movies from the external API based on various criteria.

15. Fetch Movie Info:


- Fetch detailed information about a selected movie from the external API.

controller

Here's an explanation of each controller, detailing what they do and how they achieve it:
1. Login Controller (`login.php`):
- Functionality: Handles user login.
- How it works:
- Receives POST request with username/email and password.
- Validates the credentials against the database (using the User model).
- If valid, sets session data to mark the user as logged in.
- Redirects to the home page or displays an error message.

2. Register Controller (`register.php`):


- Functionality: Handles user registration.
- How it works:
- Receives POST request with username, email, and password.
- Validates the input data.
- If input data is valid, creates a new user in the database (using the User model).
- Redirects to the login page or displays a success message.

3. Browse Controller (`browse.php`):


- Functionality: Displays a list of movies for users to browse.
- How it works:
- Fetches movie data from the external API (using the Movie model).
- Passes the movie data to the corresponding view for rendering.

4. History Controller (`history.php`):


- Functionality: Manages the user's viewing history.
- How it works:
- Fetches the user's viewing history from the database (using the UserHistory model).
- Handles actions such as clearing history or removing specific entries.
- Passes the history data to the corresponding view for rendering.

5. Watchlist Controller (`watchlist.php`):


- Functionality: Manages the user's watchlist.
- How it works:
- Fetches the user's watchlist from the database (using the UserWatchlist model).
- Handles actions such as adding movies to the watchlist, removing movies, or clearing the
entire watchlist.
- Passes the watchlist data to the corresponding view for rendering.

6. Update Account Controller (`update_account.php`):


- Functionality: Allows users to update their account information.
- How it works:
- Receives POST request with updated account details.
- Validates the input data.
- Updates the user's account information in the database (using the User model).
- Redirects to the home page or displays a success message.

7. Logout Controller (`logout.php`):


- Functionality: Logs the user out of the system.
- How it works:
- Destroys the session data to mark the user as logged out.
- Redirects to the login page or home page.

8. Stream Controller (`stream.php`):


- Functionality: Handles streaming of movies.
- How it works:
- Fetches movie details from the external API (using the Movie model).
- Records the movie watched in the user's history (using the UserHistory model).
- Passes the movie details to the corresponding view for streaming.

9. Home Controller (`home.php`):


- Functionality: Displays personalized recommendations on the home page.
- How it works:
- Fetches personalized recommendations based on the user's history and watchlist.
- Passes the recommendation data to the corresponding view for rendering.

10. Movie Info Controller (`movie_info.php`):


- Functionality: Displays detailed information about a selected movie.
- How it works:
- Fetches detailed information about the selected movie from the external API (using the
Movie model).
- Passes the movie details to the corresponding view for rendering.

Each controller encapsulates specific functionality and interacts with the models to retrieve or
manipulate data from the database. It then passes the data to the corresponding view for
rendering to the user.
Model
here's an explanation of each model in your project, detailing what they do and how they
achieve it:

1. **User Model (`User.php`):**


- **Functionality**: Handles user-related operations such as authentication, registration, and
updating account information.
- **How it works**:
- Provides methods to interact with the Users table in the database.
- Includes functions like `registerUser()`, `loginUser()`, `updateUser()`, etc.
- Utilizes SQL queries or an ORM (Object-Relational Mapping) library to perform database
operations such as INSERT, SELECT, UPDATE, DELETE.

2. **Movie Model (`Movie.php`):**


- **Functionality**: Handles fetching movie data from an external API.
- **How it works**:
- Provides methods to interact with the external API to fetch movie information.
- Includes functions like `getMovieDetails()`, `searchMovies()`, etc.
- Typically uses HTTP requests (e.g., cURL, Guzzle) to communicate with the API and retrieve
data.
- Processes the response data and returns it to the controllers for rendering.

3. **User History Model (`UserHistory.php`):**


- **Functionality**: Manages user viewing history.
- **How it works**:
- Provides methods to interact with the UserHistory table in the database.
- Includes functions like `addToHistory()`, `getHistory()`, `clearHistory()`,
`removeFromHistory()`, etc.
- Performs database operations to add, retrieve, clear, or remove history records associated
with a user.

4. **User Watchlist Model (`UserWatchlist.php`):**


- **Functionality**: Manages user watchlist.
- **How it works**:
- Provides methods to interact with the UserWatchlist table in the database.
- Includes functions like `addToWatchlist()`, `getWatchlist()`, `clearWatchlist()`,
`removeFromWatchlist()`, etc.
- Performs database operations to add, retrieve, clear, or remove watchlist records associated
with a user.

Each model encapsulates specific functionality related to its domain and interacts with the
database or external API to perform data operations. The controllers in your application use
these models to fetch or manipulate data and pass it to the views for rendering.

You might also like