# akshitjain16/repobot-ai architecture

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

- Interactive diagram: https://gitdiagram.com/akshitjain16/repobot-ai
- Repository: https://github.com/akshitjain16/repobot-ai

## Overview

##### Project Type and Purpose
- RepoBot AI is a full-stack web application built with Next.js that uses tRPC for type-safe, end-to-end APIs. Its purpose is to assist developers by interacting with and analyzing GitHub repositories, with features including natural language interactions for code explanation, project navigation, and quick answers about code structure.
- Key technologies include Next.js (for both frontend and backend rendering), tRPC (for API layer), Prisma (as the ORM layer for database interactions), and several utility libraries (e.g., usehooks-ts, zod).

##### Analyzing the File Structure
- Notice the separation within the src folder:
- The "src/app" directory holds the Next.js application pages. It includes public pages (e.g., sign-in, sign-up, landing) and a protected section (e.g., dashboard, billing, meetings, Q&A) indicating role-based access.
- The "src/api" subdirectory and “src/server/api” indicate there is a clear API structure, likely using tRPC endpoints for data operations.
- The "prisma" directory holds the schema (prisma/schema.prisma) which implies the use of a relational database.
- The "src/components/ui" directory contains a complete UI component library, which forms the building blocks for the presentation layer.
- Other directories such as "src/hooks", "src/lib", "src/styles" and "src/trpc" show the system has a well-organized and modular codebase.
- Configuration and setup files like next.config.js, tailwind.config.ts, tsconfig.json, and environment examples indicate standard practices for a modern web application.

##### Components of the System
- Frontend (Client-side)
- Built using Next.js. It handles user interface, routing, and rendering of both public and protected pages.
- UI components are encapsulated in "src/components/ui" and other custom components in "src/app" and "src/components".
- Integration of authentication flow (reflected in pages like sign-in and sign-up) and state management using hooks (e.g., use-project, use-refetch, use-toast).
- Backend (Server-side API and Business Logic)
- tRPC is used for creating a type-safe API layer. The endpoints are defined in directories like "src/app/api/trpc" and "src/server/api/routers".
- The server processes requests coming from the frontend and interacts with the database.
- Database
- Managed via Prisma (see the "prisma/schema.prisma"). This is likely a relational database (e.g., Postgres) handling persistent data – such as user profiles, token storage, GitHub repository information and more.
- External Integrations
- GitHub OAuth: Users connect their GitHub accounts using OAuth (environment variables for GITHUB_CLIENT_ID/SECRET and instructions in the README).
- GitHub API: The application uses modules like "src/lib/github-loader.ts" and "src/lib/github.ts" which are likely responsible for fetching repository data, commits, and logs.
- Middleware and Utility Layers
- Middleware in "src/middleware.ts" processes requests for authentication/authorization.
- Utility libraries ("src/lib/utils.ts", custom hooks, etc.) encapsulate recurring logic.

##### Architectural Patterns and Relationships
- The application uses a “unified” architecture with Next.js handling both frontend rendering and backend API routes.
- There is a clear separation between public and protected routes, suggesting a role-based or session-based access control.
- The tRPC API acts as the middleware connecting frontend operations and database interactions.
- External services (GitHub OAuth and API) are integrated as separate connectors/modules.
- The UI uses a component-driven design, and the codebase appears to follow best practices like modularity and separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["Next.js Frontend (Public Pages)"]:::frontend
        B["Next.js Frontend (Protected Pages)"]:::frontend
        C["UI Components Library"]:::frontend
    end
    click A "https://github.com/akshitjain16/repobot-ai/tree/main/src/app/sign-in"
    click A "https://github.com/akshitjain16/repobot-ai/tree/main/src/app/sign-up"
    click B "https://github.com/akshitjain16/repobot-ai/tree/main/src/app/(protected)"
    click C "https://github.com/akshitjain16/repobot-ai/tree/main/src/components/ui"

    %% Backend Services
    subgraph "Backend Services"
        D["tRPC API (Frontend Endpoints)"]:::backend
        E["tRPC API (Server Endpoints)"]:::backend
        F["Middleware for Auth"]:::middleware
        G["Utility Functions"]:::utility
    end
    click D "https://github.com/akshitjain16/repobot-ai/tree/main/src/app/api/trpc"
    click E "https://github.com/akshitjain16/repobot-ai/tree/main/src/server/api/routers"
    click E "https://github.com/akshitjain16/repobot-ai/blob/main/src/server/api/trpc.ts"
    click F "https://github.com/akshitjain16/repobot-ai/blob/main/src/middleware.ts"
    click G "https://github.com/akshitjain16/repobot-ai/blob/main/src/lib/utils.ts"

    %% Database Layer
    subgraph "Database Layer"
        H["Prisma Database"]:::database
    end
    click H "https://github.com/akshitjain16/repobot-ai/blob/main/prisma/schema.prisma"

    %% External Services
    subgraph "External Services"
        I["GitHub Integration"]:::external
    end
    click I "https://github.com/akshitjain16/repobot-ai/blob/main/src/lib/github-loader.ts"
    click I "https://github.com/akshitjain16/repobot-ai/blob/main/src/lib/github.ts"

    %% Connections
    A -->|"userAction"| D
    B -->|"userAction"| D
    D -->|"passesRequest"| F
    F -->|"processes"| E
    E -->|"dbQuery"| H
    E -->|"externalCall"| I
    D -->|"usesUtility"| G
    A -->|"rendersWith"| C
    B -->|"rendersWith"| C

    %% Styling Classes
    classDef frontend fill:#f9c74f,stroke:#f9844a,stroke-width:2px;
    classDef backend fill:#90be6d,stroke:#43aa8b,stroke-width:2px;
    classDef database fill:#f94144,stroke:#bc4749,stroke-width:2px;
    classDef external fill:#577590,stroke:#277da1,stroke-width:2px;
    classDef middleware fill:#f3722c,stroke:#e07a5f,stroke-width:2px;
    classDef utility fill:#4d908e,stroke:#277da1,stroke-width:2px;
```
