The model backend developed in Rust/Actix web as example for my article
This project follows a consistent naming convention for service and handler functions to ensure clarity and maintainability. These conventions are applied across all resources (e.g., users, projects, skills, etc.).
Service functions perform the core business logic and interact with the database or other backend services. They are named using action verbs that describe their operations. Here are the common naming conventions used in the service layer:
- fetch_resource_by_id: Retrieve a single resource by its ID (e.g.,
fetch_user_by_id,fetch_project_by_id). - remove_resource: Delete a single resource by its ID (e.g.,
remove_user,remove_project). - create_resource: Add a new resource to the system (e.g.,
create_user,create_project). - update_resource: Modify an existing resource by its ID (e.g.,
update_user,update_project). - list_resources: List all resources (e.g.,
list_users,list_projects).
we'll use terms that describe the specific business logic actions related to it.
E.g:
- register_resource: Register a new resource (e.g.,
register_user). - login_resource: Authenticate a resource, typically used for user authentication (e.g.,
login_user). - reset_resource_password: Reset the password for a resource, typically used for user password resets (e.g.,
reset_user_password). - validate_resource_email: Validate the email of a resource, typically used for user email validation (e.g.,
validate_user_email). - forgot_resource_password: Send a password reset link for a resource, typically used for user password resets (e.g.,
forgot_user_password).
Handler functions deal with HTTP requests and responses. They are named according to the HTTP methods they handle and are prefixed with the HTTP method name to clearly indicate their purpose. Here are the common naming conventions used in the handler layer:
- get_resource: Handle HTTP GET request to retrieve a single resource by its ID (e.g.,
get_user,get_project). - delete_resource: Handle HTTP DELETE request to delete a single resource by its ID (e.g.,
delete_user,delete_project). - post_resource: Handle HTTP POST request to create a new resource (e.g.,
post_user,post_project). - put_resource: Handle HTTP PUT request to update an existing resource by its ID (e.g.,
put_user,put_project). - get_all_resources: Handle HTTP GET request to list all resources (e.g.,
get_all_users,get_all_projects).
- post_register: Handle HTTP POST request for resource registration (e.g.,
post_register_user). - post_login: Handle HTTP POST request for resource login (e.g.,
post_login_user). - post_reset_password: Handle HTTP POST request to reset the resource's password (e.g.,
post_reset_user_password). - get_validate_email: Handle HTTP GET request for resource email validation (e.g.,
get_validate_user_email). - post_forgot_password: Handle HTTP POST request to initiate a password reset process for the resource (e.g.,
post_forgot_user_password).
By following these conventions, we ensure that our codebase is organized, readable, and maintainable. These naming conventions help quickly identify the purpose of each function and its layer within the application, facilitating easier collaboration and faster onboarding of new developers.