Skip to content

About

Exploring functional application design principles, architectural patterns, and practices through research and implementation in F#.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

関数型アーキテクチャ設計指針

関数型アーキテクチャを中心に、他のアプリケーションにも応用できる設計指針を調査・検証するリポジトリ。RealWorld(Conduit)の Web アプリケーションを、指針を検証する題材として実装している。

文書

文書の索引と、文書を置く場所の方針は docs/README.md にある。

題材アプリ

F# と PostgreSQL で実装している。RealWorld バックエンド API 2.0.0 の全エンドポイント(ユーザー、プロフィール、記事、一覧、フィード、お気に入り、タグ、コメント)を実装済みで、仕様は docs/reference-app/ にある。

準備

  • .NET 10 SDK
  • PostgreSQL 18(localhost:55432、ユーザー postgres、DB conduit)
  • Hurl(仕様の API テストを流す場合。scoop install hurl など)

使い捨てのクラスタを作るスクリプトがある。scratch/pgdata(git 管理外)にクラスタを作り、ポート 55432 で起動して DB conduit を作る。Windows では Git Bash で実行する(PowerShell の bash は WSL を指すことがある)。

bash scripts/pg-local.sh init     # 初回。クラスタを作って起動し、DB を作る
bash scripts/pg-local.sh start    # 2 回目以降
bash scripts/pg-local.sh status
bash scripts/pg-local.sh stop

接続先は、各プロジェクト(src/Conduit.Infrastructure、tests/Conduit.Infrastructure.Tests、tests/Conduit.Infrastructure.QueryPlans)の connStr で指定している。JWT の鍵は src/Conduit.Infrastructure/Shell/Program.fs の定数である(プロトタイプ)。

スキーマは、サーバーを起動する前に作る。src/Conduit.Infrastructure/schema.sql を適用するか、下の Conduit.Infrastructure.Tests を一度実行する。どちらもテーブルを作り直すので、データは消える。

psql -h localhost -p 55432 -U postgres -d conduit -v ON_ERROR_STOP=1 -f src/Conduit.Infrastructure/schema.sql

ビルドとテスト

dotnet build Conduit.slnx
dotnet run --project tests/Conduit.Domain.Tests          # Domain の判断の例示テスト(DB は使わない)
dotnet run --project tests/Conduit.Application.Tests     # 解析・判断の呼び出し・整形の例示テスト(DB は使わない)
dotnet run --project tests/Conduit.Infrastructure.Tests  # 記事一覧・フィードの SQL と参照モデルの比較(実DB。実行のたびにスキーマを作り直す)

実行

dotnet run --project src/Conduit.Infrastructure  # http://localhost:5099/api/... でサーバーを起動する

認証は JWT(HS256)で、POST /api/users か POST /api/users/login の応答の user.token を Authorization: Token <token> で送る。

仕様の API テスト(Hurl)

サーバーを起動した状態で、仕様に含まれる Hurl のテストを流す。引数なしで全ファイル、ファイルを指定すればその分だけを実行する。

HOST=http://localhost:5099 bash docs/reference-app/api/hurl/run-hurl-tests.sh
HOST=http://localhost:5099 bash docs/reference-app/api/hurl/run-hurl-tests.sh docs/reference-app/api/hurl/articles.hurl

実行計画の確認

20 万件のデータを投入してから、記事一覧の実行計画と実行時間を表示する。スキーマは上の手順で作っておく(Conduit.Infrastructure.Tests を再び実行すると、投入したデータは消える)。

psql -h localhost -p 55432 -U postgres -d conduit -v ON_ERROR_STOP=1 -f scripts/bulk.sql
dotnet run --project tests/Conduit.Infrastructure.QueryPlans         # 実行計画と実行時間を表示する
dotnet run --project tests/Conduit.Infrastructure.QueryPlans -- sql  # 生成される SQL を表示する(DB は使わない)

About

Exploring functional application design principles, architectural patterns, and practices through research and implementation in F#.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages