Installation
Honocube is designed to work within a TypeScript environment, typically as part of a monorepo or a standalone Hono project.
Prerequisites
- Node.js: v18 or higher.
- Package Manager: Yarn, NPM, or PNPM.
- Database: A database compatible with Drizzle ORM (e.g., SQLite, PostgreSQL, MySQL).
Setup
First, add the Honocube API package to your project:
# Inside your API package/app
yarn add @honocube/api
Peer Dependencies
Ensure you have the following peer dependencies installed:
yarn add hono drizzle-orm
Coming from 1.x? See the migration guide.
zod is an optional peer dependency: the framework validates with the
Standard Schema protocol, so a validator written with Zod, with
Valibot or with ArkType is accepted. Install zod only if your own resources use it.
Basic Configuration
To start using Honocube, you'll need to initialize your application configuration using createApp.
import { createApp, createDrizzleAdapter } from "@honocube/api";
import { db } from "./db"; // Your Drizzle DB instance
export const { defineResource, defineApi } = createApp({
adapter: createDrizzleAdapter(db, { dialect: "sqlite" }),
logger: {
info: (msg) => console.log(msg),
// ... other logger methods
},
// Optional: Context provider for Auth/RLS
getContext: async (c) => {
return {
user: c.get('user'),
};
},
});
Folder Structure (Recommended)
While Honocube doesn't enforce a strict folder structure, we recommend organizing your resources like this:
src/
├── resources/
│ ├── users.ts
│ ├── posts.ts
│ └── index.ts
├── db/
│ └── schema.ts
└── index.ts (Entry point)
In the next section, we'll see how to define your first resource.