{"id":50454174,"url":"https://github.com/mizcausevic-dev/haskell-policy-engine","last_synced_at":"2026-06-01T01:05:43.253Z","repository":{"id":357298436,"uuid":"1236309059","full_name":"mizcausevic-dev/haskell-policy-engine","owner":"mizcausevic-dev","description":"Type-safe policy DSL in Haskell. Algebraic data type Policy = Allow | Deny | When; predicates compose via And/Or/Not; pure total evaluator; Aeson JSON codec; Hspec + QuickCheck tests. Functional purity flex for the agent-governance theme.","archived":false,"fork":false,"pushed_at":"2026-05-12T06:20:21.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-12T08:27:37.134Z","etag":null,"topics":["access-control","aeson","ai-governance","dsl","functional-programming","haskell","hspec","platform-engineering","policy-engine","quickcheck"],"latest_commit_sha":null,"homepage":"https://github.com/mizcausevic-dev/haskell-policy-engine","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mizcausevic-dev.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-12T06:14:26.000Z","updated_at":"2026-05-12T06:20:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mizcausevic-dev/haskell-policy-engine","commit_stats":null,"previous_names":["mizcausevic-dev/haskell-policy-engine"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mizcausevic-dev/haskell-policy-engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fhaskell-policy-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fhaskell-policy-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fhaskell-policy-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fhaskell-policy-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mizcausevic-dev","download_url":"https://codeload.github.com/mizcausevic-dev/haskell-policy-engine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fhaskell-policy-engine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33755379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"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":["access-control","aeson","ai-governance","dsl","functional-programming","haskell","hspec","platform-engineering","policy-engine","quickcheck"],"created_at":"2026-06-01T01:05:43.190Z","updated_at":"2026-06-01T01:05:43.246Z","avatar_url":"https://github.com/mizcausevic-dev.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# haskell-policy-engine\n\nA small **type-safe policy DSL in Haskell** with a pure evaluator, an Aeson JSON codec, and Hspec + QuickCheck tests.\n\nPolicies are an algebraic data type:\n\n```haskell\ndata Policy\n  = Allow                                -- admit unconditionally\n  | Deny  Text                           -- reject with a textual reason\n  | When  Predicate Policy Policy        -- branch on a predicate\n```\n\nPredicates compose via `PAnd`, `POr`, `PNot`, plus atoms for country membership and bucket comparisons (`PCountryIn`, `PBucketBelow`, `PBucketAtLeast`). The `evaluate` function is total — no IO, no exceptions — so policies are trivially fuzzable and reproducible.\n\n## Quickstart\n\n```bash\nstack build\nstack test\nstack exec policy-cli\n```\n\n`stack exec policy-cli` output:\n\n```\n== policy as JSON ==\n{\"kind\":\"when\",\"predicate\":{\"op\":\"country_in\",\"countries\":[\"KP\",\"IR\"]}, ...}\n\n== evaluations ==\nUS-allow:     DAllow\nKP-geo-deny:  DDeny \"geo_blocked\"\nUS-rate-deny: DDeny \"rate_limit_exhausted\"\nDE-eu-audit:  DDeny \"audit_required_for_eu_traffic\"\n\n== round-trip via JSON ==\ndecoded policy on US-allow input: DAllow\n```\n\n## Library usage\n\n```haskell\nimport qualified Data.Map.Strict as Map\nimport           Policy\n\nmyPolicy :: Policy\nmyPolicy =\n  whenPred (PCountryIn [\"KP\", \"IR\"])\n    (deny \"geo_blocked\")\n    (whenPred (PBucketAtLeast \"rate\" 1)\n       allow\n       (deny \"rate_limit_exhausted\"))\n\nmain :: IO ()\nmain = do\n  let inp = Input \"US\" (Map.fromList [(\"rate\", 10)])\n  print (evaluate myPolicy inp)   -- DAllow\n```\n\n## JSON serialization\n\nAeson handles encoding / decoding for `Policy`, `Predicate`, `Decision`, and `Input`. The wire format uses tagged objects:\n\n```json\n{\n  \"kind\": \"when\",\n  \"predicate\": { \"op\": \"country_in\", \"countries\": [\"KP\", \"IR\"] },\n  \"then\": { \"kind\": \"deny\", \"reason\": \"geo_blocked\" },\n  \"else\": { \"kind\": \"allow\" }\n}\n```\n\n## Tests\n\nHspec test suite covers:\n\n- Allow / Deny base cases\n- Country block / rate exhaustion / safe-country happy path\n- Text equality (case-sensitivity disclosure)\n- JSON round-trip for `Policy` and `Decision`\n- `PAnd` / `POr` / `PNot` combinator semantics\n- QuickCheck properties: `evaluate` is total over generated `Deny` policies; `Allow` ignores the input\n\n## Why this design?\n\nA free-monad EDSL or a final-tagless interpreter gives more abstract power, but the closed sum-type `Policy` is **easier to serialize, easier to teach, and easier to audit** — which is what an access-control policy DSL actually needs.\n\n## Dependencies\n\n- `aeson` ≥ 2.0 — JSON codec\n- `containers` ≥ 0.6 — `Data.Map.Strict`\n- `text`, `bytestring` — stdlib\n- `hspec`, `QuickCheck` — test-only\n\n## License\n\nAGPL-3.0.\n\n---\n\n**Connect:** [LinkedIn](https://www.linkedin.com/in/mirzacausevic/) · [Kinetic Gain](https://kineticgain.com) · [Medium](https://medium.com/@mizcausevic/) · [Skills](https://mizcausevic.com/skills/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizcausevic-dev%2Fhaskell-policy-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmizcausevic-dev%2Fhaskell-policy-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizcausevic-dev%2Fhaskell-policy-engine/lists"}