backend-architect
npx machina-cli add skill k1lgor/virtual-company/13-backend-architect --openclawBackend 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
- Separation of Concerns:
- Separate Controllers (HTTP handling) from Services (Business Logic) and Data Access (Repositories/DAOs).
- Error Handling:
- Implement global error handling middleware to catch unhandled exceptions.
- Return standardized error responses to the client.
- Validation:
- Validate inputs at the controller boundary before processing.
- 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
- Step 1: Define Controllers, Services, and Repositories with clear responsibility boundaries.
- Step 2: Add a global error handler and enforce input validation at the controller boundary.
- 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.