service_layer_rules

Rules for backend service-layer code, the part of an application that coordinates business logic and data or external services. It keeps web-request handling and configuration access out of that layer.

In plain words
What is it for?
Use it when editing files in backend/services/ to coordinate repositories or software-development kits (SDKs), read configuration through the defined constants, and raise the appropriate service errors.
Why use it?
It keeps business decisions separate from HTTP details, making service code easier to maintain and reuse. It also gives failures a consistent form through domain-specific exceptions.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/modelengine-group/nexent/service_layer_rules
Clone the repo
git clone --depth 1 https://github.com/ModelEngine-Group/nexent

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 826 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00826
Opus 5 $0.00000 $0.00413
Sonnet 5 $0.00000 $0.00165
Haiku 4.5 $0.00000 $0.00083

Measured 2d ago against content hash 4cbffbffaa3f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

service_layer_rules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/backend/service_layer_rules.mdc · 113 lines

How it starts

The opening of the file, as written. The whole thing — 113 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Service Layer Rules

  • Scope: Applies to backend/services/*.py.
  • Goal: Implement core business logic and orchestrate complex workflows. Coordinate repositories/SDKs. Keep HTTP concerns out of this layer.
  • Exceptions: Raise domain/service exceptions declared in backend/consts/exceptions.py. If a new case is needed, add a new class there, then raise it here. Do not translate to HTTP here.
  • Environment variables: Do not access os.getenv() directly. Read configuration from consts.const (see environment_variable rule) or accept parameters.

Reference: backend/consts/exceptions.py

Correct example (service orchestrates business logic and raises domain exceptions)

# backend/services/agent_service.py
from typing import Any, Dict

from consts.exceptions import LimitExceededError, AgentRunException, MemoryPreparationException
# from consts.const import APPID, TOKEN  # Example: read config via consts, not os.getenv


def run_agent(task_payload: Dict[str, Any]) -> Dict[str, Any]:
    """Run agent core workflow and return domain result dict.
    Raises domain exceptions on failure; no HTTP concerns here.
    """
    if _is_rate_limited(task_payload):
        raise LimitExceededError("Too many requests for this tenant.")

    try:
        memory = _prepare_memory(task_payload)
    except Exception as exc:
        # Wrap low-level error in a domain exception for the app layer to translate
        raise MemoryPreparationException("Failed to prepare memory.") from exc

    try:
        result = _execute_core_logic(task_payload, memory)
    except Exception as exc:
        raise AgentRunException("Agent execution failed.") from exc

    # Return a plain Python object, not a Response
    return {"status": "ok", "data": result}


def _is_rate_limited(_: Dict[str, Any]) -> bool:
    return False


def _prepare_memory(_: Dict[str, Any]) -> Dict[str, Any]:
    return {"memo": "prepared"}


def _execute_core_logic(_: Dict[str, Any], __: Dict[str, Any]) -> Dict[str, Any]:
    return {"answer": "42"}

Read the full file on GitHub · 113 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 113 lines · 0 tokens per session scan A 4cbffbffaa3f

Subscribe to this mod's changes

service_layer_rules is a cursor rule published in the GitHub repository ModelEngine-Group/nexent (5,841 stars, last pushed 3d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 826 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.