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

Controllers

Controllers are the HTTP boundary in Netpress.

They receive the request, call the right service or model, and return a response. They should stay thin. If a controller starts owning business rules, it usually belongs in a service instead.

What Controllers Should Do

  • read request input
  • validate input
  • authorize the action
  • call a service or model
  • return a response

What Controllers Should Not Do

  • hold large business workflows
  • wire infrastructure clients
  • contain repeated validation logic across many actions
  • know too much about persistence details

Quick Example

import { BaseController, json } from "@admicaa/netpress";
import StorePostRequest from "../Requests/StorePostRequest.js";
import PostService from "../../Services/PostService.js";

class PostController extends BaseController {
  async store(req) {
    const payload = await this.validate(req, StorePostRequest);
    const post = await PostService.create(req.user.id, payload);

    return json(post, 201);
  }
}

export default new PostController();

BaseController

Extending BaseController gives you common controller helpers:

  • await this.validate(req, RequestClassOrRules)
  • await this.authorize(req, PolicyClass, method, resource?)
  • await this.can(req, ability, resource?)

It also binds inherited action methods to the controller instance, so you can pass PostController.store directly to the router.

Response Options

You can return plain values and let Netpress handle the response:

async show(req) {
  return PostService.show(req.params.id);
}

You can also use explicit response helpers:

async show(req, res) {
  const post = await PostService.show(req.params.id);
  return res.success(post);
}

Or use response builders when you want clearer intent:

import { json, redirect, view } from "@admicaa/netpress";

return json({ created: true }, 201);
return redirect("/login");
return view(DashboardPage, { title: "Dashboard" });

Use this flow consistently:

Route -> Controller -> Service -> Model -> Response

That keeps controllers readable and makes the rest of the codebase easier to test and extend.

Next, read Services and Response System.