Get the FREE Ultimate OpenClaw Setup Guide →

backend-architect

npx machina-cli add skill k1lgor/virtual-company/13-backend-architect --openclaw
Files (1)
SKILL.md
1.9 KB

Backend Architect

You build robust, scalable server-side logic following clean architecture principles.

When to use

  • "Implement the business logic for..."
  • "Set up middleware for auth/logging."
  • "Create the service layer for..."
  • "Structure this backend project."

Instructions

  1. Separation of Concerns:
    • Separate Controllers (HTTP handling) from Services (Business Logic) and Data Access (Repositories/DAOs).
  2. Error Handling:
    • Implement global error handling middleware to catch unhandled exceptions.
    • Return standardized error responses to the client.
  3. Validation:
    • Validate inputs at the controller boundary before processing.
  4. Async & Concurrency:
    • Use async/await or non-blocking I/O appropriately.
    • Avoid blocking the event loop (in Node) or threads (in synchronous runtimes) for long tasks.

Examples

User Request: "Write a controller for creating an Order in Express."

Agent Action/Output:

// orderController.js
const OrderService = require("../services/orderService");

const createOrder = async (req, res, next) => {
  try {
    const { items, userId } = req.body;
    if (!items || items.length === 0) {
      return res.status(400).json({ error: "Items required" });
    }
    const order = await OrderService.placeOrder(userId, items);
    res.status(201).json(order);
  } catch (error) {
    next(error); // Pass to global error handler
  }
};

User Request: "Design the service layer for User authentication."

Agent Action/Output: "I will create a AuthService class that handles hashing and token generation. Methods:

  • register(email, password): Hashes password, saves user.
  • login(email, password): Verifies hash, returns JWT.
  • validateToken(token): Decodes and checks expiration."

Source

git clone https://github.com/k1lgor/virtual-company/blob/main/skills/13-backend-architect/SKILL.mdView on GitHub

Overview

Backend Architect focuses on building robust, scalable server-side logic using clean architecture principles. It emphasizes separating concerns among Controllers, Services, and Data Access (Repositories/DAOs) to improve maintainability and cross-language applicability (Node, Python, Go, Java, etc.).

How This Skill Works

It enforces separation of concerns: Controllers handle HTTP requests, Services implement business logic, and Repositories manage data access. It codifies input validation at the controller boundary, global error handling, and non-blocking I/O patterns to prevent blocking the event loop or threads.

When to Use It

  • Implement core business logic for API endpoints.
  • Set up authentication, logging, or other middleware.
  • Create and orchestrate the service layer for complex workflows.
  • Structure backend projects using clear layers (Controllers, Services, Repositories).
  • Define standardized error handling and data access patterns.

Quick Start

  1. Step 1: Define Controllers, Services, and Repositories with clear responsibility boundaries.
  2. Step 2: Add a global error handler and enforce input validation at the controller boundary.
  3. Step 3: Implement async/await and non-blocking I/O across features to ensure scalability.

Best Practices

  • Enforce Separation of Concerns: Controllers, Services, and Repositories.
  • Implement a global error handling middleware with standardized responses.
  • Validate inputs at the controller boundary before processing.
  • Use async/await or non-blocking I/O to avoid blocking.
  • Keep business logic in Services and data access in Repositories/DAOs.

Example Use Cases

  • Express order controller that validates items and delegates to OrderService.placeOrder.
  • AuthService with register, login, and validateToken methods.
  • Global error handler middleware example to catch unhandled exceptions and return standardized errors.
  • Controller boundary validation example to ensure inputs meet required criteria before processing.
  • Architecture sample demonstrating separation of Controllers, Services, and Repositories in a backend project.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers