How microsoft/langchain4j-for-beginners works
This repository is a multi-module Java learning course, not a single application. Each numbered folder is a self-contained LangChain4j example with its own Maven build, source tree, tests, and run scripts. The root-level content mostly provides course navigation, shared docs, diagrams, translations, and repo tooling.
1. Course-level boundary
• The root README frames the repo as a staged learning path: quick chat, introduction, prompt engineering, RAG, tools, and MCP.
• Root assets include diagrams, glossary/testing docs, devcontainer setup, and automation scripts to start/stop the course environments.
• The massive translations/ and translated_images/ trees are documentation/localization artifacts, not runtime components.
2. Reusable technology stack
• The examples are primarily Java + Maven, with several modules built as Spring Boot web apps.
• LangChain4j is the core AI integration library across the repo.
• Cloud AI backends differ by module: the quick start uses GitHub Models, while later modules use Azure OpenAI GPT-5.2.
• Module 1 also includes Azure infrastructure definitions in Bicep for provisioning AI resources.
3. Module 00: quick start demos
• 00-quick-start is a set of small console-style demos showing basic LangChain4j patterns.
• It contains separate entry-point classes for chat, prompt engineering, responsible AI, file reading, and tool integration.
• This module is intentionally lightweight and is the first boundary where users see AI calls without a web server.
4. Module 01: introduction web app
• 01-introduction is a Spring Boot application with controllers, services, configuration, and request/response models.
• It has a web UI under src/main/resources/templates plus static JS/CSS assets, so the architecture is browser → controller → service → LangChain4j/Azure OpenAI.
• The ConversationService suggests stateful conversational handling, with separate controllers for chat, conversation, and general web pages.
• infra/ contains Bicep and Azure deployment files, making this the first module with explicit cloud provisioning.
5. Module 02: prompt engineering demo app
• 02-prompt-engineering is another Spring Boot web application focused on prompt pattern exploration.
• The code is organized around a service that generates GPT-5-style outputs and controllers that expose different prompt patterns.
• The templates under templates/patterns/ indicate a UI that routes users through multiple prompt-engineering scenarios.
• This module is architecture-wise a presentation layer plus one AI orchestration service, with little extra domain logic.
6. Module 03: RAG system
• 03-rag introduces a richer backend split into document ingestion, embedding generation, and retrieval/answering.
• DocumentService handles document upload/management, EmbeddingService handles vectorization, and RagService handles question answering over retrieved context.
• DTOs such as DocumentUploadRequest, RagRequest, RagResponse, SourceReference, and ErrorResponse show a clear API boundary between UI/API and backend logic.
• There is a sample document at the module root, reinforcing the ingestion-to-retrieval flow.
• This is the first module where the main data flow is not just prompt → response, but document → chunk/embedding → retrieval → grounded answer.
7. Module 04: tools and agent execution
• 04-tools adds agent-style orchestration with external tool invocation.
• Assistant represents the LangChain4j AI persona, while AgentService coordinates requests and tool execution.
• WeatherTool and TemperatureTool are the explicit external capabilities exposed to the model.
• Custom exceptions and ToolExecutionInfo show that tool calls are first-class events, not hidden implementation details.
• The UI remains browser-driven, but the important architectural boundary is now model reasoning vs. deterministic tool execution.
8. Module 05: MCP and supervisor-style agents
• 05-mcp is a console/demo-oriented module around the Model Context Protocol and agent coordination.
• StdioTransportDemo indicates an MCP transport boundary over stdin/stdout rather than HTTP.
• SupervisorAgentDemo and the agents/ package (FileAgent, ReportAgent) suggest a coordinator agent delegating work to specialized agents.
• This module is about inter-process/tool protocol integration and orchestration patterns, not a web UI.
9. UI and static asset boundary
• The web modules separate templates, static JS, and CSS from Java controllers/services.
• Each app’s frontend is simple server-rendered pages augmented by client-side JavaScript for chat/demo interactions.
• This keeps the diagrams easy to draw: browser/UI layer, server controller layer, LangChain4j service layer, and AI/tool backend.
10. Configuration and environment management
• Each runnable module has its own application.yaml and .env.example, implying local secrets/config are injected per module.
• start.sh / stop.sh scripts exist per module, plus start-all / stop-all at the repository level, which matters for how the demos are launched during the course.
• The devcontainer and .azd-env.* files show the repo is designed for reproducible cloud/dev-environment setup.
11. Testing boundary
• Every module includes targeted tests under src/test, usually one or two focused tests per concept.
• The tests are part of the learning architecture: they validate the service/controller behavior for each chapter rather than providing a single shared test suite.
• The repo-level docs/TESTING.md explains testing concepts across the course.
12. How to draw the architecture
• Treat each numbered module as an independent subsystem with its own runtime and boundary.
• Draw separate flows for: console demos (00, 05), browser-based Spring apps (01–04), RAG ingestion/retrieval (03), and tool/agent execution (04–05).
• Show Azure OpenAI/GitHub Models as external AI services, Azure infrastructure only where module 1 provisions resources, and documentation/translations as non-runtime support assets.
Main entry points: README.md Learning course · 00-quick-start/README.md Quick start · Application.java Introduction app · RagApplication.java RAG app
Components 33
Course
Repo-level learning path, docs, and shared tooling
- Learning course · Staged LangChain4j course spanning standalone demos, web apps, and agent examples
README.md - Launch scripts · Top-level scripts to start or stop all course modules
start-all.sh - AI backends · GitHub Models and Azure OpenAI model providers
Console demos
Standalone example runtimes without a web UI
- Quick start · Lightweight console demos for basic LangChain4j patterns
00-quick-start/README.md - Chat demo · Basic console chat example
00-quick-start/src/main/java/com/example/langchain4j/quickstart/BasicChatDemo.java - Prompt demo · Prompt engineering console example
00-quick-start/src/main/java/com/example/langchain4j/quickstart/PromptEngineeringDemo.java - Responsible AI · Responsible AI console example
00-quick-start/src/main/java/com/example/langchain4j/quickstart/ResponsibleAIDemo.java - Tool demo · Console tool integration example
00-quick-start/src/main/java/com/example/langchain4j/quickstart/ToolIntegrationDemo.java - MCP demos · Model Context Protocol and supervisor-agent examples
05-mcp/README.md - Stdio transport · MCP transport over stdin/stdout
05-mcp/src/main/java/com/example/langchain4j/mcp/StdioTransportDemo.java - Supervisor agent · Coordinator agent delegating to specialized agents
05-mcp/src/main/java/com/example/langchain4j/mcp/SupervisorAgentDemo.java - Worker agents · File and report agents used by the supervisor
05-mcp/src/main/java/com/example/langchain4j/mcp/agents/FileAgent.java
Web apps
Spring Boot example applications with browser-driven flows
- Introduction app · Browser-based chat and conversation demo with stateful service layer
01-introduction/src/main/java/com/example/langchain4j/app/Application.java - Web UI · Templates and static assets for the chat interface
01-introduction/src/main/resources/templates/index.html - Controllers · Chat, conversation, and page controllers
01-introduction/src/main/java/com/example/langchain4j/app/ChatController.java - Conversation · Conversation handling and LangChain4j orchestration
01-introduction/src/main/java/com/example/langchain4j/service/ConversationService.java - Azure infra · Module-specific Azure deployment definitions
01-introduction/infra/main.bicep - Prompt app · Prompt pattern exploration web application
02-prompt-engineering/src/main/java/com/example/langchain4j/prompts/app/Application.java - Pattern UI · Dashboard and scenario pages for prompt patterns
02-prompt-engineering/src/main/resources/templates/dashboard.html - Pattern controllers · Controllers for prompt pattern routes
02-prompt-engineering/src/main/java/com/example/langchain4j/prompts/controller/DemoWebController.java - Prompt service · GPT-5-style prompt orchestration
02-prompt-engineering/src/main/java/com/example/langchain4j/prompts/service/Gpt5PromptService.java - RAG app · Retrieval-augmented generation application
03-rag/src/main/java/com/example/langchain4j/rag/RagApplication.java - Document ingest · Document upload and management boundary
03-rag/src/main/java/com/example/langchain4j/rag/service/DocumentService.java - Embeddings · Text chunking and embedding generation
03-rag/src/main/java/com/example/langchain4j/rag/service/EmbeddingService.java - RAG service · Retrieval and grounded answer generation
03-rag/src/main/java/com/example/langchain4j/rag/service/RagService.java - Tools app · Agent-style web application with deterministic tools
04-tools/src/main/java/com/example/langchain4j/agents/AgentsApplication.java - Agent service · Coordinates assistant requests and tool execution
04-tools/src/main/java/com/example/langchain4j/agents/service/AgentService.java - Assistant · LangChain4j assistant interface
04-tools/src/main/java/com/example/langchain4j/agents/service/Assistant.java - Tools · Weather and temperature tools exposed to the model
04-tools/src/main/java/com/example/langchain4j/agents/tools/WeatherTool.java
Docs/localization
Reference material, diagrams, and translated assets
- Course docs · Glossary, testing guide, and contribution/support policies
docs/TESTING.md - Diagrams · Repo diagrams for major module flows
diagrams/00-tool-integration.mmd - Translations · Multilingual copies of course documentation
translations/en/README.md - Shared images · Repository-wide images and translated image assets
images
Connections 36
- Learning course → Quick start: includes · Course begins with standalone demos
- Learning course → Introduction app: includes · Course progresses into Spring Boot applications
- Learning course → Prompt app: includes · Prompt engineering chapter
- Learning course → RAG app: includes · RAG chapter
- Learning course → Tools app: includes · Tool-use and agent chapter
- Learning course → MCP demos: includes · MCP and supervisor-agent chapter
- Learning course → Course docs: supports · Reference and testing guidance
- Learning course → Translations: localizes · Multilingual documentation tree
- Learning course → Diagrams: documents · Architecture sketches
- Learning course → Launch scripts: operates · Repo-level launch/stop tooling
- Quick start → Chat demo: contains · Basic chat entry point
- Quick start → Prompt demo: contains · Prompt engineering entry point
- Quick start → Responsible AI: contains · Responsible AI entry point
- Quick start → Tool demo: contains · Tool integration entry point
- Quick start → AI backends: calls · Uses GitHub Models via LangChain4j
- Introduction app → Controllers: routes through · HTTP requests enter controller layer
- Controllers → Conversation: delegates to · Controllers call conversation service
- Introduction app → Web UI: renders · Server-rendered pages and static assets
- Conversation → AI backends: calls · Uses Azure OpenAI through LangChain4j
- Introduction app → Azure infra: provisions · Azure resources for local/cloud setup
- Prompt app → Pattern controllers: routes through · Pattern-specific controller layer
- Pattern controllers → Prompt service: delegates to · Controllers invoke prompt service
- Prompt app → Pattern UI: renders · Dashboard and pattern views
- Prompt service → AI backends: calls · GPT-5-style model execution
- RAG app → Document ingest: coordinates · Document upload and management
- RAG app → Embeddings: coordinates · Embedding generation stage
- RAG app → RAG service: coordinates · Retrieval and answer stage
- RAG service → AI backends: calls · Grounded answer generation uses model backend
- Tools app → Agent service: routes through · Agent controller delegates to service
- Agent service → Assistant: uses · Assistant interface defines model persona
- Agent service → Tools: executes · Weather and temperature tool calls
- Agent service → AI backends: calls · Model reasoning and tool selection
- MCP demos → Stdio transport: contains · Stdio transport example
- MCP demos → Supervisor agent: contains · Supervisor orchestration example
- Supervisor agent → Worker agents: delegates to · Supervisor splits work across agents
- Supervisor agent → AI backends: calls · LLM-driven coordination