Project Structure
Methods
Methods are the building blocks of your application logic in Stellify. Each method is stored as a structured JSON definition containing its signature, parameters, return type, and implementation as an array of statement references.
What are Methods?
In Stellify, methods are structured definitions that encapsulate reusable pieces of logic. Unlike traditional codebases where methods are text-based, Stellify methods are stored as JSON objects in your database, enabling powerful features like:
- Surgical refactoring - Update a method once and all references update instantly
- Deduplication - Automatically detect and reuse identical methods across your codebase
- Global method library - Share battle-tested methods across projects
- AI-native development - AI can search, analyze, and compose methods programmatically
Method Structure
A method definition contains the following key properties:
{
"uuid": "fbc60d5e-e9a2-4c0e-8d09-9a2d196d94fc",
"name": "calculateTotal",
"type": "Method",
"scope": "public",
"returnType": "float",
"parameters": [
"param-uuid-1", // References parameter definitions
"param-uuid-2"
],
"data": [
"statement-uuid-1", // Array of statement UUIDs
"statement-uuid-2",
"statement-uuid-3"
],
"method_hash": "a7b3c2d1...", // SHA-256 hash for deduplication
"usage_count": 15, // Times this method is referenced
"is_locked": true, // Part of global library
"locked_at": "2026-01-10 09:15:00"
}
Core Properties
uuid- Unique identifier for this methodname- The method name (e.g., "calculateTotal", "processPayment")type- Method type (Method, Constructor, Migration, Seeder, etc.)scope- Visibility (public, private, protected)returnType- Expected return type (string, int, array, etc.)
Composition Properties
parameters- Array of UUIDs referencing parameter clausesdata- Array of UUIDs referencing statements (the method body)
Deduplication Properties
method_hash- SHA-256 hash of the method's signature + body for deduplicationusage_count- Number of times this method is referenced across your projectsis_locked- When true, method is part of the global library and reusablelocked_at- Timestamp when method was locked to global library
Method Deduplication
Stellify automatically detects duplicate methods and enables reuse through a global method library. When you create or update a method, Stellify:
- Assembles a normalized representation of the method (signature + statements)
- Computes a SHA-256 hash of this representation
- Checks if a locked method with this hash already exists
- If found, references the existing method instead of creating a duplicate
- If not found, creates a new method with the hash for future deduplication
Benefits of Deduplication
- Eliminate duplicate code across your codebase
- Build a global library of battle-tested methods
- Methods improve through collective usage and refinement
- AI can reference existing methods instead of regenerating code
Creating Methods
You can create methods through the API or IDE. Here's how to create a method via the API:
POST /api/v1/method
{
"file": "file-uuid",
"name": "calculateDiscount",
"returnType": "float",
"parameters": []
}
The API will return the newly created method definition with a UUID. You can then add parameters and statements to build out the method logic.
Global Method Library
Stellify maintains a global library of locked methods that can be reused across projects. These are methods that have been proven reliable through usage and are marked as is_locked: true.
Searching the Global Library
Before creating a new method, you can search the global library to see if a suitable method already exists:
POST /api/v1/method/search-global
{
"name": "validateEmail",
"returnType": "bool",
"limit": 10
}
This returns locked methods sorted by usage count (most-used first), helping you find battle-tested implementations.
Locking Methods to Global Library
When you've created a high-quality, reusable method, you can lock it to the global library:
POST /api/v1/method/{uuid}/lock
{
"reasoning": "Pure utility method with no dependencies, validates email addresses using PHP's filter_var"
}
Once locked, this method becomes part of your global library and can be automatically reused when identical methods are needed.
Method Types
Stellify supports different method types for various contexts:
- Method - Standard class methods
- Constructor - Class constructors
- Migration - Database migration methods (up, down)
- Seeder - Database seeder methods (run)
- Factory - Model factory methods
- Route Handler - Route controller methods
Practical Example
Let's walk through creating a complete method with parameters and statements:
// 1. Create the method
POST /api/v1/method
{
"file": "file-uuid",
"name": "processPayment",
"returnType": "bool"
}
// 2. Add parameters
POST /api/v1/method/parameter
{
"method": "method-uuid",
"name": "amount",
"type": "float"
}
// 3. Add statements (the method body)
POST /api/v1/statement
{
"method": "method-uuid",
"data": [
"clause-uuid-1", // $total = $amount * 1.1;
"clause-uuid-2" // return $total;
]
}
// 4. The method is automatically hashed and ready for deduplication
Updating Methods
When you update a method, Stellify automatically recomputes its hash. If the updated method matches an existing locked method, you'll be notified and can choose to reference the existing implementation instead.
PUT /api/v1/method/{uuid}
{
"name": "processPayment",
"type": "Method",
"returnType": "bool",
"data": [/* updated statement UUIDs */]
}
// Response includes the updated method_hash
{
"status": 200,
"message": "Method updated.",
"method_hash": "b4c5d6e7..."
}
Best Practices
- Use descriptive names - Method names should clearly describe what the method does
- Keep methods focused - Each method should do one thing well
- Search before creating - Check the global library before creating new utility methods
- Lock reusable methods - If you create a pure utility method, lock it to share across projects
- Document complex logic - Use the reasoning field when locking methods to explain their purpose
You can review the full Methods API specification here.
- Previous
- Files
- Next
- Statements