Architecture

Architecture documentation including Infrastructure (02), Network (03), and Security (04).

02. Infrastructure Architecture

Overview Diagram

┌─────────────────────────────────────────────────────────────────────────────────┐
│                              AWS Cloud - ap-northeast-1                          │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                  │
│  ┌─── Public Subnet ───┐     ┌─── Private Subnets (Multi-AZ) ────────────────┐  │
│  │                     │     │                                                │  │
│  │  ┌─────────────┐    │     │  ┌─────────────────────────────────────────┐  │  │
│  │  │   Bastion   │    │     │  │         ECS Fargate Cluster             │  │  │
│  │  │   (t2.micro)│    │     │  │  ┌─────┐ ┌─────┐ ┌─────┐ ┌──────┐      │  │  │
│  │  └─────────────┘    │     │  │  │ API │ │ Web │ │Admin│ │ Push │      │  │  │
│  │                     │     │  │  └─────┘ └─────┘ └─────┘ └──────┘      │  │  │
│  │  ┌─────────────┐    │     │  └─────────────────────────────────────────┘  │  │
│  │  │   IGW       │    │     │                                                │  │
│  │  └─────────────┘    │     │  ┌─────────────────────────────────────────┐  │  │
│  │                     │     │  │              Data Layer                  │  │  │
│  │  ┌─────────────┐    │     │  │  ┌─────────┐ ┌───────────┐ ┌─────────┐  │  │  │
│  │  │   NAT GW    │◄───┼─────┼──│  │ Aurora  │ │ElastiCache│ │MemoryDB│  │  │  │
│  │  │ (regional)  │    │     │  │  │ MySQL   │ │  Valkey   │ │ Valkey │  │  │  │
│  │  └─────────────┘    │     │  │  └─────────┘ └───────────┘ └─────────┘  │  │  │
│  └─────────────────────┘     │  │  ┌─────────┐                            │  │  │
│                              │  │  │DocumentDB│                           │  │  │
│  ┌─── GA Subnets ──────┐     │  │  └─────────┘                            │  │  │
│  │                     │     │  └─────────────────────────────────────────┘  │  │
│  │  ┌─────────────┐    │     └────────────────────────────────────────────────┘  │
│  │  │ ECS on EC2  │    │                                                         │
│  │  │ Node Cluster│    │     ┌─── VPC Endpoints ────────────────────────────┐    │
│  │  │ ┌─────────┐ │    │     │ ECR.dkr, ECR.api, Logs, ECS, ECS-Agent,     │    │
│  │  │ │ World   │ │    │     │ ECS-Telemetry, SSM Messages, S3             │    │
│  │  │ │ Commu   │ │    │     └──────────────────────────────────────────────┘    │
│  │  │ │ Battle  │ │    │                                                         │
│  │  │ │ Chat    │ │    │                                                         │
│  │  │ │ Center  │ │    │                                                         │
│  │  │ └─────────┘ │    │                                                         │
│  │  └─────────────┘    │                                                         │
│  └─────────────────────┘                                                         │
└─────────────────────────────────────────────────────────────────────────────────┘

ECS Fargate Cluster

ServiceContainersCPU/MemoryPort
APInginx + php-fpm1024/20488082
Webnginx + php-fpm1024/20488083
Adminnginx + php-fpm1024/20488081
Pushnode:24-alpine256/5123001

Features: CodeDeploy Blue/Green deployment, App Auto Scaling (CPU/Memory based), Fargate Spot support (configurable)

ECS on EC2 Cluster (Game Nodes)

ServerProtocolPort RangePurpose
WorldUDP7551-7999World game logic
CommuUDP9551-9999Community
BattleUDP8551-8999Battle system
ChatTCP8101-8499Socket.io chat
Center-3000 (health)Coordination

Features: Bridge networking mode, Auto Scaling Group per node type, ECS Managed Scaling (target 100%)

Load Balancers

Internal ALB (Application Load Balancer)

CloudFront → VPC Origin → ALB (port 80)
                           │
                           ├─ X-Forwarded-App: api   → API TG (8082)
                           ├─ X-Forwarded-App: web   → Web TG (8083)
                           ├─ X-Forwarded-App: admin → Admin TG (8081)
                           └─ X-Forwarded-App: push  → Push TG (3001)

Internal NLB (Network Load Balancer)

Global Accelerator → NLB
                      │
                      ├─ World  (UDP 7551+)
                      ├─ Commu  (UDP 9551+)
                      ├─ Battle (UDP 8551+)
                      ├─ Chat   (TCP 8101+)
                      └─ Center (TCP 3000 health only)

CloudFront Distributions

DistributionOriginCaching
webALB (VPC Origin)Static 7d, dynamic off
adminALB (VPC Origin)Static 7d, dynamic off
apiALB (VPC Origin)Caching off
assetsS3 (OAC)7 days

Global Accelerator (Custom Routing)

ListenerPort RangeDestination
World10000-19999EC2 UDP 7550-7999
Commu20000-29999EC2 UDP 9551-9999
Battle30000-39999EC2 UDP 8550-8999
Chat40000-48999EC2 TCP 8101-8499

S3 Buckets

BucketPurposeLifecycle
*-images-tmpTemp image uploads1 day
*-images-destProcessed imagesIndefinite
*-videos-tmpTemp video uploads1 day
*-videos-quarantineModeration queue3 days
*-videos-destApproved videosIndefinite
*-logsALB/CloudFront logs365 days
*-logs-virginiaWAF logs365 days

Database Tier

ServiceEnginePortFeatures
AuroraMySQL 8.0 Serverless v23307Auto-pause 5min, KMS
ElastiCacheValkey 8.06380Cluster mode, TLS
MemoryDBValkey 7.26380Durable, ACL
DocumentDB5.0 Serverless27027TLS, audit logs

Lambda Functions

FunctionTriggerPurpose
image-validatorSQSImage processing & moderation
video-validatorSQSVideo processing, start Rekognition
video-moderation-resultSNSHandle Rekognition results
cache-invalidatorEventBridgeCloudFront invalidation
ga-port-mapping-resolverSync invokeGA port mapping lookup
scale-node-serviceManualScale game node channels

03. Network Architecture

VPC Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                         VPC (var.vpc_cidr)                                   │
│                                                                              │
│  ┌──────────────────────────────────────────────────────────────────────┐   │
│  │                    Public Subnet (single AZ)                          │   │
│  │                                                                       │   │
│  │  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐               │   │
│  │  │   Bastion   │    │     IGW     │    │   NAT GW    │               │   │
│  │  │   + EIP     │    │             │    │ (regional)  │               │   │
│  │  └─────────────┘    └─────────────┘    └──────┬──────┘               │   │
│  └──────────────────────────────────────────────┬────────────────────────┘   │
│                                                  │                           │
│  ┌──────────────────────────────────────────────┼────────────────────────┐   │
│  │              Private Subnets (Multi-AZ)      │                        │   │
│  │                                              ▼                        │   │
│  │  ┌───────────────────────────────────────────────────────────────┐   │   │
│  │  │  ECS Fargate Tasks   │   RDS Aurora   │   ElastiCache        │   │   │
│  │  │  (api/web/admin/push)│   Writer+Reader│   MemoryDB, DocDB    │   │   │
│  │  └───────────────────────────────────────────────────────────────┘   │   │
│  └───────────────────────────────────────────────────────────────────────┘   │
│                                                                              │
│  ┌───────────────────────────────────────────────────────────────────────┐   │
│  │                    GA Subnets (/28 per AZ)                            │   │
│  │                                                                       │   │
│  │  ┌───────────────────────────────────────────────────────────────┐   │   │
│  │  │  ECS on EC2 (Game Nodes)                                      │   │   │
│  │  │  World / Commu / Battle / Chat / Center                       │   │   │
│  │  └───────────────────────────────────────────────────────────────┘   │   │
│  └───────────────────────────────────────────────────────────────────────┘   │
│                                                                              │
│  ┌───────────────────────────────────────────────────────────────────────┐   │
│  │                      VPC Endpoints                                    │   │
│  │  S3, ECR.dkr, ECR.api, Logs, ECS, ECS-Agent, ECS-Telemetry, SSM     │   │
│  └───────────────────────────────────────────────────────────────────────┘   │
└──────────────────────────────────────────────────────────────────────────────┘

VPC Endpoints (9 total)

EndpointTypePurpose
s3GatewayS3 access without NAT
ecr.dkrInterfaceDocker image pull
ecr.apiInterfaceECR API calls
logsInterfaceCloudWatch Logs
ecsInterfaceECS API
ecs-agentInterfaceECS Agent communication
ecs-telemetryInterfaceECS telemetry
ssmmessagesInterfaceSSM Session Manager

Benefits: Reduces NAT Gateway data transfer costs, Improves security (traffic stays in AWS network), Lower latency for AWS service calls

Security Groups (14 total)

SG NameInboundPurpose
${env}-alb80 from CloudFrontInternal ALB
${env}-api8082 from ALBAPI service
${env}-web8083 from ALBWeb service
${env}-admin8081 from ALBAdmin service
${env}-push3001 from ALB, nodesPush service
${env}-worldUDP 7551-7999World server
${env}-commuUDP 9551-9999Community server
${env}-battleUDP 8551-8999Battle server
${env}-chatTCP 8101-8499Chat server
${env}-center3000 (health)Center server
${env}-rds3307 from app SGsAurora MySQL
${env}-elasticache6380 from app SGsElastiCache Valkey
${env}-memorydb6380 from app SGsMemoryDB Valkey
${env}-documentdb27027 from app SGsDocumentDB

04. Security Architecture

Security Layers

┌─────────────────────────────────────────────────────────────────┐
│                     Layer 1: Edge Security                       │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐          │
│  │  CloudFront │    │   WAFv2     │    │   Global    │          │
│  │    + TLS    │    │ (Rate limit)│    │ Accelerator │          │
│  └─────────────┘    └─────────────┘    └─────────────┘          │
└─────────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────────┐
│                    Layer 2: Network Security                     │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐          │
│  │  VPC        │    │  Security   │    │    VPC      │          │
│  │  Isolation  │    │   Groups    │    │  Endpoints  │          │
│  └─────────────┘    └─────────────┘    └─────────────┘          │
└─────────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────────┐
│                     Layer 3: Data Security                       │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐          │
│  │    KMS      │    │   Secrets   │    │  TLS/Auth   │          │
│  │ Encryption  │    │   Manager   │    │   (cache)   │          │
│  └─────────────┘    └─────────────┘    └─────────────┘          │
└─────────────────────────────────────────────────────────────────┘
                              │
┌─────────────────────────────────────────────────────────────────┐
│                      Layer 4: IAM Security                       │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐          │
│  │   GitHub    │    │ Task/Exec   │    │  Scoped     │          │
│  │    OIDC     │    │   Roles     │    │  Policies   │          │
│  └─────────────┘    └─────────────┘    └─────────────┘          │
└─────────────────────────────────────────────────────────────────┘

WAFv2 Configuration (PHP WAF ACL)

RuleTypeActionThreshold
Rate LimitRateBasedRuleBlock600 req/60s/IP
IP ReputationManagedRuleBlock-
Anonymous IPManagedRuleBlock-
Common RulesManagedRuleBlock**SizeRestrictions_BODY = Count
Known Bad InputsManagedRuleBlock-
Linux/UnixManagedRuleBlock-
SQLiManagedRuleBlock-
PHP RulesManagedRuleBlock-
Bot ControlManagedRuleChallengeCOMMON level

KMS Encryption

Multi-Region Key Setup

┌─────────────────────┐         ┌─────────────────────┐
│  Tokyo (Primary)    │ ──────► │ Virginia (Replica)  │
│  ap-northeast-1     │         │   us-east-1         │
└─────────────────────┘         └─────────────────────┘

What's Encrypted

ResourceKMS KeyNotes
ECR repositoriesTokyoContainer images
RDS AuroraTokyoStorage + Performance Insights
RDS master secretTokyoSecrets Manager
ElastiCacheTokyoAt-rest + in-transit
MemoryDBTokyoAt-rest
DocumentDBTokyoStorage
S3 media bucketsTokyoSSE-KMS
S3 logs bucket-AES256 (ALB limitation)
S3 logs-virginiaVirginiaSSE-KMS
CloudWatch LogsTokyo/VirginiaLog groups
SQS queuesTokyoLambda triggers
SNS topicsTokyoRekognition results

IAM Roles

RolePurposeKey Permissions
ecs_task_roleApplication permissionsS3, DynamoDB, Secrets Manager
ecs_execution_roleTask startupECR pull, Secrets, Logs
ecs_instance_roleEC2 node agentEC2ContainerService, SSM
milu2-github-actions-infraInfra deployAdministratorAccess
milu2-github-actions-app-deployApp deployECR/ECS/CodeDeploy/Lambda

GitHub OIDC Security

┌──────────────┐    1. Request token     ┌──────────────┐
│   GitHub     │ ──────────────────────► │   GitHub     │
│   Actions    │                         │    OIDC      │
│   Workflow   │ ◄────────────────────── │   Provider   │
└──────────────┘    2. JWT token         └──────────────┘
       │
       │ 3. AssumeRoleWithWebIdentity
       ▼
┌──────────────┐                         ┌──────────────┐
│     AWS      │ ◄─────────────────────  │  IAM Role    │
│     STS      │                         │ (trust OIDC) │
└──────────────┘    4. Temporary creds   └──────────────┘

Security Features:

  • No long-lived AWS credentials in GitHub
  • Scoped to specific repositories
  • Session duration: 1 hour max
  • Thumbprint validation via get_thumbprint.sh