# modamaan/ai-mock-interview architecture

> Architecture diagram of the GitHub repository modamaan/ai-mock-interview, 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/modamaan/ai-mock-interview
- Repository: https://github.com/modamaan/ai-mock-interview

## Overview

##### Main Components
- Frontend (Presentation Layer): This is built with Next.js and Tailwind CSS. It handles user interfaces such as the authentication pages (sign-in and sign-up routes in the “app/(auth)” directory), main entry pages (app/page.js and app/layout.js), and the Dashboard components (found in “app/dashboard/…”). Additionally, there is a components library (e.g., “components/ui”) which supplies shared UI elements.
- Business Logic & Routing: Next.js’s app router is utilized here. The “app/dashboard/interview”, “app/dashboard/question”, “app/dashboard/upgrade”, and similar directories represent different interactive flows of the platform. Middleware (middleware.js) ensures that user requests are processed (e.g., authentication, session management) before they reach the actual pages.
- Backend & Database Access: Although the platform is primarily built as a Next.js application, backend logic is integrated into API routes or server-side rendered pages. Supporting files in “lib” and “utils” (e.g., utils/db.js, utils/schema.js) indicate the existence of data-access layers making use of Drizzle ORM to interact with a PostgreSQL database.
- External Services: A key component is the integration with the Gemini API that powers the AI interview functionalities. There is also an ecosystem setup for deployment (via Dockerfile, compose.yaml, and Neon Serverless for PostgreSQL) that ensures scalability.

##### Relationships and Interactions
- The Frontend communicates with the backend using Next.js API routes and server-side rendering. For instance, when a user initiates a mock interview, the UI sends requests to backend routes that request AI-generated interview questions from Gemini API.
- Authentication components handle sign-in and sign-up flows and secure routes via middleware.
- The Business Logic layer then interacts with the database through Drizzle ORM. This ensures smooth data retrieval and persistence (e.g., saving interview sessions, fetching question banks).
- The external Gemini API is called from the backend business logic layer to retrieve and process AI-specific data.

