Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/docs/content/docs/dev/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ title: Authorization
description: xddd
---

<Callout type="warn" title="This documentation is under construction! 🚧">
We're working hard to bring you the best documentation experience.
</Callout>

## Configuration

You can configure the authentication settings in the `VitNodeAPI` function and `authorization` param.
Expand Down
96 changes: 96 additions & 0 deletions apps/docs/content/docs/dev/database/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: Database
description: Learn how to work with databases in VitNode plugins using Drizzle ORM and PostgreSQL.
---

VitNode plugins seamlessly integrate with databases using [Drizzle ORM](https://orm.drizzle.team/) and [PostgreSQL](https://www.postgresql.org/). This guide shows you how to define schemas, perform database operations, and manage migrations.

## Defining Schema

Create your database schema in the `database` directory of your plugin. Each table should be defined in its own file for better organization.

```ts title="plugins/{plugin_name}/src/database/categories.ts"
import { pgTable, serial, timestamp } from 'drizzle-orm/pg-core';

export const blog_categories = pgTable('blog_categories', {
id: serial().primaryKey(),
createdAt: timestamp().notNull().defaultNow(),
updatedAt: timestamp()
.notNull()
.$onUpdate(() => new Date()),
});
```

## Accessing Database

Access the database in your plugin handlers using `c.get('database')` from the Hono context. This provides a Drizzle ORM instance for all your database operations.

```ts title="plugins/{plugin_name}/src/routes/posts.ts"
export const postsRoute = buildRoute({
...CONFIG_PLUGIN,
route: {},
handler: async c => {
// [!code ++:7]
const data = await c
.get('database')
.select({
id: blog_posts.id,
title: blog_posts.title,
})
.from(blog_posts);

return c.json(data);
},
});
```

## Database Operations

VitNode provides convenient commands for managing your database schema and migrations.

### Creating Migrations

Generate migration files when you modify your database schema:

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

<Tabs groupId='package-manager' persist items={['pnpm', 'bun', 'npm']}>

```bash tab="pnpm"
pnpm db:migrate
```

```bash tab="bun"
bun db:migrate
```

```bash tab="npm"
npm run db:migrate
```

</Tabs>

### Pushing Schema Changes

Apply your schema changes directly to the database:

<Tabs groupId='package-manager' persist items={['pnpm', 'bun', 'npm']}>

```bash tab="pnpm"
pnpm db:push
```

```bash tab="bun"
bun db:push
```

```bash tab="npm"
npm run db:push
```

</Tabs>

<Callout type="info" title="Automatic Updates in Development">
VitNode automatically runs migrations and schema updates when you start your
application in development mode, keeping your database in sync with your code.
</Callout>
10 changes: 10 additions & 0 deletions apps/docs/content/docs/dev/i18n/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Expand Languages
description: Expand the languages to your application.
---

<Callout type="warn" title="This documentation is under construction! 🚧">
We're working hard to bring you the best documentation experience.
</Callout>

As default VitNode uses the `en` _(English USA)_ language for the application.
4 changes: 4 additions & 0 deletions apps/docs/content/docs/dev/i18n/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Internationalization (I18n)",
"pages": ["expand-langs", "messages", "namespaces", "..."]
}
25 changes: 3 additions & 22 deletions apps/docs/content/docs/dev/i18n/namespaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,24 @@ For example, you have a component that needs to get access to the translation st

To translate your content, select the plugin in `frontend` folder, go to `langs` folder and pick the language you want to translate.

```json title="apps/frontend/src/plugins/{your_plugin}/langs/en.json"
{
"{your_plugin}": {
"home": {
"hello": "Hello World",
"world": "World"
}
}
}
```

<Callout title="Primary key" type="warn">
Name your plugin should be a primary key in the JSON file or with the prefix `admin_` for admin plugins.

```json title="apps/frontend/src/plugins/{your_plugin}/langs/en.json"
```json title="plugins/{your_plugin}/src/locales/en.json"
{
"{your_plugin}": {
"hello": "Hello World" // ✅ This will work
},
"admin_{your_plugin}" {
"world": "World" // ✅ This will work
},
"world": "World" // ❌ This will not work
}
```

</Callout>

## Usage

To get access to the translation strings in other namespaces you need to use the `TranslationsProvider` component.

```tsx title="apps/frontend/src/app/[locale]/(main)/{your_plugin}/layout.tsx"
```tsx title="plugins/{your_plugin}/src/app/blog/layout.tsx"
import { I18nProvider } from '@vitnode/core/components/i18n-provider';

export default function Layout({ children }: { children: React.ReactNode }) {
return <I18nProvider namespaces={['welcome.home']}>{children}</I18nProvider>;
return <I18nProvider namespaces={['blog.home']}>{children}</I18nProvider>;
}
```

Expand Down
4 changes: 4 additions & 0 deletions apps/docs/content/docs/dev/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ description: Welcome to the VitNode documentation!
icon: Power
---

<Callout type="warn" title="This documentation is under construction! 🚧">
We're working hard to bring you the best documentation experience.
</Callout>

## Get started

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
Expand Down
11 changes: 9 additions & 2 deletions apps/docs/content/docs/dev/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
"swagger",
"---Framework---",
"auth",
"---API---",
"---Plugins---",
"plugins",
"rest-api",
"fetcher",
"---Rest---",
"database",
"---UI---",
"layouts-and-pages",
"admin-page",
"i18n",
"---Advanced---",
"..."
]
}
49 changes: 49 additions & 0 deletions apps/docs/content/docs/dev/plugins.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Create Plugins
description: Learn how to create plugins for VitNode to extend its functionality.
---

<Callout type="warn" title="This documentation is under construction! 🚧">
We're working hard to bring you the best documentation experience.
</Callout>

In this section we'll guide you through the process of creating your first VitNode plugin. Whether you're building a simple feature or a complex application, VitNode's plugin system has got you covered.

By creating a plugin, you can extend the functionality like:

- **🚀 APIs**: Build your own RESTful,
- **🧩 UI Components**: Create reusable components for your application,
- **📄 Pages and Layouts**: Define custom pages and layouts for your application,
- **⚡ Middleware**: Add custom middleware to handle requests and responses,
- **🗄️ Database Models**: Define your own database models and schemas,
- **🔗 Integrations**: Connect with third-party services and APIs.
- **⚙️ Custom Logic**: Implement any custom logic you need for your application.
- **🌟 And much more!**

## Create a Plugin

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

<Tabs groupId='package-manager' persist items={['pnpm', 'bun', 'npm']} label='Create a Plugin'>

```bash tab="pnpm"
pnpm create vitnode-app@canary --plugin
```

```bash tab="bun"
bun create vitnode-app@canary --plugin
```

```bash tab="npm"
npx create-vitnode-app@canary --plugin
```

</Tabs>

## Prerequisites

### Ignore `(plugins)` Folders

Before diving into plugin development, please ignore all `(plugins)` folders form search results in your IDE. These folders are generated by VitNode and contain the plugin code, which is not meant to be modified directly.

If you're using VS Code, this configuration is provided out-of-the-box via the `.vscode/settings.json` file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Routing
title: Restful API
description: Learn how to create and organize API routes in your VitNode plugins with modules, handlers, and parameter validation.
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ VitNodeAPI({
plugins: [],
authorization: {
// [!code ++]
ssoPlugins: [
ssoProviders: [
// [!code ++]
DiscordSSOApiPlugin({
// [!code ++]
Expand Down
4 changes: 4 additions & 0 deletions apps/docs/content/docs/dev/swagger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ description: Generate API documentation with OpenAPI.
icon: ListCollapse
---

<Callout type="warn" title="This documentation is under construction! 🚧">
We're working hard to bring you the best documentation experience.
</Callout>

Swagger is a tool that helps you generate API documentation with OpenAPI. It's a powerful tool that can help you write documentation automatically and validate the request.

## Usage
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/content/docs/guides/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"pages": [
"index",
"...",
"---Plugins by VitNode---",
"blog",
"--- Authorization ---",
"sso",
"--- Security ---",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/guides/sso/discord.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ VitNodeAPI({
// [!code ++]
authorization: {
// [!code ++]
ssoPlugins: [
ssoProviders: [
// [!code ++]
new DiscordSSOApiPlugin({
// [!code ++]
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/guides/sso/facebook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ VitNodeAPI({
// [!code ++]
authorization
// [!code ++]
ssoPlugins: [
ssoProviders: [
// [!code ++]
new FacebookSSOApiPlugin({
// [!code ++]
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/guides/sso/google.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ VitNodeAPI({
// [!code ++]
authorization: {
// [!code ++]
ssoPlugins: [
ssoProviders: [
// [!code ++]
new GoogleSSOApiPlugin({
// [!code ++]
Expand Down
23 changes: 0 additions & 23 deletions apps/docs/content/docs/plugins/database/index.mdx

This file was deleted.

27 changes: 0 additions & 27 deletions apps/docs/content/docs/plugins/index.mdx

This file was deleted.

19 changes: 0 additions & 19 deletions apps/docs/content/docs/plugins/meta.json

This file was deleted.

Loading