# Send Service Layer Architecture to your agent
Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.
## Fast path
- Download the package from Yavira.
- Extract it into a folder your agent can access.
- Paste one of the prompts below and point your agent at the extracted folder.
## Suggested prompts
### New install

```text
I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Then review README.md for any prerequisites, environment setup, or post-install checks. Tell me what you changed and call out any manual steps you could not complete.
```
### Upgrade existing

```text
I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Then review README.md for any prerequisites, environment setup, or post-install checks. Summarize what changed and any follow-up checks I should run.
```
## Machine-readable fields
```json
{
  "schemaVersion": "1.0",
  "item": {
    "slug": "service-layer-architecture",
    "name": "Service Layer Architecture",
    "source": "tencent",
    "type": "skill",
    "category": "开发工具",
    "sourceUrl": "https://clawhub.ai/wpank/service-layer-architecture",
    "canonicalUrl": "https://clawhub.ai/wpank/service-layer-architecture",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadUrl": "/downloads/service-layer-architecture",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=service-layer-architecture",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "packageFormat": "ZIP package",
    "primaryDoc": "SKILL.md",
    "includedAssets": [
      "README.md",
      "SKILL.md"
    ],
    "downloadMode": "redirect",
    "sourceHealth": {
      "source": "tencent",
      "slug": "service-layer-architecture",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-05-08T18:10:02.434Z",
      "expiresAt": "2026-05-15T18:10:02.434Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=service-layer-architecture",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=service-layer-architecture",
        "contentDisposition": "attachment; filename=\"service-layer-architecture-1.0.0.zip\"",
        "redirectLocation": null,
        "bodySnippet": null,
        "slug": "service-layer-architecture"
      },
      "scope": "item",
      "summary": "Item download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this item.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/service-layer-architecture"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    }
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/service-layer-architecture",
    "downloadUrl": "https://openagent3.xyz/downloads/service-layer-architecture",
    "agentUrl": "https://openagent3.xyz/skills/service-layer-architecture/agent",
    "manifestUrl": "https://openagent3.xyz/skills/service-layer-architecture/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/service-layer-architecture/agent.md"
  }
}
```
## Documentation

### Service Layer Architecture

Clean, performant API layers with proper separation of concerns and parallel data fetching.

### When to Use

Building REST APIs with complex data aggregation
GraphQL resolvers needing data from multiple sources
Any API where responses combine data from multiple queries
Systems needing testable, maintainable code

### Three-Layer Architecture

┌─────────────────────────────────────────────────────┐
│  Controllers   │  HTTP handling, validation        │
├─────────────────────────────────────────────────────┤
│  Services      │  Business logic, data enrichment  │
├─────────────────────────────────────────────────────┤
│  Queries       │  Database access, raw data fetch  │
└─────────────────────────────────────────────────────┘

### Layer 1: Controllers (HTTP Only)

// controllers/Entity.ts
import { getEntity, getEntities } from "../services/Entity";

const router = new Router();

router.get("/entity/:entityId", async (ctx) => {
  const { entityId } = ctx.params;

  if (!entityId) {
    ctx.status = 400;
    ctx.body = { error: "Invalid entity ID" };
    return;
  }

  const entity = await getEntity(entityId);
  
  if (!entity) {
    ctx.status = 404;
    ctx.body = { error: "Entity not found" };
    return;
  }
  
  ctx.status = 200;
  ctx.body = entity;
});

### Layer 2: Services (Business Logic)

// services/Entity.ts
import { queries } from "@common";

export const getEntityData = async (entity: RawEntity): Promise<EnrichedEntity> => {
  // Parallel fetch all related data
  const [metadata, score, activity, location] = await Promise.all([
    queries.getMetadata(),
    queries.getLatestScore(entity.id),
    queries.getActivity(entity.id),
    queries.getLocation(entity.slotId),
  ]);

  // Transform and combine
  return {
    ...entity,
    bonded: entity.bonded / Math.pow(10, metadata.decimals),
    total: score?.total ?? 0,
    location: location?.city,
    activity: {
      activeCount: activity?.active?.length ?? 0,
      inactiveCount: activity?.inactive?.length ?? 0,
    },
  };
};

export const getEntity = async (entityId: string): Promise<EnrichedEntity | null> => {
  const entity = await queries.getEntityById(entityId);
  if (!entity) return null;
  return getEntityData(entity);
};

export const getEntities = async (): Promise<EnrichedEntity[]> => {
  const all = await queries.allEntities();
  const enriched = await Promise.all(all.map(getEntityData));
  return enriched.sort((a, b) => b.total - a.total);
};

### Layer 3: Queries (Database Access)

// queries/Entities.ts
import { EntityModel } from "../models";

export const allEntities = async () => {
  return EntityModel.find({}).lean();  // Always use .lean()
};

export const getEntityById = async (id: string) => {
  return EntityModel.findOne({ id }).lean();
};

export const validEntities = async () => {
  return EntityModel.find({ valid: true }).lean();
};

### Parallel Data Fetching

// BAD: Sequential (slow)
const metadata = await queries.getMetadata();
const score = await queries.getScore(id);
const location = await queries.getLocation(id);
// Time: sum of all queries

// GOOD: Parallel (fast)
const [metadata, score, location] = await Promise.all([
  queries.getMetadata(),
  queries.getScore(id),
  queries.getLocation(id),
]);
// Time: max of all queries

### Layer Responsibilities

TaskLayerParse request paramsControllerValidate inputControllerSet HTTP statusControllerCombine multiple queriesServiceTransform dataServiceSort/filter resultsServiceRun database queryQuery

### Related Skills

Related: postgres-job-queue — Background job processing
Related: realtime/websocket-hub-patterns — Real-time updates from services

### NEVER Do

NEVER put database queries in controllers — Violates separation
NEVER put HTTP concerns in services — Services must be reusable
NEVER fetch related data sequentially — Use Promise.all
NEVER skip .lean() on read queries — 5-10x faster
NEVER expose raw database errors — Transform to user-friendly messages
## Trust
- Source: tencent
- Verification: Indexed source record
- Publisher: wpank
- Version: 1.0.0
## Source health
- Status: healthy
- Item download looks usable.
- Yavira can redirect you to the upstream package for this item.
- Health scope: item
- Reason: direct_download_ok
- Checked at: 2026-05-08T18:10:02.434Z
- Expires at: 2026-05-15T18:10:02.434Z
- Recommended action: Download for OpenClaw
## Links
- [Detail page](https://openagent3.xyz/skills/service-layer-architecture)
- [Send to Agent page](https://openagent3.xyz/skills/service-layer-architecture/agent)
- [JSON manifest](https://openagent3.xyz/skills/service-layer-architecture/agent.json)
- [Markdown brief](https://openagent3.xyz/skills/service-layer-architecture/agent.md)
- [Download page](https://openagent3.xyz/downloads/service-layer-architecture)