Add Service banner
drewipson drewipson

Add Service

Development community intermediate

Description

Create a new service class following the project's service layer pattern.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

Repository README

This is the README for drewipson/claude-code-config, shared by 5 entries in this directory. It describes the repository, not this entry specifically.

Add Service

Create a new service class following the project's service layer pattern.

Instructions

  1. **Determine service purpose:**

    • Ask what domain or functionality this service will handle
    • Identify what data it will manage or operations it will perform
    • Determine dependencies (other services, external APIs, file system)
  2. **Create service file in `src/services/`:**

    • Use kebab-case naming: -service.ts (e.g., workflow-service.ts)
    • Follow the established service pattern
  3. **Service template:**

import * as vscode from 'vscode';
import * as fs from 'fs/promises';
import * as path from 'path';

// Import types
import type {  } from '../core/types';

/**
 * Service handles 
 *
 * Responsibilities:
 * - 
 * - 
 * - 
 */
export class Service {
  constructor(
    // Inject dependencies if needed
  ) {}

  /**
   * 
   * @param param1 Description of param1
   * @returns Description of return value
   * @throws Description of potential errors
   */
  async mainMethod(param1: string): Promise<> {
    try {
      // Implementation
      return result;
    } catch (error) {
      // Provide meaningful error context
      throw new Error(`Failed to : ${error instanceof Error ? error.message : String(error)}`);
    }
  }

  // Additional methods...

  /**
   * Private helper method
   */
  private async helperMethod(): Promise {
    // Implementation
  }
}
  1. Add type definitions to src/core/types.ts if needed:
export interface  {
  // Define structure
}

export type  = {
  // Define options
};
  1. Import and instantiate in src/extension.ts if globally needed:
import { Service } from './services/-service';

// In activate()
const Service = new Service(/* dependencies */);

// Pass to providers or commands that need it

Service Design Principles

1. Single Responsibility

Each service should handle one domain or concern:

  • FileDiscoveryService - Discovers and categorizes files
  • HooksService - Manages hook configurations
  • FileAndHooksService - Too broad, split into separate services

2. Async by Default

All I/O operations must be async:

// Good
async readConfig(): Promise {
  const content = await fs.readFile(path, 'utf-8');
  return JSON.parse(content);
}

// Bad
readConfigSync(): Config {
  const content = fs.readFileSync(path, 'utf-8'); // Blocks extension host
  return JSON.parse(content);
}

3. Error Handling

Provide context in errors:

// Good
try {
  await fs.readFile(configPath, 'utf-8');
} catch (error) {
  throw new Error(`Failed to read config at ${configPath}: ${error.message}`);
}

// Bad
try {
  a