Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Query

ASecurity

Define a Protean query - an immutable DTO representing a read intent against a projection (read model). Queries carry the parameters needed to fetch data on the read side of CQRS and are answered by query handlers via domain.dispatch(). Queries are associated with a projection (not an aggregate) and are named for what they fetch (GetOrderById, SearchOrders, ListActiveUsers). Use when you need to define a read request, model a query parameter object, build the read side of CQRS, or when the us...

45 stars
0 votes
0 copies
0 views
Added 9/20/2026
developmentpythongo

Security Analysis

A100/100

Scanned 9/20/2026

Install to Claude Code

$npx -y skills add proteanhq/protean --skill query --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Query?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Query
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/proteanhq-query/badge)](https://www.skillsdirectory.com/skills/proteanhq-query)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: query
description: Define a Protean query - an immutable DTO representing a read intent against a projection (read model). Queries carry the parameters needed to fetch data on the read side of CQRS and are answered by query handlers via domain.dispatch(). Queries are associated with a projection (not an aggregate) and are named for what they fetch (GetOrderById, SearchOrders, ListActiveUsers). Use when you need to define a read request, model a query parameter object, build the read side of CQRS, or when the user asks to "create a query", "define a query", "add a read query", "fetch data by criteria", or "query a projection". Queries are immutable, validated at construction, and contain only basic field types.
license: Apache-2.0
compatibility: Requires Python 3.11+, protean framework
metadata:
  author: proteanhq
  version: "0.1"
  category: element
---

# Query

A query is an immutable DTO that carries a **read intent** — the parameters needed to fetch data from a projection. Queries are the read-side counterpart to commands: a command asks to *change* state, a query asks to *read* it.

## Basic structure

A query is defined with `@domain.query(part_of="<Projection>")`:

```python
from protean import Domain
from protean.fields import Identifier, String

domain = Domain()

@domain.projection
class OrderSummary:
    order_id: Identifier(identifier=True)
    customer_name: String(max_length=100)

@domain.query(part_of="OrderSummary")
class GetOrderById:
    order_id: Identifier(required=True)
```

## Key rules

1. **Queries are associated with a projection** - Specify `part_of` with the projection (read model) the query targets, not an aggregate: `@domain.query(part_of="OrderSummary")`
2. **Queries carry read intent** - They describe what to fetch, named for the result: `GetOrderById`, `SearchOrders`, `ListActiveUsers` (not imperative like commands)
3. **Queries are immutable** - Setting a field after construction raises `IncorrectUsageError`; create a new instance instead
4. **Validated at construction** - Missing/invalid fields raise `ValidationError` immediately, before dispatch
5. **Basic field types only** - Fields are simple types (String, Integer, Float, Boolean, Date, DateTime, Identifier) plus value objects; no `HasOne`, `HasMany`, or `Reference`
6. **Queries are answered by query handlers** - Define a `query_handler` and dispatch with `domain.dispatch(query)` (see the `query-handler` skill)
7. **Queries have no side effects** - Dispatch never mutates state or runs a Unit of Work; reads are stateless
8. **Lightweight DTOs** - Unlike commands/events, queries carry no metadata, stream, or event-store concerns

## Fields and options

| Field/Option | Purpose | Required |
|--------------|---------|----------|
| `part_of` | Associate the query with a projection | Yes (unless abstract) |
| `abstract` | Mark as an abstract base query | No |

### Supported field types

```python
from protean.fields import (
    String, Integer, Float, Boolean,
    DateTime, Date, Identifier,
    List, Dict, ValueObject,
)
```

Queries cannot use `HasOne`, `HasMany`, or `Reference` fields.

## Quick example

```python
from protean import Domain
from protean.fields import Identifier, Integer, String

domain = Domain()

@domain.projection
class OrderSummary:
    order_id: Identifier(identifier=True)
    customer_name: String(max_length=100)
    status: String(max_length=20)

@domain.query(part_of="OrderSummary")
class SearchOrders:
    status: String()
    page: Integer(default=1)
    page_size: Integer(default=20)

# Construct (validated, immutable); dispatch via a query handler
query = SearchOrders(status="placed")
result = domain.dispatch(query)  # requires a registered query handler
```

## Common mistakes

### Targeting an aggregate instead of a projection

```python
@domain.query(part_of="Order")  # Wrong! Queries target a read model
class GetOrderById:
    order_id: Identifier(required=True)
```

Instead: point `part_of` at the projection that serves the read:

```python
@domain.query(part_of="OrderSummary")  # Correct! A projection
class GetOrderById:
    order_id: Identifier(required=True)
```

### Naming a query like a command

```python
@domain.query(part_of="OrderSummary")
class FetchTheOrder:  # Vague/imperative
    order_id: Identifier(required=True)
```

Instead: name it for what it returns — `GetOrderById`, `SearchOrders`.

### Mutating a query after construction

```python
query = GetOrderById(order_id="ORD-001")
query.order_id = "ORD-002"  # Raises IncorrectUsageError!
```

Instead: create a new query instance.

### Putting associations in a query

```python
@domain.query(part_of="OrderSummary")
class SearchOrders:
    lines = HasMany("OrderLine")  # Wrong! No associations in queries
```

Instead: use basic fields (and value objects) only.

## Detailed references

- [Anti-patterns](references/anti-patterns.md) - Common mistakes and how to avoid them

### Complete examples

- [Simple Query](assets/query_simple.py) - Queries against a projection
- [Query Validation](assets/query_validation.py) - Field validation and immutability

### Related skills

- `query-handler` - Answers queries via `@read` and `domain.dispatch()`
- `projection` - The read model a query targets
- `command` - The write-side counterpart (intent to change state)
- `projector` - Populates the projection that queries read from

Attribution

proteanhqproteanhq
View sourceMore from proteanhq →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

281612 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2132 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

9881 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →