Cqrs Pattern

Implement CQRS pattern for Electron services. Use when creating service methods with Observable queries and ResultAsync commands.

naporin0624 Updated

File contents

CQRS Pattern

Core Principle

Aspect Query (Read) Command (Write)
Return Type Observable<T> ResultAsync<void, Error>
Side Effects None Database writes, notifications

Resources

Topic File
Service interface design SERVICE-INTERFACE.md
Observable patterns OBSERVABLE-PATTERN.md
Result types RESULT-TYPES.md
Main process subscription MAIN-PROCESS-SUBSCRIPTION.md

Quick Reference

interface UserService {
  // Queries → Observable
  list(): Observable<User[]>;
  get(id: string): Observable<User | undefined>;
  // Commands → ResultAsync
  create(data: CreateUserData): ResultAsync<void, ApplicationError>;
}

Use BehaviorSubject to bridge: commands trigger #notify.next(), queries subscribe to it.

naporin0624/claude-plugin-hono-electron/tree/main/skills/cqrs-pattern commit 9d84f2f0ae

Frequently asked questions

npx skillmds@latest add naporin0624/cqrs-pattern