Skip to content

LangChain Course Workspace, a comprehensive monorepo showcasing a full-stack AI-powered chat application. This project demonstrates the integration of modern web technologies with advanced AI orchestration using LangChain and LangGraph.

Notifications You must be signed in to change notification settings

claboran/langchain-course-ws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

LangChain Course Workspace

A comprehensive full-stack AI application suite showcasing production-ready LangChain and LangGraph implementations.

This monorepo demonstrates advanced AI agent patterns, semantic search, multi-turn conversations, and rich UI experiencesโ€”all built with modern TypeScript, Angular, and NestJS.


๐ŸŽฏ What We Built

1. Intelligent Shopping Assistant โœจ

Shopping Assistant UI

A complete e-commerce conversational AI that helps users discover products through natural language:

  • Semantic Product Search: Vector-powered search with pgvector and embeddings
  • Multi-turn Context: Remembers conversation history across interactions
  • Custom LangChain Tools: Product search with category filtering + category browsing
  • Rich UI: Interactive chat with markdown support and product cards
  • 27,752 Products: Full product catalog with vector embeddings ready for semantic search

2. General-Purpose Chat Assistant

Mermaid Diagram Example

A versatile conversational AI demonstrating LangChain fundamentals:

  • Personalization Tools: Custom LangChain tool for user context
  • Conversation Threading: UUID-based conversation management
  • Rich Content: Markdown, syntax highlighting, and Mermaid diagrams
  • Production Patterns: NgRx Signal Store, immer.js, tapResponse

3. Product Embedding Pipeline

An ETL pipeline for generating and storing vector embeddings:

  • Batch Processing: Efficiently handles 27K+ products
  • Ollama Integration: Local embeddings with nomic-embed-text (768 dimensions)
  • pgvector Storage: PostgreSQL with HNSW indexing for fast similarity search
  • Migration Support: TypeORM migrations for schema management

๐Ÿง  AI & LangChain Concepts Covered

Core LangChain Patterns

  • โœ… Agent Creation: Using createAgent with model + tools + memory
  • โœ… Custom Tools: Building domain-specific tools with the tool() function
  • โœ… Structured Output: Using toolStrategy with Zod schemas for consistent responses
  • โœ… Memory Persistence: LangGraph's MemorySaver checkpointer for conversation state
  • โœ… Conversation Threading: Managing multiple concurrent conversations with thread IDs

Vector Search & RAG

  • โœ… Embeddings: Generating vector representations with Ollama (nomic-embed-text)
  • โœ… Vector Stores: PGVectorStore integration with PostgreSQL
  • โœ… Semantic Search: Similarity search with cosine distance
  • โœ… Retrieval: Using .asRetriever() pattern with filtering
  • โœ… HNSW Indexing: Fast approximate nearest neighbor search

Production Best Practices

  • โœ… Error Handling: tapResponse pattern for structured error flows
  • โœ… Optimistic Updates: Immediate UI feedback with rollback on failure
  • โœ… Type Safety: End-to-end type safety with Zod schemas
  • โœ… Model Configuration: Centralized model provider with dependency injection
  • โœ… API Documentation: Comprehensive Swagger/OpenAPI specs


๐Ÿ—๏ธ Project Structure

The workspace is organized into several applications and libraries:

