Service Types Zome (service_types_integrity, service_types_coordinator)
1. Overview
- Purpose: Manages the lifecycle of
ServiceTypeentries. These entries define the categories or types of services, skills, or resources that can be requested or offered within the application. This zome is crucial for classifying and discovering requests and offers. - Status: Full validation workflow, tag-based discovery, and cross-zome integration operational
- Validation Workflow: Implements a moderation process for
ServiceTypeentries, involving user suggestions, admin review, and approval/rejection states (pending,approved,rejected). Onlyapprovedservice types can be actively used in new requests and offers. - Tag-Based Discovery: Comprehensive tagging system with path anchor indexing for efficient search, filtering, and cross-entity discovery
- Cross-Zome Integration: Full integration with
requests_coordinatorandoffers_coordinatorfor tag-based discovery - Zome Structure:
service_types_integrity: Handles data validation, entry definitions, and link type rules.service_types_coordinator: Provides externally callable functions for business logic, interacting with the integrity zome and managing data flows.
hREA Mapping
In the hREA/ValueFlows ontology, ServiceType entries map to ResourceSpecification (not EconomicResource). A ResourceSpecification defines the type of service — it is a template referenced by Intents inside Proposals. Concrete resource instances (EconomicResource) are never created directly from Service Types; they only arise as the result of Economic Events in a completed exchange lifecycle.
2. Integrity Zome (service_types_integrity)
2.1. Entry Types
ServiceType
The ServiceType entry defines a specific type of service or skill with technical classification.
#![allow(unused)] fn main() { #[hdk_entry_helper] #[derive(Clone, PartialEq)] pub struct ServiceType { pub name: String, // E.g., "Web Development", "Graphic Design", "Childcare" pub description: String, // A brief explanation of the service type (supports markdown, rendered on frontend with `marked` + `DOMPurify`) pub technical: bool, // Technical vs non-technical classification // REMOVED: pub tags: Vec<String> - Tags functionality has been removed as per issue #49 // pub category: Option<String>, // Optional: A broader category, e.g., "Technology", "Creative Arts" // Decision: Currently not implemented, technical field provides classification. } }
2.2. Validation Rules
ServiceTypeEntry:name: Must not be empty. Max length (e.g., 100 chars) can be enforced.description: Must not be empty. Max length (e.g., 500 chars) can be enforced.technical: Boolean field for technical classification (no validation needed).
- Updates/Deletes: Standard Holochain author validation (original author or agent with specific capabilities can update/delete).
2.3. Link Types
-
ServiceTypeStatusAnchorToServiceType- Base:
Pathanchor (e.g.,service_types.status.pending). - Target:
ActionHashof aServiceTypeentry. - Link Tag:
ActionHashof theServiceType(for easy retrieval/deduplication) or aTimestampfor ordering. - Purpose: Connects
ServiceTypeentries to their current validation status (pending,approved,rejected).
- Base:
-
TechnicalClassificationAnchorToServiceType(NEW)- Base:
Pathanchor (e.g.,service_types.classification.technicalorservice_types.classification.non_technical). - Target:
ActionHashof an approvedServiceTypeentry. - Link Tag:
ActionHashof theServiceType. - Purpose: Enables filtering approved service types by technical classification.
- Base:
-
(Implicit)
ServiceTypeUpdates- Holochain automatically links original entry actions to their updates.
REMOVED LINK TYPES :
- Tags functionality completely removedTagAnchorToServiceType- Tags functionality completely removedAllTagsAnchorToTagString
(Note: RequestToServiceType and OfferToServiceType links are defined in their respective zomes but are crucial for understanding how ServiceTypes are consumed. These links should only target approved ServiceType entries.)
3. Coordinator Zome (service_types_coordinator)
3.1. Path Anchors Used
- Status Anchors (Static Paths):
service_types.status.pending: ForServiceTypeentries awaiting admin review.service_types.status.approved: ForServiceTypeentries approved by an admin and usable in requests/offers.service_types.status.rejected: ForServiceTypeentries rejected by an admin.
- Technical Classification Anchors (Static Paths - NEW):
service_types.classification.technical: For indexing technical service types.service_types.classification.non_technical: For indexing non-technical service types.
REMOVED ANCHORS :
- Tags functionality completely removedservice_types.tags.{url_encoded_tag_string}- Tags functionality completely removedservice_types.all_tags
3.2. Key Functions
Input/Output structs (e.g., SuggestServiceTypeInput) are defined in Rust for clarity.
User-Facing Functions
suggest_service_type(input: ServiceType) -> ExternResult<Record>- Description: Allows any authenticated user to suggest a new
ServiceType. - Actions:
- Creates a new
ServiceTypeentry with the providedname,description, andtags. - Links the new
ServiceTypeentry'sActionHashto theservice_types.status.pendinganchor.
- Creates a new
- Access Control: Any valid, authenticated agent.
- Returns: The
Recordof the newly createdServiceTypeentry.
- Description: Allows any authenticated user to suggest a new
Admin-Facing Functions
(Admin role is determined by a separate mechanism, e.g., membership in an admin group or a capability grant.)
- **`admin_create_service_type(input: ServiceType) -> ExternResult<Record>`**
- **Description**: Allows an administrator to directly create and approve a `ServiceType`.
- **Actions**:
1. Creates a new `ServiceType` entry.
2. Links the `ServiceType`'s `ActionHash` to the `service_types.status.approved` anchor.
3. Links the `ServiceType`'s `ActionHash` to the appropriate technical classification anchor:
- `service_types.classification.technical` if `input.technical` is true
- `service_types.classification.non_technical` if `input.technical` is false
- **Access Control**: Admin only.
- **Returns**: The `Record` of the newly created and approved `ServiceType` entry.
-
approve_service_type(service_type_ah: ActionHash) -> ExternResult<ActionHash>- Description: Allows an administrator to approve a
ServiceTypethat is currentlypending(orrejected). - Actions:
- Validates that
service_type_ahpoints to an existingServiceTypeentry. - Removes any existing links from
service_types.status.pendingorservice_types.status.rejectedtoservice_type_ah. - Creates a link from
service_types.status.approvedtoservice_type_ah. - Fetches the
ServiceTypeentry to get its technical classification. - Links
service_type_ahfrom the appropriate technical classification anchor:service_types.classification.technicaliftechnicalis trueservice_types.classification.non_technicaliftechnicalis false
- Validates that
- Access Control: Admin only.
- Returns: The
ActionHashof the approvedServiceType.
- Description: Allows an administrator to approve a
-
reject_service_type(service_type_ah: ActionHash, reason: Option<String>) -> ExternResult<ActionHash>- Description: Allows an administrator to reject a
ServiceType(whetherpendingorapproved). reasonis optional and currently not stored directly on DHT, but could be logged or emitted as a signal.- Actions:
- Validates
service_type_ah. - Removes links from
service_types.status.pendingorservice_types.status.approvedtoservice_type_ah. - Creates a link from
service_types.status.rejectedtoservice_type_ah. - If the
ServiceTypewas previously approved:- Fetches the
ServiceTypeentry to get its technical classification. - Removes links from appropriate technical classification anchors to
service_type_ah. - Crucially: Triggers cross-zome calls or signals to
requests_coordinatorandoffers_coordinatorto handle cleanup of links from existingRequestandOfferentries that referenced thisservice_type_ah. (Requires granted capabilities).
- Fetches the
- Validates
- Access Control: Admin only.
- Returns: The
ActionHashof the rejectedServiceType.
- Description: Allows an administrator to reject a
-
admin_update_service_type(original_action_hash: ActionHash, updated_input: ServiceType) -> ExternResult<Record>- Description: Allows an administrator to update an existing
ServiceType. - Actions:
- Creates an update for the
ServiceTypeentry pointed to byoriginal_action_hash. - The status of the
ServiceType(e.g.,approved) is generally maintained unless explicitly changed by a separate call toapprove_service_typeorreject_service_type. - If the
ServiceTypeisapprovedand technical classification has changed:- Removes links from the old technical classification anchor.
- Adds links to the new technical classification anchor based on
updated_input.technical.
- Creates an update for the
- Access Control: Admin only.
- Returns: The
Recordof the updatedServiceTypeentry (new ActionHash, same EntryHash).
- Description: Allows an administrator to update an existing
-
admin_delete_service_type(original_action_hash: ActionHash) -> ExternResult<ActionHash>- Description: Allows an administrator to delete a
ServiceTypeentry. - Actions:
- Creates a delete action for the entry identified by
original_action_hash. - Removes all links from status anchors (
pending,approved,rejected) to thisServiceType's ActionHash(es). - If the
ServiceTypewasapproved:- Removes all links from technical classification anchors.
- Triggers cross-zome calls/signals for
Request/Offerlink cleanup if it wasapproved.
- Creates a delete action for the entry identified by
- Access Control: Admin only.
- Returns: The
ActionHashof the delete action.
- Description: Allows an administrator to delete a
Getter Functions
-
get_service_type(service_type_ah: ActionHash) -> ExternResult<Option<Record>>- Description: Retrieves a specific
ServiceTypeentry by itsActionHash. - Access Control: Public.
- Returns:
Some(Record)if found,Noneotherwise.
- Description: Retrieves a specific
-
get_pending_service_types() -> ExternResult<Vec<Record>>-
Description: Retrieves all
ServiceTypeentries currently linked to theservice_types.status.pendinganchor. -
Access Control: Admin only.
-
Returns: A vector of
Records. -
get_approved_service_types() -> ExternResult<Vec<Record>> -
Description: Retrieves all
ServiceTypeentries currently linked to theservice_types.status.approvedanchor. -
Access Control: Public (essential for UI selectors, general browsing).
-
Returns: A vector of
Records. -
get_rejected_service_types() -> ExternResult<Vec<Record>> -
Description: Retrieves all
ServiceTypeentries currently linked to theservice_types.status.rejectedanchor. -
Access Control: Admin only.
-
Returns: A vector of
Records. -
get_all_service_types_admin() -> ExternResult<Vec<Record>> -
Description: Retrieves all
ServiceTypeentries regardless of status (combines pending, approved, rejected, or fetches all known entries). -
Access Control: Admin only.
-
Returns: A vector of
Records.
-
Technical Classification Functions
-
get_technical_service_types() -> ExternResult<Vec<Record>>- Description: Retrieves all approved
ServiceTypeentries that are classified as technical. - Access Control: Public.
- Returns: A vector of
Records.
- Description: Retrieves all approved
-
get_non_technical_service_types() -> ExternResult<Vec<Record>>- Description: Retrieves all approved
ServiceTypeentries that are classified as non-technical. - Access Control: Public.
- Returns: A vector of
Records.
- Description: Retrieves all approved
-
get_service_types_by_classification(technical: bool) -> ExternResult<Vec<Record>>- Description: Retrieves all approved
ServiceTypeentries filtered by technical classification. - Access Control: Public.
- Returns: A vector of
Records.
- Description: Retrieves all approved
-
get_classification_statistics() -> ExternResult<(u32, u32)>- Description: Returns count statistics for technical vs non-technical service types.
- Access Control: Public.
- Returns: A tuple containing (technical_count, non_technical_count).
REMOVED FUNCTIONS :
- Tags functionality completely removedget_service_types_by_tag- Tags functionality completely removedget_service_types_by_tags- Tags functionality completely removedsearch_service_types_by_tag_prefix- Tags functionality completely removedget_tag_statistics- Tags functionality completely removedget_all_service_type_tags
Cross-Entity Discovery Functions
-
get_requests_by_classification(technical: bool) -> ExternResult<Vec<Record>>(NEW)- Description: Discovers requests associated with service types that match the technical classification.
- Implementation: Calls
get_service_types_by_classificationthen finds all requests linked to those service types. - Access Control: Public.
- Returns: A vector of Request
Records.
-
get_offers_by_classification(technical: bool) -> ExternResult<Vec<Record>>(NEW)- Description: Discovers offers associated with service types that match the technical classification.
- Implementation: Calls
get_service_types_by_classificationthen finds all offers linked to those service types. - Access Control: Public.
- Returns: A vector of Offer
Records.
REMOVED FUNCTIONS :
- Tags functionality completely removedget_requests_by_tag- Tags functionality completely removedget_offers_by_tag
3.3. Cross-Zome Interactions
-
Called by
requests_coordinatorandoffers_coordinator:- To validate that
ServiceTypeActionHashes provided duringRequest/Offercreation/update correspond to approvedServiceTypes. This is typically done by callingget_service_typeand then checking its linkage to theservice_types.status.approvedanchor, or by ensuring theActionHashis part of the list returned byget_approved_service_types.
- To validate that
-
Calls to
requests_coordinatorandoffers_coordinator:- During
reject_service_typeoradmin_delete_service_type, cross-zome calls are made to clean up links from existingRequestandOfferentries that referenced the affectedServiceType. - Tag-based discovery functions coordinate with both coordinators to provide cross-entity discovery.
- During
4. Testing Status
Backend Tests (Sweettest)
- ✅ Service type CRUD operations and status management
- ✅ Technical classification filtering and indexing
- ✅ Classification statistics and counting
- ✅ Cross-entity discovery by technical classification
- ✅ Admin workflow (suggest, approve, reject)
- ✅ Permission validation and access control
Frontend Integration
- ✅ Effect-TS Service Layer: Complete with all zome functions exposed
- ✅ Reactive Svelte Store: Full state management with caching and event bus
- ✅ UI Components: Complete table layout implementation (ServiceTypesTable.svelte)
- ✅ Technical Classification: Filter and sort controls for technical vs non-technical
- ✅ Admin Interface: Table-based management replacing card layout
- ✅ Cross-Store Integration: Requests and offers stores enhanced with classification-based discovery
- ✅ Test Coverage: All unit tests passing (part of 343 total test suite across 20 files)
5. Implementation Notes
Performance Considerations
- Path anchor indexing provides efficient classification-based queries
- Table layout improves data density and scanning ability
- Caching implemented at service and store levels
- Lazy loading and pagination patterns available for large datasets
Data Integrity
- Only approved service types can be linked to requests/offers
- Technical classification cleanup on service type deletion/rejection
- Cross-zome validation ensures consistency
User Experience
- Table Layout: Improved data density and administrative efficiency
- Technical Classification: Clear filtering between technical and non-technical services
- Responsive Design: Table works correctly on mobile devices
- Intuitive Admin Workflow: Streamlined service type moderation interface
- Performance: Maintained good performance with table display
- Accessibility: Standards maintained in new table implementation
UI/UX Improvements
- Card to Table Conversion: Enhanced administrative interface with better data scanning
- Filter/Sort Controls: Technical classification filtering for better organization
- Mobile Responsiveness: Table adapts correctly to different screen sizes
- Action Integration: Edit, delete, and view actions seamlessly integrated into table