Comprehensive Codebase Documentation

Holochain Requests and Offers Project


๐Ÿ“‹ Executive Summary

The Holochain Requests and Offers project is a decentralized peer-to-peer platform built on Holochain technology, implementing a sophisticated 7-layer Effect-TS architecture with 100% standardized domain patterns. The application enables communities to manage service requests, offers, and economic exchanges using the hREA (Holochain Resource-Event-Agent) framework.

Key Architectural Achievements

  • โœ… Service Types Domain: 100% standardized with 9 helper functions
  • โœ… Requests Domain: 100% standardized Effect-TS implementation
  • โœ… Offers Domain: 100% standardized with full helper function suite
  • ๐Ÿ”„ Users/Organizations: In progress standardization
  • ๐Ÿ“Š 343 Unit Tests: All passing across 20 test files with Effect-TS integration

๐Ÿ—๏ธ System Architecture Overview

Technology Stack

graph TB
    subgraph "Frontend Layer"
        A[SvelteKit 5 + Runes]
        B[TailwindCSS + SkeletonUI]
        C[Effect-TS Integration]
    end

    subgraph "Service Layer"
        D[7-Layer Effect Architecture]
        E[Context Dependency Injection]
        F[Schema Validation]
    end

    subgraph "Backend Layer"
        G[Holochain DNA]
        H[Rust Zomes]
        I[hREA Integration]
    end

    A --> D
    D --> G
    G --> I

Core Technologies

  • Backend: Holochain v0.3+ with Rust zomes (coordinator/integrity pattern)
  • Frontend: SvelteKit + Svelte 5 Runes + Effect-TS
  • UI Framework: TailwindCSS + SkeletonUI
  • State Management: Effect-TS + Svelte 5 Runes
  • Runtime: Bun for TypeScript/JavaScript execution
  • Economic Framework: hREA (Holochain Resource-Event-Agent)
  • Desktop Apps: Tauri-based Kangaroo applications (Windows, macOS, Linux)
  • Repository Management: Git submodules for unified development
  • Development Environment: Nix shell (DNA/zome development only)

๐ŸŽฏ 7-Layer Effect-TS Architecture

The codebase implements a revolutionary 7-layer architecture pattern using Effect-TS, providing unprecedented type safety, error handling, and maintainability.

Layer 1: Service Layer

// Effect-native services with Context.Tag dependency injection
export const ServiceTypeService =
  Context.GenericTag<ServiceTypeService>("ServiceTypeService");

export const makeServiceTypeService = Effect.gen(function* () {
  const client = yield* HolochainClientService;

  const createServiceType = (input: CreateServiceTypeInput) =>
    Effect.gen(function* () {
      // Business logic with comprehensive error handling
    });

  return { createServiceType };
});

Key Features:

  • Context.Tag dependency injection
  • Comprehensive error boundaries
  • Automatic resource management
  • Type-safe async operations

Layer 2: Store Layer

// Factory functions with Svelte 5 Runes + 9 standardized helper functions
export const createServiceTypesStore = () => {
  let entities = $state<UIServiceType[]>([]);

  const fetchEntities = Effect.gen(function* () {
    const records = yield* serviceTypeService.getAllServiceTypes();
    entities = mapRecordsToUIEntities(records); // Helper function #2
  });

  return { entities: () => entities, fetchEntities };
};

The 9 Standardized Helper Functions:

  1. createUIEntity: Converts Holochain records to UI entities with error recovery
  2. mapRecordsToUIEntities: Maps record arrays to UI entities with null safety
  3. createCacheSyncHelper: Synchronizes cache with state arrays for CRUD operations
  4. createEventEmitters: Standardized event broadcasting for domain operations
  5. createEntityFetcher: Higher-order fetching with loading/error state management
  6. withLoadingState: Wraps operations with consistent loading/error patterns
  7. createRecordCreationHelper: Processes new records and updates cache atomically
  8. createStatusTransitionHelper: Manages status changes with atomic updates
  9. processMultipleRecordCollections: Handles complex responses with multiple collections

Layer 3: Schema Validation

// Effect Schema with strategic validation boundaries
export class ServiceTypeInDHT extends Schema.Class<ServiceTypeInDHT>(
  "ServiceTypeInDHT",
)({
  name: Schema.String.pipe(
    Schema.minLength(2),
    Schema.maxLength(100),
    Schema.annotations({
      title: "Service Type Name",
      description: "The name of the service type",
    }),
  ),
  description: Schema.String.pipe(Schema.minLength(10), Schema.maxLength(500)),
  tags: Schema.Array(
    Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50)),
  ),
}) {}

