Fill in these first
- Language and framework: [e.g. PHP 8.3 with Laravel, or Node.js with Express]
- Database: [e.g. MySQL 8]
- Roles needed: [e.g. owner, admin, editor, viewer, support agent]
- Resources and actions: [e.g. articles: create, edit own, edit any, publish, delete; users: invite, change role; billing: view, change plan]
- Ownership rules: [e.g. an editor may edit only articles they created]
- Current auth: [e.g. session login with a users table, no roles yet]
Task
Build access control that denies by default and grants only what the matrix allows, including ownership checks.
Output format
- Permission matrix: | Permission | owner | admin | editor | viewer | ... |, with permissions named as resource.action.
- Schema: roles, permissions, role_permissions and user_roles tables, with keys and indexes, plus a migration.
- Seed data that loads the matrix.
- A single authorise function or policy class: given a user, a permission and an optional resource, return allow or deny, checking ownership where the matrix says "own".
- Middleware or route guard that calls it on every protected route and returns 403 with a plain message on deny.
- A cached lookup of a user's permissions per request, and how the cache clears when a role changes.
- Tests: at least one allowed and one forbidden request per role, plus the ownership edge case and a user with no role.
Rules
- Deny by default: a route with no permission set returns 403, never 200.
- Check permissions on the server for every action; hiding a button in the UI is not access control.
- Role changes are logged with who changed what and when.
- Never let a user grant a role higher than their own.






