# nathansebhastian/langchain-js architecture

> Architecture diagram of the GitHub repository nathansebhastian/langchain-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nathansebhastian/langchain-js
- Repository: https://github.com/nathansebhastian/langchain-js

## Overview

This repository is a beginner’s LangChainJS book implemented as runnable, mostly independent chapter examples, rather than one integrated application. The learning path progresses from basic model calls and user prompts through chains, conversation history, agents, and retrieval over documents, YouTube transcripts, and images; chapters 15–16 add separate Next.js chat applications. The graph groups model-provider variants by chapter capability. Edges are limited to relationships visible in excerpts or README; dashed, uncited links indicate unverified chapter-level integration.

Main entry points: [`13_Chat_YouTube/app_gemini.js`](https://github.com/nathansebhastian/langchain-js/blob/main/13_Chat_YouTube/app_gemini.js) (YouTube Chat), [`10_Agents_And_Tools/app_gemini.js`](https://github.com/nathansebhastian/langchain-js/blob/main/10_Agents_And_Tools/app_gemini.js) (Agents and Tools), [`14_Chat_Images/app_gemini.js`](https://github.com/nathansebhastian/langchain-js/blob/main/14_Chat_Images/app_gemini.js) (Image Chat), [`09_Chat_History/app_gemini.js`](https://github.com/nathansebhastian/langchain-js/blob/main/09_Chat_History/app_gemini.js) (Chat History)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_basics["Model and Prompt Basics"]
  node_simple["Basic Q&amp;A<br/>[app_gemini.js]"]
  node_provider["Model Providers<br/>[app_gpt.js]"]
  node_input["User Input"]
  node_templates["Prompt Templates<br/>[app_gemini.js]"]
end

subgraph group_chains["Chains and Agents"]
  node_lcel["LCEL Chains<br/>[create_chain.js]"]
  node_sequential["Sequential Chains<br/>[app_gemini.js]"]
  node_history["Chat History<br/>[app_gemini.js]"]
  node_agents["Agents and Tools<br/>[app_gemini.js]"]
  node_toolservices{{"Search and Wiki"}}
end

subgraph group_retrieval["Retrieval and Media"]
  node_docchat["Document Chat"]
  node_rag["Text RAG<br/>[rag_app.js]"]
  node_docformats["Document Formats<br/>[app_gemini.js]"]
  node_youtube["YouTube Chat<br/>[app_gemini.js]"]
  node_imagery["Image Chat<br/>[app_gemini.js]"]
  node_imagehelper["Image Encoding<br/>[handle_image.js]"]
end

subgraph group_webapps["Next.js Chat Apps"]
  node_chat15["Chat Interface"]
  node_action15["OpenAI Action<br/>[openai.action.ts]"]
  node_page15["App Page<br/>[page.tsx]"]
  node_chat16["Production Chat UI"]
  node_action16["Production Action<br/>[openai.action.ts]"]
  node_page16["Production Page<br/>[page.tsx]"]
end

node_learner(("Learner"))
node_llm{{"Language Model APIs"}}
node_youtube_service{{"YouTube Transcript"}}
node_user(("Chat User"))

node_learner -->|"runs example"| node_simple
node_learner -.->|"provides input"| node_input
node_learner -->|"provides values"| node_templates
node_templates -->|"invokes model"| node_llm
node_learner -->|"provides topic"| node_sequential
node_sequential -->|"invokes model"| node_llm
node_learner -->|"asks questions"| node_history
node_history -->|"invokes model"| node_llm
node_learner -->|"asks question"| node_agents
node_agents -->|"dispatches tools"| node_toolservices
node_agents -->|"invokes model"| node_llm
node_learner -->|"asks question"| node_rag
node_rag -->|"embeds and answers"| node_llm
node_learner -->|"asks questions"| node_docformats
node_docformats -->|"embeds and answers"| node_llm
node_learner -->|"supplies URL"| node_youtube
node_youtube -->|"loads transcript"| node_youtube_service
node_youtube -->|"embeds and answers"| node_llm
node_learner -->|"asks questions"| node_imagery
node_imagery -.->|"encodes image"| node_imagehelper
node_imagery -->|"invokes model"| node_llm
node_user -.->|"opens chat"| node_page15
node_page15 -.->|"renders chat"| node_chat15
node_chat15 -.->|"submits messages"| node_action15
node_action15 -.->|"requests completion"| node_llm
node_user -.->|"opens chat"| node_page16
node_page16 -.->|"renders chat"| node_chat16
node_chat16 -.->|"submits messages"| node_action16
node_action16 -.->|"requests completion"| node_llm
node_simple -.->|"invokes model"| node_llm
node_provider -.->|"uses provider"| node_llm
node_input -.->|"sends prompt"| node_llm
node_lcel -->|"invokes chain"| node_llm
node_docchat -.->|"offers retrieval example"| node_rag
node_youtube -->|"retains conversation"| node_history

click node_simple "https://github.com/nathansebhastian/langchain-js/blob/main/02_Simple_Q%26A_Gemini/app_gemini.js"
click node_provider "https://github.com/nathansebhastian/langchain-js/blob/main/03_Using_OpenAI/app_gpt.js"
click node_input "https://github.com/nathansebhastian/langchain-js/tree/main/05_Enabling_User_Input"
click node_templates "https://github.com/nathansebhastian/langchain-js/blob/main/06_Prompt_Template/app_gemini.js"
click node_lcel "https://github.com/nathansebhastian/langchain-js/blob/main/07_LCEL/create_chain.js"
click node_sequential "https://github.com/nathansebhastian/langchain-js/blob/main/08_Sequential_Chain/app_gemini.js"
click node_history "https://github.com/nathansebhastian/langchain-js/blob/main/09_Chat_History/app_gemini.js"
click node_agents "https://github.com/nathansebhastian/langchain-js/blob/main/10_Agents_And_Tools/app_gemini.js"
click node_docchat "https://github.com/nathansebhastian/langchain-js/tree/main/11_Chat_Documents"
click node_rag "https://github.com/nathansebhastian/langchain-js/blob/main/11_Chat_Documents/rag_app.js"
click node_docformats "https://github.com/nathansebhastian/langchain-js/blob/main/12_Handle_Different_Docs/app_gemini.js"
click node_youtube "https://github.com/nathansebhastian/langchain-js/blob/main/13_Chat_YouTube/app_gemini.js"
click node_imagery "https://github.com/nathansebhastian/langchain-js/blob/main/14_Chat_Images/app_gemini.js"
click node_imagehelper "https://github.com/nathansebhastian/langchain-js/blob/main/14_Chat_Images/handle_image.js"
click node_chat15 "https://github.com/nathansebhastian/langchain-js/tree/main/15_nextjs_langchain/components/chat"
click node_action15 "https://github.com/nathansebhastian/langchain-js/blob/main/15_nextjs_langchain/actions/openai.action.ts"
click node_page15 "https://github.com/nathansebhastian/langchain-js/blob/main/15_nextjs_langchain/app/page.tsx"
click node_chat16 "https://github.com/nathansebhastian/langchain-js/tree/main/16_nextjs_langchain_prod/components/chat"
click node_action16 "https://github.com/nathansebhastian/langchain-js/blob/main/16_nextjs_langchain_prod/actions/openai.action.ts"
click node_page16 "https://github.com/nathansebhastian/langchain-js/blob/main/16_nextjs_langchain_prod/app/page.tsx"

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_simple,node_provider,node_input,node_templates,node_user toneBlue
class node_lcel,node_sequential,node_history,node_agents,node_toolservices toneAmber
class node_docchat,node_rag,node_docformats,node_youtube,node_imagery,node_imagehelper,node_llm toneMint
class node_chat15,node_action15,node_page15,node_chat16,node_action16,node_page16 toneRose
class node_learner,node_youtube_service toneIndigo
```

## Components

### Model and Prompt Basics

- [Basic Q&A](https://github.com/nathansebhastian/langchain-js/blob/main/02_Simple_Q%26A_Gemini/app_gemini.js): `02_Simple_Q&A_Gemini/app_gemini.js`
- [Model Providers](https://github.com/nathansebhastian/langchain-js/blob/main/03_Using_OpenAI/app_gpt.js): `03_Using_OpenAI/app_gpt.js`
- [User Input](https://github.com/nathansebhastian/langchain-js/tree/main/05_Enabling_User_Input): `05_Enabling_User_Input`
- [Prompt Templates](https://github.com/nathansebhastian/langchain-js/blob/main/06_Prompt_Template/app_gemini.js): `06_Prompt_Template/app_gemini.js`

### Chains and Agents

- [LCEL Chains](https://github.com/nathansebhastian/langchain-js/blob/main/07_LCEL/create_chain.js): `07_LCEL/create_chain.js`
- [Sequential Chains](https://github.com/nathansebhastian/langchain-js/blob/main/08_Sequential_Chain/app_gemini.js): `08_Sequential_Chain/app_gemini.js`
- [Chat History](https://github.com/nathansebhastian/langchain-js/blob/main/09_Chat_History/app_gemini.js): `09_Chat_History/app_gemini.js`
- [Agents and Tools](https://github.com/nathansebhastian/langchain-js/blob/main/10_Agents_And_Tools/app_gemini.js): `10_Agents_And_Tools/app_gemini.js`
- **Search and Wiki**

### Retrieval and Media

- [Document Chat](https://github.com/nathansebhastian/langchain-js/tree/main/11_Chat_Documents): `11_Chat_Documents`
- [Text RAG](https://github.com/nathansebhastian/langchain-js/blob/main/11_Chat_Documents/rag_app.js): `11_Chat_Documents/rag_app.js`
- [Document Formats](https://github.com/nathansebhastian/langchain-js/blob/main/12_Handle_Different_Docs/app_gemini.js): `12_Handle_Different_Docs/app_gemini.js`
- [YouTube Chat](https://github.com/nathansebhastian/langchain-js/blob/main/13_Chat_YouTube/app_gemini.js): `13_Chat_YouTube/app_gemini.js`
- [Image Chat](https://github.com/nathansebhastian/langchain-js/blob/main/14_Chat_Images/app_gemini.js): `14_Chat_Images/app_gemini.js`
- [Image Encoding](https://github.com/nathansebhastian/langchain-js/blob/main/14_Chat_Images/handle_image.js): `14_Chat_Images/handle_image.js`

### Next.js Chat Apps

- [Chat Interface](https://github.com/nathansebhastian/langchain-js/tree/main/15_nextjs_langchain/components/chat): `15_nextjs_langchain/components/chat`
- [OpenAI Action](https://github.com/nathansebhastian/langchain-js/blob/main/15_nextjs_langchain/actions/openai.action.ts): `15_nextjs_langchain/actions/openai.action.ts`
- [App Page](https://github.com/nathansebhastian/langchain-js/blob/main/15_nextjs_langchain/app/page.tsx): `15_nextjs_langchain/app/page.tsx`
- [Production Chat UI](https://github.com/nathansebhastian/langchain-js/tree/main/16_nextjs_langchain_prod/components/chat): `16_nextjs_langchain_prod/components/chat`
- [Production Action](https://github.com/nathansebhastian/langchain-js/blob/main/16_nextjs_langchain_prod/actions/openai.action.ts): `16_nextjs_langchain_prod/actions/openai.action.ts`
- [Production Page](https://github.com/nathansebhastian/langchain-js/blob/main/16_nextjs_langchain_prod/app/page.tsx): `16_nextjs_langchain_prod/app/page.tsx`

### Other components

- **Learner**
- **Language Model APIs**
- **YouTube Transcript**
- **Chat User**

## Connections

- Learner → Basic Q&A: runs example
- Learner → User Input: provides input
- Learner → Prompt Templates: provides values (evidence: `06_Prompt_Template/app_gemini.js`)
- Prompt Templates → Language Model APIs: invokes model (evidence: `06_Prompt_Template/app_gemini.js`)
- Learner → Sequential Chains: provides topic (evidence: `08_Sequential_Chain/app_gemini.js`)
- Sequential Chains → Language Model APIs: invokes model (evidence: `08_Sequential_Chain/app_gemini.js`)
- Learner → Chat History: asks questions (evidence: `09_Chat_History/app_gemini.js`)
- Chat History → Language Model APIs: invokes model (evidence: `09_Chat_History/app_gemini.js`)
- Learner → Agents and Tools: asks question (evidence: `10_Agents_And_Tools/app_gemini.js`)
- Agents and Tools → Search and Wiki: dispatches tools (evidence: `10_Agents_And_Tools/app_gemini.js`)
- Agents and Tools → Language Model APIs: invokes model (evidence: `10_Agents_And_Tools/app_gemini.js`)
- Learner → Text RAG: asks question (evidence: `11_Chat_Documents/rag_app.js`)
- Text RAG → Language Model APIs: embeds and answers (evidence: `11_Chat_Documents/rag_app.js`)
- Learner → Document Formats: asks questions (evidence: `12_Handle_Different_Docs/app_gemini.js`)
- Document Formats → Language Model APIs: embeds and answers (evidence: `12_Handle_Different_Docs/app_gemini.js`)
- Learner → YouTube Chat: supplies URL (evidence: `13_Chat_YouTube/app_gemini.js`)
- YouTube Chat → YouTube Transcript: loads transcript (evidence: `13_Chat_YouTube/app_gemini.js`)
- YouTube Chat → Language Model APIs: embeds and answers (evidence: `13_Chat_YouTube/app_gemini.js`)
- Learner → Image Chat: asks questions (evidence: `14_Chat_Images/app_gemini.js`)
- Image Chat → Image Encoding: encodes image
- Image Chat → Language Model APIs: invokes model (evidence: `14_Chat_Images/app_gemini.js`)
- Chat User → App Page: opens chat
- App Page → Chat Interface: renders chat
- Chat Interface → OpenAI Action: submits messages
- OpenAI Action → Language Model APIs: requests completion
- Chat User → Production Page: opens chat
- Production Page → Production Chat UI: renders chat
- Production Chat UI → Production Action: submits messages
- Production Action → Language Model APIs: requests completion
- Basic Q&A → Language Model APIs: invokes model
- Model Providers → Language Model APIs: uses provider
- User Input → Language Model APIs: sends prompt
- LCEL Chains → Language Model APIs: invokes chain (evidence: `07_LCEL/create_chain.js`)
- Document Chat → Text RAG: offers retrieval example
- YouTube Chat → Chat History: retains conversation (evidence: `13_Chat_YouTube/app_gemini.js`)
