# imrajat-sharma/learn_genai architecture

> Architecture diagram of the GitHub repository imrajat-sharma/learn_genai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/imrajat-sharma/learn_genai
- Repository: https://github.com/imrajat-sharma/learn_genai

## Overview

#### Purpose and Entry Points
This is a Node.js/ES-module learning repository that progressively prototypes LLM interactions using LangChain and Mistral AI. Each `DayXX` directory is an independently runnable exercise rather than a single integrated application. Primary entry points include `Day01/chat.js`, `Day02/chat.js`, `Day03/app.js`, and HTTP/server examples in `Day08/server.js` and `Day09/server.js`. A root `cli.js` suggests a shared or alternate command-line launcher.

#### Foundational LLM Chat Flow
The first stages establish terminal-based conversational interaction: collect user input, invoke an LLM, and print a response. `Day01/chat.js` is the baseline single-turn chat implementation. `Day02/chat.js` extends that loop with contextual behavior, using `Day02/assistant.js` and `Day02/addingHistory.js` to define assistant behavior and retain prior messages.

#### Prompt Engineering and Conversation Context
Day 02 isolates prompt strategies from the transport loop. `Day02/fewshotPrompt.js` captures few-shot prompting, while `Day02/addingHistory.js` manages conversational history before model invocation. This boundary is important: chat orchestration can change independently from prompt composition and message-state construction.

#### Structured Generation
Day 03 moves from free-form chat to schema-constrained output. `Day03/app.js` appears to drive the generation flow, and `Day03/productSchema.js` defines the expected product-shaped response contract. This is the repository’s main output-validation boundary between probabilistic LLM text and application-consumable data.

#### Browser-Facing AI Prototypes
Several later stages introduce browser clients, separating UI delivery from model execution. `Day04/index.html` pairs with `Day04/quizGeneratorAI.js` for quiz-oriented generation. Streaming/agent interfaces appear in `Day07/index.html` with `Day07/streamAgent.js`. Server-backed browser examples are represented by `Day08/index.html` plus `Day08/server.js`, and `Day09/index.html` plus `Day09/server.js`.

#### Agents, Streaming, and Model Capabilities
The progression expands from direct calls into orchestration patterns. `Day05/llm.js` centralizes a basic model interaction stage; `Day06/agent.js` introduces agent-style execution; `Day07/streamAgent.js` adds incremental response delivery. Day 10 explores advanced response handling and retrieval-adjacent concepts through `Day10/embedding.js`, `Day10/structuredOutput.js`, and `Day10/stream.js`.

#### Runtime and External Boundaries
The material runtime is JavaScript on Node.js with ES Modules. LangChain mediates application-level LLM/prompt abstractions, while Mistral AI is the external model provider, with provider-specific usage visible in `Day10/mistral.js`. Credentials are environment-based, indicated by `.env.example`; model/API access should remain outside browser code, especially for server-backed stages such as `Day08/server.js` and `Day09/server.js`.

Main entry points: [`Day02/chat.js`](https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/chat.js) (Contextual chat), [`.env.example`](https://github.com/imrajat-sharma/learn_genai/blob/main/.env.example) (Environment credentials), [`Day08/server.js`](https://github.com/imrajat-sharma/learn_genai/blob/main/Day08/server.js) (Server-backed AI), [`Day09/server.js`](https://github.com/imrajat-sharma/learn_genai/blob/main/Day09/server.js) (Server-backed AI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_terminal["Terminal exercises"]
  node_day01["Single-turn chat<br/>Node.js chat<br/>[chat.js]"]
  node_day02chat["Contextual chat<br/>Node.js chat<br/>[chat.js]"]
  node_assistant["Assistant behavior<br/>prompt policy<br/>[assistant.js]"]
  node_history["Conversation history<br/>message state<br/>[addingHistory.js]"]
  node_fewshot["Few-shot prompts<br/>prompt strategy<br/>[fewshotPrompt.js]"]
  node_day03["Structured generation<br/>Node.js generation<br/>[app.js]"]
  node_productschema["Product schema<br/>output contract<br/>[productSchema.js]"]
end

subgraph group_browser["Browser prototypes"]
  node_day04ui["Quiz browser UI<br/>HTML client<br/>[index.html]"]
  node_quizai["Quiz generation<br/>LLM workflow<br/>[quizGeneratorAI.js]"]
  node_day07ui["Streaming agent UI<br/>HTML client<br/>[index.html]"]
  node_day08ui["Server demo UI<br/>HTML client<br/>[index.html]"]
  node_day08server["Server-backed AI<br/>Node.js HTTP server<br/>[server.js]"]
  node_day09ui["Server demo UI<br/>HTML client<br/>[index.html]"]
  node_day09server["Server-backed AI<br/>Node.js HTTP server<br/>[server.js]"]
end

subgraph group_advanced["Agents and advanced output"]
  node_day05["Basic LLM stage<br/>model interaction<br/>[llm.js]"]
  node_day06{{"Agent execution<br/>agent workflow<br/>[agent.js]"}}
  node_streamagent{{"Streaming agent<br/>agent stream<br/>[streamAgent.js]"}}
  node_day10["Advanced response flows<br/>LLM experiments"]
  node_mistralusage["Mistral integration<br/>provider adapter<br/>[mistral.js]"]
end

node_cli["CLI launcher<br/>Node.js entry point<br/>[cli.js]"]
node_langchain{{"LangChain<br/>LLM abstraction"}}
node_mistral(("Mistral AI<br/>external model provider"))
node_env["Environment credentials<br/>configuration boundary<br/>[.env.example]"]

node_day02chat -->|"uses"| node_assistant
node_day02chat -->|"retains context"| node_history
node_day02chat -->|"applies prompts"| node_fewshot
node_day03 -->|"constrains output"| node_productschema
node_day04ui -->|"drives"| node_quizai
node_day07ui -->|"receives stream"| node_streamagent
node_day08ui -->|"HTTP requests"| node_day08server
node_day09ui -->|"HTTP requests"| node_day09server
node_day01 -->|"invokes via"| node_langchain
node_day02chat -->|"invokes via"| node_langchain
node_day03 -->|"generates via"| node_langchain
node_quizai -->|"generates via"| node_langchain
node_day05 -->|"uses"| node_langchain
node_day06 -->|"orchestrates with"| node_langchain
node_streamagent -->|"streams via"| node_langchain
node_day08server -->|"invokes via"| node_langchain
node_day09server -->|"invokes via"| node_langchain
node_day10 -->|"uses provider integration"| node_mistralusage
node_mistralusage -->|"API calls"| node_mistral
node_langchain -->|"model requests"| node_mistral
node_env -.->|"supplies credentials"| node_mistralusage
node_env -.->|"supplies credentials"| node_day08server
node_env -.->|"supplies credentials"| node_day09server

click node_cli "https://github.com/imrajat-sharma/learn_genai/blob/main/cli.js"
click node_day01 "https://github.com/imrajat-sharma/learn_genai/blob/main/Day01/chat.js"
click node_day02chat "https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/chat.js"
click node_assistant "https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/assistant.js"
click node_history "https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/addingHistory.js"
click node_fewshot "https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/fewshotPrompt.js"
click node_day03 "https://github.com/imrajat-sharma/learn_genai/blob/main/Day03/app.js"
click node_productschema "https://github.com/imrajat-sharma/learn_genai/blob/main/Day03/productSchema.js"
click node_day04ui "https://github.com/imrajat-sharma/learn_genai/blob/main/Day04/index.html"
click node_quizai "https://github.com/imrajat-sharma/learn_genai/blob/main/Day04/quizGeneratorAI.js"
click node_day05 "https://github.com/imrajat-sharma/learn_genai/blob/main/Day05/llm.js"
click node_day06 "https://github.com/imrajat-sharma/learn_genai/blob/main/Day06/agent.js"
click node_day07ui "https://github.com/imrajat-sharma/learn_genai/blob/main/Day07/index.html"
click node_streamagent "https://github.com/imrajat-sharma/learn_genai/blob/main/Day07/streamAgent.js"
click node_day08ui "https://github.com/imrajat-sharma/learn_genai/blob/main/Day08/index.html"
click node_day08server "https://github.com/imrajat-sharma/learn_genai/blob/main/Day08/server.js"
click node_day09ui "https://github.com/imrajat-sharma/learn_genai/blob/main/Day09/index.html"
click node_day09server "https://github.com/imrajat-sharma/learn_genai/blob/main/Day09/server.js"
click node_day10 "https://github.com/imrajat-sharma/learn_genai/blob/main/Day10/structuredOutput.js"
click node_mistralusage "https://github.com/imrajat-sharma/learn_genai/blob/main/Day10/mistral.js"
click node_env "https://github.com/imrajat-sharma/learn_genai/blob/main/.env.example"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_day01,node_day02chat,node_assistant,node_history,node_fewshot,node_day03,node_productschema toneBlue
class node_day04ui,node_quizai,node_day07ui,node_day08ui,node_day08server,node_day09ui,node_day09server toneAmber
class node_day05,node_day06,node_streamagent,node_day10,node_mistralusage toneMint
class node_cli,node_langchain,node_mistral,node_env toneNeutral
```

## Components

### Terminal exercises

Progressive Node.js chat and generation prototypes.

- [Single-turn chat](https://github.com/imrajat-sharma/learn_genai/blob/main/Day01/chat.js): Node.js chat · `Day01/chat.js`
- [Contextual chat](https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/chat.js): Node.js chat · `Day02/chat.js`
- [Assistant behavior](https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/assistant.js): prompt policy · `Day02/assistant.js`
- [Conversation history](https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/addingHistory.js): message state · `Day02/addingHistory.js`
- [Few-shot prompts](https://github.com/imrajat-sharma/learn_genai/blob/main/Day02/fewshotPrompt.js): prompt strategy · `Day02/fewshotPrompt.js`
- [Structured generation](https://github.com/imrajat-sharma/learn_genai/blob/main/Day03/app.js): Node.js generation · `Day03/app.js`
- [Product schema](https://github.com/imrajat-sharma/learn_genai/blob/main/Day03/productSchema.js): output contract · Validates LLM output into application-consumable product data. · `Day03/productSchema.js`

### Browser prototypes

Client-facing exercises with local model or server execution.

- [Quiz browser UI](https://github.com/imrajat-sharma/learn_genai/blob/main/Day04/index.html): HTML client · `Day04/index.html`
- [Quiz generation](https://github.com/imrajat-sharma/learn_genai/blob/main/Day04/quizGeneratorAI.js): LLM workflow · `Day04/quizGeneratorAI.js`
- [Streaming agent UI](https://github.com/imrajat-sharma/learn_genai/blob/main/Day07/index.html): HTML client · `Day07/index.html`
- [Server demo UI](https://github.com/imrajat-sharma/learn_genai/blob/main/Day08/index.html): HTML client · `Day08/index.html`
- [Server-backed AI](https://github.com/imrajat-sharma/learn_genai/blob/main/Day08/server.js): Node.js HTTP server · Keeps model access outside browser code. · `Day08/server.js`
- [Server demo UI](https://github.com/imrajat-sharma/learn_genai/blob/main/Day09/index.html): HTML client · `Day09/index.html`
- [Server-backed AI](https://github.com/imrajat-sharma/learn_genai/blob/main/Day09/server.js): Node.js HTTP server · Keeps model access outside browser code. · `Day09/server.js`

### Agents and advanced output

Agent, streaming, embedding, and structured-response experiments.

- [Basic LLM stage](https://github.com/imrajat-sharma/learn_genai/blob/main/Day05/llm.js): model interaction · `Day05/llm.js`
- [Agent execution](https://github.com/imrajat-sharma/learn_genai/blob/main/Day06/agent.js): agent workflow · `Day06/agent.js`
- [Streaming agent](https://github.com/imrajat-sharma/learn_genai/blob/main/Day07/streamAgent.js): agent stream · `Day07/streamAgent.js`
- [Advanced response flows](https://github.com/imrajat-sharma/learn_genai/blob/main/Day10/structuredOutput.js): LLM experiments · `Day10/structuredOutput.js`
- [Mistral integration](https://github.com/imrajat-sharma/learn_genai/blob/main/Day10/mistral.js): provider adapter · `Day10/mistral.js`

### Other components

- [CLI launcher](https://github.com/imrajat-sharma/learn_genai/blob/main/cli.js): Node.js entry point · `cli.js`
- **LangChain**: LLM abstraction
- **Mistral AI**: external model provider
- [Environment credentials](https://github.com/imrajat-sharma/learn_genai/blob/main/.env.example): configuration boundary · `.env.example`

## Connections

- Contextual chat → Assistant behavior: uses
- Contextual chat → Conversation history: retains context
- Contextual chat → Few-shot prompts: applies prompts
- Structured generation → Product schema: constrains output
- Quiz browser UI → Quiz generation: drives
- Streaming agent UI → Streaming agent: receives stream
- Server demo UI → Server-backed AI: HTTP requests
- Server demo UI → Server-backed AI: HTTP requests
- Single-turn chat → LangChain: invokes via
- Contextual chat → LangChain: invokes via
- Structured generation → LangChain: generates via
- Quiz generation → LangChain: generates via
- Basic LLM stage → LangChain: uses
- Agent execution → LangChain: orchestrates with
- Streaming agent → LangChain: streams via
- Server-backed AI → LangChain: invokes via
- Server-backed AI → LangChain: invokes via
- Advanced response flows → Mistral integration: uses provider integration
- Mistral integration → Mistral AI: API calls
- LangChain → Mistral AI: model requests
- Environment credentials → Mistral integration: supplies credentials
- Environment credentials → Server-backed AI: supplies credentials
- Environment credentials → Server-backed AI: supplies credentials
