Netpress Laravel-inspired backend framework for Node.js
Frameworkv0.1.14 Starterv0.1.12 Docsv1.0.3
Overview Installation Architecture CLI
Core Concepts

Services

Services hold business logic.

In Netpress, controllers should stay focused on HTTP concerns. Services are where you put workflows, rules, integrations, and reusable application logic.

Why Services Matter

Without services, controllers often become a mix of:

  • validation
  • domain rules
  • model queries
  • side effects
  • API response formatting

That becomes hard to reuse and hard to test.

Controller -> Service -> Model / External Systems

This keeps each layer small and clear.

Example

// app/Services/UserProfileService.js
import User from '../Models/User.js';

export default class UserProfileService {
  static async updateProfile(userId, payload) {
    const user = await User.findOrFail(userId);
    return user.update(payload);
  }
}
// app/Http/Controllers/UserProfileController.js
import { BaseController } from '@admicaa/netpress';
import UserProfileService from '../../Services/UserProfileService.js';

class UserProfileController extends BaseController {
  async update(req, res) {
    const user = await UserProfileService.updateProfile(req.user.id, req.body);
    return res.success(user);
  }
}

What Belongs In A Service

  • business rules
  • multi-step workflows
  • integrations with mail, queue, cache, storage, or external APIs
  • reusable application logic shared by multiple controllers

What Should Stay Out

  • route registration
  • low-level response formatting
  • provider boot logic

Good Naming

Prefer names that describe the job clearly:

  • AuthService
  • BillingService
  • UserProfileService
  • InvoiceReminderService

Keep services boring and explicit. That is usually a good sign.