{"id":20875274,"url":"https://github.com/awakelife93/ddd-with-specification-pattern","last_synced_at":"2026-04-28T02:31:14.136Z","repository":{"id":212615502,"uuid":"731915596","full_name":"awakelife93/ddd-with-specification-pattern","owner":"awakelife93","description":"DDD Architecture + Specification pattern","archived":false,"fork":false,"pushed_at":"2023-12-17T09:33:51.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-28T19:45:35.270Z","etag":null,"topics":["ddd","ddd-architecture","design-patterns","nodejs","spec","specification","specification-by-example","specification-pattern"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/awakelife93.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-15T07:23:45.000Z","updated_at":"2023-12-15T07:32:08.000Z","dependencies_parsed_at":"2023-12-17T10:29:56.369Z","dependency_job_id":null,"html_url":"https://github.com/awakelife93/ddd-with-specification-pattern","commit_stats":null,"previous_names":["awakelife93/ddd-specification-pattern"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/awakelife93/ddd-with-specification-pattern","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awakelife93%2Fddd-with-specification-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awakelife93%2Fddd-with-specification-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awakelife93%2Fddd-with-specification-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awakelife93%2Fddd-with-specification-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awakelife93","download_url":"https://codeload.github.com/awakelife93/ddd-with-specification-pattern/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awakelife93%2Fddd-with-specification-pattern/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32363625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"online","status_checked_at":"2026-04-28T02:00:07.250Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ddd","ddd-architecture","design-patterns","nodejs","spec","specification","specification-by-example","specification-pattern"],"created_at":"2024-11-18T06:43:35.926Z","updated_at":"2026-04-28T02:31:14.117Z","avatar_url":"https://github.com/awakelife93.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Example DDD + Specification Design Pattern\n\nThis project is based on the DDD + Specification pattern.\\\nAdd as many comparison logics as necessary for various logics or domains at the abstract level.\n\n### [Demo](example.ts)\n\nThe example only uses **AND logic**, but **OR** and **NOT** can also be used if necessary.\n\n- npm i or npm install\n- npm run example\n\n```typescript\nconst currentProduct = new Product(\"book\", 1000, 0);\nconst currentOrder = new Order(currentProduct, 1, 1000);\nconst wrongProduct = new Product(\"book\", 0, 0);\nconst wrongOrder = new Order(wrongProduct, 0, 0);\n\nconst productPriceMustBeGreaterZeroSpecification =\n  new ProductPriceMustBeGreaterZeroSpecification();\nconst productNameIsNotBlankSpecification =\n  new ProductNameIsNotBlankSpecification();\nconst productDiscountWithinLimitSpecification =\n  new ProductDiscountWithinLimitSpecification();\n\nconst orderPriceConsistencySpecification =\n  new OrderPriceConsistencySpecification();\nconst orderQuantityMustBeGreaterZeroSpecification =\n  new OrderQuantityMustBeGreaterZeroSpecification();\n\nconst productAndSpecification = productPriceMustBeGreaterZeroSpecification\n  .and(productNameIsNotBlankSpecification)\n  .and(productDiscountWithinLimitSpecification);\n\nconst orderAndSpecification = orderPriceConsistencySpecification.and(\n  orderQuantityMustBeGreaterZeroSpecification\n);\n\n// true\nconst currentProductOutput =\n  productAndSpecification.isSatisfiedBy(currentProduct);\nconsole.log(`currentProductOutput = ${currentProductOutput}`);\n\n// true\nconst currentOrderOutput = orderAndSpecification.isSatisfiedBy(currentOrder);\nconsole.log(`currentOrderOutput = ${currentOrderOutput}`);\n\n// false\nconst wrongProductOutput = productAndSpecification.isSatisfiedBy(wrongProduct);\nconsole.log(`wrongProductOutput = ${wrongProductOutput}`);\n\n// false\nconst wrongOrderOutput = orderAndSpecification.isSatisfiedBy(wrongOrder);\nconsole.log(`wrongOrderOutput = ${wrongOrderOutput}`);\n```\n\n### [Specification](Specification.ts)\n\nThis project is composed of and, or, and not.\n\n```typescript\ninterface Specification\u003cT\u003e {\n  isSatisfiedBy(candidate: T): boolean;\n}\n\nabstract class CompositeSpecification\u003cT\u003e implements Specification\u003cT\u003e {\n  abstract isSatisfiedBy(candidate: T): boolean;\n\n  and(specification: CompositeSpecification\u003cT\u003e): CompositeSpecification\u003cT\u003e {\n    return new AndSpecification\u003cT\u003e(this, specification);\n  }\n\n  or(specification: CompositeSpecification\u003cT\u003e): CompositeSpecification\u003cT\u003e {\n    return new OrSpecification\u003cT\u003e(this, specification);\n  }\n\n  not(): NotSpecification\u003cT\u003e {\n    return new NotSpecification\u003cT\u003e(this);\n  }\n}\n```\n\n### Example Domain \u0026 Specification\n\n- [Order](domain/order/Order.ts)\n  - OrderPriceConsistencySpecification\n  - OrderQuantityMustBeGreaterZeroSpecification\n\n```typescript\n/**\n * @class OrderPriceConsistencySpecification\n * @description\n * The order price cannot exceed or be less than the total sum of the product price and discount price.\n */\nclass OrderPriceConsistencySpecification extends CompositeSpecification\u003cOrder\u003e {\n  isSatisfiedBy(candidate: Order): boolean {\n    if (!candidate) return false;\n\n    const totalPrice =\n      candidate.quantity *\n      (candidate.product.price - candidate.product.discountPrice);\n\n    return candidate.totalPrice === totalPrice;\n  }\n}\n\n/**\n * @class OrderQuantityMustBeGreaterZeroSpecification\n * @description\n * This specification ensures that the order quantity must be greater than zero.\n */\nclass OrderQuantityMustBeGreaterZeroSpecification extends CompositeSpecification\u003cOrder\u003e {\n  isSatisfiedBy(candidate: Order): boolean {\n    if (!candidate) return false;\n\n    return candidate.quantity \u003e 0;\n  }\n}\n```\n\n- [Product](domain/product/Product.ts)\n  - ProductPriceMustBeGreaterZeroSpecification\n  - ProductNameIsNotBlankSpecification\n  - ProductDiscountWithinLimitSpecification\n\n```typescript\n/**\n * @class ProductPriceMustBeGreaterZeroSpecification\n * @description\n * The price of the product must always be greater than 0.\n */\nclass ProductPriceMustBeGreaterZeroSpecification extends CompositeSpecification\u003cProduct\u003e {\n  isSatisfiedBy(candidate: Product): boolean {\n    if (!candidate) return false;\n\n    return candidate.price \u003e 0;\n  }\n}\n\n/**\n * @class ProductNameIsNotBlankSpecification\n * @description\n * The product name cannot be blank.\n */\nclass ProductNameIsNotBlankSpecification extends CompositeSpecification\u003cProduct\u003e {\n  isSatisfiedBy(candidate: Product): boolean {\n    if (!candidate) return false;\n\n    return candidate.name.length \u003e 0;\n  }\n}\n\n/**\n * @class ProductDiscountWithinLimitSpecification\n * @description\n * The discounted price of a product cannot be greater than the normal price.\n */\nclass ProductDiscountWithinLimitSpecification extends CompositeSpecification\u003cProduct\u003e {\n  isSatisfiedBy(candidate: Product): boolean {\n    if (!candidate) return false;\n\n    return candidate.discountPrice \u003c candidate.price;\n  }\n}\n```\n\n### Author\n\nHyunwoo Park\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawakelife93%2Fddd-with-specification-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawakelife93%2Fddd-with-specification-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawakelife93%2Fddd-with-specification-pattern/lists"}