Tinystruct Patterns

by affaan-mef648e01899bNo license275K starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated 3 days ago

tinystructフレームワークでアプリケーションモジュールまたはマイクロサービスを開発する際に使用。ルーティング、コンテキスト管理、BuilderによるJSON処理、CLI/HTTPデュアルモードのパターンをカバー。

Instructions onlySoftware Development
AI-generated overview

Guides building tinystruct Java application modules and microservices with routing, context, JSON and CLI/HTTP patterns.

What it does
This skill provides architectural and implementation patterns for developing modules on the tinystruct Java framework, where CLI and HTTP are treated equally. It covers extending AbstractApplication, defining routes and commands with @Action, handling per-request state through Context, JSON serialization with the native Builder component, configuration via application.properties, and generating the bin/dispatcher entry point. It also lists anti-patterns and testing approaches with JUnit 5.
When to use it
Use it when creating a new tinystruct Application module, defining @Action routes or command-line actions, or handling request state and JSON output. It is also meant for configuring database or system settings and for debugging routing conflicts or CLI argument parsing.
Requirements
Requires the tinystruct Java framework and a Java runtime; JUnit 5 for the described testing patterns. Instructions only; no scripts are shipped.

tinystruct 開発パターン

tinystruct Java フレームワークを使用してモジュールをビルドするためのアーキテクチャと実装パターン。CLIとHTTPが等しく扱われる軽量なシステムです。

使用するタイミング

  • AbstractApplication を拡張して新しい Application モジュールを作成するとき。
  • @Action を使用してルートとコマンドラインアクションを定義するとき。
  • Context を通じてリクエストごとの状態を処理するとき。
  • ネイティブの Builder コンポーネントを使用してJSONシリアライゼーションを行うとき。
  • application.properties でデータベース接続またはシステム設定を構成するとき。
  • ApplicationManager.init() を通じて標準的な bin/dispatcher エントリポイントを生成または再生成するとき。
  • ルーティング競合(Action)またはCLI引数解析のデバッグを行うとき。

動作の仕組み

tinystruct フレームワークは、@Action でアノテーションされたメソッドをターミナルとWeb環境の両方でルーティング可能なエンドポイントとして扱います。アプリケーションは AbstractApplication を拡張することで作成され、init() などのコアライフサイクルフックとリクエスト Context へのアクセスが提供されます。

ルーティングは ActionRegistry によって処理され、パスセグメントをメソッド引数に自動的にマッピングして依存関係を注入します。データのみのサービスでは、ゼロ依存のフットプリントを維持するために、JSONシリアライゼーションにネイティブの Builder コンポーネントを使用すべきです。フレームワークには ApplicationManager のユーティリティも含まれており、bin/dispatcher スクリプトを生成することでプロジェクトの実行環境をブートストラップします。

例

基本アプリケーション(MyService)

java
public class MyService extends AbstractApplication {    @Override    public void init() {        this.setTemplateRequired(false); // データ/APIアプリの .view 参照を無効化    }
    @Override public String version() { return "1.0.0"; }
    @Action("greet")    public String greet() {        return "Hello from tinystruct!";    }}

パラメータ付きルーティング(getUser)

java
// Web: /api/user/123 または CLI: "bin/dispatcher api/user/123" を処理@Action("api/user/(\\d+)")public String getUser(int userId) {    return "User ID: " + userId;}

HTTPモード分岐(login)

java
@Action(value = "login", mode = Mode.HTTP_POST)public boolean doLogin() {    // ログイン処理    return true;}

ネイティブJSONデータ処理(getData)

java
@Action("api/data")public Builder getData() throws ApplicationException {    Builder builder = new Builder();    builder.put("status", "success");    Builder nested = new Builder();    nested.put("id", 1);    nested.put("name", "James");    builder.put("data", nested);    return builder;}

設定

設定は src/main/resources/application.properties で管理されます。

テストパターン

JUnit 5 を使用して、アクションが ActionRegistry に登録されていることを検証することでアクションをテストします。

レッドフラグとアンチパターン

症状正しいパターン
com.google.gson または com.fasterxml.jackson のインポートorg.tinystruct.data.component.Builder を使用する。
.view ファイルの FileNotFoundExceptionAPIのみのアプリでは init() 内で setTemplateRequired(false) を呼び出す。
private メソッドへの @Action アノテーションアクションはフレームワークに登録されるために public である必要がある。
アプリ内での main(String[] args) のハードコーディングすべてのモジュールのエントリポイントとして bin/dispatcher を使用する。
手動での ActionRegistry 登録自動検出のために @Action アノテーションを優先する。

テクニカルリファレンス

詳細なガイドは references/ ディレクトリにあります:

  • アーキテクチャと設定 [blocked] — 抽象化、パッケージマップ、プロパティ
  • ルーティングと@Action [blocked] — アノテーションの詳細、モード、パラメータ
  • データ処理 [blocked] — JSONのためのネイティブ Builder の使用
  • システムと使用方法 [blocked] — Context、セッション、イベント、CLI使用方法
  • テストパターン [blocked] — JUnit 5 統合と ActionRegistry テスト

Source and attribution

Source:affaan-m/eccindocs/ja-JP/skills/tinystruct-patternsat commitef648e0

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal

Tinystruct Patterns Agent Skill | SourceWeft