# rajkmt/brokod-mock architecture

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

- Interactive diagram: https://gitdiagram.com/rajkmt/brokod-mock
- Repository: https://github.com/rajkmt/brokod-mock

## Overview

##### Project type and purpose
- BroKod Mock is a full-stack, mock frontend application built with Next.js 13 (App Router), React, TypeScript, Tailwind CSS, and Drizzle ORM.
- It demonstrates modern best practices for a real-world web app: page and layout composition, styling with utility classes, type-safe database access, and basic authentication flows.

##### File structure
- Top-level directories:
- app/ – Next.js App Router directory hosting routes, layouts, and page components
- components/ – Shared UI primitives (Buttons, Dialogs, Inputs, etc.)
- utils/, lib/ – Utility functions, OpenAI integration, database connection (Drizzle ORM), schema definitions
- Key patterns:
- app/(auth)/sign-in & sign-up – dedicated authentication routes
- app/dashboard – protected area with its own layout, sub-routes for listing interviews, viewing details, starting interviews, and feedback
- React Server Components vs. Client Components distinguished by file extensions (.jsx/.tsx) and the use of 'use client' where needed
- Drizzle configuration (drizzle.config.js), database schema (utils/schema.js), and database utilities (utils/db.js) for ORM layer
- Configuration and deployment:
- next.config.mjs, tsconfig.json, tailwind.config.js, postcss.config.mjs
- middleware.js – route protection/auth checks
- .env.local for DATABASE_URL, deployed on Vercel

##### Extract insights from the README
- Emphasis on learning: modular structure, clean code, beginner-friendly
- Architectural notes: App Router, Drizzle ORM, TypeScript, Tailwind CSS

##### Main components
a. Client (Browser)
- Renders React components, fetches data, handles user interactions (sign in/up, dashboard, interview flows)
b. Next.js App Server
- App Router → Routes & nested layouts
- Server Components → data fetching, page rendering
- Client Components → interactive UI (recording answers, modal dialogs)
- Middleware → authentication guard
c. ORM/Database Layer
- Drizzle ORM (drizzle.config.js) communicates with the relational database (via utils/db.js, utils/schema.js)
d. External Services
- OpenAI API (app/utils/openai.js) – invoked during interview or answer recording
e. Static Assets CDN
- tailwind.css, globals.css, public/

##### Relationships and interactions
- Client ↔ Next.js Server: HTTP(S) requests for navigation and data-fetching (using fetch or Next.js fetch abstraction)
- Next.js Server ↔ Database: Drizzle ORM issues SQL queries over DATABASE_URL
- Next.js Server ↔ OpenAI API: REST calls from openai.js to obtain AI responses
- Middleware sits in front of protected routes (dashboard) to enforce authentication
- Static assets served from /public or built into Vercel CDN

##### Architectural patterns and design principles
- App Router nested layouts for route scoping (auth vs. dashboard vs. root layouts)
- Separation of concerns:
- Page files handle routing
- _components subdirectories for route-specific UI pieces
- components/ui for reusable design system
- utils/lib for pure utility logic
- Type safety end-to-end (TypeScript + Drizzle ORM types)
- CSS-in-JS avoidance → Tailwind utility classes for predictable styling
- Server Components wherever possible for performance, Client Components only for interactivity

