Jump to content

Recommended Posts

Posted

Export your ProcessWire site structure as comprehensive, AI-optimized documentation for ChatGPT, Claude, Copilot, and other AI coding assistants.

context1.thumb.png.d61f3fd6c1273ae1893f386a0cbc11ba.png

What It Does

Context automatically generates complete documentation of your ProcessWire site in formats specifically optimized for working with AI:

πŸ“Š Site Structure

  • Complete page hierarchy exported as JSON, TOON, and ASCII tree
  • Shows all relationships, templates, URLs, and metadata
  • Smart collapsing for large page lists

πŸ“‹ Templates & Fields

  • All template definitions with complete field configurations
  • Field types, options, requirements, default values
  • Special handling for Repeater, Matrix, Table fields

πŸ“¦ Content Samples

  • Real page examples exported for each template
  • Shows actual data formats and field usage
  • Helps AI understand your content patterns

πŸ’Ύ Code Snippets

  • Customized selector patterns for your site type
  • Helper functions and utility code
  • API implementation examples

πŸ€– AI Prompts

  • Ready-to-use project context file
  • Template creation prompts
  • Debugging assistance prompts

Dual Format Export (The Game Changer!)

Context exports in two formats simultaneously:

JSON Format

Standard format for development tools, APIs, and compatibility

TOON Format (AI-Optimized) ✨

Token-Oriented Object Notation designed specifically for AI prompts:

  • 30-60% fewer tokens than JSON
  • Significantly reduces API costs
  • Same data, more compact representation
  • No external dependencies - pure PHP

Real Savings Example

For a typical ProcessWire site with 50 templates:

structure.json  (15,000 tokens)  β†’  structure.toon  (8,500 tokens)  = 43% savings
templates.json  (8,000 tokens)   β†’  templates.toon  (4,000 tokens)  = 50% savings
samples/*.json  (12,000 tokens)  β†’  samples/*.toon  (6,500 tokens)  = 46% savings

Cost Impact (Claude Sonnet pricing):

  • JSON export: $0.105 per AI interaction
  • TOON export: $0.057 per AI interaction
  • Save ~$5/month if you use AI assistants 100 times/month

Installation

cd /site/modules/
git clone https://github.com/mxmsmnv/Context.git

Then in admin: Modules β†’ Refresh β†’ Install

Or download from ProcessWire Modules Directory

Quick Start

  1. Setup β†’ Modules β†’ Context β†’ Configure
  2. Choose your site type (Blog, E-commerce, Business, Catalog, Generic)
  3. βœ… Enable "Export TOON Format" (recommended for AI work!)
  4. Enable optional features:
    • βœ… Export Content Samples
    • βœ… Create Code Snippets
    • βœ… Create AI Prompts
  5. Click "Export Context for AI"

Files appear in /site/assets/context/

Generated Files

/site/assets/context/
β”œβ”€β”€ README.md                      # Complete documentation
β”œβ”€β”€ structure.json / .toon         # Page hierarchy
β”œβ”€β”€ structure.txt                  # ASCII tree
β”œβ”€β”€ templates.json / .toon         # All templates & fields
β”œβ”€β”€ config.json / .toon            # Site configuration
β”œβ”€β”€ modules.json / .toon           # Installed modules
β”œβ”€β”€ classes.json / .toon           # Custom Page classes
β”‚
β”œβ”€β”€ samples/                       # Real content examples
β”‚   β”œβ”€β”€ product-samples.json
β”‚   └── product-samples.toon       # 46% smaller!
β”‚
β”œβ”€β”€ snippets/                      # Code patterns
β”‚   β”œβ”€β”€ selectors.php              # Customized for your site type
β”‚   β”œβ”€β”€ helpers.php                # Utility functions
β”‚   └── api-examples.php           # REST API examples
β”‚
└── prompts/                       # AI instructions
    └── project-context.md         # Complete project overview

Using with AI Assistants

Upload TOON files to save tokens and costs:

πŸ“Ž structure.toon
πŸ“Ž templates.toon
πŸ“Ž prompts/project-context.md

Then ask your AI assistant: "Help me create a blog post template with title, body, author, categories, and featured image. Follow the existing patterns from templates.toon"

The AI has complete context of your site and can generate code that follows your exact patterns!

Site Type Customization

Code snippets automatically adapt to your site type:

Blog / News / Magazine

  • Post listings, author archives, category filtering
  • Recent posts, popular content, related articles

E-commerce / Online Store

  • Product listings, cart logic, order processing
  • Inventory management, payment integration

Business / Portfolio / Agency

  • Service pages, team members, case studies
  • Testimonials, project galleries

Catalog / Directory / Listings

  • Brand hierarchies, category filters
  • Advanced search, sorting, pagination

Generic / Mixed Content

  • General purpose patterns for any site type

Features Overview

Always Exported (Core)

  • βœ… Complete page tree structure
  • βœ… All templates with field definitions
  • βœ… Site configuration and settings
  • βœ… Installed modules list
  • βœ… Custom Page classes
  • βœ… README with complete documentation

Optional (Configurable)

  • βš™οΈ Content samples (1-10 per template)
  • βš™οΈ API JSON schemas
  • βš™οΈ URL routing structure
  • βš™οΈ Performance metrics
  • βš™οΈ Code snippets library
  • βš™οΈ AI prompt templates
  • βš™οΈ IDE integration files (.cursorrules, .claudecode.json)

Advanced Settings

  • Auto-update on template/field changes
  • Maximum tree depth (3-20 levels)
  • JSON children limit (prevent huge files)
  • Compact mode for large lists
  • Custom AI instructions

Why TOON Format?

TOON is specifically designed for AI prompts. Here's the difference:

JSON (verbose):

{
  "products": [
    {"id": 1, "title": "Dark Chocolate", "price": 12.99},
    {"id": 2, "title": "Milk Chocolate", "price": 9.99}
  ]
}

TOON (compact):

products[2]{id,title,price}:
1,Dark Chocolate,12.99
2,Milk Chocolate,9.99

Same data, 50% fewer tokens!

Use Cases

  • πŸ€– AI-Assisted Development Upload your site context to Claude/ChatGPT and get code that follows your exact patterns
  • πŸ“š Developer Onboarding New team members get complete site documentation instantly
  • πŸ”„ Site Migration Export complete site structure for documentation or migration planning
  • πŸ“– Code Standards Maintain consistency across your team with AI that knows your patterns
  • πŸ’° Cost Optimization Reduce AI API costs by 30-60% with TOON format

Links

Screenshots

Spoiler

context2.thumb.png.5ebd5d2b1a3dd62e4cfd664e31a0bad9.png

context3.thumb.png.6c328e0e2893b75e54764ed2869994a0.png

Example Workflow

  1. Export your site Click one button, get complete documentation in both JSON and TOON formats
  2. Upload to AI Upload .toon files to Claude/ChatGPT for maximum efficiency
  3. Build features faster AI knows your exact site structure, templates, and patterns
  4. Save money Use 30-60% fewer tokens on every AI interaction

Perfect for ProcessWire developers who use AI coding assistants! The TOON format support makes it significantly more cost-effective to work with Claude, ChatGPT, and similar tools.

Questions? Suggestions? Let me know! πŸš€

  • Like 5
  • Thanks 2
  • 3 weeks later...
Posted

Thanks @maximusΒ for sharing. I am testing the module, and found two issues:


1. After the module has been installed the "Submit" button of its settings page must be clicked or else the actual settings are not the same as seen in the GUI. By default, a lot of "Module Configuration" settings seems to be turned on (their checkboxes are on), like "TOON Format Export", "Content Samples", ect. but they are not on. I had to manuallyΒ "Submit" the settings so that the module settings are actually the same as seen on the module config page.

2. InΒ Context.module.php
$matrixTypes = $matrixField->type->getMatrixTypes($matrixField);
foreach($matrixTypes as $mt) {
Β  Β  if($mt->name === $name) {

But $mt->name is meaningless asΒ $matrixTypes is the following kind of array:
array
'matrix_email_block_image' => 1
'matrix_email_block_button' => 3
'matrix_email_block_text' => 4
'matrix_email_block_spacer' => 5

$mt->name is an attempt to access the name property of an integer. And that happens in two locations:

image.png.10958ea7110f14bfd50ea64a98a5e529.png

Posted

Thanks for the detailed bug report! Both issues are fixed in v1.1.5:

  1. getMatrixTypes() error - Fixed array iteration (was treating integers as objects)
  2. Default settings - Added __construct() to apply defaults on install

The module is now available on GitHub. Please update and let me know if everything works correctly.

  • Like 1
Posted (edited)

Thank you @maximusΒ I checked both issues and they are indeed resolved.

I wonder if you use Tracy Debugger for the admin? It is easy to spot warnings if it always runs, which is the case for me almost all the time. Sometimes, I disable it when I need unmodified HTML in the browser, but after that I reenable it.

BTW, could you make the /site/assets/context path configurable? I recently tested PHPStorm with Junie by adding to its .junie directory what @interrobangΒ shared with us:
https://processwire.com/talk/topic/29439-cursor-might-be-my-vscode-replacement/#findComment-251674

Specifically:
https://github.com/phlppschrr/processwire-knowledge-base/tree/master

I adjusted the rootΒ SKILL.md (removed references to Python scripts and such) and Junie can pick up all skills perfectly.

If I could set the module to generate files to /.junie/skills/docs, the Junie agent would start using them too.Β That would be real magic :)

Edited by szabesz
typo

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
Γ—
Γ—
  • Create New...