GitHub - Improve your Code with DeepSeek and Serverless App
Introduction As software development grows in complexity, maintaining clean, efficient, and well-structured code becomes a major challenge. Poorly written code can lead to increased maintenance costs, decreased readability, and technical debt. With generative AI, developers now have access to intelligent code analysis tools that provide feedbacks and actionable improvements. This post is about a serverless application that use AWS Bedrock with DeepSeek R1 LLM to analyze GitHub commits, detect potential issues, and suggest improvements based on Domain-Driven Design (DDD) and Clean Code principles. This approach ensures that code remains scalable, maintainable, and aligned with best practices. By leveraging AWS Bedrock, this project achieves seamless AI integration within a serverless architecture, ensuring cost-effectiveness, performance, and reliability. About This Project Overview This project is designed to automate code analysis in a GitHub repository. Every time a developer pushes a commit, a GitHub webhook triggers an AWS Lambda function, which then analyzes the commit and provides feedback using DeepSeek R1 LLM. Key Technologies Serverless Framework: Manages and deploys AWS resources, including Lambda, API Gateway, and DynamoDB. AWS Lambda: Processes GitHub webhooks and triggers AI-based code validation. DeepSeek R1 LLM: A generative AI model that analyzes commit changes and suggests improvements. DynamoDB: Stores commit metadata and AI-generated recommendations for future reference. CloudWatch: Provides logging and monitoring for the Lambda functions. GitHub Webhooks: Automatically sends commit data to the API for processing. Project Structure Breakdown The project is structured into several key components, each responsible for handling a specific part of the process: ├── layers/ # Shared dependencies for Lambda functions │ ├── common/ │ │ ├── requirements.txt # Defines Python dependencies ├── src/ │ ├── functions/ # Lambda functions that process GitHub webhooks │ │ ├── commit_analyzer.py # Analyzes commit data and sends it to DeepSeek AI │ ├── helpers/ # Utility classes for handling Lambda payloads and responses │ │ ├── lambda_payload.py │ │ ├── lambda_response.py │ ├── infrastructure/ # YAML configurations for AWS resource deployment │ │ ├── resources.yml │ ├── services/ # External service integrations (GitHub, DynamoDB, AI model) │ │ ├── bedrock.py # Handles AWS Bedrock interactions │ │ ├── dynamodb.py # Interfaces with DynamoDB to store results │ │ ├── github.py # Manages GitHub structure returns │ ├── __init__.py ├── .env.example # Example environment configuration file ├── deploy-example.sh # Deployment script for easy setup ├── README.md # Documentation for the project ├── serverless.yml # Serverless Framework configuration file How It Works A developer commits changes to the repository. GitHub sends a webhook event to the API Gateway. The API Gateway triggers an AWS Lambda function. The Lambda function analyzes the commit and extracts relevant code changes. The extracted code is processed by DeepSeek R1 LLM for improvement suggestions. The AI-generated recommendations are stored in DynamoDB for reference. The developer receives feedback on code quality and best practices. API Testing Example To test the AI-based code analysis manually, you can use the following cURL request: curl --location --request POST 'https://example.com/commit/analyze' \ --header 'Content-Type: application/json' \ --data-raw '{ "ref": "refs/heads/develop", "before": "a1b2c3d4e5f678901234567890abcdef12345678", "after": "f1e2d3c4b5a678901234567890abcdef98765432", "repository": { "id": 123456789, "node_id": "R_kgDOPQRSTU", "name": "fake-repo", "full_name": "johnDoe/fake-repo", "private": false, "owner": { "name": "johnDoe", "email": "johndoe@users.noreply.github.com", "login": "johnDoe", "id": 987654321, "node_id": "MDQ6VXNlcjk4NzY1NDMyMQ==", "avatar_url": "https://avatars.githubusercontent.com/u/987654321?v=4", "gravatar_id": "", "url": "https://api.github.com/users/johnDoe", "html_url": "https://github.com/johnDoe", "followers_url": "https://api.github.com/users/johnDoe/followers", "following_url": "https://api.github.com/users/johnDoe/following{/other_user}", "gists_url": "https://api.github.com/users/johnDoe/gists{/gist_id}", "starred_url": "https://api.github.com/users/johnDoe/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/johnDoe/subscriptions", "organizations_url": "https://api.github.com/users/johnDoe/orgs", "repos_url": "https://api.github.com/users/johnDoe/repos", "events_url": "https://api.github

