Harmony is a music app that showcases the top 10 songs in Hebrew and the top 10 songs in Arabic, relevant to the current time. By clicking on a song's title, users can access its lyrics/artist as well as its translation into the other language.
- React
- Redux Toolkit & Rtk query
- Axios
- React Router
- i18next
- Styled Components
- React Youtube
- React Share
- Node.js
- Mongodb
- Express.js
- Axios
- Pino
- Mocha
- Cheerio
- Puppeteer
- Openai Api
- Spotify Api
- Youtube Api
- Google Api
- PassportJS
- NodeCron
- Json Web Token
git clone https://github.com/Makes-Innovation-Hub/harmony.git
After you clone the folder to your computer please open the folder with Vs code and then open your terminal in your Vs code.
In order to run the app locally you will need to install all the dependencies by the following command:
npm run installAll
In order to config all env files in the client please enter the following command:
# Client .env example
VITE_SERVER_PORT=5000
VITE_SERVER_BASE_URL=http://localhost
VITE_RENDER_URL= Put your production server url
# This can be either local or production
# If its production then it works on Render
VITE_ENVIRONMENT = local | production
In order to config all env files in the server please enter the following command:
cd server
npm run config
PORT = 5000 || 3000 or the port you prefer
NODE_ENV = development || production
PORT=5000
NODE_ENV="development"
MONGO_URI_DEV = explanation below
MONGO_URI_PROD = explanation below
OPEN_AI_API_KEY = explanation below
SPOTIFY_CLIENT_ID = explanation below
SPOTIFY_CLIENT_SECRET = explanation below
YOUTUBE_API_KEY= explanation below
BASE_SERVER_URL= http://localhost
SERVER_PORT=5000
CLIENT_PORT=5173
RENDER_URL = Put your production server url
PRODUCTION_FRONT_URL = Put your production client url
SERAP_API_KEY = [Create your own account here](https://serpapi.com/)
### All are necessary to run Auth but only google is in use
GOOGLE_CLIENT_ID= explanation below
GOOGLE_CLIENT_SECRET= explanation below
FACEBOOK_APP_ID= explanation below
FACEBOOK_APP_SECRET= explanation below
APPLE_CLIENT_ID= explanation below
APPLE_TEAM_ID= explanation below
APPLE_KEY_ID= explanation below
APPLE_PRIVATE_KEY_PATH= explanation below
SESSION_SECERT= explanation below
VITE_CLIENT_ID= explanation below
-
sign in to mongodb website: https://www.mongodb.com/
-
press "Next" button
-
IP Address: 0.0.0.0/0
-
goto "Add your connection string into your application code" and copy it, inside it enter the password you choose from previous step above.
this lone string will be your MONGO_URI_DEV & MONGO_URI_PROD
- open ai website: https://openai.com/
- goto menu
- goto Log in
- press API box
- upper menu right side, press "Personal"
- press "View API keys"
- press "+ Create new secret key" button
-
open spotify website for developer: https://developer.spotify.com/
-
goto login and log to spotify with the platform you prefer (email/facebook etc..)
-
press on the Dashboarded in the username button in the right top corner.
-
press "Create App"
-
choose "Settings" button
-
There you can find your Spotify client ID & Spotify client secret
In order to use the YouTube Data API, you'll need to obtain an API key. Follow the steps below to generate your API key.
Navigate to the Google Developers Console.
- In the left sidebar, click on "Library".
- Search for "YouTube Data API" and click on it.
- Click the "Enable" button.
After you create the API key, it will be displayed on the screen. Copy this key to use it in the project.
Save the API Key as an environment variable for the server with the name "YOUTUBE_API_KEY="
This section guides you through setting up Google authentication in your application using Passport.js. Follow these steps to enable users to sign in with their Google accounts.
Before you start, ensure you have Passport.js and the Google OAuth strategy installed. If not, run the following command:
npm install passport passport-google-oauth20
1. Go to the Google Developers Console
5. Add your application's redirect URI, which will be used for the OAuth callback. It usually looks like http://localhost:5000/auth/google/callback.
1. Go to the Passport.js and click on Strategies
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
passport.use(new GoogleStrategy({
clientID: YOUR_CLIENT_ID,
clientSecret: YOUR_CLIENT_SECRET,
callbackURL: "http://localhost:5000/auth/google/callback"
},
function(accessToken, refreshToken, profile, cb) {
// In this function, find or create a user in your database and call cb
cb(null, user);
}
));
app.get('/auth/google',
passport.authenticate('google', { scope: ['profile', 'email'] }));
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
After configuring Passport.js with Google OAuth and setting up your routes, it's crucial to test the integration to ensure that users can authenticate successfully using their Google accounts. Follow these steps to test the Google authentication flow:
Ensure your application is running. If you're using Node.js, you can typically start your application with:
node app.js
Open a web browser and navigate to the route that initiates the authentication process with Google. Based on the previous setup, this URL will be:
http://localhost:5000/auth/google
You should be redirected to the Google sign-in page. Choose an account or log in with your Google credentials. After successful authentication, Google will ask for your consent to share your profile and email address with your application.
After giving consent, you should be redirected back to your application, as specified in your OAuth callback URL. If you set up everything correctly, you should reach the success redirect URL ('/' in the example) after successful authentication.
Ensure that your application correctly receives and processes the user information from Google. This typically involves checking whether the user's data is correctly retrieved in the callback function provided to the GoogleStrategy and whether any user session or database records are correctly updated.
If the authentication process does not work as expected:
Check the console for any errors. Verify that the CLIENT_ID and CLIENT_SECRET are correctly set. Ensure the callback URL in your Google project matches the one in your Passport configuration exactly. Make sure you're handling the failureRedirect properly in your routes to catch any failed authentication attempts.
Implement a logout route to allow users to end their session. Here's a simple example:
app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
});
This ensures that users can log out of their session in your application, providing a complete authentication flow.
This documentation provides an overview of the routes and functionalities of the playlist in the backend server.
- Method: GET
- Description: Retrieves data for a specific playlist identified by its ID. It fetches data from the YouTube API, stores it in the database, and returns the playlist data.
- Query Parameters:
id
: The ID of the playlist (required).update
: Optional query parameter. If set to "true", the data will be updated from the YouTube API even if it exists in the database.
- Response: Returns JSON data containing information about the playlist.
- Method: GET
- Description: Retrieves the profile picture URL of a YouTube channel identified by its ID.
- Query Parameters:
id
: The ID of the YouTube channel (required).
- Response: Returns JSON data containing the profile picture URL.
- Method: GET
- Description: Retrieves data for all playlists. This route is for testing purposes and returns mock data.
- Response: Returns JSON data containing information about all playlists.
This file contains controller functions for handling requests related to playlists.
- Description: Retrieves playlist data from the YouTube API or database, updates if necessary, and returns the data.
- Usage: Called when accessing the
/api/v1/playlist/playlistData
route. - Query Parameters:
id
(required) (Playlist ID),update
(optional). - Returns: JSON data containing playlist information.
- Description: Retrieves the profile picture URL of a YouTube channel.
- Usage: Called when accessing the
/api/v1/playlist/profilePic
route. - Query Parameters:
id
(required) (Channel ID). - Returns: JSON data containing the profile picture URL.
- Description: Returns mock data for all playlists.
- Usage: Called when accessing the
/api/v1/playlist/allPlaylistData
route. - Returns: JSON data containing mock playlist information.
- Description: Defines the schema for storing playlist data in the MongoDB database.
- Fields:
playlistId
: String (required, unique)items
: Array of objects containing video detailsupdatedAt
: Date (default: current date)
- Usage: Used to interact with the
playlists
collection in the database.
- Description: Scheduled task to update playlists in the database every week.
- Scheduled Time: Every Sunday at 4:00 AM.
- Functionality: Checks if any playlist needs an update based on the last update time.
- Express: Web framework for Node.js.
- Axios: Promise-based HTTP client for making HTTP requests.
- Mongoose: MongoDB object modeling tool.
- Node-cron: Cron-like scheduler for Node.js.
- YOUTUBE_API_KEY: API key required for accessing the YouTube Data API.
- Ensure MongoDB is installed and running.
- Set up environment variables, including the
YOUTUBE_API_KEY
. - Install dependencies using
npm install
. - Start the server using
npm start
.
In the client folder:
1. cd client
2. npm run dev
In the server folder:
1. cd server
2. nodemon server.js