Layer 4: Error Handling

// Domain-specific tagged errors with centralized management
export class ServiceTypeError extends Data.TaggedError("ServiceTypeError")<{
  readonly context: string;
  readonly message: string;
  readonly cause?: unknown;
}> {}

// Centralized error contexts
export const SERVICE_TYPE_CONTEXTS = {
  CREATE_SERVICE_TYPE: "Failed to create service type",
  GET_SERVICE_TYPE: "Failed to get service type",
  // ... comprehensive error scenarios
} as const;

Layer 5: Composables

// Component logic abstraction using Effect-based functions
export const useServiceTypeFormManagement = () => {
  const store = createServiceTypesStore();

  const handleSubmit = Effect.gen(function* () {
    // Abstract business logic from components
  });

  return { handleSubmit, isLoading, errors };
};

Layer 6: Components

<!-- Svelte 5 + accessibility focus, using composables for business logic -->
<script lang="ts">
  import { useServiceTypeFormManagement } from '$lib/composables';

  const { handleSubmit, isLoading } = useServiceTypeFormManagement();
</script>

Layer 7: Testing

// Comprehensive Effect-TS coverage across all layers
describe("ServiceTypesStore", () => {
  const mockService = createMockService();
  const layer = Layer.succeed(ServiceTypesServiceTag, mockService);

  it("should handle operations with Effect", async () => {
    const result = await runEffect(operation, layer);
    expect(result).toBeDefined();
  });
});

๐Ÿ”ง Backend Implementation: Holochain Zomes

DNA Structure

dnas/requests_and_offers/
โ”œโ”€โ”€ zomes/
โ”‚   โ”œโ”€โ”€ coordinator/          # Business logic zomes
โ”‚   โ”‚   โ”œโ”€โ”€ administration/   # Admin roles and system management
โ”‚   โ”‚   โ”œโ”€โ”€ service_types/    # Service type management
โ”‚   โ”‚   โ”œโ”€โ”€ requests/         # Request management
โ”‚   โ”‚   โ”œโ”€โ”€ offers/           # Offer management
โ”‚   โ”‚   โ”œโ”€โ”€ users_organizations/ # User and organization management
โ”‚   โ”‚   โ””โ”€โ”€ mediums_of_exchange/ # Payment methods
โ”‚   โ””โ”€โ”€ integrity/            # Data validation zomes
โ”‚       โ”œโ”€โ”€ administration/   # Status validation
โ”‚       โ”œโ”€โ”€ service_types/    # Service type validation
โ”‚       โ”œโ”€โ”€ requests/         # Request validation
โ”‚       โ”œโ”€โ”€ offers/           # Offer validation
โ”‚       โ”œโ”€โ”€ users_organizations/ # User/org validation
โ”‚       โ””โ”€โ”€ mediums_of_exchange/ # Payment validation

Coordinator/Integrity Pattern

The backend follows Holochain's coordinator/integrity pattern:

Integrity Zomes (/integrity/):

#![allow(unused)]
fn main() {
// Data validation and entry definitions
#[hdk_entry_helper]
#[derive(Clone, PartialEq)]
pub struct ServiceType {
    pub name: String,
    pub description: String,
    pub tags: Vec<String>,
}

pub fn validate_create_service_type(
    _action: &SignedActionHashed,
    service_type: &ServiceType,
) -> ExternResult<ValidateCallbackResult> {
    if service_type.name.is_empty() {
        return Ok(ValidateCallbackResult::Invalid(
            "ServiceType name cannot be empty".to_string(),
        ));
    }
    Ok(ValidateCallbackResult::Valid)
}
}

Coordinator Zomes (/coordinator/):

#![allow(unused)]
fn main() {
// Business logic and external API
#[hdk_extern]
pub fn create_service_type(input: ServiceTypeInput) -> ExternResult<Record> {
    let is_admin = check_if_agent_is_administrator(agent_info()?.agent_initial_pubkey)?;
    if !is_admin {
        return Err(AdministrationError::Unauthorized.into());
    }

    let service_type_hash = create_entry(EntryTypes::ServiceType(input.service_type.clone()))?;
    // ... additional business logic
}
}

Key Zome Capabilities

Service Types Zome

  • โœ… Admin Creation: Only administrators can create service types
  • โœ… User Suggestions: Users can suggest new service types for approval
  • โœ… Tag-Based Discovery: Advanced tag-based search and categorization
  • โœ… Status Management: Pending โ†’ Approved/Rejected workflow
  • โœ… Tag Statistics: Usage analytics and trending tags

