# harshitvashisht11/brainrot architecture

> Architecture diagram of the GitHub repository harshitvashisht11/brainrot, 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/harshitvashisht11/brainrot
- Repository: https://github.com/harshitvashisht11/brainrot

## Overview

##### Project Type & Purpose
- It’s a full-stack web application built with Next.js using the new App Router (as seen in the “src/app” folder).
- The main objective is to analyze Github “brain rot” (likely meaning an analysis of Github profiles or repositories) by using AI (via MetaLLama3 hosted on AWS Bedrock) alongside Github API integrations.
- The README and file tree indicate that the project handles dynamic routing (e.g., “src/app/analyze/[username]/page.tsx”) and makes calls to a Github API utility (“src/lib/github.ts”) and AI service (“src/lib/ai.ts”).

##### Key Components
a. Client Browser
- Represents the end user (developer or visitor) interacting with the web app.
- A browser that loads the Next.js application pages and static assets from the “public” directory.

b. Next.js Application Layer
- Home page (src/app/page.tsx)
- Page (src/app/analyze/[username]/page.tsx)
- Layout and global styles (src/app/layout.tsx, src/app/globals.css)
- UI Components: Represent the reusable UI building blocks, for example:
- Custom components (e.g., AnalysisAnimation, AnalysisCard, ProfileCard)
- UI primitives found under “src/components/ui” (like button, card, dialog, etc.)
- Client-Side Logic: Use hooks (e.g., “src/hooks/use-toast.ts”) and context for interactive behavior.

c. Service/External Integrations
- AWS Bedrock (MetaLLama3):
- An external service component that handles AI processing.
- Github API:
- Use of the Github token provided via environment variables.

d. Utility Libraries and Configurations
- Utility and helper functions (in “src/lib/utils.ts”) and shared types (“src/lib/types.ts”, “src/types/github-analysis.ts”)
- Configuration files (Next.js config, Tailwind config, etc.) can be noted as supporting elements for build, styling, and project settings.

##### Relationships and Interactions
- Data Flow:
- The browser sends requests to the Next.js application.
- The Next.js pages (using dynamic routing like “/analyze/[username]”) render client views.
- On particular interactions (for example, triggering an analysis), the app calls utility libraries (e.g., “ai.ts” and “github.ts”).
- These utilities then reach out to external services (AWS Bedrock for AI and GitHub for data).
- The results travel back through these layers and ultimately update the UI.
- Separation of concerns:
- UI components handle presentation.
- Page components manage routing and state.
- Library files take care of external integrations.

##### Architectural Patterns and Design Principles
- Next.js App Directory Pattern: Use separate folders for pages/routes (dynamic for user-specific analysis).
- Component-Based Architecture: The “components” and “components/ui” directories show an emphasis on reusable UI pieces.
- Service Integration: Encapsulation of calls to Github and AWS Bedrock via dedicated libraries (“src/lib/github.ts” and “src/lib/ai.ts”).
- Environment Configuration: Configuration through environment variables (as outlined in the README with “.env.example”) makes it clear that external credentials are injected at runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Client Browser"]:::client
    end

    %% Application Layer
    subgraph "Application Layer"
        NextJsApp["Next.js Application"]:::app
        Home["Home Page"]:::app
        Layout["Layout & Global Styles"]:::app
        Dynamic["Dynamic Analysis Page"]:::app
        UIComp["Custom UI Components"]:::app
        UIPrim["UI Primitives"]:::app
        Hooks["Client-Side Hooks"]:::app
    end

    %% Utility & Configurations
    subgraph "Utility & Configurations"
        UtilLib["Utility Lib & Shared Types"]:::util
    end

    %% External Services
    subgraph "External Services"
        AIBedrock["AWS Bedrock (MetaLLama3)"]:::external
        Github["Github API"]:::external
    end

    %% Connections
    Browser -->|"requests"| NextJsApp
    NextJsApp -->|"renders"| Home
    NextJsApp -->|"renders"| Dynamic
    Home -->|"uses"| Layout
    Dynamic -->|"uses"| Layout
    Home -->|"utilizes"| UIComp
    Home -->|"utilizes"| UIPrim
    Dynamic -->|"utilizes"| UIComp
    Dynamic -->|"utilizes"| UIPrim
    Dynamic -->|"state_management"| Hooks
    Dynamic -->|"helper_calls"| UtilLib
    Dynamic -->|"AI_Processing_Request"| AIBedrock
    Dynamic -->|"Github_Data_Request"| Github

    %% Styles
    classDef client fill:#FFDDC1,stroke:#000,stroke-width:2px
    classDef app fill:#C1FFD7,stroke:#000,stroke-width:2px
    classDef external fill:#FFC1C1,stroke:#000,stroke-width:2px
    classDef util fill:#C1C1FF,stroke:#000,stroke-width:2px

    %% Click Events
    click Browser "https://github.com/harshitvashisht11/brainrot/tree/master/public"
    click NextJsApp "https://github.com/harshitvashisht11/brainrot/tree/master/src/app"
    click Home "https://github.com/harshitvashisht11/brainrot/blob/master/src/app/page.tsx"
    click Layout "https://github.com/harshitvashisht11/brainrot/blob/master/src/app/layout.tsx, src/app/globals.css"
    click Dynamic "https://github.com/harshitvashisht11/brainrot/blob/master/src/app/analyze/[username]/page.tsx"
    click UIComp "https://github.com/harshitvashisht11/brainrot/tree/master/src/components"
    click UIPrim "https://github.com/harshitvashisht11/brainrot/tree/master/src/components/ui"
    click Hooks "https://github.com/harshitvashisht11/brainrot/blob/master/src/hooks/use-toast.ts"
    click AIBedrock "https://github.com/harshitvashisht11/brainrot/blob/master/src/lib/ai.ts"
    click Github "https://github.com/harshitvashisht11/brainrot/blob/master/src/lib/github.ts"
    click UtilLib "https://github.com/harshitvashisht11/brainrot/blob/master/src/lib/utils.ts, src/lib/types.ts, src/types/github-analysis.ts"
```
