When we think of "directories," our minds often jump to nested folders on a computer's file system. It's a powerful model for organizing files, but what if we could apply that same intuitive, hierarchical structure to more complex business data? What if your product catalog, organizational chart, or multi-tenant user base could be managed with the same simplicity as creating a folder?
Traditional methods for managing structured data like a product catalog often involve rigid database schemas or unwieldy JSON blobs. These can be difficult to query, slow to evolve, and a headache to maintain.
This is where directories.do changes the game. We provide a simple, powerful API to manage any hierarchical data structure programmatically. Let's move beyond folders and explore a real-world workflow: building a fully dynamic, queryable e-commerce product catalog.
A product catalog is inherently hierarchical. Categories contain sub-categories, which in turn contain products, each with its own set of variants and attributes. Modeling this with directories.do isn't just possible; it's a perfect fit.
Let's imagine we're building the backend for a new online store. Using the directories.do SDK, we can define our entire catalog structure with a few simple API calls.
First, we initialize the Directories agent. This is our gateway to all directory operations.
import { Directories } from '@do-sdk/core';
// Initialize the Directories agent
const directoryService = new Directories();
Now, let's create our top-level categories. The recursive: true option is incredibly useful here, as it automatically creates any parent directories (/products) that don't already exist.
// Create the main category for 'Electronics'
await directoryService.create({
path: '/products/electronics/laptops',
metadata: {
displayName: 'Laptops',
categoryLead: 'jane.doe@example.com',
onSale: false
},
recursive: true
});
console.log('Successfully created laptops category!');
This is where the power of flexible metadata comes into play. We're not just creating a path; we're attaching a rich object of product-specific information directly to it.
// Add a specific MacBook Pro to the laptops category
const newProduct = await directoryService.create({
path: '/products/electronics/laptops/macbook-pro-16',
metadata: {
productName: 'MacBook Pro 16-inch',
sku: 'MBP16-M3-SIL',
price: 2499.00,
currency: 'USD',
stockLevel: 42,
specs: {
cpu: 'M3 Pro',
ram: '18GB',
storage: '512GB SSD'
},
imageUrls: ['/cdn/mbp16-1.jpg', '/cdn/mbp16-2.jpg']
}
});
console.log('Added new product:', newProduct.path);
Our product is now neatly organized at /products/electronics/laptops/macbook-pro-16, and all its associated data is stored right there with it.
Once populated, your directory becomes a powerful, queryable data source.
List all products in a category:
// Get all entries under the 'laptops' path
const laptops = await directoryService.list({
path: '/products/electronics/laptops'
});
// `laptops` will be an array of all products in that category
console.log(laptops);
Find products based on metadata:
Need to find all products with low stock? Or everything under $500? You can query your directory based on metadata fields.
// (Example of a powerful query)
const lowStockItems = await directoryService.query({
pathPrefix: '/products',
filter: {
metadata: {
stockLevel: { lt: 10 } // 'lt' for less than
}
}
});
console.log('These items need restocking:', lowStockItems);
The true power of this model is automation. By treating your directory as a programmable resource, you can build sophisticated, agentic workflows that manage your business logic for you.
By leveraging directories.do, you're building more than just a product catalog. You're creating an intelligent, scalable, and automated system that can grow and adapt with your business needs. This API directory approach frees you from the constraints of traditional databases and empowers you to build smarter, more efficient applications.
Ready to move beyond folders? Explore the documentation and start building with the directories.do API today!