Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Consumer Documentation Planning

This document specifies what the Context7-style consumer documentation should contain when the AnyFS library is implemented. This is a planning/specification document, not actual API documentation.


Purpose

When AnyFS is implemented, we need a Context7-style reference document that LLMs can use to correctly consume the AnyFS API. This document specifies what that reference should contain.

Why Context7-style?

  • LLMs need quick decision trees to select the right components
  • Copy-paste-ready patterns reduce hallucination
  • Common mistakes section prevents known pitfalls
  • Trait hierarchy helps understand what to implement

Required Sections

The consumer documentation MUST include these sections:

1. Quick Decision Trees

Decision trees help LLMs quickly navigate to the right component. Include:

Decision TreePurpose
Which Crate?anyfs-backend vs anyfs
Which Backend?Memory, SQLite, VRootFs, etc.
Which Middleware?Quota, PathFilter, ReadOnly, etc.
Which Trait Level?Fs, FsFull, FsFuse, FsPosix

Format: ASCII tree diagrams with terminal answers.

Example structure (to be filled with actual API when implemented):

Is data persistence required?
├─ NO → MemoryBackend
└─ YES → Is encryption needed?
         ├─ YES → SqliteBackend with `encryption` feature
         └─ NO → [continue decision tree...]

2. Common Patterns

Provide copy-paste-ready code for these scenarios:

PatternDescription
Simple File Operationsread, write, delete, check existence
Directory Operationscreate, list, remove
Sandboxed AI AgentFull middleware stack example
Persistent DatabaseSqliteBackend setup
Type-Safe WrappersUser-defined newtypes for compile-time safety
Streaming Large Filesopen_read/open_write usage

Requirements for each pattern:

  • Complete, runnable code blocks
  • All imports included
  • Proper error handling (no .unwrap())
  • Minimal code that demonstrates the concept

3. Trait Hierarchy Diagram

Visual representation of the trait hierarchy:

FsPosix  ← Full POSIX (handles, locks, xattr)
    ↑
FsFuse   ← FUSE-mountable (+ inodes)
    ↑
FsFull   ← std::fs features (+ links, permissions, sync, stats)
    ↑
   Fs    ← Basic filesystem (90% of use cases)
    ↑
FsRead + FsWrite + FsDir  ← Core traits

With clear guidance: “Implement the lowest level you need. Higher levels include all below.”

4. Backend Implementation Pattern

Template for implementing custom backends. The consumer docs should include:

LevelTraits to ImplementResult
MinimumFsRead + FsWrite + FsDirFs
ExtendedAdd FsLink, FsPermissions, FsSync, FsStatsFsFull
FUSEAdd FsInodeFsFuse
POSIXAdd FsHandles, FsLock, FsXattrFsPosix

Each level should have a complete template showing all required method signatures.

5. Middleware Implementation Pattern

Template showing:

  • How to wrap an inner backend with a generic type parameter
  • Which methods to intercept vs delegate
  • The Layer trait for .layer() syntax
  • Common middleware patterns table:
PatternInterceptDelegateExample
LoggingAll (before/after)AllTracing
Block writesWrite methods → errorRead methodsReadOnly
Transform dataread/writeEverything elseEncryption
Check accessAll (before)AllPathFilter
Enforce limitsWrite methods (check size)Read methodsQuota

6. Adapter Patterns

Templates for interoperability:

Adapter TypeDescription
FROM externalWrap external crate’s filesystem as AnyFS backend
TO externalWrap AnyFS backend to satisfy external crate’s trait

7. Error Handling Reference

All FsError variants with when to use each:

VariantWhen to Return
NotFoundPath doesn’t exist
AlreadyExistsPath already exists (create conflict)
NotAFileExpected file, got directory
NotADirectoryExpected directory, got file
DirectoryNotEmptyCan’t remove non-empty directory
ReadOnlyWrite blocked by ReadOnly middleware
AccessDeniedBlocked by PathFilter or permissions
QuotaExceededSize/count limit exceeded
NotSupportedBackend doesn’t support this operation
BackendBackend-specific error

8. Common Mistakes & Fixes

MistakeFix
Using unwrap()Always use ? or handle FsError
Assuming paths normalizedUse canonicalize() first
Forgetting parent dirsUse create_dir_all
Holding handles too longDrop promptly
Mixing backend typesUse FileStorage::boxed()
Testing with real filesUse MemoryBackend

Document Structure

When creating the actual consumer documentation, follow this structure:

# AnyFS Implementation Patterns

## Quick Decision Trees
### Which Crate Do I Need?
### Which Backend Should I Use?
### Do I Need Middleware?
### Which Trait Level?

## Common Patterns
### Simple File Operations
### Directory Operations
### Sandboxed AI Agent
### Persistent Database
### Type-Safe Wrapper Types

## Trait Hierarchy (Pick Your Level)

## Pattern 1: Implement a Backend
### Minimum: Implement Fs
### Add Links/Permissions: Implement FsFull
### Add FUSE Support: Implement FsFuse

## Pattern 2: Implement Middleware
### Template
### Common Middleware Patterns

## Pattern 3: Implement an Adapter
### Adapter FROM another crate
### Adapter TO another crate

## Error Handling Reference

## Common Mistakes & Fixes

## Quick Reference: What to Implement

Creation Guidelines

When creating the actual consumer documentation after implementation:

  1. Use actual tested code - Every example must compile and run
  2. Include all imports - LLMs need complete context
  3. Show error handling - Never use .unwrap() in examples
  4. Keep examples minimal - Shortest code that demonstrates the pattern
  5. Update with API changes - This doc must stay in sync with implementation
  6. Validate against real usage - Test each pattern before including it

Quality Checklist

Before publishing the consumer documentation:

  • All code examples compile
  • All code examples run without panics
  • Decision trees lead to correct answers
  • Error variants match actual FsError enum
  • Trait hierarchy matches actual trait definitions
  • Common mistakes reflect actual issues found in testing

DocumentPurpose
LLM Development MethodologyFor implementers: how to structure code for LLM development
This documentSpecification for consumer documentation
Backend GuideDesign for backend implementation
Middleware TutorialDesign for middleware creation

Tracking

This planning document should be replaced with actual consumer documentation when:

  1. AnyFS is implemented - The crates exist and compile
  2. API is stable - No major breaking changes expected
  3. Examples are tested - All patterns verified working

GitHub Issue: Create Context7-style consumer documentation

  • Status: Blocked by AnyFS implementation
  • Template: This planning document