Role Directory Structure - CrewAI
Introduction to Role Directory Structure
In CrewAI, roles are a fundamental concept used to define permissions and responsibilities. Understanding the directory structure for roles is crucial for managing and organizing your role-based access control (RBAC) system effectively.
Basic Directory Structure
The basic directory structure for roles in CrewAI is organized to separate different aspects of role management. Here is a simple example of what the directory structure might look like:
roles/ ├── admin/ │ ├── permissions.json │ ├── users.json ├── editor/ │ ├── permissions.json │ ├── users.json ├── viewer/ │ ├── permissions.json │ ├── users.json
Each role (e.g., admin, editor, viewer) has its own directory containing JSON files that define the permissions and associated users for that role.
Permissions File
The permissions.json
file within each role directory defines what actions users assigned to that role can perform. Here is an example of a permissions.json
file for the admin role:
{ "permissions": [ "create_user", "delete_user", "update_settings", "view_reports" ] }
This file lists all the permissions granted to the admin role. Each permission is represented as a string within the permissions array.
Users File
The users.json
file within each role directory specifies which users are assigned to that role. Here is an example of a users.json
file for the admin role:
{ "users": [ "user1@example.com", "user2@example.com" ] }
This file lists the email addresses of users who have been assigned the admin role.
Adding a New Role
To add a new role, create a new directory under the roles
directory and add the necessary permissions.json
and users.json
files. Here is an example of adding a new role called "contributor":
roles/ ├── contributor/ │ ├── permissions.json │ ├── users.json
Populate the permissions.json
and users.json
files with the appropriate data for the contributor role.
Example of Complete Role Directory
Here is an example of a complete role directory structure for a hypothetical CrewAI project:
roles/ ├── admin/ │ ├── permissions.json │ ├── users.json ├── editor/ │ ├── permissions.json │ ├── users.json ├── viewer/ │ ├── permissions.json │ ├── users.json ├── contributor/ │ ├── permissions.json │ ├── users.json
This structure shows multiple roles, each with its own permissions and users defined.
Conclusion
Understanding the role directory structure in CrewAI is essential for managing roles and permissions effectively. By organizing roles in a consistent directory structure, you can easily manage user access and ensure that each role has the appropriate permissions.