# anirudh-1106/ai-code-reviewer architecture

> Architecture diagram of the GitHub repository anirudh-1106/ai-code-reviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anirudh-1106/ai-code-reviewer
- Repository: https://github.com/anirudh-1106/ai-code-reviewer

## Overview

1. **Overall shape**
   - This repo is a Python-based code review tool with **two presentation layers** over a shared analysis engine:
     - a **Streamlit app** for the primary interactive workflow (`app.py`)
     - a **Reflex full-stack UI** variant (`full_stack_using_reflex/`, `pages/`, `components/`)

2. **Core architecture boundary**
   - The most important boundary is between:
     - **analysis services**: parsing, static checks, style checks, AI suggestion generation
     - **UI layers**: Streamlit and Reflex screens, which only orchestrate input/output and display results
   - This separation makes the code review logic reusable across both front ends.

3. **Static analysis pipeline**
   - The local analysis path is split into focused modules:
     - `code_parser.py` for syntax parsing/validation
     - `code_visitor.py` for traversing code context and tracking symbols
     - `error_detector.py` for unused imports, variables, functions, and undefined names
     - `style_analyzer.py` for PEP 8 checks, likely via `pycodestyle`
   - `code_analyzer.py` appears to be the orchestration layer that combines these checks into one report.

4. **AI suggestion layer**
   - `ai_suggestor.py` is the external-LLM integration boundary.
   - The readme shows it uses the LangChain ecosystem plus provider APIs such as **Groq** and **Anthropic**, with `.env` keys.
   - This layer turns static-analysis findings and source code into:
     - summary explanations
     - refactoring guidance
     - improved code suggestions
     - assistant/chat responses based on current analysis context

5. **Result aggregation**
   - The app merges static findings and AI output into a single review artifact.
   - Based on the readme, that artifact includes:
     - issue list
     - score/grade
     - original vs improved code diff
     - markdown report content
   - This aggregated result is what both front ends present to the user.

6. **Streamlit workflow**
   - `app.py` is the main entry point for the Streamlit version.
   - It likely handles the full single-session flow:
     - accept pasted code or demo code
     - run analysis
     - show findings and AI suggestions
     - offer report export and PDF download
   - This is the simplest execution path and the clearest “one-page” user journey.

7. **Reflex workflow**
   - The Reflex app lives in `full_stack_using_reflex/` with `state.py` as the state/action layer.
   - `pages/` defines route-based screens such as:
     - `index.py`
     - `about.py`
     - `assistant.py`
     - `history.py`
     - `posts.py`
   - `components/` contains reusable UI pieces like header, navbar, hero, footer, and premium sections.

8. **State and interaction model**
   - Reflex’s `state.py` is the main state boundary for:
     - current code under review
     - analysis results
     - assistant conversation context
     - review history
   - That suggests the Reflex version is more stateful and multi-page than the Streamlit variant, which is usually more linear and session-oriented.

9. **Report/export path**
   - The project supports report generation as a downstream output of the analysis pipeline.
   - The readme mentions:
     - **markdown report content**
     - **PDF download support**
   - `reportlab` is the key external dependency that affects this export boundary.

10. **Support files and configuration**
   - `requirements.txt` defines the Python dependency boundary.
   - `rxconfig.py` configures the Reflex app runtime.
   - `language_config.py` and `generic_static.py` likely provide language-specific defaults or shared constants for the analysis pipeline.
   - `assets/` holds UI/static resources for the front ends.

11. **Data flow summary**
   - The end-to-end flow is:
     - user provides Python code
     - parser validates syntax
     - static analyzers detect issues
     - AI suggester generates explanations and improved code
     - results are merged into a review summary
     - UI renders the review, diff, and export options
     - assistant/history features reuse the same review context

12. **What to draw in an architecture diagram**
   - Show three major layers:
     - **UI layer**: Streamlit + Reflex pages/components
     - **analysis layer**: parser / visitor / detectors / style analyzer / analyzer orchestrator
     - **AI integration layer**: `ai_suggestor.py` talking to external LLM APIs
   - Then add output sinks for **history**, **assistant chat**, and **report export** as consumers of the same analysis result.

Main entry points: [`code_analyzer.py`](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_analyzer.py) (Analyzer), [`full_stack_using_reflex/full_stack_using_reflex.py`](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/full_stack_using_reflex/full_stack_using_reflex.py) (Reflex App), [`ai_suggestor.py`](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/ai_suggestor.py) (AI Suggester), [`app.py`](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/app.py) (App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui_streamlit["Streamlit UI"]
  node_app_py["App<br/>streamlit entry<br/>[app.py]"]
end

subgraph group_ui_reflex["Reflex UI"]
  node_reflex_main["Reflex App<br/>reflex entry"]
  node_reflex_state["State<br/>[state.py]"]
  node_page_index["Home<br/>reflex page<br/>[index.py]"]
  node_page_about["About<br/>reflex page<br/>[about.py]"]
  node_page_assistant["Assistant<br/>reflex page<br/>[assistant.py]"]
  node_page_history["History<br/>reflex page<br/>[history.py]"]
  node_page_posts["Posts<br/>reflex page<br/>[posts.py]"]
  node_components["UI Parts<br/>reflex components"]
end

subgraph group_analysis["Analysis Engine"]
  node_parser["Parser<br/>[code_parser.py]"]
  node_visitor["Visitor<br/>[code_visitor.py]"]
  node_errors["Detector<br/>static checks<br/>[error_detector.py]"]
  node_style["Style<br/>pep8 checks<br/>[style_analyzer.py]"]
  node_analyzer["Analyzer<br/>orchestrator<br/>[code_analyzer.py]"]
  node_external_linters["Linters<br/>lint adapters"]
end

subgraph group_ai["AI Suggestions"]
  node_suggester["AI Suggester<br/>llm integration<br/>[ai_suggestor.py]"]
end

subgraph group_support["Support Files"]
  node_lang_config["Language Config<br/>defaults<br/>[language_config.py]"]
  node_generic_static["Static Defaults<br/>shared constants<br/>[generic_static.py]"]
  node_requirements["Deps<br/>[requirements.txt]"]
  node_rxconfig["Rx Config<br/>runtime config<br/>[rxconfig.py]"]
  node_assets[("Assets<br/>static resources")]
end

node_app_py -->|"run analysis"| node_analyzer
node_app_py -->|"request AI"| node_suggester
node_analyzer -->|"parse"| node_parser
node_analyzer -->|"inspect symbols"| node_visitor
node_analyzer -->|"detect issues"| node_errors
node_analyzer -->|"check style"| node_style
node_style -->|"adapter"| node_external_linters
node_analyzer -->|"apply rules"| node_lang_config
node_analyzer -->|"shared defaults"| node_generic_static
node_suggester -->|"use findings"| node_analyzer
node_suggester -.->|"depends on"| node_requirements
node_reflex_main -->|"bind state"| node_reflex_state
node_reflex_main -->|"serve page"| node_page_index
node_reflex_main -->|"serve page"| node_page_about
node_reflex_main -->|"serve page"| node_page_assistant
node_reflex_main -->|"serve page"| node_page_history
node_reflex_main -->|"serve page"| node_page_posts
node_reflex_main -->|"compose ui"| node_components
node_page_index -->|"review code"| node_analyzer
node_page_assistant -->|"chat help"| node_suggester
node_page_history -->|"read history"| node_reflex_state
node_components -->|"render assets"| node_assets
node_app_py -->|"load assets"| node_assets
node_analyzer -->|"hand off context"| node_suggester
node_suggester -->|"assist user"| node_page_assistant

click node_app_py "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/app.py"
click node_reflex_main "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/full_stack_using_reflex/full_stack_using_reflex.py"
click node_reflex_state "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/full_stack_using_reflex/state.py"
click node_page_index "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/index.py"
click node_page_about "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/about.py"
click node_page_assistant "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/assistant.py"
click node_page_history "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/history.py"
click node_page_posts "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/posts.py"
click node_components "https://github.com/anirudh-1106/ai-code-reviewer/tree/main/components"
click node_parser "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_parser.py"
click node_visitor "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_visitor.py"
click node_errors "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/error_detector.py"
click node_style "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/style_analyzer.py"
click node_analyzer "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_analyzer.py"
click node_suggester "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/ai_suggestor.py"
click node_external_linters "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/external_linters.py"
click node_lang_config "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/language_config.py"
click node_generic_static "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/generic_static.py"
click node_requirements "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/requirements.txt"
click node_rxconfig "https://github.com/anirudh-1106/ai-code-reviewer/blob/main/rxconfig.py"
click node_assets "https://github.com/anirudh-1106/ai-code-reviewer/tree/main/assets"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_py toneBlue
class node_reflex_main,node_reflex_state,node_page_index,node_page_about,node_page_assistant,node_page_history,node_page_posts,node_components toneAmber
class node_parser,node_visitor,node_errors,node_style,node_analyzer,node_external_linters toneMint
class node_suggester toneRose
class node_lang_config,node_generic_static,node_requirements,node_rxconfig,node_assets toneIndigo
```

## Components

### Streamlit UI

Single-page review workflow

- [App](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/app.py): streamlit entry · Main Streamlit review workflow · `app.py`

### Reflex UI

Multi-page app and shared components

- [Reflex App](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/full_stack_using_reflex/full_stack_using_reflex.py): reflex entry · Reflex runtime bootstrap · `full_stack_using_reflex/full_stack_using_reflex.py`
- [State](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/full_stack_using_reflex/state.py): ui state · Shared state and actions for review and chat · `full_stack_using_reflex/state.py`
- [Home](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/index.py): reflex page · Primary review screen · `pages/index.py`
- [About](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/about.py): reflex page · Project information screen · `pages/about.py`
- [Assistant](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/assistant.py): reflex page · Chat and guidance screen · `pages/assistant.py`
- [History](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/history.py): reflex page · Past reviews and sessions · `pages/history.py`
- [Posts](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/pages/posts.py): reflex page · Additional content screen · `pages/posts.py`
- [UI Parts](https://github.com/anirudh-1106/ai-code-reviewer/tree/main/components): reflex components · Reusable layout and presentation components · `components`

### Analysis Engine

Parsing, static checks, and orchestration

- [Parser](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_parser.py): syntax parser · Validates and parses source code · `code_parser.py`
- [Visitor](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_visitor.py): symbol visitor · Tracks code context and symbols · `code_visitor.py`
- [Detector](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/error_detector.py): static checks · Finds unused and undefined code issues · `error_detector.py`
- [Style](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/style_analyzer.py): pep8 checks · Runs formatting and style analysis · `style_analyzer.py`
- [Analyzer](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/code_analyzer.py): orchestrator · Combines parser and checkers into one report · `code_analyzer.py`
- [Linters](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/external_linters.py): lint adapters · External linting integration used by analysis · `external_linters.py`

### AI Suggestions

LLM-backed review assistance

- [AI Suggester](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/ai_suggestor.py): llm integration · Generates explanations and improved code suggestions · `ai_suggestor.py`

### Support Files

Config and shared defaults

- [Language Config](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/language_config.py): defaults · Language-specific analysis settings · `language_config.py`
- [Static Defaults](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/generic_static.py): shared constants · Generic analysis settings and shared constants · `generic_static.py`
- [Deps](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/requirements.txt): python deps · Project dependency boundary · `requirements.txt`
- [Rx Config](https://github.com/anirudh-1106/ai-code-reviewer/blob/main/rxconfig.py): runtime config · Reflex app runtime configuration · `rxconfig.py`
- [Assets](https://github.com/anirudh-1106/ai-code-reviewer/tree/main/assets): static resources · UI static files and media · `assets`

## Connections

- App → Analyzer: run analysis · Streamlit entry invokes the analysis pipeline
- App → AI Suggester: request AI · Streamlit entry requests generated guidance
- Analyzer → Parser: parse · Analyzer starts with syntax validation
- Analyzer → Visitor: inspect symbols · Analyzer uses visitor context for semantic checks
- Analyzer → Detector: detect issues · Analyzer collects unused and undefined code findings
- Analyzer → Style: check style · Analyzer runs PEP 8 and formatting checks
- Style → Linters: adapter · Style analysis delegates to linting adapters
- Analyzer → Language Config: apply rules · Language settings influence analysis behavior
- Analyzer → Static Defaults: shared defaults · Shared constants inform analysis defaults
- AI Suggester → Analyzer: use findings · AI suggestions are grounded in static analysis results
- AI Suggester → Deps: depends on · AI layer relies on project dependencies and providers
- Reflex App → State: bind state · Reflex app connects routes to shared state
- Reflex App → Home: serve page · Registers the main review route
- Reflex App → About: serve page · Registers the about route
- Reflex App → Assistant: serve page · Registers the assistant route
- Reflex App → History: serve page · Registers the history route
- Reflex App → Posts: serve page · Registers the posts route
- Reflex App → UI Parts: compose ui · Routes reuse shared header, navbar, hero, and footer pieces
- Home → Analyzer: review code · UI triggers the shared analysis engine
- Assistant → AI Suggester: chat help · Assistant page reuses the AI suggestion layer
- History → State: read history · History page reads stored review context
- UI Parts → Assets: render assets · Presentation components consume static resources
- App → Assets: load assets · Streamlit UI uses static resources for presentation
- Analyzer → AI Suggester: hand off context · Analysis findings feed the AI review summary
- AI Suggester → Assistant: assist user · Generated guidance is shown in assistant workflows
