File size: 6,952 Bytes
52327b3
88d205f
1e22c34
 
 
52327b3
1e22c34
52327b3
88d205f
 
52327b3
 
88d205f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
title: Code Review Agent
emoji: πŸ‘€
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 5.33.1
app_file: app.py
pinned: true
short_description: An AI-powered code review agent that analyzes Github Repos
---

# Code Review Agent

[![agent-demo-track](https://img.shields.io/badge/Gradio-agent--demo--track-orange)](https://huggingface.co/Agents-MCP-Hackathon)
[![MCP-Server](https://img.shields.io/badge/MCP-Server-blue)](https://www.gradio.app/guides/building-mcp-server-with-gradio)

A professional-grade code review agent that leverages AI to provide comprehensive code analysis and actionable recommendations. Built for the Gradio MCP Hackathon, this tool helps developers improve code quality through automated reviews powered by advanced AI models.

![Gradio MCP Hackathon](https://cdn-uploads.huggingface.co/production/uploads/60d2dc1007da9c17c72708f8/4HXPmk3CW5zQmVLBxh2Nx.png)

## πŸš€ Features

- **Multi-Language Support**: Analyzes code in 15+ programming languages including Python, JavaScript, TypeScript, Java, C++, and more
- **Enterprise-Grade UI**: Professional Gradio interface with modern design and intuitive workflow
- **Advanced Analysis**: Comprehensive insights on security vulnerabilities, performance bottlenecks, and code quality issues
- **GitHub Integration**: Support for both public and private GitHub repositories with secure token authentication
- **MCP Server**: Functions as a Model Context Protocol (MCP) server, allowing LLMs to use this tool for code review operations
- **Professional Reporting**: Detailed reports with actionable recommendations organized by priority
- **Customizable Reviews**: Select specific languages to focus the review on parts of your codebase that matter most

## πŸ—οΈ Architecture

The system follows a robust 4-layer architecture designed for extensibility and maintainability:

1. **Presentation Layer**: Gradio-based UI with professional dashboard and intuitive controls
2. **Application Layer**: Core business logic and review engine with modular components
3. **Service Layer**: External integrations and analysis services with clean interfaces
4. **MCP Layer**: Implements the Model Context Protocol (MCP) server functionality, allowing LLMs to use this tool for code review operations through standardized communication

## πŸ“‹ Requirements

- Python 3.8+
- Git
- Internet connection for AI model access
- GitHub token (optional, for private repositories)

## πŸ”§ Installation

```bash
# Clone the repository
git clone https://huggingface.co/spaces/c1r3x/code-review-agent
cd code-review-agent

# Install dependencies
pip install -r requirements.txt

# Set up environment variables (optional)
cp sample.env .env
# Edit .env with your configuration
```

## πŸš€ Usage

```bash
python src/main.py
```

Then open your browser to http://localhost:7860 to access the Code Review Agent.

### Analyzing a Repository

1. Enter the GitHub repository URL in the input field
2. Optionally enter your GitHub token for private repositories
3. Select the programming languages to focus the review on
4. Click "Submit" to start the analysis
5. View the comprehensive report with actionable recommendations

## 🐳 Docker Deployment

```bash
# Build and run with Docker Compose
docker-compose up -d
```

Access the application at http://localhost:7860

## πŸ”Œ MCP Server Functionality

This application functions as a Model Context Protocol (MCP) server, allowing Large Language Models (LLMs) to use it as a tool for code review operations:

- **MCP Integration**: Exposes code review capabilities through standardized MCP endpoints
- **LLM Tool Usage**: Can be called by LLMs like Claude, GPT-4, and others that support the MCP protocol
- **Tool Operations**: Provides repository analysis, code review, and report generation as MCP operations
- **Structured Responses**: Returns analysis results in structured formats compatible with LLM processing

To use this as an MCP server with your LLM:

1. Deploy the application using the instructions above
2. Configure your MCP client to connect to the server endpoint
3. The LLM can then use the code review capabilities through MCP tool calls

## πŸ§ͺ Testing

```bash
# Run the test suite
python -m pytest tests/
```

## πŸ“ Project Structure

```
β”œβ”€β”€ .gitignore              # Git ignore file
β”œβ”€β”€ Dockerfile              # Docker configuration
β”œβ”€β”€ LICENSE                 # MIT License file
β”œβ”€β”€ README.md               # Project documentation
β”œβ”€β”€ app.py                  # Entry point for Hugging Face Spaces
β”œβ”€β”€ docker-compose.yml      # Docker Compose configuration
β”œβ”€β”€ modal_deploy.py         # Modal deployment configuration
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ sample.env              # Sample environment variables
β”œβ”€β”€ setup.py                # Package setup configuration
β”œβ”€β”€ src/                    # Source code directory
β”‚   β”œβ”€β”€ __init__.py         # Package initialization
β”‚   β”œβ”€β”€ core/               # Core application logic
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ agent_manager.py    # Agent orchestration
β”‚   β”‚   └── language_detector.py # Language detection
β”‚   β”œβ”€β”€ main.py             # Main application entry point
β”‚   β”œβ”€β”€ mcp/                # MCP server implementation
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── ai_review.py    # AI review integration
β”‚   β”œβ”€β”€ services/           # Service layer components
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ code_analyzer.py       # Code analysis
β”‚   β”‚   β”œβ”€β”€ performance_analyzer.py # Performance analysis
β”‚   β”‚   β”œβ”€β”€ report_generator.py     # Report generation
β”‚   β”‚   β”œβ”€β”€ repository_service.py   # Repository operations
β”‚   β”‚   └── security_scanner.py     # Security scanning
β”‚   └── ui/                 # User interface components
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ components/     # UI components
β”‚       β”œβ”€β”€ gradio_app.py   # Gradio application
β”‚       └── styles/         # UI styling
└── tests/                  # Test directory
    β”œβ”€β”€ test_agent_manager.py
    β”œβ”€β”€ test_ai_review.py
    β”œβ”€β”€ test_code_analyzer.py
    β”œβ”€β”€ test_language_detector.py
    β”œβ”€β”€ test_performance_analyzer.py
    β”œβ”€β”€ test_report_generator.py
    β”œβ”€β”€ test_repository_service.py
    └── test_security_scanner.py
```

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.