Communitygithub.com

giuseppe-trisciuoglio/clean-architecture

Java 21+ Spring Boot 3.5+ アプリケーション向けに、クリーンアーキテクチャ、ヘキサゴナルアーキテクチャ(ポート&アダプター)、およびドメイン駆動設計の実装パターンを提供します。階層化アーキテクチャの構築、フレームワークからのドメインロジックの分離、ポートとアダプターの実装、エンティティ/値オブジェクト/集約の作成、またはモノリシックコードベースのテスト容易性と保守性向上のためのリファクタリングに使用します。

clean-architecture とは?

このスキルは、Clean Architecture、Hexagonal Architecture(Ports & Adapters)、およびDomain-Driven Design(DDD)の実装パターンをJava 21+とSpring Boot 3.5+アプリケーション向けに提供します。階層化されたアーキテクチャを構造化し、ドメインロジックをフレームワークや永続化の詳細から分離するための実践的なガイダンスを提供します。具体的には、アダプター層(RESTコントローラーやJPAリポジトリなど)との明確な契約を定義するポートインターフェースの実装方法、エンティティ、値オブジェクト、集約などのドメインオブジェクトの設計、およびアプリケーションサービスを介してユースケースを調整する方法を示します。このスキルは、テスト容易性を高め、保守性を改善し、技術的関心事の変更からコアビジネスロジックを保護するためにモノリシックコードベースをリファクタリングするのに特に役立ちます。Codex CLI、Cline、およびVS Codeでサポートされています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit/tree/main/skills/clean-architecture

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

clean-architecture は何をしますか?

Java 21+ Spring Boot 3.5+ アプリケーション向けに、クリーンアーキテクチャ、ヘキサゴナルアーキテクチャ(ポート&アダプター)、およびドメイン駆動設計の実装パターンを提供します。階層化アーキテクチャの構築、フレームワークからのドメインロジックの分離、ポートとアダプターの実装、エンティティ/値オブジェクト/集約の作成、またはモノリシックコードベースのテスト容易性と保守性向上のためのリファクタリングに使用します。

概要

このスキルは、Java 21+ および Spring Boot 3.5+ を使用する開発者を対象としており、堅牢でテスタブル、かつ保守可能なアプリケーションを構築するためのアーキテクチャパターンを提供します。これには以下のパターンが含まれます:

  • クリーンアーキテクチャ: 関心の分離と依存関係のルールに焦点を当て、レイヤーの依存関係が内側に向かうようにします。
  • ヘキサゴナルアーキテクチャ(ポート&アダプター): ドメインロジックの内外との通信に明確なポート(インターフェース)とアダプター(実装)を定義します。
  • ドメイン駆動設計 (DDD): コアドメインに重点を置き、エンティティ、値オブジェクト、集約、ドメインイベントなどの戦術的パターンを使用します。

実装戦略

1. レイヤー構造

Maven/Gradle モジュールまたは Java パッケージを使用して、明確なアーキテクチャバウンダリを定義します:

com.example.myapp
├── domain          # エンティティ、値オブジェクト、集約、ドメインイベント、リポジトリインターフェース
├── application     # アプリケーションサービス、ユースケースインターフェース、DTO
├── infrastructure  # 永続化(JPA)、メッセージング(Kafka/RabbitMQ)、外部 API クライアント
└── interfaces      # REST コントローラー、GraphQL リゾルバー、gRPC サービス

2. 依存関係のルール

  • ドメイン: 外部依存関係なし。純粋な Java ロジックのみ。
  • アプリケーション: domain に依存、フレームワーク固有のアノテーションは使用しない。
  • インフラストラクチャ: domain と application に依存。
  • インターフェース: application と domain に依存。

3. ポートとアダプター

ポート(インターフェース) はドメインレイヤーで定義します:

public interface OrderRepository {
    Optional<Order> findById(OrderId id);
    void save(Order order);
}

アダプター(実装) はインフラストラクチャレイヤーで定義します:

@Repository
public class JpaOrderRepository implements OrderRepository {
    private final JpaOrderEntityRepository jpaRepository;
    private final OrderMapper mapper;

    public JpaOrderRepository(JpaOrderEntityRepository jpaRepository, OrderMapper mapper) {
        this.jpaRepository = jpaRepository;
        this.mapper = mapper;
    }

    @Override
    public Optional<Order> findById(OrderId id) {
        return jpaRepository.findById(id.value()).map(mapper::toDomain);
    }

    @Override
    public void save(Order order) {
        jpaRepository.save(mapper.toEntity(order));
    }
}

4. アプリケーションサービス

アプリケーションサービスはユースケースを調整し、トランザクションとセキュリティを管理します:

@Service
@Transactional
public class CreateOrderService {
    private final OrderRepository orderRepository;
    private final PaymentService paymentService;
    private final EventPublisher eventPublisher;

    public CreateOrderService(OrderRepository orderRepository, PaymentService paymentService, EventPublisher eventPublisher) {
        this.orderRepository = orderRepository;
        this.paymentService = paymentService;
        this.eventPublisher = eventPublisher;
    }

    public CreateOrderResponse execute(CreateOrderCommand command) {
        Order order = Order.create(command.customerId(), command.items());
        PaymentResult payment = paymentService.charge(order.total());
        order.confirmPayment(payment.transactionId());
        orderRepository.save(order);
        eventPublisher.publish(new OrderCreatedEvent(order.id()));
        return new CreateOrderResponse(order.id().value(), order.status());
    }
}

5. ドメインオブジェクト

集約ルート: 一貫性とカプセル化を保証します:

public class Order {
    private final OrderId id;
    private OrderStatus status;
    private final List<OrderItem> items;
    private Money total;

    private Order(OrderId id, List<OrderItem> items) {
        this.id = id;
        this.status = OrderStatus.PENDING;
        this.items = Collections.unmodifiableList(items);
        this.total = items.stream().map(OrderItem::subtotal).reduce(Money.ZERO, Money::add);
    }

    public static Order create(CustomerId customerId, List<OrderItem> items) {
        return new Order(OrderId.generate(), items);
    }

    public void confirmPayment(TransactionId transactionId) {
        if (status != OrderStatus.PENDING) {
            throw new IllegalStateException("Order must be in PENDING status to confirm payment");
        }
        this.status = OrderStatus.CONFIRMED;
    }

    // ゲッター...
}

値オブジェクト: 不変で自己検証可能:

public record OrderId(UUID value) {
    public OrderId {
        Objects.requireNonNull(value, "OrderId value must not be null");
    }

    public static OrderId generate() {
        return new OrderId(UUID.randomUUID());
    }

    public static OrderId fromString(String value) {
        return new OrderId(UUID.fromString(value));
    }
}

テスト戦略

  • 単体テスト: Mock を使用してドメインオブジェクトとアプリケーションサービスをテストします。
  • 統合テスト: 実際のデータベース(Testcontainers を使用)とインフラストラクチャアダプターをテストします。
  • アーキテクチャテスト: ArchUnit を使用してアーキテクチャルールを強制します(例: "ドメインレイヤーが Spring に依存してはならない")。

アーキテクチャテストの例 (ArchUnit)

@AnalyzeClasses(packages = "com.example.myapp")
class ArchitectureTest {

    @ArchTest
    static final ArchRule domain_should_not_depend_on_infrastructure =
            classes()
                    .that().resideInAPackage("..domain..")
                    .should().onlyDependOnClassesThat().resideInAnyPackage("..domain..", "java..");

    @ArchTest
    static final ArchRule application_should_not_depend_on_spring =
            classes()
                    .that().resideInAPackage("..application..")
                    .should().onlyDependOnClassesThat().resideInAnyPackage("..application..", "..domain..", "java..");
}

制限事項

  • Java 21+ および Spring Boot 3.5+ 専用に設計されています。
  • インフラストラクチャ層で Jakarta EE を使用する必要があります(Spring Boot 3.x 以前の javax ではありません)。
  • DDD の戦術的パターンに重点を置いており、戦略的設計(境界づけられたコンテキスト、コンテキストマッピングなど)は対象外です。
  • CI/CD パイプライン、インフラストラクチャのプロビジョニング、またはクラウドへのデプロイの自動化は含まれません。
  • 高度なパターン(例: CQRS、イベントソーシング、Saga)は対象範囲外です。
  • Kotlin または他の JVM 言語は現在サポートされていません。