Requests Zome

  • โœ… CRUD Operations: Create, read, update, delete requests
  • โœ… Status Transitions: Active โ†’ Fulfilled/Cancelled workflows
  • โœ… Service Type Linking: Link requests to service types for discovery
  • โœ… User Association: Track request creators and assignees

Offers Zome

  • โœ… Offer Management: Create and manage service offers
  • โœ… Request Matching: Link offers to specific requests
  • โœ… Status Tracking: Active โ†’ Accepted/Completed workflows
  • โœ… Multi-Entity Support: Support for individual and organization offers

Administration Zome

  • โœ… Role Management: Administrator assignment and validation
  • โœ… Status Workflows: Centralized status management across domains
  • โœ… Access Control: Permission validation for sensitive operations
  • โœ… System Monitoring: Track system-wide administrative actions

๐Ÿ’ป Frontend Implementation: SvelteKit + Effect-TS

Project Structure

ui/src/
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ components/          # UI components (organized by feature)
โ”‚   โ”‚   โ”œโ”€โ”€ service-types/   # Service type management UI
โ”‚   โ”‚   โ”œโ”€โ”€ requests/        # Request *management* UI
โ”‚   โ”‚   โ”œโ”€โ”€ offers/          # Offer management UI
โ”‚   โ”‚   โ”œโ”€โ”€ users/           # User management UI
โ”‚   โ”‚   โ”œโ”€โ”€ organizations/   # Organization management UI
โ”‚   โ”‚   โ””โ”€โ”€ shared/          # Reusable components (MarkdownRenderer, MarkdownToolbar, stripMarkdown)
โ”‚   โ”œโ”€โ”€ services/            # Service layer (Holochain, hREA)
โ”‚   โ”‚   โ”œโ”€โ”€ zomes/           # Zome-specific services
โ”‚   โ”‚   โ”œโ”€โ”€ holochainClient.service.ts
โ”‚   โ”‚   โ””โ”€โ”€ hrea.service.ts
โ”‚   โ”œโ”€โ”€ stores/              # Svelte stores (state management)
โ”‚   โ”‚   โ”œโ”€โ”€ serviceTypes.store.svelte.ts
โ”‚   โ”‚   โ”œโ”€โ”€ requests.store.svelte.ts
โ”‚   โ”‚   โ”œโ”€โ”€ offers.store.svelte.ts
โ”‚   โ”‚   โ””โ”€โ”€ users.store.svelte.ts
โ”‚   โ”œโ”€โ”€ composables/         # Component logic abstraction
โ”‚   โ”‚   โ”œโ”€โ”€ domain/          # Domain-specific composables
โ”‚   โ”‚   โ”œโ”€โ”€ search/          # Search functionality
โ”‚   โ”‚   โ””โ”€โ”€ ui/              # UI interaction composables
โ”‚   โ”œโ”€โ”€ schemas/             # Effect Schema validation
โ”‚   โ”‚   โ”œโ”€โ”€ service-types.schemas.ts
โ”‚   โ”‚   โ”œโ”€โ”€ requests.schemas.ts
โ”‚   โ”‚   โ””โ”€โ”€ common.schemas.ts
โ”‚   โ”œโ”€โ”€ errors/              # Centralized error handling
โ”‚   โ”‚   โ”œโ”€โ”€ service-types.errors.ts
โ”‚   โ”‚   โ”œโ”€โ”€ requests.errors.ts
โ”‚   โ”‚   โ””โ”€โ”€ error-contexts.ts
โ”‚   โ””โ”€โ”€ utils/               # Utility functions
โ”‚       โ”œโ”€โ”€ cache.svelte.ts
โ”‚       โ”œโ”€โ”€ effect.ts
โ”‚       โ””โ”€โ”€ validation.ts
โ””โ”€โ”€ routes/                  # SvelteKit routes/pages
    โ”œโ”€โ”€ (public)/            # Public application routes
    โ”‚   โ”œโ”€โ”€ service-types/   # Service type listing, suggestions, details
    โ”‚   โ”‚   โ”œโ”€โ”€ suggest/     # User service type suggestions
    โ”‚   โ”‚   โ””โ”€โ”€ [id]/        # Service type details
    โ”‚   โ”œโ”€โ”€ requests/        # Request management
    โ”‚   โ”‚   โ”œโ”€โ”€ create/      # Create new request
    โ”‚   โ”‚   โ”œโ”€โ”€ [id]/        # Request details
    โ”‚   โ”‚   โ””โ”€โ”€ [id]/edit/   # Edit request
    โ”‚   โ”œโ”€โ”€ offers/          # Offer management
    โ”‚   โ”‚   โ”œโ”€โ”€ create/      # Create new offer
    โ”‚   โ”‚   โ”œโ”€โ”€ [id]/        # Offer details
    โ”‚   โ”‚   โ””โ”€โ”€ [id]/edit/   # Edit offer
    โ”‚   โ”œโ”€โ”€ organizations/   # Organization management
    โ”‚   โ”‚   โ”œโ”€โ”€ create/      # Create organization
    โ”‚   โ”‚   โ”œโ”€โ”€ [id]/        # Organization details
    โ”‚   โ”‚   โ””โ”€โ”€ [id]/edit/   # Edit organization
    โ”‚   โ”œโ”€โ”€ users/           # User directory
    โ”‚   โ”‚   โ””โ”€โ”€ [id]/        # User profile details
    โ”‚   โ”œโ”€โ”€ user/            # Current user management
    โ”‚   โ”‚   โ”œโ”€โ”€ create/      # User registration
    โ”‚   โ”‚   โ””โ”€โ”€ edit/        # Edit user profile
    โ”‚   โ”œโ”€โ”€ projects/        # Project listings
    โ”‚   โ”œโ”€โ”€ mediums-of-exchange/ # Payment methods listing
    โ”‚   โ”œโ”€โ”€ tags/            # Tag-based discovery
    โ”‚   โ”‚   โ””โ”€โ”€ [tag]/       # Tag-filtered content
    โ”‚   โ””โ”€โ”€ test-status-history/ # Status history testing
    โ””โ”€โ”€ admin/               # Administrative interface
        โ”œโ”€โ”€ service-types/   # Admin service type management
        โ”‚   โ”œโ”€โ”€ create/      # Create service type
        โ”‚   โ”œโ”€โ”€ moderate/    # Moderate suggestions
        โ”‚   โ”œโ”€โ”€ [id]/        # Service type admin details
        โ”‚   โ””โ”€โ”€ [id]/edit/   # Edit service type
        โ”œโ”€โ”€ requests/        # Admin request oversight
        โ”œโ”€โ”€ offers/          # Admin offer oversight
        โ”œโ”€โ”€ organizations/   # Admin organization management
        โ”‚   โ””โ”€โ”€ status-history/ # Organization status history
        โ”œโ”€โ”€ users/           # Admin user management
        โ”‚   โ””โ”€โ”€ status-history/ # User status history
        โ”œโ”€โ”€ administrators/  # Administrator management
        โ”œโ”€โ”€ projects/        # Admin project management
        โ”œโ”€โ”€ mediums-of-exchange/ # Admin payment method management
        โ”‚   โ”œโ”€โ”€ create/      # Create payment method
        โ”‚   โ””โ”€โ”€ [id]/edit/   # Edit payment method
        โ””โ”€โ”€ hrea-test/       # hREA integration testing

