Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/langchain-reference-architecture

@0d57af8
Run it yourself

A reference layered architecture for production LangChain 1.0 / LangGraph 1.0 services — LLM factory with version-safe defaults, chain/graph registry, retriever and tool DI, Pydantic-validated config, per-request tenant scoping, middleware ordering, checkpointer selection per environment. Use when starting a new service, refactoring a tangled chain, or onboarding a team to existing code. Trigger with "langchain architecture", "langchain llm factory", "langchain chain registry", "langchain dependency injection", "langchain project structure".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/langchain-reference-architecture

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesone-pager.md

≈893 tokens on demand. Your agent reads this file only when SKILL.md points to it.

langchain-reference-architecture — One-Pager

A reference layered architecture for production LangChain 1.0 / LangGraph 1.0 services that prevents the chain-in-route-handler, import-time-retriever, and per-env-checkpointer tangles that strangle 8-month-old codebases.

The Problem

By month eight, a LangChain service that started as a single FastAPI route has accumulated twelve chain definitions inlined in handlers, three retrievers constructed at module-import scope, max_retries=6 hardcoded in four places, no tenant scoping, a RunnableWithMessageHistory backed by InMemoryChatMessageHistory that loses every conversation on pod restart (P22), and a retriever that was bound to tenant_id="acme" at import and now returns Acme's documents to every other tenant (P33). A code review turns up the P33 leak on a Friday. The fix is not "move one line" — the fix is an architecture that made the wrong thing hard to write in the first place.

The Solution

Five layers with a strict dependency direction — app/ (FastAPI routes) → services/ (chain and graph definitions) → adapters/ (LLM factory, retriever factory, vendor clients) → config/ (Pydantic Settings) → domain/ (Pydantic models, typed state). Chains take their dependencies through constructor arguments, not imports. An LLM factory is the single source of version-safe defaults (timeout 30s, max_retries 2, cache). A chain/graph registry replaces scattered import sites with registry.get("support_agent", tenant=...). Retriever and tool factories are keyed by request — not module — scope, so P33 cannot happen. Config is one Pydantic Settings class with SecretStr for keys and Literal[...] for env names. Middleware composition order (redact → cache → model, per L31) is wired once in the DI layer. Checkpointer selection is per env: MemorySaver in dev, PostgresSaver in staging and prod. Import-linter enforces the layer graph in CI.

Who / What / When

Aspect Details
Who Tech leads and architects designing a new LangChain 1.0 / LangGraph 1.0 service, or refactoring a tangled chain, or onboarding a team to existing code
What Layered directory tree, LLM factory, chain/graph registry, per-request retriever and tool factories, Pydantic Settings module, middleware composition order, per-env checkpointer selection, import-linter config, testing strategy, 4 deep references
When At project kickoff (before file 3), or at the code review that surfaces P22 / P33 / scattered max_retries=6, or during onboarding — this skill is the paper map that prevents the 30-file mess

Key Features

  1. 5-layer dependency rule enforced by import-linter — app → services → adapters → config → domain, never the reverse; CI fails the PR if a route imports a vendor client directly, so the tangles never accumulate
  2. LLM factory + chain/graph registry — Single source of version-safe defaults (timeout=30, max_retries=2) reused by every chain; registry exposes registry.get("support_agent", tenant=...) so there is one place to look, not twelve
  3. Per-request retriever/tool factories + per-env checkpointer — Retriever construction time stays under 5ms so per-request construction is cheap; P33 is architecturally impossible because no retriever is ever bound at import; MemorySaver in dev, PostgresSaver in staging/prod means P22 is impossible in the environments that matter

Quick Start

See SKILL.md for full instructions.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides a production-ready reference architecture for LangChain and LangGraph applications, emphasizing security through strict layering, secret handling, and tenant isolation. It identifies an inherent indirect prompt injection attack surface that exists when LLM agents process untrusted external inputs via routes and retrievers.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: MEDIUM · 1 issue

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
What it can do
Reads files Edits files
version
2.7.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 3 allowed tools
ReadWriteEdit
Other metadata
tags
[
  "saas",
  "langchain",
  "langgraph",
  "python",
  "langchain-1.0",
  "architecture",
  "reference-architecture",
  "patterns"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/langchain-reference-architecture