A functional, fully-typed TypeScript code reviewer that leverages functional programming principles and AI analysis to automatically review code.
- π― Functional Programming with fp-ts
- π Fully typed with TypeScript (strict mode)
- π€ AI-powered analysis via OpenAI (ai SDK)
- π‘οΈ Robust, composable error handling with Either
- π§© Pure, composable functions and modular architecture
# Clone the repository
git clone <repository-url>
cd ai-agent-code-reviewer
# Install dependencies
pnpm install
# Environment variables
cp .env.example .env
# Edit .env with your OpenAI API keyCreate a .env file with your OpenAI API key:
OPENAI_API_KEY=your_api_key_here# TypeScript (recommended)
npm run review:functional # Functional code reviewer
npm run review:examples # Usage examples
npm run type-check # Type check only (no JS emit)
# JavaScript (legacy)
npm run review # Original code reviewer# Review a specific file
npm run review:functional test/sample.js
# Or using tsx directly
npx tsx src/code-reviewer-functional.ts your-file.js# Run functional usage examples
npm run review:examples test/sample.jssrc/
βββ types/
β βββ index.ts # Type definitions
βββ utils/
β βββ error-handling.ts # Functional error handling utilities
β βββ functional.ts # Functional helpers
βββ examples/
β βββ functional-usage.ts # Usage examples
βββ code-reviewer-functional.ts # Main functional code reviewer
// Pure function - always returns the same result
export const createTimestamp = (): string => new Date().toISOString();// Composition using F.pipe
export const getLanguageFromFilename = F.pipe(getFileExtension, detectLanguage);// Either for safe error handling
const result = await safeReadFile(filename);
if (result._tag === "Left") {
return createFailedReview(filename, result.left.message);
}export const analyzeCodeWithAI = async (
config: CodeReviewerConfig,
code: string,
filename: string,
language: SupportedLanguage
) => {
/* ... */
};-
π Bugs & Logic Issues
- Runtime errors
- Edge cases
- Off-by-one errors
-
β‘ Performance Concerns
- Inefficient algorithms
- Memory leaks
- Unnecessary operations
-
π Security Issues
- Input validation
- SQL injection
- XSS vulnerabilities
-
π Code Quality
- Readability
- Maintainability
- Best practices
-
π§ͺ Testing Gaps
- Missing test cases
- Untestable patterns
β
Review complete: test/sample.js
π Code Review Results for test/sample.js
Language: JavaScript
Reviewed: 2025-10-05T11:27:44.676Z
============================================================
### 1. Bugs and Logic Issues
- **Issue Type:** Null check
- **Location:** Line 2
- **Problem:** No null check for userData.email
- **Fix:** Add validation before accessing properties
- **Priority:** High
============================================================
npm run type-check// Main types
interface ReviewResult {
filename: string;
language: SupportedLanguage;
analysis: string;
timestamp: string;
success: true;
}
interface ReviewError {
filename: string;
error: string;
timestamp: string;
success: false;
}const results = await batchReview([
"src/utils.ts",
"src/types.ts",
"src/main.ts",
]);const transformResults = F.pipe(
results,
filter(isSuccessfulReview),
map(getAnalysis),
join("\n\n")
);const safeReview = async (filename: string) => {
const result = await reviewer.reviewFile(filename);
return result.success ? E.right(result) : E.left(result.error);
};Project is configured with:
- Strict Mode: Maximum type safety
- No Emit: Type-checking only (no JS output)
- ES Modules: Full ESM support
- Functional Types: Types tailored for FP
fp-ts: Functional programming in TypeScriptai: AI SDK@ai-sdk/openai: OpenAI integration
typescript: TypeScript compilertsx: TypeScript executor@types/node: Node.js types
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License. See the LICENSE file for details.
- fp-ts - Functional programming in TypeScript
- OpenAI - AI API for code analysis
- TypeScript - Static type system
Enjoy building in a functional and type-safe way! π