Applications

  • chat-api (apps/chat-api): A NestJS backend providing the AI chat logic.

    • Implements LangGraph MemorySaver for conversation threading.
    • Custom LangChain tools for user personalization.
    • Swagger UI for interactive API documentation.
    • ๐Ÿ“– Detailed Documentation
  • chat-ui (apps/chat-ui): An AnalogJS/Angular frontend.

    • Uses NgRx Signal Store for reactive state management.
    • Shared Zod schemas for validation and type safety.
    • Proxy-based integration with the backend.
    • Includes comprehensive service documentation for the chat store.
  • ecommerce-assistant-api (apps/ecommerce-assistant-api): A conversational e-commerce assistant API.

    • Semantic product search using pgvector and LangChain.
    • Multi-turn conversations with memory persistence.
    • Custom LangChain tools for product search and category browsing.
    • Structured responses with Markdown support.
    • Swagger UI for interactive API documentation.
    • ๐Ÿ“– Detailed Documentation
  • ecommerce-assistant-ui (apps/ecommerce-assistant-ui): An AnalogJS/Angular frontend for the shopping assistant.

    • Interactive chat interface with product recommendations.
    • Rendered with Markdown and custom product cards.
    • Built with NgRx Signal Store.
    • ๐Ÿ“– Detailed Documentation
  • product-ingest (apps/product-ingest): An embedding pipeline for e-commerce product data.

    • Processes product catalogs and generates vector embeddings for semantic search.
    • First step in building an intelligent e-commerce agent.
    • Integrates with vector databases for efficient product knowledge retrieval.
    • ๐Ÿ“– Detailed Documentation
  • hello-agent (apps/hello-agent): A CLI tool built with Nest Commander for quick AI interactions.

Infrastructure

Libraries

  • chat-components (libs/chat-components): Reusable Angular UI components (message bubbles, markdown rendering).

    • ๐Ÿ“– Detailed Documentation
    • Features markdown rendering with syntax highlighting.
    • Supports Mermaid diagram visualization.
    • Optimized for performance and accessibility.
  • model-provider (libs/model-provider): A shared library for MistralAI configuration and integration.

    • ๐Ÿ“– Detailed Documentation
    • Provides centralized Mistral AI model management.
    • Supports both synchronous and asynchronous configuration.
    • Enables dependency injection across the workspace.
  • communication (libs/communication): Shared utilities for API communication, validation, and error handling.

    • ๐Ÿ“– Detailed Documentation
    • Zod schema validation with structured error responses.
    • Standardized API error handling wrappers.
    • Type-safe conversation ID validation.
    • Used by chat-ui and ecommerce-assistant-ui server routes.

๐Ÿ› ๏ธ Tech Stack

AI & LangChain

  • LLM: Mistral AI (mistral-large-latest)
  • Orchestration: LangChain JS - Agent framework with custom tools
  • Memory: LangGraph - MemorySaver checkpointer for conversation state
  • Embeddings: Ollama - nomic-embed-text (768 dimensions)
  • Vector Database: PostgreSQL + pgvector extension

Backend

  • Framework: NestJS - Enterprise Node.js framework
  • Build Tool: Vite - Fast development and production builds
  • Validation: Zod schemas + class-validator
  • API Docs: Swagger/OpenAPI with interactive UI
  • ORM: TypeORM for database migrations

Frontend

Workspace & Tooling

  • Monorepo: Nx - Smart, fast build system
  • Package Manager: npm
  • TypeScript: Full type safety across the stack
  • Infrastructure: Docker Compose for local development

๐Ÿ›๏ธ Architecture Overview

graph TD;
    A[User] --> B[Chat UI];
    B --> C[Chat API];
    C --> D[LangChain Agent];
    D --> E[Mistral AI];
    D --> F[MemorySaver];
    E --> G[Response];
    F --> G;
    G --> B;
    
    subgraph Frontend
    B[Chat UI] --> H[NgRx Signal Store];
    B --> I[Chat Components];
    I --> J[Markdown Renderer];
    I --> K[Mermaid Support];
    end
    
    subgraph Backend
    C[Chat API] --> L[Model Provider];
    C --> M[Custom Tools];
    C --> N[Swagger Docs];
    end
    
    subgraph Shared
    O[Zod Schemas] --> B;
    O --> C;
    P[Model Provider] --> C;
    Q[Communication Utils] --> B;
    Q --> C;
    end
Loading

