# Seishiro API

![](https://img.shields.io/npm/v/seishiro?style=for-the-badge)

### What Is Seishiro API ?

Seishiro is a library **orchestrator API** that **eliminates the complexity of managing folder routing structures**. Instead of managing dozens of scattered route files, Seishiro centralizes control of your application in a single Registry.

Whether you are building a Web (REST), Mobile, or Server-Side Rendering (SSR) application, Seishiro ensures consistent data flow standards.

### Why Seishiro?

Seishiro was born out of a common concern in modern application development: increasingly complex routing and inconsistent responses.

1. **Eliminating Routing Complexity**\
   Seishiro's main vision is to eliminate traditional folder routing management. Inspired by the flexibility of GraphQL, Seishiro uses a Single Request Command Dispatcher system. You no longer need to create dozens of route files; just use one endpoint as the control center for all your application actions.
2. **Standardized Protocol Response**\
   We believe developers shouldn't have to waste time setting HTTP statuses, manual headers, or different JSON structures in each file.
   1. **Auto-Building Response**: Seishiro automatically builds consistent status codes, headers, and data structures.
   2. **Immutable Structure**: Seishiro's response structure will never change, ensuring that the integration between the Backend and Frontend (Web, Mobile, SSR) is always in sync without any surprise breaking changes.
3. **Developer-Centric Workflow**\
   Seishiro follows the natural workflow of developers. By separating Registry, Policy, and Message, you can focus on business logic without having to think about the data delivery infrastructure repeatedly.
4. **Integrated Versioning & Lifecycle**\
   One of our main missions is to simplify application maintenance on the client side.
   1. **Auto-Update Signal**: Through the versioning system in PolicyBuilder, Seishiro can detect the client version and provide direct instructions to display an update banner or force an automatic update on the View side.
   2. **Consistency at Scale**: Ensures that the application version running on the user's device is always compatible with the API on the server.

### Key Value Propositions

* **Centralized Control**: Manage all application endpoints in one RegistryBuilder.
* **Protocol Agnostic**: One logic for multiple protocols: API Action, Server Action (Next.js), and System Action.
* **Smart Messaging**: Multi-language error messaging system with dynamic variable support.
* **Security Layer**: Endpoint protection based on registry list encryption via AES-256-CTR.
* **Version Enforcement**: Full control over the client versions allowed to access the system.

### How It Works?

1. **The Policy**: Checks whether the client has the appropriate permissions and version.
2. **The Registry**: Searches for the appropriate controller and middleware for the request.
3. **The Message**: Formats the response into the desired language in case of an error or success.

### Quick Start For Example!

Get full control over your API in just a few simple steps:

```bash
npm install seishiro
# Or Use Bun?
bun add seishiro
```

<pre class="language-typescript"><code class="lang-typescript">import { RegistryBuilder, PolicyBuilder, Actions } from "seishiro"

<strong>// Set Your Variable Message
</strong><strong>const message = new MessageBuilder("en")
</strong>// Default Variable Message
message.set("no-response-sending", "Server not response!")
message.set("no-registry", "Registry not found!")
message.set("internal-server-error", "Internal server error!")
// Costum Variable Message
<strong>message.set("user-not-login", "{{username}} has not login!")
</strong><strong>message.set("user-not-found", "{{username}} not found!")
</strong>
<strong>// Register your logic
</strong><strong>const registry = new RegistryBuilder()
</strong><strong>registry.set("user:profile", GetUserProfile, AuthMiddleware);
</strong>
<strong>// Set Your Policy Rules
</strong><strong>const policy = new PolicyBuilder({
</strong><strong>  passkey: process.env.SEISHIRO_PASSKEY, // For Book Registry Access
</strong><strong>  version_now: "1.4.5", // Only support number (0-9.)
</strong><strong>  version_min: "1.4.0", // Minimum version
</strong><strong>  version_forceupdate: true, // Force Update
</strong><strong>})
</strong>
<strong>// Setup Action
</strong><strong>const action = new Actions({
</strong><strong>  registry: registry,
</strong><strong>  message: message,
</strong><strong>  policy: policy,
</strong><strong>})
</strong>
<strong>// Execute anywhere
</strong><strong>const response = await action.APIAction({ type: "user:detail", data: { username: "@me" } });
</strong></code></pre>

### Explore the Documentation

* [Getting Started](https://nakikoneko.gitbook.io/seishiroapi/section/installation): Installation and initial setup.
* [Core Concepts](https://nakikoneko.gitbook.io/seishiroapi/core-library/registry): Understanding Registry, Message, and Policy.
* [Advanced Usage](https://nakikoneko.gitbook.io/seishiroapi/section/book-registry): About Book Registry and why use Encrypted.
