ai-era-architecture-principles
npx skills add https://github.com/shimo4228/claude-code-learned-skills --skill ai-era-architecture-principles
Agent 安装分布
Skill 文档
AI Era Architecture Principles
Extracted: 2026-02-09 Context: When deciding whether to use large frameworks (LangChain, LiteLLM, etc.) vs custom implementation in the Claude Code era
Problem
Traditional software development wisdom says “Don’t Reinvent the Wheel” â use existing libraries and frameworks to save development time. But in the AI-driven development era with Claude Code, is this still the best approach?
Key Questions:
- Should I use LangChain for LLM applications?
- Should I use a large framework with 50+ dependencies?
- When is custom implementation better than a comprehensive library?
Solution: The Three Principles
1. Micro-Dependencies Principle
Avoid large frameworks when Claude Code can implement needed features in hours.
Traditional Development:
Custom implementation: weeks â months â°
Use existing framework: days â weeks â
Claude Code Era:
Custom implementation: hours â 1 day â
Use existing framework: still brings 50+ dependencies â
Example (pdf2anki project):
- â With LangChain: 50+ dependencies, black-box abstractions, breaking changes
- â Custom: 6 dependencies (anthropic, pymupdf, pydantic, pyyaml, typer, rich)
- â Result: 3,348 lines, full control, 96% test coverage, transparent
Benefits:
- Minimal dependencies â Easier maintenance
- No black-box abstractions â Full transparency
- No framework lock-in â Complete flexibility
- Faster startup/install â Better user experience
2. Perfect Fit Principle
Generic abstractions â Domain-specific design
Large frameworks provide generic solutions that work for many use cases. But your project has specific requirements. With Claude Code, you can implement exactly what you need.
Example (pdf2anki project):
# Project-specific requirements:
@dataclass(frozen=True) # â Immutability requirement
class Section:
# Structure-aware chunking for long documents
heading_stack: tuple[str, ...]
# Per-section model routing (Haiku vs Sonnet)
char_count: int
# Batch API with 50% discount (Claude-specific)
client.messages.batches.create(requests=[...])
# Prompt caching control (Claude-specific)
system=[{
"type": "text",
"text": SYSTEM_PROMPT,
"cache_control": {"type": "ephemeral"} # â Direct control
}]
These features are perfectly tailored to the project’s needs. A generic framework would either:
- Not support these features, or
- Support them through complex configuration/plugins
Benefits:
- Code matches domain model exactly
- No unused features â Simpler codebase
- Direct control over critical features
3. Full Control Principle
Complete control over API calls, cost tracking, error handling
With direct SDK usage, you understand every line of code. With frameworks, behavior is hidden behind abstractions.
Example:
# â
Direct SDK: Crystal clear what happens
client = anthropic.Anthropic()
response = client.messages.create(
model=model,
max_tokens=max_tokens,
system=[...], # Explicit prompt caching
messages=[...]
)
cost = (response.usage.input_tokens / 1_000_000) * PRICE_PER_1M
# â Framework: What's happening internally?
llm = ChatAnthropic(model=model)
chain = prompt | llm | parser
result = chain.invoke({"text": text}) # Caching enabled? Cost?
Benefits:
- Debugging is easy â No abstraction layers to dig through
- Testing is simple â Mock at SDK level
- Performance optimization â Profile exact bottlenecks
- Cost control â Track every token
The New Mantra
Traditional Era
“Don’t Reinvent the Wheel”
AI Era (with Claude Code)
“Don’t Import the Warehouse for a Single Wheel”
Why?
- Claude Code can build the exact wheel you need in hours
- Importing the warehouse (large framework) brings:
- 50+ dependencies you don’t need
- Features you’ll never use
- Complexity you don’t want
- Breaking changes you must handle
When to Use Large Frameworks
Large frameworks ARE valuable when:
-
You need 80%+ of the framework’s features
- Example: Django for full-stack web apps (ORM, auth, admin, forms, templates)
-
The framework provides critical infrastructure you can’t easily replicate
- Example: React for complex UI state management
-
You’re prototyping and speed > control
- Example: Using LangChain to quickly test different LLM providers
-
The framework has strong network effects
- Example: TensorFlow/PyTorch for ML (ecosystem, community, tools)
When to Avoid Large Frameworks
Avoid large frameworks when:
-
You need < 20% of the framework’s features
- Example: Using LangChain just for API calls to Claude/OpenAI
-
Your requirements are highly specific
- Example: Custom cost tracking, specific batching logic, domain-specific optimizations
-
You value simplicity and control
- Example: CLI tools, libraries, utilities
-
The framework is rapidly changing
- Example: Early-stage AI frameworks with frequent breaking changes
Decision Framework
âââââââââââââââââââââââââââââââââââââââââââââââ
â Do I need > 50% of the framework features? â
âââââââââââââââ¬ââââââââââââââââââââââââââââââââ
â
No âââ´ââ Yes
â â
â âââ Use Framework
â
â¼
âââââââââââââââââââââââââââââââââââââââââââââââ
â Are my requirements highly specific? â
âââââââââââââââ¬ââââââââââââââââââââââââââââââââ
â
No âââ´ââ Yes
â â
â âââ Custom Implementation
â
â¼
âââââââââââââââââââââââââââââââââââââââââââââââ
â Can Claude Code implement it in < 1 day? â
âââââââââââââââ¬ââââââââââââââââââââââââââââââââ
â
No âââ´ââ Yes
â â
â âââ Custom Implementation
â
âââ Consider Framework
Real-World Example: pdf2anki
Decision: Add OpenAI API support alongside Claude API
Option 1: Use LangChain
- Dependencies: +10 packages (langchain, langchain-core, langchain-anthropic, langchain-openai, etc.)
- Code: ~200 lines (shorter)
- Control: Limited (cost tracking, batch API, caching = opaque)
- Maintenance: Must track LangChain updates
Option 2: Custom Provider Abstraction
- Dependencies: +1 package (openai SDK)
- Code: ~500 lines (longer, but all visible)
- Control: Complete (cost tracking, batch API, caching = explicit)
- Maintenance: Only SDK updates (Anthropic, OpenAI)
Chosen: Option 2 with conditional dependencies (even better!)
[project.optional-dependencies]
claude = ["anthropic>=0.40.0"]
openai = ["openai>=1.0.0"]
all = ["anthropic>=0.40.0", "openai>=1.0.0"]
Users install only what they need:
pip install pdf2anki[claude] # Only Anthropic SDK
pip install pdf2anki[openai] # Only OpenAI SDK
pip install pdf2anki[all] # Both (for comparison)
Result:
- Micro-Dependencies â (users choose)
- Perfect Fit â (domain-specific features preserved)
- Full Control â (transparent cost tracking, batch API)
When to Use This Skill
Trigger: When you or the user are considering adding a large framework (especially for LLM applications).
Questions to Ask:
- What percentage of the framework’s features will we actually use?
- Can Claude Code implement the needed features in < 1 day?
- Are there project-specific requirements that need fine-grained control?
- How important is dependency minimization for this project?
Remember: In the AI era, the cost of custom implementation has dropped dramatically. Factor this into your architecture decisions.
Related Patterns
python-optional-dependencies.md– Implementation pattern for multi-provider supportcost-aware-llm-pipeline.md– Custom cost tracking implementationlong-document-llm-pipeline.md– Domain-specific document processing