# Cqrs Pattern

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

- Skill: `naporin0624/cqrs-pattern` (Agent Skill, multi-file: 7 files)
- Install (CLI): `npx skillmds@latest add naporin0624/cqrs-pattern`
- Raw SKILL.md: https://api.skillmd.com/api/skills/naporin0624/cqrs-pattern/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: naporin0624 (https://skillmd.com/u/naporin0624)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/naporin0624/cqrs-pattern

---


# 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](SERVICE-INTERFACE.md) |
| Observable patterns | [OBSERVABLE-PATTERN.md](OBSERVABLE-PATTERN.md) |
| Result types | [RESULT-TYPES.md](RESULT-TYPES.md) |
| Main process subscription | [MAIN-PROCESS-SUBSCRIPTION.md](MAIN-PROCESS-SUBSCRIPTION.md) |

## Quick Reference

```typescript
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.

