This project provides a clustering service for managing objects and their associated values, leveraging both in-memory and Redis data models. It includes functionalities for adding objects, computing recommendations, and finding common values. The project also integrates linting with TSLint, testing with Jest, and continuous integration with GitHub Actions.
- Add objects and their associated values.
- Compute and update recommendations for values.
- Find the most common values associated with a target value or an object.
- In-memory and Redis-based data models.
- Continuous integration with GitHub Actions.
- Linting with TSLint.
- Overview
- Features
- Table of Contents
- Setup
- Usage
- Testing
- Linting
- Continuous Integration
- Contributing
- License
- Node.js (version 16.x or 18.x recommended)
- Redis (optional, for Redis data model)
-
Clone the repository:
git clone https://github.com/ofirelarat/recommendations-api.git cd clustering-service
-
Install dependencies:
npm install
-
Set up Redis (optional, if using Redis data model):
- Install Redis locally or run it using Docker:
docker run --name redis -p 6379:6379 -d redis:alpine
Example of using the clustering service with the in-memory data model:
import { InMemoryDataModel } from './repositories/InMemoryDataModel';
import { ClusteringService } from './ClusteringService';
const dataModel = new InMemoryDataModel();
const clusteringService = new ClusteringService(dataModel);
// Add objects
await clusteringService.addObject({ id: '1', values: ['a', 'b', 'c'] });
await clusteringService.addObject({ id: '2', values: ['b', 'd'] });
// Add range of values
await clusteringService.addRange('1', ['d', 'e']);
// Find common values
const commonValues = await clusteringService.findMostCommonValues('a', 2);
console.log(commonValues); // Output: ['b', 'c']
Example of using the clustering service with the Redis data model:
import Redis from 'ioredis';
import { RedisDataModel } from './repositories/RedisDataModel';
import { ClusteringService } from './ClusteringService';
const redisClient = new Redis();
const dataModel = new RedisDataModel(redisClient);
const clusteringService = new ClusteringService(dataModel);
// Add objects
await clusteringService.addObject({ id: '1', values: ['a', 'b', 'c'] });
await clusteringService.addObject({ id: '2', values: ['b', 'd'] });
// Add range of values
await clusteringService.addRange('1', ['d', 'e']);
// Find common values
const commonValues = await clusteringService.findMostCommonValues('a', 2);
console.log(commonValues); // Output: ['b', 'c']
// Disconnect Redis
redisClient.disconnect();
- Ensure Docker and Docker Compose are installed on your machine.
- Navigate to
./sample/
dir - Run the following command to build and start the services:
docker-compose up --build
This command will build the Docker images for both the frontend and backend, start the services, and set up the necessary dependencies.
Accessing the Sample App Backend API: The backend API will be accessible at http://localhost:5000. Frontend Application: The frontend application will be accessible at http://localhost:3000.
If you would link to test changes in the src code using the sample app use npm link
to create local version of the lib and run the backend manually with the new version using build & start commands
To run the tests, use the following command:
npm test
This project uses GitHub Actions for continuous integration. The workflow is defined in .github/workflows/test.yml.
.github/workflows/test.yml
.
To run TSLint, use the following command:
npm run lint
TSLint is configured in tslint.json
. You can customize the linting rules according to your project's requirements.
The GitHub Actions workflow is set up to run on pull requests to the main branch. It includes steps for linting, building, and testing the project.
The workflow file is located at .github/workflows/test.yml.
We welcome contributions to this project. To contribute:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
Please ensure your code adheres to the project's coding standards and passes all tests.
This project is licensed under the MIT License. See the LICENSE file for details.