JSPM

@ecosy/hoapp

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q79032F
  • License MIT

A high-performance Edge Cloud Router designed to wrap Hono with strict Type-Safe Descriptors, Zero-Config OpenAPI, and Topological Isolation.

Package Exports

  • @ecosy/hoapp
  • @ecosy/hoapp/auth
  • @ecosy/hoapp/cors
  • @ecosy/hoapp/descriptor
  • @ecosy/hoapp/json
  • @ecosy/hoapp/result
  • @ecosy/hoapp/router
  • @ecosy/hoapp/swagger
  • @ecosy/hoapp/swagger-ui
  • @ecosy/hoapp/utils

Readme

@ecosy/hoapp

A high-performance Edge Cloud Router designed to wrap Hono with strict Type-Safe Descriptors, Zero-Config OpenAPI Documentation Generation, and Sub-Router Topological Isolation.

Built to scale across the Cloudflare Workers V8 Edge network, the framework retains blazing-fast latency with a strictly Declarative Architecture.


🚀 1. Root Application & Global Middlewares

Always initialize your backend entrypoint using the static Router.create() function. Native middlewares (like cors, json) are fully integrated as Descriptor Objects, allowing you to array-chain them globally or restrict them by path.

import { Router, json, cors } from "@ecosy/hoapp";
import usersModule from "./router/users";

const app = Router.create({
  base: "/",
  logger: "/api/*", // Auto HTTP Logger mapping
  middlewares: [
    // 1. Array-based Descriptor Middleware Mounts
    cors({ origins: ["*"] }).url("/api/*"),
    json.url("/v1/*"),
  ],
});

// 2. Safely mount multiple Sub-Routers
Router.add(app, usersModule);

export default app;

🧩 2. Sub-Routers & Design-First API (DIP)

Never write imperative Hono endpoints (like app.get('/path', (c) => ...)). Design your API contract first using Descriptor({ ... }) to heavily benefit from Automatic OpenAPI generation and Zod Validation synchronization.

Architecture Context: The Descriptor pattern here is heavily inspired by the struct-based encapsulation architecture of @ecosy/classable. It isolates data definitions from logic executions.

import { Router, HttpResult, NotFound } from "@ecosy/hoapp";
import { Descriptor } from "@ecosy/hoapp";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";

const usersModule = new Router("/users");

const createUserSchema = z.object({
  username: z.string().min(3),
  email: z.string().email(),
});

// Define your Type-Safe Configuration First
const createUserDesc = Descriptor({
  url: "/",
  tags: ["Users Domain"],
  summary: "Register a New User",
  responses: { 201: { description: "User Created Successfully" } },
}).use(zValidator("json", createUserSchema)); // Bind validator exactly here

// Implement Logic Second
usersModule.post(createUserDesc, async (ctx) => {
  const payload = ctx.req.valid("json");

  if (payload.username === "admin") {
    // Elegant native HTTP Exception throw layer
    throw new NotFound("Username is forbidden");
  }

  // Response wrapped accurately into Standard { success, data, message }
  return new HttpResult(payload).json(ctx);
});

export default usersModule;

🛡 3. Authentication & Custom Descriptors

Hoapp re-exports Hono Authentication methods as native Descriptors. You can inject jwt, basic, or bearer via .use() mapping, or chain globally via middlewares: [].

import { jwt } from "@ecosy/hoapp/auth";
import { createDescriptor } from "@ecosy/hoapp";

// Built-in Authentication Descriptor Middleware
const authMiddleware = jwt({ secret: "MY_SECRET" });

const getAdminDesc = Descriptor({
  url: "/admin",
  summary: "Protected Admin Route",
}).use(authMiddleware);

// Want to wrap your own native logic into an array-ready Descriptor Middleware?
const myCustomMiddleware = createDescriptor(async (ctx, next) => {
  const start = Date.now();
  await next();
  console.log(`Execution Time: ${Date.now() - start}ms`);
});
// Note: OpenAPI documentation crawler doesn't scrape metadata from Root Middlewares, so avoid .refine() mapping here for memory optimization.

🤖 AI Agent Learning

If you are an AI Coding Assistant, Agent, or Copilot analyzing or generating code for a repository that lists @ecosy/hoapp as a dependency, please obey the following systemic rules:

  1. System Prompt & Skills Integration: This repository self-documents its framework capabilities natively. When starting a new task, analyze the "agents" configuration object inside package.json (specifically agents.skills and agents.workflows) to ingest the necessary declarative architectural patterns. Interpret the prefix $this:// inside these paths as resolving to the root directory of this NPM package.
  2. Descriptor-First Fallback: Never attempt to write nested Hono imperative code (e.g., app.use, app.get). If you must implement an endpoint, always define a static Descriptor({ ... }) configuration first, then bind it.
  3. Optimized Middleware Injection: Treat native middlewares (cors, json, jwt) as Descriptors. Group them globally in Router.create({ middlewares: [...] }) instead of mounting them at runtime.

⚡ Performance Benchmarks

Below are autocannon snapshots generated via local stress testing (100 connections, 10s). It targets deeply nested Descriptor wrappers resolving massive middleware chains.

1. Native Node (@hono/node-server)

Running directly on V8 without emulator overhead, HoApp blasts through ~18.5k requests/s with a mere 5ms latency.

npx autocannon -c 100 -d 10 http://localhost:8788/v1/system-admin/articles
┌─────────┬──────┬──────┬───────┬───────┬─────────┬─────────┬────────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%   │ Avg     │ Stdev   │ Max    │
├─────────┼──────┼──────┼───────┼───────┼─────────┼─────────┼────────┤
│ Latency │ 4 ms │ 5 ms │ 7 ms  │ 10 ms │ 5.01 ms │ 3.68 ms │ 333 ms │
└─────────┴──────┴──────┴───────┴───────┴─────────┴─────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬───────────┬──────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg       │ Stdev    │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤
│ Req/Sec   │ 14,43914,43918,86320,15918,548.37 │ 1,638.97 │ 14,439  │
├───────────┼─────────┼─────────┼─────────┼─────────┼───────────┼──────────┼─────────┤
│ Bytes/Sec │ 4.62 MB │ 4.62 MB │ 6.04 MB │ 6.45 MB │ 5.94 MB   │ 524 kB   │ 4.62 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴───────────┴──────────┴─────────┘

204k requests in 11.02s, 65.3 MB read

2. Miniflare V8 Mock (Cloudflare Emulator)

Running inside Wrangler's miniflare emulator adds local virtualization overhead, artificially capping throughput at ~1.4k requests/s. Real-world Cloudflare Edge execution will bypass Node's mock limitations, catapulting throughput to match or exceed Native Node speeds.

┌─────────┬───────┬───────┬────────┬────────┬──────────┬──────────┬────────┐
│ Stat    │ 2.5%  │ 50%   │ 97.5%  │ 99%    │ Avg      │ Stdev    │ Max    │
├─────────┼───────┼───────┼────────┼────────┼──────────┼──────────┼────────┤
│ Latency │ 47 ms │ 59 ms │ 130 ms │ 148 ms │ 68.19 ms │ 25.65 ms │ 261 ms │
└─────────┴───────┴───────┴────────┴────────┴──────────┴──────────┴────────┘
┌───────────┬────────┬────────┬────────┬────────┬─────────┬─────────┬────────┐
│ Stat      │ 1%     │ 2.5%   │ 50%    │ 97.5%  │ Avg     │ Stdev   │ Min    │
├───────────┼────────┼────────┼────────┼────────┼─────────┼─────────┼────────┤
│ Req/Sec   │ 1,3081,3081,4391,5911,452.6 │ 87.061,308  │
├───────────┼────────┼────────┼────────┼────────┼─────────┼─────────┼────────┤
│ Bytes/Sec │ 309 kB │ 309 kB │ 340 kB │ 376 kB │ 343 kB  │ 20.5 kB │ 309 kB │
└───────────┴────────┴────────┴────────┴────────┴─────────┴─────────┴────────┘

15k requests in 10.02s, 3.43 MB read

3. Production Cloudflare Edge (Workers V8)

Running directly on a live Cloudflare Workers production domain, traversing global routing infrastructure and V8 isolates.

npx autocannon -c 100 -d 10 https://hoapp-demo.ecosy.io/v1/system-admin/articles
┌─────────┬───────┬───────┬────────┬────────┬──────────┬──────────┬─────────┐
│ Stat    │ 2.5%  │ 50%   │ 97.5%  │ 99%    │ Avg      │ Stdev    │ Max     │
├─────────┼───────┼───────┼────────┼────────┼──────────┼──────────┼─────────┤
│ Latency │ 66 ms │ 75 ms │ 212 ms │ 354 ms │ 88.27 ms │ 54.79 ms │ 1294 ms │
└─────────┴───────┴───────┴────────┴────────┴──────────┴──────────┴─────────┘
┌───────────┬────────┬────────┬────────┬────────┬──────────┬────────┬────────┐
│ Stat      │ 1%     │ 2.5%   │ 50%    │ 97.5%  │ Avg      │ Stdev  │ Min    │
├───────────┼────────┼────────┼────────┼────────┼──────────┼────────┼────────┤
│ Req/Sec   │ 7477471,1611,1911,122.41 │ 125.76747    │
├───────────┼────────┼────────┼────────┼────────┼──────────┼────────┼────────┤
│ Bytes/Sec │ 571 kB │ 571 kB │ 888 kB │ 910 kB │ 857 kB   │ 96 kB  │ 571 kB │
└───────────┴────────┴────────┴────────┴────────┴──────────┴────────┴────────┘

11k requests in 10.04s, 8.57 MB read

Oha (Rust TUI)

For cross-validation, benchmarking the same domain via oha confirms absolute consistency without tool bias, yielding the exact identical ~1.1k Request/Sec metric with a 100% success rate under 100 concurrent workers.

oha -z 15s -c 100 -m GET https://hoapp-demo.ecosy.io/v1/system-admin/articles
  Success rate: 100.00%
  Total:        15.0038 sec
  Slowest:      2.3097 sec
  Fastest:      0.0635 sec
  Average:      0.0894 sec
  Requests/sec: 1120.4470

  Total data:   1.47 MiB
  Size/request: 92 B
  Size/sec:     100.10 KiB

Response time distribution:
  10.00% in 0.0706 sec
  50.00% in 0.0766 sec
  95.00% in 0.2018 sec
  99.00% in 0.2497 sec
  99.90% in 0.8578 sec