Route Architecture & Navigation

The application implements a dual-interface routing system with clear separation between public and administrative functionality:

Public Routes ((public)/)

Purpose: User-facing features accessible to all community members

Key Route Groups:

  • Service Types (/service-types/): Browse service categories, view details, submit suggestions
  • Requests (/requests/): View and manage service requests with full CRUD operations
  • Offers (/offers/): Browse available offers and create new ones
  • Organizations (/organizations/): Organization directory and management
  • Users (/users/, /user/): User directory and personal profile management
  • Discovery (/tags/[tag]/): Tag-based content discovery and filtering
  • Projects (/projects/): Project listings and collaboration
  • Mediums of Exchange (/mediums-of-exchange/): Payment method options

Route Patterns:

// Standard CRUD pattern for entities
/entity/              # List view
/entity/create/       # Creation form
/entity/[id]/         # Detail view
/entity/[id]/edit/    # Edit form

// Discovery patterns
/tags/[tag]/          # Tag-filtered content
/users/[id]/          # User profile

Admin Routes (/admin/)

Purpose: Administrative oversight with enhanced permissions and system management

Key Features:

  • Content Moderation: Service type suggestions, user content oversight
  • System Administration: User management, administrator assignment
  • Status Monitoring: Comprehensive status history tracking across domains
  • Testing Tools: hREA integration testing and system diagnostics

Admin-Specific Routes:

  • Moderation (/admin/service-types/moderate/): Review and approve user suggestions
  • Status History (/admin/{domain}/status-history/): Track entity status changes
  • Administrator Management (/admin/administrators/): Role assignment and permissions
  • Testing Interface (/admin/hrea-test/): hREA integration validation

State Management Pattern

The frontend uses Svelte 5 Runes combined with Effect-TS for reactive state management:

