R3 Cloud Platform – Monorepo + Infra + Core Code

Copy this entire HTML file to Claude on your PC and say: “Extract all code blocks and build the full repo + missing files following the same patterns.”

1. Monorepo structure

r3/
  infra/
    terraform/
      main.tf
      variables.tf
      networking.tf
      security.tf
      compute.tf
      data.tf
      automation.tf
      analytics.tf
      monitoring.tf
      cicd.tf
      auth.tf
      frontend.tf
      multiregion.tf
      billing.tf
      outputs.tf

  backend/
    api/
      handlers/
      routers/
      models/
      utils/
    lambdas/
      core_agent/
        index.py
      task_worker/
        index.py
      embeddings/
        index.py
      orchestrator/
        index.py
    ecs/
      Dockerfile
      app.py
    bedrock/
      prompts/
      templates/
      retrieval/
    common/
      config.py
      logging.py
      auth.py

  agents/
    registry/
    marketplace/
    templates/
    builtins/
      summarizer/
      classifier/
      fetcher/
      workflow/
      retriever/

  frontend/
    src/
      components/
      pages/
      hooks/
      context/
      api/
      auth/
      styles/
    public/
    amplify/
    package.json

  sdk/
    python/
      r3/
        client.py
        auth.py
        agents.py
        storage.py
        events.py
    js/
      src/
        client.js
        auth.js
        agents.js
        storage.js
        events.js

  docs/
    architecture/
    api/
    agents/
    sdk/
    deployment/
    operations/
    security/

  scripts/
    bootstrap.sh
    deploy.sh
    teardown.sh
    seed.sh

2. Root bootstrap script (top-level r3/)

#!/usr/bin/env bash
set -euo pipefail

AWS_REGION="${AWS_REGION:-us-east-1}"
TF_STATE_BUCKET="${TF_STATE_BUCKET:-r3-tf-state}"
TF_STATE_TABLE="${TF_STATE_TABLE:-r3-tf-locks}"
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

echo "== R3 FULL AWS PLATFORM BOOTSTRAP =="
echo "Region: $AWS_REGION"
echo

if ! aws s3 ls "s3://$TF_STATE_BUCKET" >/dev/null 2>&1; then
  aws s3 mb "s3://$TF_STATE_BUCKET" --region "$AWS_REGION"
  aws s3api put-bucket-versioning \
    --bucket "$TF_STATE_BUCKET" \
    --versioning-configuration Status=Enabled
fi

if ! aws dynamodb describe-table --table-name "$TF_STATE_TABLE" >/dev/null 2>&1; then
  aws dynamodb create-table \
    --table-name "$TF_STATE_TABLE" \
    --attribute-definitions AttributeName=LockID,AttributeType=S \
    --key-schema AttributeName=LockID,KeyType=HASH \
    --billing-mode PAY_PER_REQUEST \
    --region "$AWS_REGION"
  aws dynamodb wait table-exists --table-name "$TF_STATE_TABLE"
fi

cd "$PROJECT_ROOT/infra/terraform"

cat > backend_override.tf <<EOF
terraform {
  backend "s3" {
    bucket         = "$TF_STATE_BUCKET"
    key            = "r3-platform/terraform.tfstate"
    region         = "$AWS_REGION"
    dynamodb_table = "$TF_STATE_TABLE"
    encrypt        = true
  }
}
EOF

terraform init -upgrade
terraform apply -auto-approve

echo "✅ R3 AWS PLATFORM DEPLOYED"

3. Terraform root (infra/terraform)

3.1 main.tf

terraform {
  required_version = ">= 1.6.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = var.aws_region
}

module "networking"  { source = "./" }
module "security"    { source = "./" }
module "compute"     { source = "./" }
module "data"        { source = "./" }
module "automation"  { source = "./" }
module "analytics"   { source = "./" }
module "monitoring"  { source = "./" }
module "cicd"        { source = "./" }
module "auth"        { source = "./" }
module "frontend"    { source = "./" }
module "multiregion" { source = "./" }
module "billing"     { source = "./" }

3.2 variables.tf

variable "aws_region" {
  type    = string
  default = "us-east-1"
}

4. Networking (networking.tf)

resource "aws_vpc" "r3" {
  cidr_block           = "10.0.0.0/16"
  enable_dns_support   = true
  enable_dns_hostnames = true
  tags = { Name = "r3-vpc" }
}

resource "aws_internet_gateway" "igw" {
  vpc_id = aws_vpc.r3.id
}

resource "aws_subnet" "public_a" {
  vpc_id                  = aws_vpc.r3.id
  cidr_block              = "10.0.1.0/24"
  availability_zone       = "us-east-1a"
  map_public_ip_on_launch = true
}

resource "aws_subnet" "private_a" {
  vpc_id            = aws_vpc.r3.id
  cidr_block        = "10.0.101.0/24"
  availability_zone = "us-east-1a"
}

resource "aws_eip" "nat" {
  vpc = true
}

resource "aws_nat_gateway" "nat" {
  allocation_id = aws_eip.nat.id
  subnet_id     = aws_subnet.public_a.id
}

5. Security (security.tf)

resource "aws_kms_key" "r3" {
  description = "R3 master encryption key"
}

resource "aws_secretsmanager_secret" "r3" {
  name = "r3-master-secret"
}

resource "aws_guardduty_detector" "main" {
  enable = true
}

resource "aws_iam_role" "lambda_exec" {
  name = "r3-lambda-exec"
  assume_role_policy = data.aws_iam_policy_document.lambda_assume.json
}

data "aws_iam_policy_document" "lambda_assume" {
  statement {
    actions = ["sts:AssumeRole"]
    principals { type = "Service" identifiers = ["lambda.amazonaws.com"] }
  }
}

6. Compute (compute.tf)

resource "aws_lambda_function" "core_agent" {
  function_name = "r3-core-agent"
  role          = aws_iam_role.lambda_exec.arn
  handler       = "index.handler"
  runtime       = "python3.11"
  filename      = "../../backend/lambdas/core_agent/core_agent.zip"
}

resource "aws_apigatewayv2_api" "http" {
  name          = "r3-api"
  protocol_type = "HTTP"
}

resource "aws_apigatewayv2_integration" "lambda" {
  api_id           = aws_apigatewayv2_api.http.id
  integration_type = "AWS_PROXY"
  integration_uri  = aws_lambda_function.core_agent.invoke_arn
}

resource "aws_apigatewayv2_route" "agent" {
  api_id    = aws_apigatewayv2_api.http.id
  route_key = "POST /agent"
  target    = "integrations/${aws_apigatewayv2_integration.lambda.id}"
}

7. Data (data.tf – starter)

resource "aws_s3_bucket" "raw" {
  bucket = "r3-raw-data"
}

resource "aws_dynamodb_table" "agent_state" {
  name         = "r3-agent-state"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "agent_id"

  attribute {
    name = "agent_id"
    type = "S"
  }
}

resource "aws_rds_cluster" "aurora" {
  cluster_identifier = "r3-core-db"
  engine             = "aurora-postgresql"
  engine_mode        = "serverless"
  database_name      = "r3"
  master_username    = "r3admin"
  master_password    = "ChangeMe123!"
}

8. Automation (automation.tf – starter)

resource "aws_sqs_queue" "tasks" {
  name = "r3-agent-tasks"
}

resource "aws_cloudwatch_event_rule" "tick" {
  name                = "r3-agent-tick"
  schedule_expression = "rate(5 minutes)"
}

resource "aws_cloudwatch_event_target" "tick_target" {
  rule      = aws_cloudwatch_event_rule.tick.name
  target_id = "lambda"
  arn       = aws_lambda_function.core_agent.arn
}

9. Analytics (analytics.tf – starter)

resource "aws_glue_catalog_database" "r3" {
  name = "r3_catalog"
}

resource "aws_athena_workgroup" "r3" {
  name = "r3-analytics"
}

