business-data-access

Implement database-backed services and repositories with enforced data-access boundaries in ChatbotX.

722|195|Updated Dec 9, 2024
One-click install
npx skills add https://github.com/ChatbotXIO/ChatbotX --skill business-data-access
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: business-data-access
Source: https://github.com/ChatbotXIO/ChatbotX/tree/main/.agents/skills/business-data-access
Command: npx skills add https://github.com/ChatbotXIO/ChatbotX --skill business-data-access

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents app, worker, and integration code from importing the database directly by routing all database-backed reads and mutations through business services or repositories.

Core Features & Use Cases

  • Boundary Enforcement: Blocks direct db imports in apps/builder, apps/worker, and integrations, allowing them only in packages/business and packages/database/src/repositories.
  • Service and Repository Patterns: Provides templates for BaseService-based services with cache invalidation, event emission, and transaction propagation via tx parameters.
  • Use Case: When adding a feature that lists workspace tags in the builder app, create or reuse a tagService method in packages/business instead of querying the database from the app layer.

Quick Start

Ask the agent to add a new business service for workspace tags that the builder app can call without importing the database directly.

Frequently Asked Questions about business-data-access

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I access the database from app or worker code without direct db imports?

Call a service from @chatbotx.io/business or a repository from @chatbotx.io/database/repositories instead of importing db. Services handle business semantics, cache invalidation, and events, while repositories cover low-level persistence like shard routing and pagination.

When should I use a business service versus a repository?

Use a service when the method has business semantics, authorization constraints, cache invalidation, event emission, or cross-table composition. Use a repository for low-level persistence concerns such as shard routing, specialized pagination, or reusable raw query mechanics.

Where are direct database imports allowed in the ChatbotX monorepo?

Direct db imports are allowed only in packages/business/src and packages/database/src/repositories. The apps/builder, apps/worker, and integrations layers must go through services or repositories, and legacy direct imports are exceptions rather than patterns to copy.

How do I pass transactions through nested service calls?

Accept an optional tx parameter of type DatabaseClient in service methods and default it to db with const { tx = db } = props. Pass the same tx through nested service and repository calls so composed operations share one transaction.

How do services handle cache invalidation and domain events?

Services extend BaseService to call invalidateCacheTags with workspace-scoped tag keys after mutations. They emit domain events when mutations affect downstream workflows, and fire-and-forget events should attach .catch(() => {}) where the local pattern does.