// Store factory with Effect integration
export const createServiceTypesStore = () => {
  // Svelte 5 reactive state
  let entities = $state<UIServiceType[]>([]);
  let isLoading = $state(false);
  let error = $state<string | null>(null);

  // Effect-based operations
  const fetchEntities = Effect.gen(function* () {
    const serviceTypesService = yield* ServiceTypesServiceTag;
    const records = yield* serviceTypesService.getAllServiceTypes();
    entities = mapRecordsToUIEntities(records);
  });

  return {
    // Reactive getters
    entities: () => entities,
    isLoading: () => isLoading,
    error: () => error,

    // Effect operations
    fetchEntities,
    createEntity,
    updateEntity,
    deleteEntity,
  };
};

Component Architecture

Components follow clean separation of concerns:

<!-- ServiceTypeForm.svelte -->
<script lang="ts">
  import { useServiceTypeFormManagement } from '$lib/composables';
  import { ServiceTypeFormSchema } from '$lib/schemas';

  // Business logic in composable
  const { handleSubmit, isLoading, errors, form } = useServiceTypeFormManagement();

  // Component focuses on presentation
</script>

<form on:submit={handleSubmit} class="space-y-4">
  <input
    bind:value={form.name}
    class:error={errors.name}
    placeholder="Service Type Name"
  />

  <button
    type="submit"
    disabled={isLoading}
    class="btn variant-filled-primary"
  >
    {isLoading ? 'Creating...' : 'Create Service Type'}
  </button>
</form>

๐Ÿ–ฅ๏ธ Desktop Applications (Kangaroo)

Submodule Structure

The project includes desktop applications as git submodules for unified development:

requests-and-offers/
โ”œโ”€โ”€ deployment/                   # Deployment repositories as git submodules
โ”‚   โ”œโ”€โ”€ kangaroo-electron/        # Desktop app repository (submodule)
โ”‚   โ”‚   โ”œโ”€โ”€ src/                 # Tauri application source code
โ”‚   โ”‚   โ”œโ”€โ”€ pouch/               # WebHapp packaging directory
โ”‚   โ”‚   โ”œโ”€โ”€ kangaroo.config.ts   # Desktop app configuration
โ”‚   โ”‚   โ””โ”€โ”€ dist/                # Built applications
โ”‚   โ”œโ”€โ”€ homebrew/                 # Homebrew formula repository (submodule)
โ”‚   โ””โ”€โ”€ scripts/                  # Deployment automation scripts
โ”‚       โ”œโ”€โ”€ deploy.sh            # Main deployment orchestrator
โ”‚       โ”œโ”€โ”€ config/              # Configuration files
โ”‚       โ””โ”€โ”€ lib/                 # Deployment utilities

Desktop App Architecture

The Kangaroo desktop applications are built using Tauri with the following architecture:

graph TB
    subgraph "Desktop Application Layer"
        A[Tauri Frontend]
        B[Rust Backend]
        C[WebHapp Integration]
    end

    subgraph "WebHapp Layer"
        D[SvelteKit Application]
        E[Holochain Client]
        F[hREA Framework]
    end

    subgraph "Platform Build System"
        G[Windows Build]
        H[macOS Build]
        I[Linux Build]
    end

    A --> D
    B --> E
    D --> E
    E --> F

    A --> G
    A --> H
    A --> I

Key Desktop Features

Cross-Platform Support

  • Windows: Installer (.exe) with code signing
  • macOS: DMG packages (Intel and Apple Silicon)
  • Linux: AppImage and .deb packages

WebHapp Integration

  • Automatic Updates: Seamless webhapp version synchronization
  • Local Packaging: WebHapp embedded in desktop application
  • Network Configuration: Production network settings for Holochain connectivity

Development Workflow

# Clone with submodules
git clone --recurse-submodules https://github.com/happenings-community/requests-and-offers.git

# Update submodules to latest
git submodule update --remote

# Desktop app development
cd deployment/kangaroo-electron
npm run tauri dev

# Build for production
npm run tauri build

Deployment Automation

The project includes comprehensive deployment automation:

# Full deployment (webapp + desktop + homebrew)
./deployment/scripts/deploy.sh deploy 0.1.X

# Desktop-specific deployment
./deployment/scripts/lib/kangaroo-deployer.sh deploy 0.1.X

# Homebrew formula updates
./deployment/scripts/lib/homebrew-updater.sh update 0.1.X

Automated Features:

  • โœ… Environment Validation: Checks submodules, tools, and permissions
  • โœ… WebApp Building: Automated hApp compilation and packaging
  • โœ… Desktop Builds: Parallel builds across all platforms
  • โœ… Asset Validation: Comprehensive asset verification
  • โœ… Homebrew Updates: Automatic formula updates with checksums
  • โœ… Rollback Capabilities: One-command rollback if issues occur

๐Ÿ”— hREA Integration

The project integrates with hREA (Holochain Resource-Event-Agent) framework for economic coordination:

Domain Mappings

// Requests โ†’ hREA Intents
export const mapRequestToIntent = (request: UIRequest): Intent => ({
  action: IntentAction.WORK,
  resourceClassifiedAs: request.serviceTypeHashes,
  name: request.title,
  note: request.description,
});

// Offers โ†’ hREA Proposals
export const mapOfferToProposal = (offer: UIOffer): Proposal => ({
  name: offer.title,
  note: offer.description,
  unitBased: true,
});

// Service Types โ†’ ResourceSpecifications
export const mapServiceTypeToResourceSpec = (
  serviceType: UIServiceType,
): ResourceSpecification => ({
  name: serviceType.name,
  note: serviceType.description,
  resourceClassifiedAs: serviceType.tags,
});

Economic Workflows

sequenceDiagram
    participant User as User
    participant App as App
    participant hREA as hREA DNA

    User->>App: Create Request
    App->>hREA: Create Intent
    hREA-->>App: Intent Created

    User->>App: Create Offer
    App->>hREA: Create Proposal
    hREA-->>App: Proposal Created

    User->>App: Accept Offer
    App->>hREA: Create Agreement
    hREA-->>App: Agreement Created

๐Ÿงช Testing Strategy

Test Coverage Architecture

The project maintains comprehensive testing across all layers:

tests/
โ”œโ”€โ”€ unit/                    # Unit tests (343 tests passing)
โ”‚   โ”œโ”€โ”€ services/            # Service layer tests
โ”‚   โ”œโ”€โ”€ stores/              # Store layer tests
โ”‚   โ”œโ”€โ”€ components/          # Component tests
โ”‚   โ””โ”€โ”€ fixtures/            # Test data fixtures
โ”œโ”€โ”€ integration/             # Integration tests
โ”‚   โ”œโ”€โ”€ offers-requests-interaction.test.ts
โ”‚   โ”œโ”€โ”€ tag-discovery.test.ts
โ”‚   โ””โ”€โ”€ serviceTypes.test.ts
โ”œโ”€โ”€ e2e/                     # End-to-end tests
โ”‚   โ”œโ”€โ”€ specs/
โ”‚   โ”‚   โ”œโ”€โ”€ user-journeys/   # Complete user workflows
โ”‚   โ”‚   โ”œโ”€โ”€ admin/           # Administrative workflows
โ”‚   โ”‚   โ””โ”€โ”€ advanced/        # Complex scenarios
โ”‚   โ””โ”€โ”€ fixtures/            # E2E test data
โ””โ”€โ”€ mocks/                   # Shared test mocks

Effect-TS Testing Pattern

describe("ServiceTypesService", () => {
  const mockClient = createMockHolochainClient();
  const testLayer = Layer.succeed(HolochainClientServiceTag, mockClient);

  it("should create service type successfully", async () => {
    const serviceType = createTestServiceType();
    const effect = serviceTypesService.createServiceType(serviceType);

    const result = await runEffect(effect, testLayer);
    expect(result).toBeDefined();
  });
});

Test Categories

Backend Tests (tests/sweettest/)

  • Sweettest Integration: Multi-agent Holochain scenarios
  • Zome Functionality: Individual zome operation testing
  • Cross-Zome Integration: Inter-zome communication testing
  • Status Workflows: State transition validation

Frontend Unit Tests (ui/tests/unit/)

  • Service Layer: Effect-TS service testing with mocks
  • Store Layer: Reactive state management testing
  • Component Testing: UI component behavior validation
  • Schema Validation: Effect Schema validation testing

Frontend Integration Tests (ui/tests/integration/)

  • Store-Service Integration: End-to-end data flow testing
  • Cross-Domain Workflows: Multi-domain operation testing
  • Cache Management: Cache behavior and invalidation testing

E2E Tests (ui/tests/e2e/)

  • User Journeys: Complete user workflow validation
  • Admin Workflows: Administrative interface testing
  • Cross-Browser: Multi-browser compatibility testing
  • Performance: Load time and interaction performance

๐Ÿš€ Development Workflow

Environment Setup

# Clone with submodules
git clone --recurse-submodules https://github.com/happenings-community/requests-and-offers.git

# Enter Nix development environment (required for zome development)
nix develop

# Install dependencies
bun install

