# krishn404/git-friend architecture

> Architecture diagram of the GitHub repository krishn404/git-friend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishn404/git-friend
- Repository: https://github.com/krishn404/git-friend

## Overview

##### Project Type and Purpose
- Git-Friend is a full-stack web application built with Next.js (v13 app router), React, and TypeScript.
- It provides an AI-powered GitHub assistant featuring:
– AI Chat for GitHub questions
– Dynamic README generation
– Gitmoji (commit emoji) lookup
– Google Authentication and user sessions

##### High-Level Architectural Overview
A. Client-Side (Browser)
- Next.js page components under /app/… (ai-chat, generate-readme, git-mojis)
- Shared UI library in /components/ui (Radix-based controls, toasts, dialogs, etc.)
- Auth components in /components/auth (login modal, protected-route wrapper)
- Global context in /context/auth-context.tsx to hold user session state
- Hooks in /hooks (for detecting mobile, toasting messages)

B. Server-Side (Next.js Server + API Routes)
- Server components and layouts under /app/layout.tsx, app/page.tsx
- API endpoints under /app/api/… implemented as serverless functions:
– /api/chat/route.ts → forwards chat queries to AI service (Groq or OpenAI)
– /api/generate-readme/route.ts → calls AI to produce README content
– /api/fetch-repo-data/route.ts → optionally fetches metadata from GitHub
– /api/git-mojis and /gitmojis → returns list of emojis or single emoji

C. Libraries & Utilities (lib/)
- lib/firebase.ts → initialize Firebase App and Auth
- lib/redis.ts → connect to Upstash Redis for caching or rate-limiting
- lib/timeout-utils.ts, utils.ts → shared helper functions

D. External Services
- Google Identity Platform (OAuth2) for user sign-in
- Firebase Auth (session management, optional Firestore/Storage)
- Upstash Redis (REST API, caching intermediate AI results or emoji lists)
- GitHub REST API via Octokit (for fetch-repo-data endpoint)
- AI API (Groq or OpenAI) for chat and text generation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Tier
    subgraph "Presentation Tier"
        direction TB
        AIChatPage["AI Chat Page"]:::frontend
        AIChatLoading["AI Chat Loading"]:::frontend
        GenReadmePage["Generate README Page"]:::frontend
        GitmojisPage["Gitmojis Page"]:::frontend
        GitmojisLoading["Gitmojis Loading"]:::frontend
        HomePage["Home Page"]:::frontend
        SharedUI["UI Library"]:::frontend
        AuthComponentsDir["Auth Components"]:::frontend
        LoginModal["Login Modal"]:::frontend
        ProtectedRoute["Protected Route Wrapper"]:::frontend
        UserAuthButton["User Auth Button"]:::frontend
        ThemeProvider["Theme Provider"]:::frontend
        AuthContext["Auth Context"]:::frontend
        HooksDir["Hooks Directory"]:::frontend
        MobileHook["use-mobile Hook"]:::frontend
        ToastHook["use-toast Hook"]:::frontend
    end

    %% Application Tier
    subgraph "Application Tier"
        direction TB
        Layout["Global Layout"]:::backend
        APIChat["Chat API Route"]:::backend
        GenReadmeAPI["Generate README API Route"]:::backend
        FetchRepoAPI["Fetch Repo Data API Route"]:::backend
        SingleGitmojiAPI["Single Gitmoji API Route"]:::backend
        GitmojisAPI["Gitmojis List API Route"]:::backend
    end

    %% Data/Integration Tier
    subgraph "Data/Integration Tier"
        direction TB
        GoogleOAuth["Google OAuth2"]:::external
        FirebaseAuth["Firebase Auth"]:::external
        Redis["Upstash Redis"]:::external
        GitHubAPI["GitHub REST API"]:::external
        AIService["AI API (Groq/OpenAI)"]:::external
    end

    %% Auth Flow
    HomePage -->|"OAuth2 redirect"| GoogleOAuth
    GoogleOAuth -->|"tokens & session"| FirebaseAuth
    FirebaseAuth -->|"store session"| AuthContext

    %% UI & Context Usage
    AuthContext -->|provides state| ProtectedRoute
    ProtectedRoute -->|wraps| AIChatPage
    ProtectedRoute -->|wraps| GenReadmePage
    ProtectedRoute -->|wraps| GitmojisPage
    LoginModal -->|used by| AuthComponentsDir
    UserAuthButton -->|triggers| LoginModal
    ThemeProvider -->|wraps| SharedUI

    %% Client to Serverless API Flows
    AIChatPage -->|"XHR POST to /api/chat"| APIChat
    GenReadmePage -->|"Fetch to /api/generate-readme"| GenReadmeAPI
    GitmojisPage -->|"Fetch to /api/gitmojis"| GitmojisAPI
    GitmojisPage -->|"Fetch to /api/git-moji"| SingleGitmojiAPI
    HomePage -->|"Fetch to /api/fetch-repo-data"| FetchRepoAPI

    %% API to External Services
    APIChat -->|"RPC call"| AIService
    GenReadmeAPI -->|"RPC call"| AIService
    FetchRepoAPI -->|"REST call"| GitHubAPI
    GitmojisAPI -->|"cache lookup"| Redis
    GitmojisAPI -->|"cache miss then store TTL"| Redis

    %% Click Events
    click AIChatPage "https://github.com/krishn404/git-friend/blob/main/app/ai-chat/page.tsx"
    click AIChatLoading "https://github.com/krishn404/git-friend/blob/main/app/ai-chat/loading.tsx"
    click GenReadmePage "https://github.com/krishn404/git-friend/blob/main/app/generate-readme/page.tsx"
    click GitmojisPage "https://github.com/krishn404/git-friend/blob/main/app/git-mojis/page.tsx"
    click GitmojisLoading "https://github.com/krishn404/git-friend/blob/main/app/git-mojis/loading.tsx"
    click HomePage "https://github.com/krishn404/git-friend/blob/main/app/page.tsx"
    click Layout "https://github.com/krishn404/git-friend/blob/main/app/layout.tsx"
    click APIChat "https://github.com/krishn404/git-friend/blob/main/app/api/chat/route.ts"
    click GenReadmeAPI "https://github.com/krishn404/git-friend/blob/main/app/api/generate-readme/route.ts"
    click FetchRepoAPI "https://github.com/krishn404/git-friend/blob/main/app/api/fetch-repo-data/route.ts"
    click SingleGitmojiAPI "https://github.com/krishn404/git-friend/blob/main/app/api/git-moji/route.ts"
    click GitmojisAPI "https://github.com/krishn404/git-friend/blob/main/app/api/gitmojis/route.ts"
    click SharedUI "https://github.com/krishn404/git-friend/tree/main/components/ui"
    click AuthComponentsDir "https://github.com/krishn404/git-friend/tree/main/components/auth"
    click LoginModal "https://github.com/krishn404/git-friend/blob/main/components/auth/login-modal.tsx"
    click ProtectedRoute "https://github.com/krishn404/git-friend/blob/main/components/auth/protected-route.tsx"
    click UserAuthButton "https://github.com/krishn404/git-friend/blob/main/components/auth/user-auth-button.tsx"
    click ThemeProvider "https://github.com/krishn404/git-friend/blob/main/components/theme-provider.tsx"
    click AuthContext "https://github.com/krishn404/git-friend/blob/main/context/auth-context.tsx"
    click HooksDir "https://github.com/krishn404/git-friend/tree/main/hooks"
    click MobileHook "https://github.com/krishn404/git-friend/blob/main/hooks/use-mobile.tsx"
    click ToastHook "https://github.com/krishn404/git-friend/blob/main/hooks/use-toast.ts"
    click FirebaseAuth "https://github.com/krishn404/git-friend/blob/main/lib/firebase.ts"
    click Redis "https://github.com/krishn404/git-friend/blob/main/lib/redis.ts"
    click TimeoutUtils "https://github.com/krishn404/git-friend/blob/main/lib/timeout-utils.ts"
    click Utils "https://github.com/krishn404/git-friend/blob/main/lib/utils.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
```
