# adgpt/codecritic-ai architecture

> Architecture diagram of the GitHub repository adgpt/codecritic-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adgpt/codecritic-ai
- Repository: https://github.com/adgpt/codecritic-ai

## Overview

##### Project Type & Purpose
- CodeCritic-AI is a modern, frontend-heavy, AI-powered code review assistant. It gives feedback on code quality in “real time.”
- The README highlights features such as a code editor with syntax highlighting, AI-powered code analysis (leveraging an external Gemini API), secure authentication via Supabase (with Google and GitHub OAuth), and a modern UI built with shadcn-ui and Tailwind CSS.

##### File Structure
- There’s no explicit separate backend folder—instead, the architecture is built around a frontend application (using Vite, React, and TypeScript) with integration to external services.
- Look at the “src” directory:
- “components” contain UI parts such as CodeEditor, CodeReviewer, Navbar, ReviewSummary, and others.
- “contexts” holds AuthContext.tsx, indicating that user authentication and state management are handled in a React context.
- “hooks” and “lib” directories suggest custom utilities for toast notifications (and probably other shared logic) as well as integrations such as Supabase.
- “pages” show route components including Home, Login, NotFound, Profile, etc.
- “services” (with codeAnalysisService.ts) likely encapsulate API calls to AI-code analysis endpoints.
- There is also a “supabase” directory with migration SQL scripts, which means that Supabase is used not only for authentication but also for managing the underlying user profile and possibly other database-backed logic.
- Various configuration and environment files such as .env, Vite config, Tailwind, and tsconfig indicate a tightly integrated deployment and development setup.

##### Key Components
a. Frontend Application (SPA)
- Developed with React, TypeScript, and Vite.
- Components are split into UI elements (in “components/ui”) and functional sections (CodeEditor, CodeReviewer, Navbar, etc.).
- Pages (Home, Login, Profile, etc.) and routing logic.
- Context providers (such as AuthContext) responsible for managing state and user sessions.
b. External Services & APIs
- Supabase: Used for secure authentication, OAuth integrations (Google, GitHub), and database management.
- Gemini API: Integrated via environment variables for AI-powered code analysis (as mentioned in the README).
c. Code Analysis Service
- Represented by src/services/codeAnalysisService.ts, which likely communicates with the Gemini API or other AI endpoints.
d. Database & Migrations
- A Supabase database with user profiles and associated RLS (Row Level Security) policies managed under the “supabase/migrations” directory.
e. Build & Configuration Utilities
- Vite for frontend tooling.
- Tailwind CSS and shadcn-ui for the user interface.
- ESLint configurations, environment settings, and other build tools acting as supporting infrastructure.

##### Relationships and Interactions
- The Frontend (SPA) interacts directly with:
- Supabase for authentication and to fetch/store user profile information.
- The Code Analysis Service for sending code to be reviewed and receiving AI feedback.
- The AuthContext in React manages session state and permissions that are used across the application.
- UI Components (like the CodeEditor, CodeReviewer, and Navbar) communicate with each other (or via context) and with Services to reflect real-time results.
- External APIs (Gemini API) are called indirectly from the services layer, ensuring separation of concerns.

##### Architectural Patterns & Design Principles
- Component-Based Architecture: The project uses a very modular approach, with clearly separated UI components and custom hooks.
- Separation of Concerns: The use of contexts (AuthContext) and services (codeAnalysisService) decouples business logic from the UI.

##### Customizing for CodeCritic-AI
- Because CodeCritic-AI is a full-stack-like application with a strong emphasis on frontend functionality and external API integrations:
- Separation between the presentation layer (React components/pages, UI components library) and the service layer (code analysis service).
- Authentication process that relies on Supabase and the integrations with Google/GitHub.
- Incorporate specific modules like the “CodeEditor” and “CodeReviewer” to show where the AI feedback loop is initiated in the user experience.
- Do not overcomplicate by splitting every minor file; focus on logical groupings (e.g., UI components, service integration, authentication/context, and database management).

- Main UI and routing structure (SPA with React and TypeScript)
- Communication paths for user authentication (Supabase OAuth), fetching/updating user profile data, and handling secure sessions through AuthContext.
- Services used to power the AI feedback loop, including the Gemini API integration for code analysis.
- The supporting infrastructure that uses migrations and configurations (environment variables, build configurations) to glue these elements together.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Build & Configuration Utilities"
        Config["Build & Config Utilities"]:::config
    end

    subgraph "Frontend SPA"
        App["Main App (src)"]:::frontend
        UI["UI Components (src/components)"]:::frontend
        Shadcn["shadcn-ui Components (src/components/ui)"]:::frontend
        Pages["Routing & Pages (src/pages)"]:::frontend
        Auth["Auth Context (src/contexts/AuthContext.tsx)"]:::frontend
        Analysis["Code Analysis Service (src/services/codeAnalysisService.ts)"]:::service
    end

    subgraph "External Services"
        Supa["Supabase (Auth & DB)"]:::external
        Migrations["Database Migrations (supabase/migrations)"]:::external
        Gemini["Gemini API"]:::external
    end

    Config --> App
    App --> UI
    App --> Pages
    App --> Auth
    App --> Analysis
    UI -->|"sends_code_for_review"| Analysis
    Auth -->|"authenticates_and_fetches_profile"| Supa
    Analysis -->|"calls_for_analysis"| Gemini
    Supa -->|"managed_by"| Migrations

    click App "https://github.com/adgpt/codecritic-ai/tree/main/src/"
    click UI "https://github.com/adgpt/codecritic-ai/tree/main/src/components"
    click Shadcn "https://github.com/adgpt/codecritic-ai/tree/main/src/components/ui"
    click Pages "https://github.com/adgpt/codecritic-ai/tree/main/src/pages"
    click Auth "https://github.com/adgpt/codecritic-ai/blob/main/src/contexts/AuthContext.tsx"
    click Analysis "https://github.com/adgpt/codecritic-ai/blob/main/src/services/codeAnalysisService.ts"
    click Supa "https://github.com/adgpt/codecritic-ai/blob/main/src/lib/supabase.ts"
    click Migrations "https://github.com/adgpt/codecritic-ai/tree/main/supabase/migrations"
    click Config "https://github.com/adgpt/codecritic-ai/blob/main/vite.config.ts"

    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#dfd,stroke:#333,stroke-width:2px;
    classDef external fill:#fbb,stroke:#333,stroke-width:2px;
    classDef config fill:#ffd,stroke:#333,stroke-width:2px;
```
