The full project wiki is in the wiki folder.
Welcome to the Crispy Crumbs backend. This server is built using NodeJS integrated with MongoDB to provide a robust backend for the Crispy Crumbs video sharing platform.
- Ofek Avan Danan
- Zohar Mzhen
- Dolev Menajem
- The server is built and tested to run from a Windows machine.
- Node.js
- MongoDB
- By default, CrispyCrumbs will use the "CrispyCrumbs" database in "mongodb://localhost:27017/CrispyCrumbs" connection and will overwrite anything in it.
- C++ Recommendations Server: provide video recommendations tailored for each user. Activate the C++ TCP Recommendations Server according to the instructions provided in the repository before starting the Node.js server. Without it, the server will display random videos in the suggested videos section.
- Download CrispyCrumbsServer zip and extract it.
- Or clone the repository.
Note: If you're interested in using the website quickly, you can run only the CrispyCrumbs website initialization script, which will also initialize the server (without updating the JWT secret).
-
Open a command prompt in the
CrispyCrumbsServerproject folder. -
Run the initialization script:
.\init_server.cmd -
You may update the JWT secret if prompted.
-
In the future, to start the server without modifying the config files and database, run
npm startto start the server. -
The script accept the flag
-forceto restart the server.
-
Open
CrispyCrumbsServer\config\config.jsfile and choose a new JWT secret key:// config/config.js module.exports = { jwtSecret: 'your-jwt-secret-here', // Replace this with your actual secret key // other configurations... };
- Open MongoDB Compass.
- Connect to the URI
mongodb://localhost:27017/CrispyCrumbs. - Open or create a database named
CrispyCrumbs. - Open or create two collections:
usersandvideos. - Ensure
usersandvideosare empty. - In
users, selectADD DATA > IMPORT JSON OR CSV FILE. - Choose
CrispyCrumbsServer\FilesForMongoDB\CrispyCrumbs.users.json. - In
videos, selectADD DATA > IMPORT JSON OR CSV FILEand chooseCrispyCrumbsServer\FilesForMongoDB\CrispyCrumbs.videos.json. - Go to the
indexestab and create the following indexes: a. On fieldstitleanddescriptionof typetext; b. On fieldtitleof type1 (asc); c. On fieldtagsof type1 (asc). as such: a
b
c 
- Open a terminal in the
CrispyCrumbsServerproject folder. - Run
npm install. - Activate the C++ TCP server according to the instructions on the repository. This is necessary for video recommendations.
- Run
node server.js. Now the server should be running!
- Clone or download the CrispyCrumbsWeb repository.
- Follow the instructions in the repository to set up and run the web version of Crispy Crumbs.
- Clone or download the CrispyCrumbsAndroid repository.
- Follow the instructions in the repository to set up and run the Android version of Crispy Crumbs.
graph TD;
NodeJS_Server["NodeJS Server - Backend"] <--> React_Web["React Frontend"];
NodeJS_Server <--> Android_App["Android App - Frontend"];
NodeJS_Server <--> TCP_Server["C++ Recommendation Server - Backend"];
NodeJS_Server <--> MongoDB["MongoDB Database"];
-
Get User Details
GET /:id- Function:
getUserDetails - Description: Retrieves detailed information about a user.
-
Get Basic User Details
GET /basic/:id- Function:
getUserBasicDetails - Description: Retrieves basic information about a user.
-
Update User
PUT /:id- Function:
updateUser - Description: Updates user details. Requires authentication and user verification.
-
Delete User
DELETE /:id- Function:
deleteUser - Description: Deletes a user along with all their data. Requires authentication and user verification.
-
Get User Videos
GET /:id/videos- Function:
getUserVideos - Description: Retrieves videos uploaded by a user.
-
Upload Video
POST /:id/videos- Function:
createUserVideo - Description: Uploads a new video. Requires authentication and user verification.
-
Edit Video
PUT /:id/videos/:videoId- Function:
editVideo - Description: Edits an existing video. Requires authentication and user verification.
-
Delete Video
DELETE /:id/videos/:videoId- Function:
deleteVideo - Description: Deletes a video. Requires authentication and user verification.
-
Authentication and Validation
-
POST /validateToken- Function:
validateToken - Description: Validates the JWT token.
- Function:
-
POST /tokens- Function:
login - Description: Logs in a user and provides a JWT token.
- Function:
-
POST /- Function:
signup - Description: Signs up a new user.
- Function:
-
-
Follow/Unfollow User
POST /follow- Function:
followUnfollowUser - Description: Follows or unfollows a user. Requires authentication and user verification.
-
Check Username/Email Availability
-
POST /isUsernameAvailable- Function:
isUsernameAvailable - Description: Checks if a username is available.
- Function:
-
POST /isEmailAvailable- Function:
isEmailAvailable - Description: Checks if an email is available.
- Function:
-
-
Get All Videos
GET /- Function:
getAllVideos - Description: Retrieves all videos including most viewed, recent, following, and random videos.
-
Get Following Videos
GET /followers- Function:
getFollowingVideos - Description: Retrieves videos from followed users. Requires authentication.
-
Get Video by ID
GET /:id- Function:
getVideoById - Description: Retrieves a video by its ID.
-
Like/Dislike Video
-
POST /like- Function:
likeVideo - Description: Likes a video. Requires authentication and user verification.
- Function:
-
POST /dislike- Function:
dislikeVideo - Description: Dislikes a video. Requires authentication and user verification.
- Function:
-
-
Add/Edit/Delete Comment
-
POST /comment- Function:
addComment - Description: Adds a comment to a video. Requires authentication and user verification.
- Function:
-
PUT /comment- Function:
editComment - Description: Edits a comment. Requires authentication and user verification.
- Function:
-
DELETE /comment- Function:
deleteComment - Description: Deletes a comment. Requires authentication and user verification.
- Function:
-
-
Get Video Recommendations
GET /:videoId/recommendations- Function:
getRecommendations - Description: Retrieves recommended videos based on watch history and video popularity. Requires the TCP server to be running for full functionality.
-
Check Following Status
POST /isFollowing- Function:
isFollowing - Description: Checks if the user is following another user. Requires authentication.
-
Verify Token Middleware
verifyToken- Description: Middleware to verify JWT token.
-
Verify User ID Middleware
verifyUserId- Description: Middleware to verify if the user ID in the request matches the user ID from the token.
Our project was a collaborative effort. We initially met to plan and divided tasks using Jira. The journey was both educational and enjoyable.