Skip to content

[Phase 1] Rust core — pm-core / pm-storage / pm-api / pm-codegen / pm-core-wasm #5

Description

@n-guitar

親 issue: #3
関連 ADR: #2 (ADR-0005, 0006, 0008)

目的

YuiPath の心臓部となる Rust crate 群を、ストレージとフレームワークから独立した形で 実装する。Pattern A / B / ローカル開発 / WASM のすべてが本 phase の crate に依存する。

完了条件 (DoD)

  • cargo test --workspace が通る (in-memory ストレージで pm-api E2E)
  • cargo run -p pm-codegen で packages/shared-types/ と OpenAPI が生成される
  • CI で codegen drift が検出される
  • pm-core-wasm を web から呼んで critical path 計算結果がモックと一致する

crate 別の実装範囲

crates/pm-core (純粋ドメイン)

  • types/: Project, Task, Resource, Comment, Calendar, Event, ID 型 newtype
  • serde 設定 (tag = "kind" / rename_all = "snake_case")
  • #[cfg_attr(feature = "codegen", derive(TS, JsonSchema))]
  • calendar: is_working_day / working_days_between / add_working_days (mock の primitives.jsx を移植)
  • status: 7-state taxonomy (STATUSES 移植) + progress マッピング
  • critical_path: 依存解決 + クリティカルパス計算
  • detectors: 「要注意 (今)」detector framework (mock の DETECTORS_NOW 配列を移植)
  • 単体テスト: 既知データセットで mock と同一結果

crates/pm-storage (trait 定義のみ)

  • ProjectStore trait (ADR-0006)
  • EventLog trait
  • Authenticator trait + AuthContext
  • エラー型 StorageError (NotFound / Conflict (optimistic lock) / Backend(...))

crates/pm-storage-mem (テスト用)

  • InMemoryProjectStore / InMemoryEventLog / StubAuth
  • pm-api のテストはこれを使う

crates/pm-events

  • Event 構造 (ADR-0002 のスキーマに対応)
  • TargetRef enum
  • TimeRange

crates/pm-api

  • axum::Router ファクトリ pub fn router(state: AppState) -> Router
  • routes/projects.rs / tasks.rs / resources.rs / comments.rs / events.rs
  • #[utoipa::path(...)] で OpenAPI 自動生成 (ADR-0008)
  • tower middleware: trace / cors / auth (Authenticator 経由)
  • error → JSON 変換層
  • integration tests (pm-storage-mem 注入)

crates/pm-core-wasm

  • #[wasm_bindgen] で公開する関数を選定:
    • compute_critical_path(tasks: JsValue) -> JsValue
    • evaluate_detectors(ctx: JsValue) -> JsValue
    • calc_working_days(...) 系
  • serde-wasm-bindgen でシリアライズ
  • wasm-pack build --target web --release + wasm-opt -Oz < 500KB gzip
  • benchmarks/critical-path: 1k タスクで p50 < 5ms

crates/pm-codegen (ADR-0008)

  • ts-rs export 設定 → packages/shared-types/src/*.ts
  • schemars 出力 → packages/shared-types/schemas/*.json
  • utoipa::OpenApi → packages/shared-types/openapi.json
  • openapi-typescript で packages/api-client/src/index.ts 生成
  • 生成物に「DO NOT EDIT」ヘッダ + ソース ADR への注記

非対象

  • 具体的なストレージ実装 (sqlite / dynamodb) → Phase 3 / 4
  • frontend 統合 → Phase 2
  • AI / MCP → スコープ外 (ADR-0003)

参照

  • mock の data.jsx / primitives.jsx / screens.jsx (要移植ロジック)
  • ADR-0002 (event log スキーマ)
  • ADR-0006 (trait 仕様)
  • ADR-0008 (codegen)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions