CodeCoach is a modern web application built with Next.js 14 using the App Router. It follows a serverless architecture with API routes handling backend logic and a client-side React application for the user interface.
- Frontend: React (Next.js), Tailwind CSS, Shadcn UI, Lucide Icons, Monaco Editor.
- Backend: Next.js API Routes (
/api/analyze,/api/convert). - AI Integration: OpenRouter API (using
deepseek/deepseek-chat-v3.1:free) for code analysis and conversion. - Authentication & Database: Supabase (Auth for user management, potentially DB for history - though currently using localStorage with a note about Supabase integration).
- State Management: React Hooks (
useState,useEffect,useContext) and LocalStorage for persistence.
- Framework: Next.js 14.1.0
- Language: TypeScript
- Styling: Tailwind CSS +
tailwindcss-animate - UI Components: Radix UI primitives (via Shadcn UI pattern)
- Code Editor:
@monaco-editor/react - Animations: GSAP (listed in dependencies, though usage not deeply verified in inspected files), CSS transitions.
- Icons:
lucide-react - Utilities:
clsx,tailwind-merge
- Endpoint:
/api/analyze - Process:
- Receives code and complexity level.
- Calls AI to add inline comments explaining the code.
- Calls AI again to generate structured feedback (Quality Score, Line-by-line feedback, Suggestions, Learning Tips).
- Returns both to the frontend.
- UI: Displays annotated code in a read-only Monaco editor and feedback in a structured display component.
- Endpoint:
/api/convert - Process:
- Generates a natural language description of the source code functionality.
- Generates target language code based on that description (to ensure idiomatic translation).
- Performs basic regex-based validation and cleaning.
- If validation fails, attempts an AI-based fix.
- Validation: Includes language-specific checks (e.g., Python imports, JS/TS variable declarations).
- Storage: Primarily uses
localStoragefor history and user preferences (use-preferences.ts). - Sync: There is code in
history-panel.tsxreferencinguserIdandsaveHistoryItem, suggesting a hybrid approach or a transition to Supabase-backed history. - Features: Search, Filter (Analyze/Convert/Favorites), Delete.
- Theming: Dark/Light mode support via
next-themes. - Responsiveness: Mobile-friendly layout with collapsible panels.
- Accessibility: ARIA labels, keyboard shortcuts (Ctrl+Enter, Ctrl+K, etc.), tooltips.
- Modular Components: UI is broken down into small, reusable components (
code-editor.tsx,history-panel.tsx,dashboard-dialogs.tsx). - Type Safety: TypeScript is used throughout, with interfaces for props and API responses.
- Modern Patterns: Uses Next.js App Router, Server Actions (or API routes in this case), and React Hooks effectively.
- Robust Error Handling: API routes have try-catch blocks and return appropriate error codes. The conversion logic includes a self-correction loop.
- Clean UI Code: Uses
shadcn/uipatterns for consistent and accessible design.
- AI Model Dependency: Relies heavily on a specific free model (
deepseek-chat-v3.1:free). If this model becomes unavailable or changes, the app breaks. Abstraction layerfetchWithKeyRotationhelps but model dependence is high. - History Sync: The
HistoryPanelseems to rely onlocalStorageeven when a user is logged in (based on theloadHistoryfunction reading from localStorage). Syncing this with Supabase would be a logical next step. - Validation Logic: The regex-based validation in
route.tsis a good start but might be fragile for complex code. - Security:
evalchecks are present, which is good. API keys are managed via a rotation manager, which is a best practice.
The application is well-structured and uses a modern, robust stack. The separation of concerns between the UI and the AI logic is clear. The "CodeCoach" core value proposition is well-implemented with a sophisticated multi-step AI workflow for high-quality results.