# gijela/cr-mentor architecture

> Architecture diagram of the GitHub repository gijela/cr-mentor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gijela/cr-mentor
- Repository: https://github.com/gijela/cr-mentor

## Overview

##### Main System Components

The system architecture should be divided into these key components:

a) Frontend Layer (apps/admin):
- User Interface (React-based)
- Authentication System
- Code Review Interface
- Knowledge Base Management Interface
- Theme and Internationalization Support

b) Backend Services (apps/api, apps/server):
- API Gateway
- Authentication Service
- GitHub Integration Service
- Knowledge Base Service
- LLM Integration Service
- Code Analysis Service

c) External Integrations:
- GitHub API
- LLM Services
- Supabase (for RAG implementation)
- Storage Services

##### Key Relationships to Highlight

a) Code Review Flow:
**GitHub Repository -> GitHub Integration Service -> Code Analysis Service -> LLM Service -> Knowledge Base Service -> User Interface**

b) Knowledge Base Flow:
**User Interface -> Knowledge Base Service -> Supabase RAG -> Storage Service**

##### Architectural Patterns to Emphasize

- Microservices Architecture (separate apps for admin, server, and API)
- Monorepo Structure (workspace with shared packages)
- Event-Driven Architecture (for real-time updates)
- RAG (Retrieval Augmented Generation) Pattern

Use these visual elements:

- Rectangles: Main services
- Hexagons: External services
- Rounded rectangles: UI components

- Blue: Frontend components
- Green: Backend services
- Purple: External services
- Orange: Data stores
- Gray: Infrastructure components

##### Implementation Details

a) Frontend Architecture:
- React Components
- State Management
- Routing System
- Internationalization
- Theme System

b) Backend Services:
- API Routes
- Authentication Flow
- GitHub Integration
- LLM Processing Pipeline
- Knowledge Base Management

c) Data Flow:
- User Interactions
- Code Review Process
- Knowledge Base Updates
- Authentication Flow

##### Technical Stack Indicators

- React
- Next.js
- Supabase
- GitHub API
- LLM Services
- TailwindCSS
- TypeScript

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        UI["Frontend UI Layer"]
        Auth["Authentication System"]
        CRI["Code Review Interface"]
        KBM["Knowledge Base Management"]
        Theme["Theme System"]
        I18n["Internationalization"]
        State["State Management"]
        Router["Routing System"]
        DataFetch["Data Fetching Layer"]
    end

    subgraph Backend
        API["API Gateway"]
        GitService["GitHub Integration Service"]
        KBService["Knowledge Base Service"]
        LLMService["LLM Integration"]
        CodeAnalysis["Code Analysis Service"]
        SupabaseInt["Supabase Integration"]
    end

    subgraph External
        GitHub[("GitHub API")]
        LLM[("LLM Services")]
        Supabase[("Supabase RAG")]
        Storage[("Storage Services")]
    end

    %% Frontend Relationships
    UI --> Router
    UI --> State
    UI --> DataFetch
    UI --> Theme
    UI --> I18n
    Router --> Auth
    Router --> CRI
    Router --> KBM

    %% Backend Relationships
    API --> GitService
    API --> KBService
    API --> LLMService
    API --> CodeAnalysis
    KBService --> SupabaseInt

    %% External Relationships
    GitService --> GitHub
    LLMService --> LLM
    SupabaseInt --> Supabase
    KBService --> Storage

    %% Main Flows
    GitHub --> GitService
    GitService --> CodeAnalysis
    CodeAnalysis --> LLMService
    LLMService --> KBService
    KBService --> UI

    %% Click Events
    click UI "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/components"
    click Auth "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/pages/(external)/login"
    click CRI "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/pages/(admin)/(with-layout)/pullRequest"
    click KBM "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/pages/(admin)/(with-layout)/knowledgeBase"
    click Theme "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/components/theme"
    click I18n "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/locales"
    click GitService "https://github.com/Gijela/CR-Mentor/tree/main/apps/server/lib/agentTools/github"
    click KBService "https://github.com/Gijela/CR-Mentor/tree/main/apps/server/components/KnowledgeBase"
    click LLMService "https://github.com/Gijela/CR-Mentor/tree/main/apps/server/lib/model"
    click API "https://github.com/Gijela/CR-Mentor/tree/main/apps/api/src"
    click SupabaseInt "https://github.com/Gijela/CR-Mentor/blob/main/apps/server/lib/utils/supabase.ts"
    click CodeAnalysis "https://github.com/Gijela/CR-Mentor/blob/main/apps/server/lib/prompt/github/pull_request.ts"
    click State "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/atoms"
    click DataFetch "https://github.com/Gijela/CR-Mentor/tree/main/apps/admin/src/hooks/query"
    click Router "https://github.com/Gijela/CR-Mentor/blob/main/apps/admin/src/router.tsx"

    classDef frontend fill:#3b82f6,color:white
    classDef backend fill:#22c55e,color:white
    classDef external fill:#a855f7,color:white
    classDef storage fill:#f97316,color:white

    class UI,Auth,CRI,KBM,Theme,I18n,State,Router,DataFetch frontend
    class API,GitService,KBService,LLMService,CodeAnalysis,SupabaseInt backend
    class GitHub,LLM,Supabase,Storage external
    class Storage storage
```