##### Architectural Patterns and Key Technologies
- Next.js’s App Router: Implements page-based navigation, dynamic routing (e.g., pages like interview/[interviewId]), and server-side rendering.
- MVC/Component Pattern: The project is divided between UI components (in “components” and “app/_components”), business logic (organized in structured directories under “app/dashboard”), and data management (found in “lib” and “utils”).
- Integration Components: The use of Docker (Dockerfile, .dockerignore, compose.yaml) for containerization and deployment, and configuration files (drizzle.config.js, tailwind.config.js, next.config.mjs) further clarify the tech stack.
- Database Abstraction: Drizzle ORM abstracts PostgreSQL database interactions.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    U("User Browser"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        F1("Authentication: Sign-In & Sign-Up"):::ui
        F2("Main Entry & Layout"):::ui
        F3("Dashboard Page & Layout"):::ui
        F4("Dashboard UI Components"):::ui
        F5("General UI Components"):::ui
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        BL1("Next.js App Router"):::backend
        BL2("Interview Route"):::backend
        BL3("Question/Upgrade Routes"):::backend
        BL4("Middleware"):::backend
    end

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        direction TB
        DP1("DB Utils"):::database
        DP2("Schema Definitions"):::database
        DP3("Drizzle ORM Config"):::database
        DP4("Lib Utils"):::database
        DB("PostgreSQL (Neon Serverless)"):::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        ES1("Gemini API Integration"):::external
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        direction TB
        DI1("Dockerfile"):::infrastructure
        DI2(".dockerignore"):::infrastructure
        DI3("compose.yaml"):::infrastructure
        DI4("tailwind.config.js"):::infrastructure
        DI5("next.config.mjs"):::infrastructure
    end

    %% Data Flow Connections
    U -->|"triggers"| F1
    U -->|"triggers"| F2
    U -->|"triggers"| F3
    U -->|"triggers"| F4
    U -->|"triggers"| F5

    F1 -->|"sends request"| BL1
    F2 -->|"sends request"| BL1
    F3 -->|"sends request"| BL1
    F4 -->|"sends request"| BL1
    F5 -->|"sends request"| BL1

    %% Middleware intercepts before routing
    BL1 -->|"processed by"| BL4
    BL4 -->|"forwards to"| BL2
    BL4 -->|"forwards to"| BL3

    %% Business Logic calls backend resources
    BL1 -->|"DB operations via ORM"| DP1
    BL1 -->|"DB operations via ORM"| DP2
    BL1 -->|"uses config"| DP3
    BL1 -->|"util functions"| DP4
    DP1 -->|"persists/retrieves"| DB
    DP2 -->|"persists/retrieves"| DB
    DP3 -->|"persists/retrieves"| DB
    DP4 -->|"persists/retrieves"| DB

    %% External API integration
    BL1 -->|"calls"| ES1

    %% Deployment links (Deployment deploys components)
    DI1 ---|"deploys"| F1
    DI1 ---|"deploys"| F2
    DI1 ---|"deploys"| F3
    DI1 ---|"deploys"| F4
    DI1 ---|"deploys"| F5
    DI1 ---|"deploys"| BL1
    DI1 ---|"deploys"| DP1
    DI1 ---|"deploys"| ES1

    DI2 ---|"configures"| F1
    DI2 ---|"configures"| BL1
    DI2 ---|"configures"| DP1

    DI3 ---|"orchestrates"| DI1
    DI4 ---|"styles"| F1
    DI4 ---|"styles"| F2
    DI4 ---|"styles"| F3
    DI5 ---|"configures"| BL1

    %% Click Events for Frontend
    click F1 "https://github.com/modamaan/ai-mock-interview/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.jsx"
    click F1 "https://github.com/modamaan/ai-mock-interview/blob/main/app/(auth)/sign-up/[[...sign-up]]/page.jsx"
    click F2 "https://github.com/modamaan/ai-mock-interview/blob/main/app/page.js"
    click F2 "https://github.com/modamaan/ai-mock-interview/blob/main/app/layout.js"
    click F3 "https://github.com/modamaan/ai-mock-interview/blob/main/app/dashboard/page.jsx"
    click F3 "https://github.com/modamaan/ai-mock-interview/blob/main/app/dashboard/layout.jsx"
    click F4 "https://github.com/modamaan/ai-mock-interview/tree/main/app/dashboard/_components"
    click F5 "https://github.com/modamaan/ai-mock-interview/tree/main/app/_components"

    %% Click Events for Business Logic
    click BL2 "https://github.com/modamaan/ai-mock-interview/tree/main/app/dashboard/interview/[interviewId]"
    click BL3 "https://github.com/modamaan/ai-mock-interview/tree/main/app/dashboard/question"
    click BL3 "https://github.com/modamaan/ai-mock-interview/tree/main/app/dashboard/upgrade"
    click BL4 "https://github.com/modamaan/ai-mock-interview/blob/main/middleware.js"

    %% Click Events for Data Persistence
    click DP1 "https://github.com/modamaan/ai-mock-interview/blob/main/utils/db.js"
    click DP2 "https://github.com/modamaan/ai-mock-interview/blob/main/utils/schema.js"
    click DP3 "https://github.com/modamaan/ai-mock-interview/blob/main/drizzle.config.js"
    click DP4 "https://github.com/modamaan/ai-mock-interview/blob/main/lib/utils.js"

    %% Click Event for External Service
    click ES1 "https://github.com/modamaan/ai-mock-interview/blob/main/utils/GeminiAIModal.js"

    %% Click Events for Deployment & Infrastructure
    click DI1 "https://github.com/modamaan/ai-mock-interview/tree/main/Dockerfile"
    click DI2 "https://github.com/modamaan/ai-mock-interview/blob/main/.dockerignore"
    click DI3 "https://github.com/modamaan/ai-mock-interview/blob/main/compose.yaml"
    click DI4 "https://github.com/modamaan/ai-mock-interview/blob/main/tailwind.config.js"
    click DI5 "https://github.com/modamaan/ai-mock-interview/blob/main/next.config.mjs"

    %% Styles
    classDef ui fill:#ffefc6,stroke:#d48c00,stroke-width:2px;
    classDef backend fill:#c6e2ff,stroke:#00509e,stroke-width:2px;
    classDef database fill:#d3f9d8,stroke:#038c18,stroke-width:2px;
    classDef external fill:#ffe4e1,stroke:#d40000,stroke-width:2px;
    classDef infrastructure fill:#f9d6ff,stroke:#9900cc,stroke-width:2px;
    class U external
```
