How aws-samples/codenator-automatic-code-generation-and-execution-using-llm works
Project Type and Purpose
• Full-stack, microservices-style AWS cloud solution for automatic code generation, scanning, execution, and storage using Large Language Models (LLMs).
• Purpose: Orchestrate LLM code generation (via Bedrock/SageMaker), perform static security scans (CodeGuru/Semgrep), execute code in a sandboxed container, store tasks/results, and present a WebUI for user interaction.
Main Components
a. Frontend (WebUI)
• Gradio-based UI in src/codenator/web_ui
• User submits prompts, views code, approves executions, and sees results.
b. Controller (Orchestration Layer)
• In src/codenator/controller
• Central logic: retrieves prompts, invokes API layer, processes LLM responses, coordinates scanning, execution, and persistence.
• Prompt Store (DynamoDB) for prompt versioning.
c. API Layer (LLM Service)
• In src/codenator/api_layer
• Uniform interface to LLM providers (Bedrock, SageMaker).
• Runs on ECS Fargate, stores models in DynamoDB.
d. Code Scanner (Guardrail)
• In src/codenator/code_scanner
• Static analysis via Amazon CodeGuru or Semgrep.
e. Code Executor (Task Executor)
• In src/codenator/code_executor
• Runs code in encrypted, sandboxed Docker containers.
• Uses Amazon KMS for encryption.
f. Task Store
• In src/codenator/task_store
• Persists tasks and results in Amazon OpenSearch Serverless.
g. Shared Storage & Logging
• S3 buckets for shared files, execution logs, user feedback.
h. Optional Authentication Layer
• CloudFormation templates for Cognito integration (auth-layer.yaml, web-ui-auth.yaml).
Relationships & Data Flow
1. User → WebUI: prompt submission and approval.
2. WebUI → Controller: POST requests with user input.
3. Controller → Prompt Store (DynamoDB): fetch/store prompt templates.
4. Controller → API Layer: invoke LLM, retrieve generated code.
5. Controller → Code Scanner: submit generated code for static analysis.
6. Controller → (on pass) Code Executor: send encrypted code to run in a container.
7. Code Executor → S3: write execution output and logs.
8. Controller → Task Store (OpenSearch): index task metadata, code, results.
9. Controller → WebUI: return final results to user.
10. Logging & Feedback → S3: user-provided feedback stored.
Architectural Patterns & Principles
• Microservices: each component is a separate container/Docker image, independently deployable (Dockerfile per service).
• API-Oriented: well-defined HTTP handlers in each microservice.
• Event/Request-Driven orchestration by Controller.
• Infrastructure as Code: all AWS resources deployed via CloudFormation nested templates.
• Security by Design: encryption (KMS), manual approval gates, static analysis.