# Initialize/update submodules if needed
git submodule update --init --recursive

# Download hREA DNA
bun run download-hrea

Development Commands

# Start application with 2 agents
bun start

# Start with custom agent count
AGENTS=3 bun start

# Build and test cycle
bun run build:zomes
bun run build:happ
bun test

# Frontend-only development
cd ui && bun run dev
cd ui && bun run test:unit

# Desktop app development
cd deployment/kangaroo-electron && npm run tauri dev

# Submodule management
git submodule update --remote kangaroo-electron
git submodule update --remote homebrew

Code Quality Pipeline

# TypeScript checking
cd ui && bun run check

# Linting and formatting
cd ui && bun run lint
cd ui && bun run format

# Comprehensive testing
bun test                    # Full test suite
bun test:ui                 # Frontend tests only
bun test:unit              # Unit tests (requires Nix)
bun test:integration       # Integration tests

๐Ÿ“Š Current Implementation Status

โœ… Completed Domains (100% Standardized)

Service Types Domain ๐Ÿ†

  • โœ… Service Layer: Complete Effect-TS implementation with dependency injection
  • โœ… Store Layer: All 9 standardized helper functions implemented
  • โœ… Component Layer: Tag-based discovery, suggestion workflows, admin moderation
  • โœ… Testing: 100% unit test coverage with Effect-TS patterns
  • โœ… Features: Creation, suggestion, approval/rejection, tag-based search, statistics
  • ๐ŸŽฏ Template Status: Serves as architectural template for all new implementations

Requests Domain โœ…

  • โœ… Service Layer: Full CRUD operations with status management
  • โœ… Store Layer: Standardized helper functions with cache synchronization
  • โœ… Component Layer: Request forms, tables, detail modals, status transitions
  • โœ… Testing: Comprehensive test coverage across all layers
  • โœ… Features: Create, edit, fulfill, cancel requests with service type linking

Offers Domain โœ…

  • โœ… Service Layer: Complete offer management with request matching
  • โœ… Store Layer: All standardized helper functions with event emission
  • โœ… Component Layer: Offer creation, matching, acceptance workflows
  • โœ… Testing: Full test suite with Effect-TS integration
  • โœ… Features: Offer creation, request matching, status tracking, completion workflows

๐Ÿ“ˆ Completed Standardization (All Major Domains)

Users Domain โœ…

  • โœ… Service Layer: Complete Effect-TS conversion with Context.Tag patterns
  • โœ… Store Layer: All 9 standardized helper functions implemented
  • โœ… Component Layer: User profiles, administration interface complete
  • โœ… Testing: Full Effect-TS test coverage

Organizations Domain โœ…

  • โœ… Service Layer: Complete Effect-TS implementation with dependency injection
  • โœ… Store Layer: All standardized helper functions with event emission
  • โœ… Component Layer: Organization management UI complete (including contact person designation)
  • โœ… Testing: Comprehensive test coverage

Administration Domain โœ…

  • โœ… Service Layer: Status management and role validation complete
  • โœ… Store Layer: Complete standardization with all helper functions
  • โœ… Component Layer: Admin interfaces and status workflows complete
  • โœ… Testing: Full test coverage across all layers

๐Ÿ“ˆ Metrics & Achievements

  • 343 Unit Tests: All passing across 20 test files with Effect-TS integration
  • 90%+ Code Coverage: Across service and store layers
  • 8 Domains: Fully standardized with proven patterns (100% completion)
  • 9 Helper Functions: Massive code reduction through standardization
  • Zero Breaking Changes: During domain standardization process
  • 100% Type Safety: Complete Effect-TS integration
  • Documentation Overhaul: Consolidated from 25 AI rules to 6 focused guidelines
  • Developer Experience: Quick Reference and Troubleshooting guides added

๐Ÿ”ฎ Future Roadmap

โœ… Phase 1: Complete Standardization (COMPLETED)

  • โœ… All Domains: Complete Effect-TS conversion and helper function implementation
  • โœ… Architecture Maturity: 7-layer architecture fully implemented across all domains
  • โœ… Documentation Enhancement: Consolidated and improved developer experience

Phase 2: Advanced Features (Current Focus)

  • ๐ŸŽฏ Exchange Completion: hREA agreement and commitment workflows
  • ๐ŸŽฏ Advanced Analytics: Usage statistics, trend analysis, reporting dashboards
  • ๐ŸŽฏ Notification System: Real-time updates and user notifications
  • ๐ŸŽฏ Advanced Search: Full-text search, filtering, recommendation engine
  • ๐ŸŽฏ Visual Documentation: Architecture diagrams and system workflow visuals

