A powerful and flexible command-line interface (CLI) for managing TSDIAPI projects.
TSDIAPI is a modern, ESM-based framework built with TypeScript and Fastify, focusing on high performance, modularity, and flexibility. The CLI enables developers to rapidly build APIs with a well-structured, plugin-based architecture.
π Documentation: For detailed documentation, visit https://tsdiapi.com/
TSDIAPI CLI is designed to simplify working with TSDIAPI-based servers. It provides:
β
Quick project setup β Initialize new API projects with ease.
β
ESM support β Leverage modern JavaScript features with ESM modules.
β
Modular plugin system β Extend functionality dynamically.
β
Automatic code generation β Generate controllers, services, and features effortlessly.
β
Configuration management β Easily handle environment variables and settings.
β
Fastify-powered backend β Lightweight, high-performance server with a flexible routing system.
By default, the generated project provides a solid foundation leveraging Fastify, TypeBox, and TypeDI for a scalable and maintainable API architecture.
npx @tsdiapi/cli create myapi
cd my-api
npm startTo install TSDIAPI CLI globally using npm:
npm install -g @tsdiapi/cliOnce installed, use the tsdiapi command from any terminal.
To create a new Fastify-based API project, use:
tsdiapi init <project-name>This guides you through an interactive setup, allowing you to configure details like project name, host, and port.
For a fast setup that skips all prompts and immediately starts the server, use:
tsdiapi start <project-name>| Command | Description |
|---|---|
init |
Creates a new project with interactive setup. |
create |
Alias for init, creates a new project with optional skipping. |
start |
Creates a new project with defaults and starts it immediately. |
TSDIAPI supports modular plugins to add features like PrismaORM, WebSockets, JWT authentication, etc.
To install a new plugin, use:
tsdiapi plugins add <plugin-name>For example, to add Prisma support:
tsdiapi plugins add prismaSome plugins require additional setup. Use:
tsdiapi plugins config <plugin-name>π Explore all available plugins
TSDIAPI CLI features a powerful code generation system that detects installed plugins and their generators dynamically.
To generate code, use:
tsdiapi generate <resource|pluginName> <name>Example:
tsdiapi generate module userThis will create a UserController.
| Resource | Description |
|---|---|
feature |
Generate a new feature module. |
service |
Generate a new service. |
module |
Generate a new module. |
<plugin> |
Use a specific plugin's generator. |
Below is a comprehensive list of all available commands in the TSDIAPI CLI, along with their descriptions.
| Command | Description |
|---|---|
tsdiapi init [name] |
Initializes a new TSDIAPI project with an interactive setup. |
tsdiapi create <name> |
Alias for init, creates a new project. |
tsdiapi start <name> |
Quickly creates a project with default settings and starts the server. |
tsdiapi plugins add <pluginName> |
Adds a plugin to the project. |
tsdiapi add <pluginName> |
Alias for plugins add, adds a plugin to the project. |
tsdiapi plugins config <pluginName> |
Configures an installed plugin. |
tsdiapi config <pluginName> |
Alias for plugins config, configures a plugin. |
tsdiapi plugins update <pluginName> |
Updates an installed plugin. |
tsdiapi generate <pluginArg> <name> |
Generates files using a plugin or built-in generator. |
tsdiapi prisma |
Adds PrismaORM to the project. |
tsdiapi feature <name> |
Generates a new feature module. |
tsdiapi service <name> [feature] |
Generates a new service with optional feature module. |
tsdiapi module <name> [feature] |
Generates a new module with optional feature module. |
| Command | Description |
|---|---|
tsdiapi dev plugin <name> |
Creates a new plugin with an interactive setup. |
tsdiapi dev check |
Validates the configuration of a plugin. |
- Plugins define generators, introducing new capabilities.
- The CLI automatically detects installed plugins and their generators.
- No manual setupβjust install plugins and start generating code.
TSDIAPI provides a structured route-building system via useRoute(), using Fastify & TypeBox.
import { AppContext } from "@tsdiapi/server";
import { Type } from "@sinclair/typebox";
export default function userController({ useRoute }: AppContext) {
useRoute()
.get("/users/:id")
.params(Type.Object({ id: Type.String() }))
.code(200, Type.Object({ id: Type.String(), name: Type.String() }))
.handler(async (req) => {
return { id: req.params.id, name: "John Doe" };
})
.build();
}- TypeBox schemas ensure runtime validation.
- useRoute() API provides chained route configuration.
You can extend functionality with custom plugins. Each plugin can define:
| Lifecycle Hook | Description |
|---|---|
onInit |
Runs before server starts β used for setup tasks. |
beforeStart |
Runs before listening β useful for last checks. |
afterStart |
Runs after server starts β ideal for background tasks. |
export function myPlugin() {
return {
name: "myPlugin",
async onInit(context) {
console.log("myPlugin: Initialized!");
},
async afterStart(context) {
console.log("myPlugin: Server started!");
},
};
}Register it in createApp:
import { createApp } from "@tsdiapi/server";
import { myPlugin } from "./api/plugins/myPlugin";
await createApp({
plugins: [myPlugin()],
});TSDIAPI automatically loads .env variables for easy configuration.
PORT=3000
HOST=localhost
const port = context.projectConfig.get("PORT", 3000);
const host = context.projectConfig.get("HOST", "localhost");TSDIAPI automatically generates OpenAPI documentation.
Once your server is running, check Swagger UI:
π http://localhost:3000/docs
TSDIAPI CLI allows developers to create custom plugins that extend the framework. Plugins can introduce new services, middleware, configurations, and generators.
To generate a new plugin, use:
tsdiapi dev plugin <name>This will guide you through configuring the plugin, including:
- Name (automatically converted to the correct format).
- Description.
- Author name.
- GitHub repository URL (optional).
- Automatic file loading support.
Once configured, the CLI will generate the necessary files and set up a base plugin structure.
To check if a plugin's configuration is correct, use:
tsdiapi dev checkThis command validates the plugin's configuration and ensures it follows best practices.
TSDIAPI is an open-source project. Contributions are welcome! π
π§ Contact: unbywyd
With TSDIAPI, you can build fast, modular, and scalable APIs with ease.
Dive in and start building today! π