An intelligent, conversational code review platform
Submit code in any language, receive structured AI-powered feedback with severity-rated issues, then ask follow-up questions in a live chat β all driven by Azure OpenAI and delivered in real time.
![]() |
![]() |
![]() |
|
|
Submit Code ββ> AI Reviews It ββ> Structured Feedback ββ> Ask Follow-Up Questions
(any language) (GPT-4o) (scored, categorized) (conversational chat)
| Layer | Technology | Version | Role |
|---|---|---|---|
| Core | |||
| Ruby on Rails | 8.0.4 | Full-stack web framework | |
| PostgreSQL | 14+ | Primary database | |
| AI / LLM | |||
| LangChainrb | 0.19.5 | AI orchestration framework | |
| Azure OpenAI | GPT-4o | LLM provider | |
| ruby-openai | 8.3.0 | OpenAI API client | |
| Frontend & Real-Time | |||
| Hotwire | β | Turbo + Stimulus (SPA-like, no JS framework) | |
| Turbo Streams | β | Real-time DOM updates over WebSockets | |
| esbuild | β | JavaScript bundling | |
| Propshaft | β | Asset pipeline | |
| Infrastructure | |||
| Solid Queue | β | Background job processing (DB-backed) | |
| Solid Cache | β | Database-backed caching | |
| Solid Cable | β | WebSocket pub/sub (Action Cable adapter) | |
| Puma | β | Web server | |
| Kamal | β | Docker-based deployment | |
User submits code ββ> Prompt Template + Few-Shot Examples ββ> Azure OpenAI (GPT-4o)
|
<ββββββββββββββββββββββββββββββββββββββββββββββββββββ-β
v
StructuredOutputParser (JSON Schema Enforcement)
|
v
ββββββββββββββββββββββββββββββββββββββββββββ
| { overall_score: 7, |
| summary: "Generally clean code...", |
| bugs: [...], |
| security: [...], |
| performance: [...], |
| code_quality: [...], |
| best_practices: [...] } |
ββββββββββββββββββββββββββββββββββββββββββββ
- Each issue includes: severity (
critical/major/minor), line number, description, suggestion - Malformed JSON from the LLM is auto-corrected via
OutputFixingParser - Token usage (prompt + completion + total) tracked per review
Language-specific YAML examples teach the AI what quality looks like:
app/prompts/examples/
βββ ruby.yml # N+1 queries, mass assignment, find_by vs where.first
βββ python.yml # SQL injection, hardcoded credentials, non-Pythonic patterns
βββ javascript.yml # XSS vulnerabilities, missing error handling, === vs ==
βββ default.yml # Generic fallback
Adding a new language or improving review quality requires zero code changes β edit or add a YAML file.
You: "Can you explain the SQL injection issue in more detail?"
AI: "The SQL injection on line 15 occurs because user input is
interpolated directly into the query string..."
You: "Show me the corrected version."
AI: "Here's the fixed code using parameterized queries: ..."
You: "Would using a scope be even better?"
AI: "Yes! Here's a scope-based approach: ..."
- Powered by
Langchain::Assistantβ manages message history automatically - Conversation history persisted in
messagestable and reloaded for each request - Initial code + review seeded as first two messages when a review completes
- Chat suggestions appear as clickable pills for common questions
The review page uses a two-column layout with live updates:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Review Title [ruby] [Completed] [8/10] |
βββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ€
| | |
| Submitted Code | Follow-Up Chat |
| βββββββββββββββββββββββββββββ | ββββββββββββββββββββββββββββββββ |
| | def find_user(id) | | | Explain the critical | |
| | User.where(id: id) | | | issue [Send] | |
| | .first | | ββββββββββββββββββββββββββββββββ |
| | end | | |
| βββββββββββββββββββββββββββββ | ββββββββββββββββββββββββββββββββ |
| | | [You] Explain the critical | |
| AI Feedback | | issue | |
| βββββββββββββββββββββββββββββ | | | |
| | 7/10 - Generally clean.. | | | [AI] The main issue is on | |
| | | | | line 2 where... | |
| | Bugs & Errors (1) | | ββββββββββββββββββββββββββββββββ |
| | | minor | find_by... | | |
| | | | ββββββββββββ ββββββββββββββββ |
| | Security (1) | | | Show fix | | Security ? | |
| | ... | | ββββββββββββ ββββββββββββββββ |
| βββββββββββββββββββββββββββββ | |
| col-8 | col-4 |
βββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββ€
| [Back to Reviews] [New Review] |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Left column (
col-8): Submitted code + AI feedback with scored issue cards - Right column (
col-4): Sticky chat panel that stays visible while scrolling - Stacks to single column on screens < 1024px
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Rails App |
| |
| βββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββ |
| | CodeReviews |βββββ>| CodeReviewJob (Solid Queue) | |
| | Controller | | | |
| βββββββββββββββββββββ | βββββββββββββββββββββββββββββββββ | |
| | | CodeReviewService | | |
| βββββββββββββββββββββ | | - Prompt Templates | | |
| | CodeReviewMessages | | | - Few-Shot Examples | | |
| | Controller | | | - Structured Output Parser | | |
| βββββββββ¬ββββββββββββ | ββββββββββββββββ¬βββββββββββββββββ | |
| | ββββββββββββββββββ¬β | |
| | | | |
| v v | |
| βββββββββββββββββββββ βββββββββββββββββββββββββββββββββββ | |
| | ChatMessageJob | | Turbo::StreamsChannel | | |
| | (Solid Queue) | | broadcast_update_to | | |
| | | | - #code_review_feedback | | |
| | βββββββββββββββββ | | - #header_meta | | |
| | | Assistant | | | - #chat_panel | | |
| | | Service | | βββββββββββββββββββββββββββββββββββ | |
| | | (LangChain | | | |
| | | Assistant) | |ββββββ> Azure OpenAI (GPT-4o) | |
| | βββββββββββββββββ | | |
| βββββββββββββββββββββ | |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| |
ββββββββββ PostgreSQL ββββββββββββββ
(data + jobs + cache + cable)
Code Review Flow
- User submits code via the form β
CodeReviewsController#create CodeReviewJobruns in the background (Solid Queue)CodeReviewServicebuilds prompts (system + few-shot + user), calls Azure OpenAI via LangChain- Response parsed into structured JSON (with auto-fix on malformed output)
- Conversation seeded β initial code + review saved as messages for future chat
- Three Turbo Streams broadcast live: feedback, header badges, and chat panel
Follow-Up Chat Flow
- User types a question β
CodeReviewMessagesController#create - User message saved to DB and broadcast instantly via Turbo Stream
- Typing indicator (animated dots) appears in the chat
ChatMessageJobinitializesCodeReviewAssistantServicewith full conversation historyLangchain::Assistantgenerates a context-aware response- Reply saved to DB, typing indicator removed, AI response broadcast to chat
code_reviews
| Column | Type | Description |
|---|---|---|
title |
string |
Review title (required) |
language |
string |
Programming language (default: ruby) |
code |
text |
Submitted code snippet (required) |
feedback |
text |
Raw AI feedback text |
status |
integer |
0 pending β 1 processing β 2 completed β 3 failed |
structured_feedback |
jsonb |
Parsed JSON: score, summary, categorized issues |
overall_score |
integer |
Code quality score (1-10) |
prompt_tokens |
integer |
LLM prompt token count |
completion_tokens |
integer |
LLM completion token count |
total_tokens |
integer |
Total token usage |
messages
| Column | Type | Description |
|---|---|---|
code_review_id |
bigint |
FK to code_reviews |
role |
string |
user, assistant, or system |
content |
text |
Message body |
prompt_tokens |
integer |
Token usage (if tracked) |
completion_tokens |
integer |
Token usage (if tracked) |
total_tokens |
integer |
Token usage (if tracked) |
app/
βββ assets/stylesheets/
β βββ application.css # Custom CSS: grid, cards, chat, responsive
βββ controllers/
β βββ code_reviews_controller.rb # index, show, new, create, retry
β βββ code_review_messages_controller.rb # Chat message creation + Turbo broadcast
βββ javascript/controllers/
β βββ chat_controller.js # Stimulus: send, suggestions, auto-resize, scroll
βββ jobs/
β βββ code_review_job.rb # Background review + 3 Turbo Stream broadcasts
β βββ chat_message_job.rb # Background chat response + Turbo Stream
βββ models/
β βββ code_review.rb # Status enum, has_many :messages
β βββ message.rb # belongs_to :code_review, role validation
βββ prompts/
β βββ code_review_prompt.rb # Templates, JSON schema, few-shot builder
β βββ examples/ # Language-specific YAML few-shot examples
β βββ ruby.yml
β βββ python.yml
β βββ javascript.yml
β βββ default.yml
βββ services/
β βββ code_review_service.rb # Review orchestration: prompt β LLM β parse β save
β βββ code_review_assistant_service.rb # Chat: LangChain Assistant + conversation memory
βββ views/
βββ code_reviews/
β βββ show.html.erb # Two-column layout (col-8 + col-4)
β βββ _feedback.html.erb # Score bar + categorized issue cards
β βββ _chat.html.erb # Chat UI with Stimulus + Turbo Streams
β βββ _chat_panel.html.erb # Conditional: chat / waiting / failed state
β βββ _header_meta.html.erb # Status + score badges (broadcast target)
βββ code_review_messages/
βββ _message.html.erb # Chat bubble (user right / AI left)
config/
βββ initializers/langchain.rb # Azure OpenAI LLM setup (LANGCHAIN_LLM constant)
βββ routes.rb # RESTful routes + nested messages
| Method | Path | Action |
|---|---|---|
GET |
/ |
List all reviews |
GET |
/code_reviews/new |
New review form |
POST |
/code_reviews |
Submit code for review |
GET |
/code_reviews/:id |
View review + chat |
POST |
/code_reviews/:id/retry |
Retry a failed review |
POST |
/code_reviews/:id/messages |
Send a follow-up chat message |
| Requirement | Version |
|---|---|
| Ruby | 3.3.1+ |
| Node.js | 20.x |
| Yarn | 1.x or 4.x |
| PostgreSQL | 14+ |
git clone https://github.com/mahendraxceed/ai_code_review_assistant.git
cd ai_code_review_assistant
bin/setupCreate a .env file in the project root:
AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_DEPLOYMENT=your-deployment-name
AZURE_OPENAI_API_VERSION=2024-02-15-previewNote:
.envis gitignored β never commit API keys.
bin/devVisit http://localhost:3000 β submit some code and watch the AI review it in real time.
| Decision | Rationale |
|---|---|
| PostgreSQL only | Solid Queue, Solid Cache, and Solid Cable all use Postgres β zero external infrastructure beyond the database |
| Custom CSS grid | Lightweight .row / .col-8 / .col-4 system. Wide 1400px container for reviews, 960px for everything else. No framework bloat |
| Background jobs for LLM | AI calls take 3-15s. Solid Queue keeps the request cycle fast; Turbo Streams deliver results the moment they're ready |
| Conversation seeding | When a review completes, initial code + AI feedback are saved as the first two messages. The LangChain Assistant gets full context for follow-ups |
| Partial-based broadcasts | Each live section has its own partial and target ID. broadcast_update_to swaps inner HTML while preserving the wrapper |
| YAML few-shot examples | Review quality is improved by editing YAML files, not code. Easy to add new languages or refine existing examples |
bin/rails test # Unit and integration tests
bin/rails test:system # System tests (requires Chrome)This project is proprietary. All rights reserved.