Introduction
As software development grows in complexity, maintaining clean, efficient, and well-structured code becomes a major challenge. Poorly written code can lead to increased maintenance costs, decreased readability, and technical debt. With generative AI, developers now have access to intelligent code analysis tools that provide feedbacks and actionable improvements.
This post is about a serverless application that use AWS Bedrock with DeepSeek R1 LLM to analyze GitHub commits, detect potential issues, and suggest improvements based on Domain-Driven Design (DDD) and Clean Code principles. This approach ensures that code remains scalable, maintainable, and aligned with best practices.
By leveraging AWS Bedrock, this project achieves seamless AI integration within a serverless architecture, ensuring cost-effectiveness, performance, and reliability.
About This Project
Overview
This project is designed to automate code analysis in a GitHub repository. Every time a developer pushes a commit, a GitHub webhook triggers an AWS Lambda function, which then analyzes the commit and provides feedback using DeepSeek R1 LLM.
Key Technologies
- Serverless Framework: Manages and deploys AWS resources, including Lambda, API Gateway, and DynamoDB.
- AWS Lambda: Processes GitHub webhooks and triggers AI-based code validation.
- DeepSeek R1 LLM: A generative AI model that analyzes commit changes and suggests improvements.
- DynamoDB: Stores commit metadata and AI-generated recommendations for future reference.
- CloudWatch: Provides logging and monitoring for the Lambda functions.
- GitHub Webhooks: Automatically sends commit data to the API for processing.
Project Structure Breakdown
The project is structured into several key components, each responsible for handling a specific part of the process:
├── layers/ # Shared dependencies for Lambda functions
│ ├── common/
│ │ ├── requirements.txt # Defines Python dependencies
├── src/
│ ├── functions/ # Lambda functions that process GitHub webhooks
│ │ ├── commit_analyzer.py # Analyzes commit data and sends it to DeepSeek AI
│ ├── helpers/ # Utility classes for handling Lambda payloads and responses
│ │ ├── lambda_payload.py
│ │ ├── lambda_response.py
│ ├── infrastructure/ # YAML configurations for AWS resource deployment
│ │ ├── resources.yml
│ ├── services/ # External service integrations (GitHub, DynamoDB, AI model)
│ │ ├── bedrock.py # Handles AWS Bedrock interactions
│ │ ├── dynamodb.py # Interfaces with DynamoDB to store results
│ │ ├── github.py # Manages GitHub structure returns
│ ├── __init__.py
├── .env.example # Example environment configuration file
├── deploy-example.sh # Deployment script for easy setup
├── README.md # Documentation for the project
├── serverless.yml # Serverless Framework configuration file
How It Works
- A developer commits changes to the repository.
- GitHub sends a webhook event to the API Gateway.
- The API Gateway triggers an AWS Lambda function.
- The Lambda function analyzes the commit and extracts relevant code changes.
- The extracted code is processed by DeepSeek R1 LLM for improvement suggestions.
- The AI-generated recommendations are stored in DynamoDB for reference.
- The developer receives feedback on code quality and best practices.
API Testing Example
To test the AI-based code analysis manually, you can use the following cURL request:
curl --location --request POST 'https://example.com/commit/analyze' \
--header 'Content-Type: application/json' \
--data-raw '{
"ref": "refs/heads/develop",
"before": "a1b2c3d4e5f678901234567890abcdef12345678",
"after": "f1e2d3c4b5a678901234567890abcdef98765432",
"repository": {
"id": 123456789,
"node_id": "R_kgDOPQRSTU",
"name": "fake-repo",
"full_name": "johnDoe/fake-repo",
"private": false,
"owner": {
"name": "johnDoe",
"email": "johndoe@users.noreply.github.com",
"login": "johnDoe",
"id": 987654321,
"node_id": "MDQ6VXNlcjk4NzY1NDMyMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/987654321?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/johnDoe",
"html_url": "https://github.com/johnDoe",
"followers_url": "https://api.github.com/users/johnDoe/followers",
"following_url": "https://api.github.com/users/johnDoe/following{/other_user}",
"gists_url": "https://api.github.com/users/johnDoe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/johnDoe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/johnDoe/subscriptions",
"organizations_url": "https://api.github.com/users/johnDoe/orgs",
"repos_url": "https://api.github.com/users/johnDoe/repos",
"events_url": "https://api.github.com/users/johnDoe/events{/privacy}",
"received_events_url": "https://api.github.com/users/johnDoe/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"html_url": "https://github.com/johnDoe/fake-repo",
"description": "A fake repository for testing purposes",
"fork": false,
"url": "https://github.com/johnDoe/fake-repo",
"created_at": 1742164973,
"updated_at": "2025-03-16T22:42:57Z",
"pushed_at": 1742165040,
"git_url": "git://github.com/johnDoe/fake-repo.git",
"ssh_url": "git@github.com:johnDoe/fake-repo.git",
"clone_url": "https://github.com/johnDoe/fake-repo.git",
"svn_url": "https://github.com/johnDoe/fake-repo",
"size": 100,
"stargazers_count": 10,
"watchers_count": 10,
"language": "JavaScript",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 2,
"archived": false,
"disabled": false,
"open_issues_count": 1,
"license": "MIT",
"allow_forking": true,
"is_template": false,
"visibility": "public",
"default_branch": "develop"
},
"pusher": {
"name": "johnDoe",
"email": "johndoe@users.noreply.github.com"
},
"sender": {
"login": "johnDoe",
"id": 987654321,
"node_id": "MDQ6VXNlcjk4NzY1NDMyMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/987654321?v=4",
"url": "https://api.github.com/users/johnDoe",
"html_url": "https://github.com/johnDoe",
"followers_url": "https://api.github.com/users/johnDoe/followers",
"following_url": "https://api.github.com/users/johnDoe/following{/other_user}",
"gists_url": "https://api.github.com/users/johnDoe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/johnDoe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/johnDoe/subscriptions",
"organizations_url": "https://api.github.com/users/johnDoe/orgs",
"repos_url": "https://api.github.com/users/johnDoe/repos",
"events_url": "https://api.github.com/users/johnDoe/events{/privacy}",
"received_events_url": "https://api.github.com/users/johnDoe/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"created": false,
"deleted": false,
"forced": false,
"base_ref": null,
"compare": "https://github.com/johnDoe/fake-repo/compare/a1b2c3d4e5f6...f1e2d3c4b5a6",
"commits": [
{
"id": "f1e2d3c4b5a678901234567890abcdef98765432",
"tree_id": "5a6b7c8d9e0f1234567890abcdef987654321234",
"distinct": true,
"message": "fix: updated authentication logic",
"timestamp": "2025-03-16T19:44:00-03:00",
"url": "https://github.com/johnDoe/fake-repo/commit/f1e2d3c4b5a678901234567890abcdef98765432",
"author": {
"name": "John Doe",
"email": "johndoe@users.noreply.github.com",
"username": "johnDoe"
},
"committer": {
"name": "GitHub",
"email": "noreply@github.com",
"username": "web-flow"
},
"added": ["src/auth.js"],
"removed": [],
"modified": ["src/index.js"]
}
],
"head_commit": {
"id": "f1e2d3c4b5a678901234567890abcdef98765432",
"tree_id": "5a6b7c8d9e0f1234567890abcdef987654321234",
"distinct": true,
"message": "fix: updated authentication logic",
"timestamp": "2025-03-16T19:44:00-03:00",
"url": "https://github.com/johnDoe/fake-repo/commit/f1e2d3c4b5a678901234567890abcdef98765432",
"author": {
"name": "John Doe",
"email": "johndoe@users.noreply.github.com",
"username": "johnDoe"
},
"committer": {
"name": "GitHub",
"email": "noreply@github.com",
"username": "web-flow"
},
"added": ["src/auth.js"],
"removed": [],
"modified": ["src/index.js"]
}
}'
Upon execution, the request triggers the AI-powered analysis, and you will receive a detailed JSON response with suggested improvements for your committed code.
How to Configure GitHub Webhooks
To enable automated AI code validation in your repository, follow these steps:
- Navigate to your repository on GitHub.
- Click on Settings > Webhooks.
- Click "Add Webhook".
- Set the Payload URL:
https://example.com/commit/analyze
. - Choose Content Type:
application/json
. - Select the events that trigger the webhook: Push events.
- Click "Add Webhook" to save the configuration.
Now, every new commit automatically triggers the AI analysis, and improvement suggestions will be generated.
Conclusion
This project showcases how generative AI can revolutionize software development by providing real-time feedback on code quality. By using AWS Bedrock with DeepSeek R1 LLM, this solution ensures:
- Consistent adherence to best coding practices
- Improved readability and maintainability of code
- Automated, AI-driven reviews that enhance development workflows
Developers can now spend less time debugging and more time building high-quality software.
To explore the full project, visit: GitHub IA - Code Validation.
Note: The DeepSeek R1 LLM is a recent model in the AWS marketplace and in the market, so its use may have quality issues, especially for languages other than English and Chinese.