サポートされているプラットフォーム

  • Codex CLI (Recommended)
  • Cline
  • VS Code

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

giuseppe-trisciuoglio/aws-lambda-java-integration

Provides AWS Lambda integration patterns for Java with cold start optimization. Use when deploying Java functions to AWS Lambda, choosing between Micronaut and Raw Java approaches, optimizing cold starts below 1 second, configuring API Gateway or ALB integration, or implementing serverless Java applications. Triggers include "create lambda java", "deploy java lambda", "micronaut lambda aws", "java lambda cold start", "aws lambda java performance", "java serverless framework".

giuseppe-trisciuoglio/aws-lambda-php-integration

Provides AWS Lambda integration patterns for PHP with Symfony using the Bref framework. Creates Lambda handler classes, configures runtime layers, sets up SQS/SNS event triggers, implements warm-up strategies, and optimizes cold starts. Use when deploying PHP/Symfony applications to AWS Lambda, configuring API Gateway integration, implementing serverless PHP applications, or optimizing Lambda performance with Bref. Triggers include "create lambda php", "deploy symfony lambda", "bref lambda aws", "php lambda cold start", "aws lambda php performance", "symfony serverless", "php serverless framework".

giuseppe-trisciuoglio/aws-lambda-python-integration

Provides AWS Lambda integration patterns for Python with cold start optimization. Use when deploying Python functions to AWS Lambda, choosing between AWS Chalice and raw Python approaches, optimizing cold starts, configuring API Gateway or ALB integration, or implementing serverless Python applications. Triggers include "create lambda python", "deploy python lambda", "chalice lambda aws", "python lambda cold start", "aws lambda python performance", "python serverless framework".

giuseppe-trisciuoglio/aws-lambda-typescript-integration

Provides AWS Lambda integration patterns for TypeScript with cold start optimization. Use when creating or deploying TypeScript Lambda functions, choosing between NestJS framework and raw TypeScript approaches, optimizing cold starts, configuring API Gateway or ALB integration, or implementing serverless TypeScript applications. Triggers include "create lambda typescript", "deploy typescript lambda", "nestjs lambda aws", "raw typescript lambda", "aws lambda typescript performance".

giuseppe-trisciuoglio/aws-rds-spring-boot-integration

Provides patterns to configure AWS RDS (Aurora, MySQL, PostgreSQL) with Spring Boot applications. Configures HikariCP connection pools, implements read/write splitting, sets up IAM database authentication, enables SSL connections, and integrates with AWS Secrets Manager. Use when setting up RDS connections in Spring Boot, configuring connection pooling, or managing database credentials securely.

giuseppe-trisciuoglio/aws-sdk-java-v2-bedrock

Provides Amazon Bedrock patterns using AWS SDK for Java 2.x. Invokes foundation models (Claude, Llama, Titan), generates text and images, creates embeddings for RAG, streams real-time responses, and configures Spring Boot integration. Use when asking about Bedrock integration, Java SDK for AI models, AWS generative AI, Claude/Llama invocation, embeddings for RAG, or Spring Boot AI setup.

giuseppe-trisciuoglio/aws-sdk-java-v2-core

Provides AWS SDK for Java 2.x client configuration, credential resolution, HTTP client tuning, timeout, retry, and testing patterns. Use when creating or hardening AWS service clients, wiring Spring Boot beans, debugging auth or region issues, or choosing sync vs async SDK usage.

giuseppe-trisciuoglio/aws-sdk-java-v2-dynamodb

Provides Amazon DynamoDB patterns using AWS SDK for Java 2.x. Use when creating, querying, scanning, or performing CRUD operations on DynamoDB tables, working with indexes, batch operations, transactions, or integrating with Spring Boot applications.

giuseppe-trisciuoglio/aws-sdk-java-v2-kms

Provides AWS Key Management Service (KMS) patterns using AWS SDK for Java 2.x. Use when creating/managing encryption keys, encrypting/decrypting data, generating data keys, digital signing, key rotation, or integrating encryption into Spring Boot applications.

giuseppe-trisciuoglio/aws-sdk-java-v2-lambda