10. Monitoring (monitoring.tf – starter)

resource "aws_cloudwatch_metric_alarm" "lambda_errors" {
  alarm_name          = "r3-lambda-errors"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = 1
  metric_name         = "Errors"
  namespace           = "AWS/Lambda"
  period              = 300
  statistic           = "Sum"
  threshold           = 0
  alarm_description   = "Lambda errors detected"
  dimensions = {
    FunctionName = aws_lambda_function.core_agent.function_name
  }
}

11. Core Lambda agent (backend/lambdas/core_agent/index.py)

import json
import boto3

bedrock = boto3.client("bedrock-runtime")

def handler(event, context):
    prompt = None
    try:
        if isinstance(event, dict):
            body = event.get("body")
            if body:
                body = json.loads(body)
                prompt = body.get("prompt")
        if not prompt:
            prompt = "Hello from R3 core agent"
    except Exception:
        prompt = "Hello from R3 core agent"

    resp = bedrock.invoke_model(
        modelId="anthropic.claude-3-sonnet",
        body=json.dumps({"prompt": prompt})
    )
    output = json.loads(resp["body"].read())

    return {
        "statusCode": 200,
        "body": json.dumps({"reply": output})
    }

12. ECS agent (backend/ecs)

Dockerfile

FROM python:3.11-slim
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]

app.py

import time

def main():
    while True:
        print("R3 ECS agent running")
        time.sleep(10)

if __name__ == "__main__":
    main()

13. Frontend (minimal React shell – frontend/src/App.js)

import React, { useState } from "react";

function App() {
  const [reply, setReply] = useState("");

  async function callAgent() {
    const res = await fetch("YOUR_API_URL/agent", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ prompt: "Hello agent" })
    });
    const data = await res.json();
    setReply(JSON.stringify(data, null, 2));
  }

  return (
    <div style={{ padding: 24, color: "#f5f5f5", background: "#05060a", minHeight: "100vh" }}>
      <h1>R3 Cloud Platform</h1>
      <button onClick={callAgent}>Call Core Agent</button>
      <pre>{reply}</pre>
    </div>
  );
}

export default App;

14. Python SDK stub (sdk/python/r3/client.py)

import requests

class R3Client:
    def __init__(self, base_url: str, token: str | None = None):
        self.base_url = base_url.rstrip("/")
        self.token = token

    def _headers(self):
        h = {"Content-Type": "application/json"}
        if self.token:
            h["Authorization"] = f"Bearer {self.token}"
        return h

    def call_agent(self, prompt: str):
        import json
        resp = requests.post(
            f"{self.base_url}/agent",
            headers=self._headers(),
            data=json.dumps({"prompt": prompt}),
            timeout=30,
        )
        resp.raise_for_status()
        return resp.json()

15. JS SDK stub (sdk/js/src/client.js)

export class R3Client {
  constructor(baseUrl, token = null) {
    this.baseUrl = baseUrl.replace(/\/$/, "");
    this.token = token;
  }

  headers() {
    const h = { "Content-Type": "application/json" };
    if (this.token) h["Authorization"] = `Bearer ${this.token}`;
    return h;
  }

  async callAgent(prompt) {
    const res = await fetch(`${this.baseUrl}/agent`, {
      method: "POST",
      headers: this.headers(),
      body: JSON.stringify({ prompt })
    });
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    return await res.json();
  }
}

16. Outputs (outputs.tf)

output "api_url" {
  value = aws_apigatewayv2_api.http.api_endpoint
}

How to use this with Claude on your PC

  1. Save this file as r3.html.
  2. Open it in a browser or text editor and copy all content.
  3. Paste into Claude and say:
    “Extract every code block, create the full repo on disk, and generate all missing files following the same patterns (Terraform modules, auth, CI/CD, Cognito, Amplify, Bedrock, dashboards, token economy, etc.).”
  4. Then ask Claude to:

This HTML is your “seed crystal” — Claude can grow the full system from it.