Data Flow

  1. User Interaction: User sends a message through the chat interface
  2. State Management: NgRx Signal Store manages conversation state
  3. API Request: Chat UI sends request to NestJS backend
  4. AI Processing: LangChain agent processes request with context from MemorySaver
  5. Model Integration: Mistral AI generates response using the configured model
  6. Response Handling: Backend returns structured response with conversation context
  7. Content Rendering: Chat UI displays response with markdown, code highlighting, and diagrams

๐Ÿ“š Buildable Libraries & Shared Code

This workspace uses buildable libraries with npm workspaces for code sharing between applications. This enables:

  • โœ… Type-safe imports across apps
  • โœ… Shared validation logic (Zod schemas)
  • โœ… Reusable utility functions
  • โœ… Nx build caching and optimization

Shared Libraries

  • @langchain-course-ws/communication: Validation utilities (safeParseOrThrow, callWithErrorHandling)
  • @langchain-course-ws/model-provider: LangChain model configuration (Mistral AI, Ollama embeddings)
  • @langchain-course-ws/chat-components: Reusable Angular chat UI components

Key Configuration

NPM Workspaces (package.json):

{
  "workspaces": ["dist/libs/*"]
}

This creates Node.js-resolvable symlinks:

node_modules/@langchain-course-ws/communication โ†’ dist/libs/communication

Auto-Build Dependencies (nx.json):

{
  "targetDefaults": {
    "@analogjs/platform:vite-dev-server": {
      "dependsOn": ["^build"]
    }
  }
}

Libraries are automatically built before serving applications.

Development Workflow

# Libraries auto-build, no manual steps needed
nx serve chat-ui

# If you add a new library, recreate symlinks
npm install --legacy-peer-deps

๐Ÿ“– Full Documentation: See docs/BUILDABLE_LIBRARIES.md for complete details on:

  • How buildable libraries work with AnalogJS SSR
  • Adding new libraries
  • Troubleshooting module resolution
  • Import guidelines

๐Ÿšฆ Getting Started

Prerequisites

Required:

  • Node.js v18 or higher
  • npm (comes with Node.js)
  • Mistral AI API Key (Get one here)

For E-Commerce Assistant:

  • Docker (for PostgreSQL + pgvector)
  • Ollama (Download) with nomic-embed-text model

Quick Start (Chat Assistant)

  1. Clone and install dependencies:

    git clone <repository-url>
    cd langchain-course-ws
    npm install
  2. Configure environment:

    # Create .env file in the root
    cat > .env << EOF
    MISTRAL_API_KEY=your_mistral_api_key_here
    EOF
  3. Start the applications:

    # Option 1: Run both API and UI together
    npm run dev
    
    # Option 2: Run individually
    npm run chat-api:dev      # API on http://localhost:3311
    npm run chat-ui:dev       # UI on http://localhost:4200
  4. Access the applications:

Full Setup (E-Commerce Assistant)

Click to expand full setup instructions

1. Install Ollama and Pull Model

# Install Ollama (see https://ollama.ai/)
# Then pull the embedding model:
ollama pull nomic-embed-text

2. Start Infrastructure

# Start PostgreSQL with pgvector
docker-compose -f iac/docker-compose.postgres.yml up -d

# WSL2 only: Start Ollama proxy
docker-compose -f iac/docker-compose.nginx.yml up -d

3. Configure Environment

# Update .env with additional settings
cat >> .env << EOF
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/langchain
OLLAMA_BASE_URL=http://localhost:11435
PORT=3312
EOF

4. Run Database Migration

npm run product-ingest:migrate

5. Ingest Product Data

# Build and run the ingestion pipeline
npm run product-ingest:build
node dist/apps/product-ingest/main.js ingest

This will process 27,752 products and generate embeddings. Time varies based on your hardware (5-30+ minutes depending on CPU/GPU).

6. Start E-Commerce Assistant

# Terminal 1: Start API
npm run ecommerce-assistant-api:dev

# Terminal 2: Start UI
npm run ecommerce-assistant-ui:dev

7. Access E-Commerce Assistant

See detailed documentation:



๐Ÿงช Testing

The workspace uses Vitest for unit testing and Playwright for E2E testing.

