This project is a backend service for fetching and caching YouTube video details and comments. It's built with NestJS and uses Redis for caching.
The Swagger documentation for this API is available at:
URL: http://164.90.185.174:3009/codematic/documentation#/
To access the documentation, use the following credentials:
- Username: codematic
- Password: codematic123!
The frontend client that uses this service can be accessed at:
URL: http://164.90.185.174:3010/
- Create a
.envfile in the root directory of the project with the following structure:
NODE_ENV=testing
PORT=3009
YOUTUBE_API_KEY=your_youtube_api_key
YOUTUBE_VIDEO_DETAILS_URL=/videos?part=snippet,statistics&id=VIDEO_ID&key=API_KEY
YOUTUBE_VIDEO_COMMENTS_URL=/commentThreads?part=snippet&videoId=VIDEO_ID&key=API_KEY
YOUTUBE_BASE_URL=https://www.googleapis.com/youtube/v3
REDIS_HOST=your_redis_host
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
SWAGGER_USER=your_swagger_username
SWAGGER_PASSWORD=your_swagger_password
VIDEO_DETAILS_CACHE_EXPIRY_TIME=600
VIDEO_COMMENTS_CACHE_EXPIRY_TIME=3600
RATE_LIMIT_WINDOW_SEC=3600
RATE_LIMIT_MAX=100
Replace the placeholder values with your actual configuration.
The project uses GitHub Actions for CI/CD. The workflow is defined in .github/workflows/main.yml. It includes steps for testing and deploying the application.
To set up the workflow:
- Go to your GitHub repository settings.
- Navigate to "Secrets and variables" > "Actions".
- Add the following secrets:
SERVER_IP: Your server's IP addressSERVER_USERNAME: SSH username for your serverSERVER_PASSWORD: SSH password for your server- All the environment variables from your
.envfile (e.g.,NODE_ENV,PORT,YOUTUBE_API_KEY, etc.)
The project includes a Dockerfile and a docker-compose.yml file for containerization.
To build and run the Docker container:
docker build -t codematic-youtube-backend .
docker run -p 3009:3009 --env-file .env codematic-youtube-backendTo run with Docker Compose:
docker-compose up -dTo run the project locally without Docker:
-
Install dependencies:
npm install
-
Start the development server:
npm run start:dev
The application will be available at http://localhost:3009.
The project includes a test suite. To run the tests:
npm run testTo run tests with coverage:
npm run test:covThe test coverage results will be available in the coverage directory after running npm run test:cov.
The application implements rate limiting to prevent abuse. The rate limit is configured in the .env file:
RATE_LIMIT_WINDOW_SEC: The time window in secondsRATE_LIMIT_MAX: The maximum number of requests allowed within the time window
The rate limiting is implemented using a guard (RateLimitGuard) that checks the request rate for each IP address.
- The project uses NestJS as its framework.
- Redis is used for caching to improve performance and reduce load on the YouTube API.
- The application is configured to run on port 3009 by default, but this can be changed in the
.envfile. - Make sure to keep your YouTube API key and other sensitive information secure and never commit them to version control.
For any additional help or information, please refer to the official NestJS documentation.