# nimit23/orationaiassign architecture

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

- Interactive diagram: https://gitdiagram.com/nimit23/orationaiassign
- Repository: https://github.com/nimit23/orationaiassign

## Overview

##### Project Type and Purpose
- This is a modern, full-stack web application (“orationAiAssign”) built in Next.js + TypeScript, using tRPC as the API layer, a SQL database for persistence, and an external AI service for career counseling.
- The primary purpose is to provide users with a responsive chat UI, store conversation history, and generate AI-driven career advice.

##### File‐Structure Analysis
- Top-level configs:
- next.config.ts – Next.js build/deploy settings
- eslint.config.mjs, postcss.config.mjs – linting and CSS pipeline
- tsconfig.json – TypeScript compiler options
- src/app directory follows the Next.js App Router pattern:
- layout.tsx – root layout and shared UI
- page.tsx – chat page entrypoint
- globals.css – global styles
- package.json lists dependencies (Next.js, tRPC, database client, AI SDK).

##### Key Architectural Insights from README
- tRPC is used for end-to-end typed API calls between front end and server functions.
- A SQL database persists message history (likely via an ORM like Prisma).
- An AI service (e.g., OpenAI API) is called from server endpoints to generate counsel.
- Deployed on Vercel, leveraging edge/serverless functions.

a. Client Side (Browser):
- Next.js React App (app/layout.tsx + page.tsx)
- UI: chat interface, input form, history view
b. API Layer (Serverless Functions):
- tRPC router & procedures (e.g., sendMessage, fetchHistory)
- Next.js server runtime (Node.js/Edge)
c. Database:
- SQL database (PostgreSQL/MySQL)
- ORM layer (Prisma or equivalent)
d. External AI Service:
- OpenAI or similar LLM API
e. Deployment Platform:
- Vercel (build, hosting, serverless)

##### Relationships & Data Flow
- The browser sends user input over a tRPC client call.
- tRPC routes the call to a serverless function.
- The server function writes the message to the SQL DB (ORM).
- It then calls the AI service, receives generated advice, and persists the AI response.
- The function returns the combined response to the client UI.
- On page load or “history” requests, the client calls a tRPC fetchHistory endpoint to read from the DB.

##### Architectural Patterns & Principles
- Full-Stack React (Next.js App Router) with SSR/CSR hybrid
- End-to-end type safety via tRPC
- Serverless functions for API endpoints
- Single source of truth for state in the database
- Separation of concerns: UI ⇆ API ⇆ Persistence ⇆ External services

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Browser / Next.js React UI"
        direction TB
        layout["layout.tsx"]:::frontend
        page["page.tsx"]:::frontend
        globalsCSS["globals.css"]:::frontend
    end

    %% Configuration Files
    subgraph "Configuration & Docs"
        direction TB
        nextConfig["next.config.ts"]:::config
        tsconfig["tsconfig.json"]:::config
        eslintCfg["eslint.config.mjs"]:::config
        postcssCfg["postcss.config.mjs"]:::config
        packageJSON["package.json"]:::config
        packageLock["package-lock.json"]:::config
        readme["README.md"]:::config
    end

    %% API Layer
    subgraph "API Layer (Serverless Functions)"
        direction TB
        trpcRouter["tRPC Router"]:::api
        sendMsg["Procedure: sendMessage"]:::api
        fetchHist["Procedure: fetchHistory"]:::api
        serverRuntime["Next.js Server Runtime"]:::api
    end

    %% Persistence & External Services
    subgraph "Persistence & External Services"
        direction TB
        db[(SQL Database)]:::db
        orm["ORM (Prisma)"]:::db
        aiService["External AI Service\n(OpenAI)"]:::external
    end

    %% Deployment
    vercel["Vercel Platform"]:::external

    %% Connections
    layout -->|uses| page
    page -->|tRPC call sendMessage| sendMsg
    sendMsg -->|INSERT message| orm
    orm -->|writes to| db
    sendMsg -->|calls AI API| aiService
    aiService -->|returns advice| sendMsg
    sendMsg -->|response JSON| page
    page -->|tRPC call fetchHistory| fetchHist
    fetchHist -->|SELECT history| orm
    orm -->|reads from| db
    fetchHist -->|return history| page
    serverRuntime --> sendMsg
    serverRuntime --> fetchHist
    vercel --> serverRuntime
    vercel --> layout

    %% Click Events
    click layout "https://github.com/nimit23/orationaiassign/blob/main/src/app/layout.tsx"
    click page "https://github.com/nimit23/orationaiassign/blob/main/src/app/page.tsx"
    click globalsCSS "https://github.com/nimit23/orationaiassign/blob/main/src/app/globals.css"
    click nextConfig "https://github.com/nimit23/orationaiassign/blob/main/next.config.ts"
    click tsconfig "https://github.com/nimit23/orationaiassign/blob/main/tsconfig.json"
    click eslintCfg "https://github.com/nimit23/orationaiassign/blob/main/eslint.config.mjs"
    click postcssCfg "https://github.com/nimit23/orationaiassign/blob/main/postcss.config.mjs"
    click packageJSON "https://github.com/nimit23/orationaiassign/blob/main/package.json"
    click packageLock "https://github.com/nimit23/orationaiassign/blob/main/package-lock.json"
    click readme "https://github.com/nimit23/orationaiassign/blob/main/README.md"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef api fill:#d4edda,stroke:#333,stroke-width:1px
    classDef db fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef external fill:#e2e3ff,stroke:#333,stroke-width:1px
    classDef config fill:#f0f0f0,stroke:#333,stroke-width:1px
```
