{"id":17965907,"url":"https://github.com/artumarinn/discount-service","last_synced_at":"2026-04-04T21:33:14.105Z","repository":{"id":259521748,"uuid":"877344388","full_name":"artumarinn/discount-service","owner":"artumarinn","description":"The Discount Service project is a microservice designed to manage discounts within an application through a RESTful API. ","archived":false,"fork":false,"pushed_at":"2025-01-07T18:52:56.000Z","size":4326,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-16T13:01:43.213Z","etag":null,"topics":["docker","docker-compose","express","microservice","nodejs","postgresql"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/artumarinn.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}},"created_at":"2024-10-23T13:47:22.000Z","updated_at":"2025-01-07T18:52:59.000Z","dependencies_parsed_at":"2024-10-26T06:52:29.017Z","dependency_job_id":"b2612355-794d-445b-b681-f9e3ae473f03","html_url":"https://github.com/artumarinn/discount-service","commit_stats":{"total_commits":17,"total_committers":2,"mean_commits":8.5,"dds":0.4117647058823529,"last_synced_commit":"efe242052a9ba31600aa6b96b7780390469f1c51"},"previous_names":["artumarinn/discount-service"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/artumarinn/discount-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artumarinn%2Fdiscount-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artumarinn%2Fdiscount-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artumarinn%2Fdiscount-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artumarinn%2Fdiscount-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artumarinn","download_url":"https://codeload.github.com/artumarinn/discount-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artumarinn%2Fdiscount-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31415110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","express","microservice","nodejs","postgresql"],"created_at":"2024-10-29T13:06:01.159Z","updated_at":"2026-04-04T21:33:14.076Z","avatar_url":"https://github.com/artumarinn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## Overview\n\nThe Discount Service is a microservice that provides an efficient way to manage discounts within a broader application through a RESTful API. It enables users to create, retrieve, update, and delete discount records stored in a PostgreSQL database. Designed to be modular, scalable, and easy to deploy, this service is containerized using Docker, ensuring consistent performance across various environments.\n\nThis microservice is ideal for e-commerce platforms, retail management systems, or any application requiring a robust discount management feature. By decoupling the discount functionality into its own microservice, it allows for easier maintenance, scaling, and integration with other services within the larger application ecosystem.\n\n## 🚀 Features\n\n- **Create Discounts**: Add new discounts with name and percentage.\n- **Retrieve Discounts**: Fetch all existing discounts.\n- **Update Discounts**: Modify existing discounts.\n- **Delete Discounts**: Remove discounts from the database.\n\n## 🛠 Tech Stack\n\n- **Node.js**: JavaScript runtime for building scalable network applications.\n- **Express**: Web framework for Node.js to build APIs quickly and easily.\n- **PostgreSQL**: Powerful, open-source relational database management system.\n- **Docker**: Platform for developing, shipping, and running applications in containers.\n\n## 📁 Project Structure\n\n```\ndiscount-service/\n│\n├── config/\n│   └── database.js             # Database connection configuration\n│\n├── controllers/\n│   └── discountController.js   # Logic for handling discount requests\n│\n├── models/\n│   └── discountModel.js        # Database queries related to discounts\n│\n├── routes/\n│   └── discountRoutes.js       # Routes for the discount API\n│\n├── .env                        # Environment variables\n├── .gitignore                  # Specifies ignored files\n├── Dockerfile                  # Docker image instructions\n├── docker-compose.yml          # Docker services configuration\n└── app.js                      # Application entry point\n```\n\n## 📄 File Descriptions\n\n### `config/database.js`\nContains PostgreSQL database connection configuration using the `pg` library, with connection details from environment variables.\n\n### `controllers/discountController.js`\nManages incoming HTTP requests for discounts with functions to create, retrieve, update, and delete discounts.\n\n### `models/discountModel.js`\nContains database queries for the discounts table with CRUD operations.\n\n### `routes/discountRoutes.js`\nDefines API routes and maps HTTP methods to controller functions.\n\n### `app.js`\nApplication entry point that sets up the Express server, middleware, and routes.\n\n## 📊 How the Discount Service Works\n\n### Diagram Explanation\n\nThe diagram illustrates the flow of requests and data within the Discount Service microservice:\n\n1. **User Interaction**:\n   - Users interact with the system through various interfaces such as web browsers, mobile apps, and back-office web applications.\n\n2. **API Gateway**:\n   - Although the API Gateway is not implemented in this specific setup, it is shown to represent the entry point for user requests. In a full system, the API Gateway would route requests to the appropriate microservices.\n\n3. **Discount Service**:\n   - The Discount Service is the core microservice responsible for managing discount operations. It handles incoming requests to create, retrieve, update, and delete discount records.\n\n4. **PostgreSQL Database**:\n   - The Discount Service communicates with a PostgreSQL database to store and retrieve discount data. This ensures data persistence and allows for efficient querying and manipulation of discount records.\n\n### Workflow\n\n1. **Request Initiation**:\n   - Users send requests to the API Gateway, which would typically route these requests to the appropriate microservices, including the Discount Service.\n\n2. **Processing Requests**:\n   - The Discount Service processes the incoming requests. Depending on the request type (GET, POST, PUT, DELETE), it performs the necessary operations such as creating, retrieving, updating, or deleting discount records.\n\n3. **Database Interaction**:\n   - The Discount Service interacts with the PostgreSQL database to store or retrieve discount data. This ensures that all discount-related operations are backed by a reliable database system.\n\n4. **Response Generation**:\n   - After processing the request and interacting with the database, the Discount Service generates a response and sends it back to the user through the API Gateway.\n\nBy following this architecture and workflow, the Discount Service ensures a modular, scalable, and efficient way to manage discounts within a broader application ecosystem.\n\n## 🚀 Deployment Instructions\n\n### Prerequisites\n- Docker and Docker Compose installed\n\n### Setup Steps\n\n1. **Clone the Repository**\n   ```bash\n   git https://github.com/artumarinn/discount-service.git\n   cd discount-service\n   ```\n\n2. **Configure Environment**\n   Create a `.env` file in the root directory:\n   ```env\n   DB_USER=your_db_user\n   DB_HOST=postgres\n   DB_NAME=discounts\n   DB_PASSWORD=your_db_password\n   DB_PORT=5432\n   ```\n\n3. **Build and Run**\n   ```bash\n   docker-compose up -d\n   ```\n\n4. **Verify Deployment**\n   ```bash\n   docker ps\n   ```\n   You should see both PostgreSQL and Node.js containers running.\n\n5. **Access the API**\n   The API will be available at `http://localhost:3000/api/discounts`\n\n### Stopping the Service\n```bash\ndocker-compose down\n```\n\n## 📜 API Documentation\n\n### Endpoints\n\n### GET `/api/v1`\nRetrieves all existing discounts.\n\n---\n\n### GET `/api/v1/{discount_id}`\nRetrieves a single discount by its ID.\n\n---\n\n### POST `/api/v1`\nCreates a new discount.\n\n---\n\n### PUT `/api/v1/{discount_id}`\nUpdate a discount.\n\n---\n\n### PATCH `/api/v1/invalidate-expired/`\nInvalidates a discount by setting its valid_until date to the current date. This endpoint is used to mark a discount as invalid if it has expired.\n\n**Request body:**\n```\n{\n  \"valid_until\": \"YYYY-MM-DDTHH:MM:SSZ\"\n}\n```\n\n**Responsive:**\n```\n{\n  \"message\": \"Discount invalidated successfully\"\n}\n```\n\n---\n\n### DELETE `/api/v1/{discount_id}`\nDelete a discount.\n\n**Request body:**\n```\n{\n  \"code\": \"string\",\n  \"discountPercent\": \"number\",\n  \"isActive\": \"boolean\"\n}\n```\n\n## 💡 Implementation\n\nThe Discount Service offers a clean and organized architecture:\n\n- **Separation of Concerns**: The project is modular, with clear separation between routes, controllers, and models, facilitating maintenance and scalability.\n- **Environment Management**: Environment variables allow easy configuration without altering the codebase, promoting security and flexibility.\n- **Containerization**: Docker simplifies the deployment process, providing consistency across different systems and reducing setup time.\n\n## 📦 Docker Integration\n\nThe service uses Docker Compose to manage:\n- **PostgreSQL database container**\n- **Node.js application container**\n- **Container networking**\n- **Environment variable management**\n\nThis ensures consistent development and deployment environments across different machines.\n\n## 🔧 Development\n\nThe microservice is built to be extensible. Future improvements could include:\n\n- **Adding authentication** for better security.\n- **Enhancing error handling** and logging.\n- **Integrating with other microservices** for more comprehensive application scenarios.\n- **Implementing caching** to optimize read performance.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartumarinn%2Fdiscount-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartumarinn%2Fdiscount-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartumarinn%2Fdiscount-service/lists"}