Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.9 KB

File metadata and controls

50 lines (36 loc) · 1.9 KB

OPA project structure

This document describes the folder layout and how to extend it.


Current layout

opa-project/
├── docker-compose.yml      # Run OPA with policies mounted
├── policies/               # Rego policy files (all loaded automatically)
│   ├── policy.rego         # authz package
│   └── rbac.rego           # rbac package
├── scripts/                # Helper scripts
│   └── run-project.sh
└── docs/                   # Documentation
    ├── project-structure.md
    └── run-and-test-with-postman.md

Why this structure

Folder / file Purpose
policies/ All .rego files live here. Add more files (e.g. rbac.rego, org.rego) and load them via bundle or multiple run arguments. Keeps policy code separate from tooling.
scripts/ One-off or helper scripts (run, build, test). Keeps the repo root clean.
docs/ Guides and references.
docker-compose.yml At root so docker compose works from the project root without extra config.

Adding more policies

  1. Add new .rego files under policies/ (e.g. policies/org.rego).
  2. OPA loads the whole policies/ directory, so new files are picked up automatically.
  3. Restart: docker compose down && docker compose up -d.
  4. Query via POST /v1/data/<package>/<rule> — the package name matches the package declaration in your .rego file.

Optional additions (as you grow)

  • tests/ or policies/*_test.rego — OPA test files (opa test policies/).
  • data/ — Static JSON/YAML that policies reference (e.g. role mappings), loaded via --data or bundle.
  • .opa/ or config.yaml — OPA config for discovery, caching, etc., when you need it.

For a single policy and Docker-based run, the current structure is enough; add the above when you introduce more policies or automation.