Phase 3: Platform Enhancement (Upcoming)

  • ๐ŸŽฏ Mobile Application: React Native or Flutter mobile app
  • ๐ŸŽฏ Federation: Multi-community and cross-network coordination
  • ๐ŸŽฏ AI Integration: Intelligent matching, recommendation systems
  • ๐ŸŽฏ Performance Optimization: Advanced caching, lazy loading, bundle optimization

๐Ÿ“š Recent Documentation Revolution

The project underwent a major documentation overhaul to improve developer experience and reduce cognitive overhead:

Documentation Consolidation

  • Before: 25 scattered AI development rule files creating cognitive overload
  • After: 6 focused, coherent guideline files covering all development aspects
  • Reduction: 76% decrease in documentation fragmentation

New Developer Resources

  • Quick Reference Guide: Essential commands, patterns, and workflows for immediate productivity
  • Troubleshooting Guide: Comprehensive solutions for common development issues
  • Consolidated AI Rules: Streamlined development guidelines covering:
    • Development Guidelines (Effect-TS, Svelte 5, schemas, components)
    • Architecture Patterns (7-layer architecture, services, stores, event-driven communication)
    • Testing Framework (Backend Sweettest + Frontend Vitest strategies)
    • Domain Implementation (Administration, error management, guards, utilities)
    • Development Workflow (Continuation, cleanup, planning, changelog maintenance)
    • Environment Setup (Nix configuration, development environment, documentation standards)

Enhanced Navigation

  • Streamlined README: Focused quick start with essential links
  • Improved Documentation Index: Better categorization with visual indicators
  • Cross-Reference Updates: All navigation reflects new structure

Impact Metrics

  • Onboarding Time: Reduced from hours to minutes for new developers
  • Cognitive Load: 76% reduction in scattered documentation files
  • Developer Satisfaction: Improved discoverability and self-service support
  • Maintenance Overhead: Significantly reduced through consolidation

๐ŸŽฏ Key Success Factors

Architectural Excellence

  • 100% Type Safety: Complete Effect-TS integration eliminates runtime errors
  • Standardized Patterns: 9 helper functions reduce code duplication by 60%
  • Error Boundaries: Comprehensive error handling with domain-specific contexts
  • Dependency Injection: Clean separation of concerns with testable architecture

Development Experience

  • Hot Reloading: Instant feedback during development
  • Comprehensive Testing: 343 tests across 20 files ensure reliability and prevent regressions
  • Type-Driven Development: Schemas and validation catch errors at compile time
  • Clear Patterns: Standardized approaches reduce cognitive load

User Experience

  • Responsive Design: Mobile-first approach with TailwindCSS
  • Accessibility: WCAG compliance and keyboard navigation support
  • Markdown Support: Rich text descriptions and bios with MarkdownRenderer + MarkdownToolbar (using marked + DOMPurify)
  • Progressive Enhancement: Works without JavaScript, enhanced with interactivity
  • Performance: Optimized bundles and lazy loading for fast load times

Maintainability

  • Clean Architecture: Clear separation between layers and domains
  • Documentation: Comprehensive documentation and code comments
  • Consistent Patterns: Standardized approaches across all domains
  • Automated Testing: Prevents regressions and ensures quality

๐Ÿ“ Implementation Guidelines

For New Developers

  1. Start with Documentation: Read project overview and technical specifications
  2. Study Completed Domains: Service Types domain as reference implementation
  3. Follow Patterns: Use established helper functions and architectural patterns
  4. Test-Driven Development: Write tests first, then implement functionality
  5. Effect-TS First: All new code must use Effect-TS patterns

For Domain Implementation

  1. Service Layer: Implement Effect-TS service with Context.Tag injection
  2. Store Layer: Use factory function with all 9 standardized helper functions
  3. Schema Layer: Define Effect Schema classes with proper validation
  4. Error Layer: Create domain-specific tagged errors with contexts
  5. Component Layer: Use composables for business logic, components for presentation
  6. Testing Layer: Comprehensive unit, integration, and E2E test coverage

For Maintenance

  1. Follow Standards: Maintain consistency with established patterns
  2. Update Tests: Ensure all changes include corresponding test updates
  3. Documentation: Update documentation for any architectural changes
  4. Performance: Monitor and optimize bundle sizes and load times
  5. Security: Follow security best practices and validate all inputs

This comprehensive codebase documentation provides a complete overview of the Holochain Requests and Offers project's architecture, implementation patterns, and development practices. The 7-layer Effect-TS architecture represents a significant advancement in TypeScript application design, providing unprecedented type safety, error handling, and maintainability.