Provides AWS Lambda patterns using AWS SDK for Java 2.x. Use when invoking Lambda functions, creating/updating functions, managing function configurations, working with Lambda layers, or integrating Lambda with Spring Boot applications.

giuseppe-trisciuoglio/aws-sdk-java-v2-messaging

Provides AWS messaging patterns using AWS SDK for Java 2.x for SQS queues and SNS topics. Handles sending/receiving messages, FIFO queues, DLQ, subscriptions, and pub/sub patterns. Use when implementing messaging with SQS or SNS.

giuseppe-trisciuoglio/aws-sdk-java-v2-rds

Provides AWS RDS (Relational Database Service) management patterns using AWS SDK for Java 2.x. Use when creating, modifying, monitoring, or managing Amazon RDS database instances, snapshots, parameter groups, and configurations.

giuseppe-trisciuoglio/aws-sdk-java-v2-s3

Provides Amazon S3 patterns and examples using AWS SDK for Java 2.x. Use when working with S3 buckets, uploading/downloading objects, multipart uploads, presigned URLs, S3 Transfer Manager, object operations, or S3-specific configurations.

giuseppe-trisciuoglio/aws-sdk-java-v2-secrets-manager

Provides AWS Secrets Manager patterns for AWS SDK for Java 2.x, including secret retrieval, caching, rotation-aware access, and Spring Boot integration. Use when storing or reading secrets in Java services, replacing hardcoded credentials, or wiring secret-backed configuration into applications.

giuseppe-trisciuoglio/better-auth

Provides Better Auth integration patterns for NestJS backend and Next.js frontend with Drizzle ORM and PostgreSQL. Use when setting up Better Auth with NestJS backend, integrating Next.js App Router frontend, configuring Drizzle ORM schema, implementing social login (GitHub, Google), adding plugins (2FA, Organization, SSO, Magic Link, Passkey), implementing email/password authentication with session management, or creating protected routes and middleware.

giuseppe-trisciuoglio/chunking-strategy

Provides chunking strategies for RAG systems. Generates chunk size recommendations (256-1024 tokens), overlap percentages (10-20%), and semantic boundary detection methods. Validates semantic coherence and evaluates retrieval precision/recall metrics. Use when building retrieval-augmented generation systems, vector databases, or processing large documents.

giuseppe-trisciuoglio/docs-updater

Provides automated documentation updates by analyzing git changes between the current branch and the last release tag. Performs git diff analysis to identify modifications, then updates README.md, CHANGELOG.md following Keep a Changelog standard, and discovers documentation folders for contextual updates. Use when preparing a release, maintaining documentation sync, or before creating a pull request. Triggers on "update docs", "update changelog", "sync documentation", "update readme", "prepare release documentation".

giuseppe-trisciuoglio/drawio-logical-diagrams

Creates professional logical flow diagrams and logical system architecture diagrams using draw.io XML format (.drawio files). Use when creating: (1) logical flow diagrams showing data/process flow between system components, (2) logical architecture diagrams representing system structure without cloud provider specifics, (3) BPMN process diagrams, (4) UML diagrams (class, sequence, activity), (5) data flow diagrams (DFD), (6) decision flowcharts, or (7) system interaction diagrams. This skill focuses on generic/abstract representations, not AWS/Azure-specific architectures (use aws-drawio-architecture-diagrams for cloud diagrams).

giuseppe-trisciuoglio/drizzle-orm-patterns

Provides comprehensive Drizzle ORM patterns for schema definition, CRUD operations, relations, queries, transactions, and migrations. Proactively use for any Drizzle ORM development including defining database schemas, writing type-safe queries, implementing relations, managing transactions, and setting up migrations with Drizzle Kit. Supports PostgreSQL, MySQL, SQLite, MSSQL, and CockroachDB.

giuseppe-trisciuoglio/github-issue-workflow

Provides a structured 8-phase workflow for resolving GitHub issues in Claude Code. Covers fetching issue details, analyzing requirements, implementing solutions, verifying correctness, performing code review, committing changes, and creating pull requests. Use when user asks to resolve, implement, work on, fix, or close a GitHub issue, or references an issue URL or number for implementation.

関連スキル