##### Final recommendations
- Be exhaustive: include every major route group, data flow, and integration point
- Nested layout hierarchy to show how pages and components compose
- Critical configs (middleware.js, drizzle.config.js) as part of the backend

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Browser"
        direction TB
        Browser["Browser"]:::frontend
        CDN["Static Assets CDN"]:::frontend
    end

    %% Server Layer
    subgraph "Next.js Server"
        direction TB
        Middleware["Auth Middleware (middleware.js)"]:::server
        Router["App Router"]:::server
        ServerComp["Server Components"]:::server
        ClientComp["Client Components"]:::server
    end

    %% Auth Routes
    subgraph "Authentication Routes"
        direction TB
        SignIn["Sign-In Page"]:::server
        SignUp["Sign-Up Page"]:::server
    end

    %% Dashboard and Interview Workflows
    subgraph "Dashboard (Protected)"
        direction TB
        DashLayout["Dashboard Layout"]:::server
        DashHome["Dashboard Home"]:::server

        subgraph "Interview Workflows"
            direction TB
            InterviewDetails["Interview Details Page"]:::server
            InterviewFeedback["Interview Feedback Page"]:::server
            InterviewStart["Interview Start Page"]:::server
            QuestionsSection["Questions Section"]:::server
            RecordAnswerSection["Record Answer Section"]:::server
        end
    end

    %% ORM / Database Layer
    subgraph "Database Layer"
        direction TB
        DrizzleConfig["Drizzle Config"]:::db
        DBConn["Database Connection"]:::db
        Schema["Schema Definitions"]:::db
        ORM["Drizzle ORM"]:::db
        ORM --> Schema
        ORM --> DBConn
        DrizzleConfig --> ORM
    end

    %% External Service
    OpenAI["OpenAI API"]:::external

    %% Utility Functions
    subgraph "Utilities"
        direction TB
        UtilsJS["utils.js"]:::utils
        UtilsTS["utils.ts"]:::utils
    end

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        direction TB
        NextConfig["next.config.mjs"]:::config
        TSConfig["tsconfig.json"]:::config
        TailwindConfig["tailwind.config.js"]:::config
        PostCSS["postcss.config.mjs"]:::config
        GitIgnore[".gitignore"]:::config
        Middleware --> NextConfig
    end

    %% Shared UI Primitives
    subgraph "UI Primitives"
        direction TB
        ButtonJS["button.jsx"]:::frontend
        ButtonTS["button.tsx"]:::frontend
        Dialog["dialog.jsx"]:::frontend
        Input["input.jsx"]:::frontend
        Collapsible["collapsible.jsx"]:::frontend
        Textarea["textarea.jsx"]:::frontend
    end

    %% Static Assets
    Public["public/ (static files)"]:::frontend

    %% Connections
    Browser -->|"HTTP requests"| Router
    Browser -->|"loads static assets"| Public
    Public -->|served via CDN| CDN
    Router -->|"fetch user data"| ORM
    Router -->|"submit interview answer"| ORM
    Router -->|"calls OpenAI"| OpenAI
    Middleware -->|protects| DashLayout
    Router --> SignIn
    Router --> SignUp
    Router --> DashLayout
    DashLayout --> DashHome
    DashHome --> InterviewDetails
    InterviewDetails --> InterviewFeedback
    InterviewFeedback --> InterviewStart
    InterviewStart --> QuestionsSection
    InterviewStart --> RecordAnswerSection
    Router --> ServerComp
    Router --> ClientComp

    %% Click Events
    click Browser "https://github.com/rajkmt/brokod-mock/tree/main/public/"
    click CDN "https://github.com/rajkmt/brokod-mock/tree/main/public/"
    click Middleware "https://github.com/rajkmt/brokod-mock/blob/main/middleware.js"
    click Router "https://github.com/rajkmt/brokod-mock/blob/main/app/layout.js"
    click ServerComp "https://github.com/rajkmt/brokod-mock/blob/main/app/page.js"
    click SignIn "https://github.com/rajkmt/brokod-mock/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.jsx"
    click SignUp "https://github.com/rajkmt/brokod-mock/blob/main/app/(auth)/sign-up/[[...sign-up]]/page.jsx"
    click DashLayout "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/layout.jsx"
    click DashHome "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/page.jsx"
    click InterviewDetails "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/interview/[interviewId]/page.jsx"
    click InterviewFeedback "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/interview/[interviewId]/feedback/page.jsx"
    click InterviewStart "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/interview/[interviewId]/start/page.jsx"
    click QuestionsSection "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/interview/[interviewId]/start/_components/QuestionsSection.jsx"
    click RecordAnswerSection "https://github.com/rajkmt/brokod-mock/blob/main/app/dashboard/interview/[interviewId]/start/_components/RecordAnswerSection.jsx"
    click ButtonJS "https://github.com/rajkmt/brokod-mock/blob/main/components/ui/button.jsx"
    click ButtonTS "https://github.com/rajkmt/brokod-mock/blob/main/components/ui/button.tsx"
    click Dialog "https://github.com/rajkmt/brokod-mock/blob/main/components/ui/dialog.jsx"
    click Input "https://github.com/rajkmt/brokod-mock/blob/main/components/ui/input.jsx"
    click Collapsible "https://github.com/rajkmt/brokod-mock/blob/main/components/ui/collapsible.jsx"
    click Textarea "https://github.com/rajkmt/brokod-mock/blob/main/components/ui/textarea.jsx"
    click OpenAI "https://github.com/rajkmt/brokod-mock/blob/main/app/utils/openai.js"
    click DrizzleConfig "https://github.com/rajkmt/brokod-mock/blob/main/drizzle.config.js"
    click DBConn "https://github.com/rajkmt/brokod-mock/blob/main/utils/db.js"
    click Schema "https://github.com/rajkmt/brokod-mock/blob/main/utils/schema.js"
    click UtilsJS "https://github.com/rajkmt/brokod-mock/blob/main/lib/utils.js"
    click UtilsTS "https://github.com/rajkmt/brokod-mock/blob/main/lib/utils.ts"
    click NextConfig "https://github.com/rajkmt/brokod-mock/blob/main/next.config.mjs"
    click TSConfig "https://github.com/rajkmt/brokod-mock/blob/main/tsconfig.json"
    click TailwindConfig "https://github.com/rajkmt/brokod-mock/blob/main/tailwind.config.js"
    click PostCSS "https://github.com/rajkmt/brokod-mock/blob/main/postcss.config.mjs"
    click GitIgnore "https://github.com/rajkmt/brokod-mock/blob/main/.gitignore"

    %% Styles
    classDef frontend fill:#E0F2FF,stroke:#0C4A6E,color:#0C4A6E;
    classDef server fill:#E6FFFA,stroke:#065F46,color:#065F46;
    classDef db fill:#FFFBEB,stroke:#92400E,color:#92400E;
    classDef external fill:#F5F3FF,stroke:#6D28D9,color:#6D28D9;
    classDef utils fill:#F3F4F6,stroke:#374151,color:#374151;
    classDef config fill:#FDF2F8,stroke:#9D174D,color:#9D174D;
```
