콘텐츠로 이동

모노레포 설정

새로운 모노레포를 생성하려면 원하는 디렉토리에서 다음 명령어를 실행하세요:

Terminal window
npx create-nx-workspace@21.6.5 dungeon-adventure --pm=pnpm --preset=@aws/nx-plugin --iacProvider=CDK --ci=skip --aiAgents

이 명령은 dungeon-adventure 디렉토리 내에 NX 모노레포를 설정합니다. VSCode에서 디렉토리를 열면 다음과 같은 파일 구조를 볼 수 있습니다:

  • 디렉터리.nx/
  • 디렉터리.vscode/
  • 디렉터리node_modules/
  • 디렉터리packages/ 하위 프로젝트가 위치할 폴더
  • .gitignore
  • .npmrc
  • .prettierignore
  • .prettierrc
  • nx.json Nx CLI 및 모노레포 기본값 구성
  • package.json 모든 노드 의존성 정의
  • pnpm-lock.yaml 또는 bun.lock, yarn.lock, package-lock.json (패키지 매니저에 따라 다름)
  • pnpm-workspace.yaml pnpm 사용 시
  • README.md
  • tsconfig.base.json 모든 노드 기반 하위 프로젝트가 상속할 기본 설정
  • tsconfig.json
  • aws-nx-plugin.config.mts AWS용 Nx 플러그인 구성

이제 @aws/nx-plugin을 사용하여 다양한 하위 프로젝트 생성을 시작할 수 있습니다.

먼저 Game API를 생성해 보겠습니다. 다음 단계에 따라 GameApi라는 tRPC API를 생성합니다:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#trpc-api
  5. 필수 매개변수 입력
    • name: GameApi
  6. 클릭 Generate

파일 트리에 몇 가지 새 파일이 나타난 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

이제 스토리 에이전트를 생성해 보겠습니다.

스토리 에이전트: Python 프로젝트

섹션 제목: “스토리 에이전트: Python 프로젝트”

Python 프로젝트를 생성하려면:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - py#project
  5. 필수 매개변수 입력
    • name: story
  6. 클릭 Generate

파일 트리에 새 파일이 나타난 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

스토리 에이전트: Strands 에이전트

섹션 제목: “스토리 에이전트: Strands 에이전트”

py#strands-agent 생성기를 사용하여 Strands 에이전트를 프로젝트에 추가하려면:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - py#strands-agent
  5. 필수 매개변수 입력
    • project: story
  6. 클릭 Generate

파일 트리에 새 파일이 나타난 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

스토리 에이전트가 플레이어의 인벤토리를 관리할 수 있도록 도구를 제공하는 MCP 서버를 생성해 보겠습니다.

먼저 TypeScript 프로젝트를 생성합니다:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#project
  5. 필수 매개변수 입력
    • name: inventory
  6. 클릭 Generate

이렇게 하면 빈 TypeScript 프로젝트가 생성됩니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

다음으로 TypeScript 프로젝트에 MCP 서버를 추가합니다:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#mcp-server
  5. 필수 매개변수 입력
    • project: inventory
  6. 클릭 Generate

이렇게 하면 MCP 서버가 추가됩니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

작업 5: 사용자 인터페이스(UI) 생성

섹션 제목: “작업 5: 사용자 인터페이스(UI) 생성”

이 작업에서는 게임과 상호작용할 수 있는 UI를 생성합니다.

UI를 생성하려면 다음 단계에 따라 GameUI라는 웹사이트를 생성합니다:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#react-website
  5. 필수 매개변수 입력
    • name: GameUI
  6. 클릭 Generate

파일 트리에 새 파일이 나타난 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

Amazon Cognito를 통해 인증된 액세스가 필요한 Game UI를 구성해 보겠습니다. 다음 단계를 따르세요:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#react-website#auth
  5. 필수 매개변수 입력
    • cognitoDomain: game-ui
    • project: @dungeon-adventure/game-ui
    • allowSignup: true
  6. 클릭 Generate

파일 트리에 새 파일이 생성/변경된 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

이전에 생성한 Game API에 Game UI를 연결하도록 구성해 보겠습니다.

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - api-connection
  5. 필수 매개변수 입력
    • sourceProject: @dungeon-adventure/game-ui
    • targetProject: @dungeon-adventure/game-api
  6. 클릭 Generate

파일 트리에 새 파일이 생성/변경된 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

CDK 인프라스트럭처를 위한 마지막 하위 프로젝트를 생성해 보겠습니다.

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#infra
  5. 필수 매개변수 입력
    • name: infra
  6. 클릭 Generate

파일 트리에 새 파일이 생성/변경된 것을 확인할 수 있습니다.

자세한 파일 내용을 확인하려면 여기를 클릭하세요.

작업 6: 인프라스트럭처 업데이트

섹션 제목: “작업 6: 인프라스트럭처 업데이트”

이미 생성된 구성 요소 일부를 인스턴스화하기 위해 packages/infra/src/stacks/application-stack.ts를 업데이트합니다:

import {
GameApi,
GameUI,
InventoryMcpServer,
RuntimeConfig,
StoryAgent,
UserIdentity,
} from ':dungeon-adventure/common-constructs';
import { Stack, StackProps, CfnOutput } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class ApplicationStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const userIdentity = new UserIdentity(this, 'UserIdentity');
const gameApi = new GameApi(this, 'GameApi', {
integrations: GameApi.defaultIntegrations(this).build(),
});
const { userPool, userPoolClient } = userIdentity;
const mcpServer = new InventoryMcpServer(this, 'InventoryMcpServer');
// Use Cognito for user authentication with the agent
const storyAgent = new StoryAgent(this, 'StoryAgent', {
authorizerConfiguration: {
customJwtAuthorizer: {
discoveryUrl: `https://cognito-idp.${Stack.of(userPool).region}.amazonaws.com/${userPool.userPoolId}/.well-known/openid-configuration`,
allowedAudience: [userPoolClient.userPoolClientId],
},
},
environment: {
INVENTORY_MCP_ARN: mcpServer.agentCoreRuntime.arn,
},
});
// Add the Story Agent ARN to runtime-config.json so it can be referenced by the website
RuntimeConfig.ensure(this).config.agentArn =
storyAgent.agentCoreRuntime.arn;
new CfnOutput(this, 'StoryAgentArn', {
value: storyAgent.agentCoreRuntime.arn,
});
new CfnOutput(this, 'InventoryMcpArn', {
value: mcpServer.agentCoreRuntime.arn,
});
// Grant the agent permissions to invoke our mcp server
mcpServer.agentCoreRuntime.grantInvoke(storyAgent.agentCoreRuntime);
// Grant the authenticated role access to invoke the api
gameApi.grantInvokeAccess(userIdentity.identityPool.authenticatedRole);
// Ensure this is instantiated last so our runtime-config.json can be automatically configured
new GameUI(this, 'GameUI');
}
}
이제 처음으로 코드를 빌드할 시간입니다

명령줄을 사용하여 다음을 실행합니다:

Terminal window
pnpm nx run-many --target build --all

다음과 같은 프롬프트가 표시됩니다:

Terminal window
NX The workspace is out of sync
[@nx/js:typescript-sync]: Some TypeScript configuration files are missing project references to the projects they depend on or contain outdated project references.
This will result in an error in CI.
? Would you like to sync the identified changes to get your workspace up to date?
Yes, sync the changes and run the tasks
No, run the tasks without syncing the changes

이 메시지는 NX가 자동으로 업데이트할 수 있는 일부 파일을 감지했음을 나타냅니다. 이 경우 참조 프로젝트에 대한 TypeScript 참조가 설정되지 않은 tsconfig.json 파일을 가리킵니다.

Yes, sync the changes and run the tasks 옵션을 선택하여 진행합니다. 동기화 생성기가 누락된 TypeScript 참조를 자동으로 추가하므로 모든 IDE 관련 가져오기 오류가 자동으로 해결됩니다!

모든 빌드 아티팩트는 이제 모노레포 루트의 dist/ 폴더 내에서 사용할 수 있습니다. 이는 @aws/nx-plugin으로 생성된 프로젝트의 표준 관행으로, 생성된 파일이 파일 트리를 어지럽히지 않도록 합니다. 파일을 정리하려면 생성된 파일이 파일 트리 전체에 흩어져 있을 걱정 없이 dist/ 폴더를 삭제하면 됩니다.

축하합니다! AI 던전 어드벤처 게임의 핵심을 구현하기 위해 필요한 모든 하위 프로젝트를 성공적으로 생성했습니다. 🎉🎉🎉