{"id":27700881,"url":"https://github.com/luizcurti/api-product-search","last_synced_at":"2026-04-12T00:39:15.428Z","repository":{"id":289572066,"uuid":"971701236","full_name":"luizcurti/api-product-search","owner":"luizcurti","description":"REST API for product search, built with Node.js, Express, and MongoDB.","archived":false,"fork":false,"pushed_at":"2025-04-24T00:11:08.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T19:06:47.021Z","etag":null,"topics":["docker","docker-compose","kubernetes","mongodb","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luizcurti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-23T23:42:46.000Z","updated_at":"2025-04-24T00:13:23.000Z","dependencies_parsed_at":"2025-04-24T00:34:14.187Z","dependency_job_id":"4029fec0-2095-4183-b083-a8ab2ec7732f","html_url":"https://github.com/luizcurti/api-product-search","commit_stats":null,"previous_names":["luizcurti/api-product-search"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizcurti%2Fapi-product-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizcurti%2Fapi-product-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizcurti%2Fapi-product-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizcurti%2Fapi-product-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luizcurti","download_url":"https://codeload.github.com/luizcurti/api-product-search/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250878875,"owners_count":21501742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","kubernetes","mongodb","nodejs","typescript"],"created_at":"2025-04-25T19:07:03.000Z","updated_at":"2026-04-12T00:39:15.420Z","avatar_url":"https://github.com/luizcurti.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📦 Product Stock Search API\n\n**Product Stock Search** is a simple API for managing and searching Stock Keeping Unit (SKU) information. It allows users to search for specific products and retrieve a complete list of all registered items. This API is ideal for integration with inventory management systems, e-commerce platforms, or other logistics solutions.\n\n### ⚠️ Disclaimer\n\nThis project is **not** intended to be a full-featured production API.  \nIt is a **simple demonstration** of how to structure a TypeScript-based Node.js API using:\n\n- MongoDB for persistence  \n- Jest for unit testing  \n- Joi for request validation  \n- Docker \u0026 Docker Compose for containerization  \n- Kubernetes\n\nThe goal is to showcase clean code organization, basic error handling, and how different technologies can work together in a small backend service.\n\n\n---\n\n## ✨ Features\n\n- **🔍 Search Product** (`GET /product/:productId`) — Search for a specific product by its ID and receive details about stock, orders, and refunds. The `productId` parameter is validated with Joi (alphanumeric, hyphens and underscores only).\n- **📋 List All Products** (`GET /product/`) — Returns a list of all registered products with their current stock.\n\n---\n\n## 🛠 Technologies\n\n- Node.js  \n- TypeScript  \n- Express.js  \n- MongoDB / Mongoose  \n- Joi (request validation)  \n- Jest  \n- Docker  \n- Docker Compose  \n- Kubernetes\n\n---\n\n## � API Endpoints\n\n### `GET /product/:productId`\n\nReturns stock and transaction details for a specific product.\n\n**URL params:**\n- `productId` (required) — alphanumeric string, hyphens and underscores allowed (validated with Joi)\n\n**Success response `200`:**\n```json\n{\n  \"productId\": \"QQO675265-24-21\",\n  \"originalValue\": 100,\n  \"order\": 15,\n  \"refund\": 3,\n  \"stockNumber\": 88\n}\n```\n\n**Validation error `400`:**\n```json\n{\n  \"error\": \"productId must contain only alphanumeric characters, hyphens or underscores.\"\n}\n```\n\n**Not found `404`:**\n```json\n{\n  \"error\": \"Product not found.\"\n}\n```\n\n---\n\n### `GET /product/`\n\nReturns the full list of products with their current stock.\n\n**Success response `200`:**\n```json\n[\n  { \"productId\": \"QQO675265-24-21\", \"stock\": 100 },\n  { \"productId\": \"LTV719449-39-39\", \"stock\": 50 }\n]\n```\n\n**Not found `404`:**\n```json\n{\n  \"error\": \"No items found in stock.\"\n}\n```\n\n---\n\n## �🚀 Getting Started\n\n### ✅ Using Docker\n\n1. **Clone the repository:**\n   ```bash\n   git clone https://github.com/luizcurti/api-product-search.git\n   cd api-product-search\n    ```\n\n### ✅ Running with Docker Compose\n2. **Build and start the application using Docker Compose:**\n   ```bash\n    docker-compose up --build\n    ```\n\nThis will start the following services:\n\n- MongoDB (for data persistence)\n- Node.js application (your Product Stock Search API)\n- A seed process to initialize the database\n\nThe application will be accessible at http://localhost:3000 and MongoDB will be accessible at localhost:27017.\n\n### ✅ Deploying to Kubernetes\nIf you want to deploy the application to a Kubernetes cluster, follow the steps below:\n\n1. **Ensure your Kubernetes cluster is up and running (you can use Minikube, Docker Desktop, or Kind).**\n- For Minikube, use:\n   ```bash\n    minikube start\n   ```\n- For Kind, use:\n   ```bash\n    kind create cluster\n   ```\n- For Docker Desktop, make sure Kubernetes is enabled in the Docker Desktop settings.\n\n2. **Apply the Deployment and Service YAML file to Kubernetes:**\nEnsure your cluster is configured correctly (check the context with kubectl config current-context).\n   ```bash\n    kubectl apply -f deployment.yaml\n   ```\n\nThis will:\n- Create a Deployment with 10 replicas of the Node.js application.\n- Create a Service of type LoadBalancer to expose your app.   \n\n3. **Check if the pods are running correctly:**\n   ```bash\n    kubectl get pods\n   ```\n\nThis will list the pods running for your application. You should see something like this:\n   ```bash\n    NAME                                  READY   STATUS    RESTARTS   AGE\n    productidsearch-deployment-xxxxxxxx   1/1     Running   0          5m\n    productidsearch-deployment-xxxxxxxx   1/1     Running   0          5m\n   ```\n4. **Access your application:**\n\n- If you're using Minikube, run the following command to access your app:\n   ```bash\n   minikube service productidsearch-service\n   ```\nThis will open a browser window with your app's endpoint.\n- Alternatively, you can use kubectl port-forward to forward a port to your local machine:\n   ```bash\n   kubectl port-forward service/productidsearch-service 8080:80\n   ```\n\n### 📈 Load Testing\nTo run a simple load test using [k6](https://k6.io/):\n  ```bash\n  k6 run src/tests/k6LoadTest.js\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizcurti%2Fapi-product-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluizcurti%2Fapi-product-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizcurti%2Fapi-product-search/lists"}