# Run all tests
npx nx run-many -t test

# Run specific project tests
npm run chat-api:test
npm run chat-ui:test
npm run chat-components:test
npm run communication:test

๐Ÿ”ง Useful Nx Commands

  • Visual Graph: npx nx graph - See how projects depend on each other.
  • Generate Code: npx nx g @nx/angular:component my-component --project=chat-ui
  • Linting: npx nx run-many -t lint

๐Ÿ“– Documentation

๐Ÿ“‚ Internal Documentation (This Repository)

Applications:

Libraries:

Infrastructure & Services:

๐ŸŒ External Resources

LangChain & AI:

Frontend Technologies:

Backend & Tooling:

  • NestJS - Enterprise Node.js framework
  • Nx - Smart monorepo tools
  • Zod - TypeScript-first schema validation

๐Ÿ”ฎ Future Improvements

Short-term Enhancements

  • Streaming Responses: Implement Server-Sent Events (SSE) for real-time message streaming
  • Persistent Memory: Replace in-memory checkpointer with PostgreSQL/Redis storage
  • Dynamic Categories: Auto-detect product categories from database instead of hardcoding
  • User Authentication: Add login/signup with session management
  • Conversation Management: Add UI for viewing, searching, and deleting past conversations

Advanced Features

  • Hybrid Search: Combine semantic search with keyword search and filters (price, rating)
  • Product Comparison: Tool for side-by-side product comparison
  • Shopping Cart: Full cart management with checkout flow
  • Personalized Recommendations: User preference learning and recommendation engine
  • Multi-modal Support: Image understanding for product visuals
  • Voice Interface: Speech-to-text and text-to-speech integration

Technical Improvements

  • Rate Limiting: Implement API rate limiting per user/session
  • Conversation Summarization: Automatic summarization for long conversations
  • Observability: Add logging, metrics, and tracing (OpenTelemetry)
  • Increased Test Coverage: More comprehensive unit and integration tests
  • CI/CD: Automated deployment pipeline
  • Production Deployment: Containerization and cloud deployment (AWS/Azure/GCP)

๐Ÿ“Š Project Structure

langchain-course-ws/
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ chat-api/                    # NestJS API with LangChain agent
โ”‚   โ”œโ”€โ”€ chat-ui/                     # AnalogJS/Angular frontend
โ”‚   โ”œโ”€โ”€ ecommerce-assistant-api/     # E-commerce semantic search API
โ”‚   โ”œโ”€โ”€ ecommerce-assistant-ui/      # Shopping assistant UI
โ”‚   โ”œโ”€โ”€ product-ingest/              # Vector embedding pipeline
โ”‚   โ””โ”€โ”€ hello-agent/                 # CLI demo tool
โ”œโ”€โ”€ libs/
โ”‚   โ”œโ”€โ”€ chat-components/             # Reusable Angular UI components
โ”‚   โ”œโ”€โ”€ communication/               # Shared API utilities and validation
โ”‚   โ””โ”€โ”€ model-provider/              # Mistral AI configuration library
โ”œโ”€โ”€ iac/
โ”‚   โ”œโ”€โ”€ docker-compose.postgres.yml  # PostgreSQL + pgvector
โ”‚   โ””โ”€โ”€ docker-compose.nginx.yml     # Ollama proxy (WSL2)
โ”œโ”€โ”€ data/                            # Product datasets
โ””โ”€โ”€ doc-images/                      # Documentation images

๐Ÿ™ Acknowledgments

Built as part of the LangChain learning journey. Special thanks to the open-source communities behind:

  • LangChain & LangGraph
  • Angular & AnalogJS
  • Nx & NestJS
  • Mistral AI & Ollama

Made with โค๏ธ and AI

About

LangChain Course Workspace, a comprehensive monorepo showcasing a full-stack AI-powered chat application. This project demonstrates the integration of modern web technologies with advanced AI orchestration using LangChain and LangGraph.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages