# Bricks Builder Theme Architecture

Reference material for Bricks Builder internals, key functions, and common filters.

## Theme Architecture

The Bricks theme (when available in a `bricks/` folder) follows this structure:

### Entry Points
- `functions.php` - Constants, global functions, loads `includes/init.php`
- `includes/init.php` - `Theme` singleton class that bootstraps all components

### Core Components (`includes/`)

| File | Class | Purpose |
|------|-------|---------|
| `elements.php` | `Elements` | Registers all builder elements |
| `elements/base.php` | `Element` | Abstract base class for elements |
| `frontend.php` | `Frontend` | Frontend rendering |
| `query.php` | `Query` | Custom query loop system |
| `api.php` | `Api` | REST API endpoints (`bricks/v1/`) |
| `templates.php` | `Templates` | Template management |
| `helpers.php` | `Helpers` | Utility functions |

### Namespace Convention

All classes use `Bricks` namespace. Integrations use nested namespaces:
```php
Bricks\Integrations\Dynamic_Data\Providers
Bricks\Integrations\Form\Init
```

## Key Functions

```php
bricks_is_builder()         // In builder (main or iframe)
bricks_is_builder_iframe()  // In builder iframe preview
bricks_is_frontend()        // Not in builder

bricks_render_dynamic_data( $content, $post_id, $context )
// Context: 'text', 'image', 'link'
```

## Common Filters

```php
// Modify element controls
add_filter( 'bricks/elements/{element_name}/controls', $callback );

// Modify element control groups
add_filter( 'bricks/elements/{element_name}/control_groups', $callback );

// Register custom dynamic data providers
add_filter( 'bricks/dynamic_data/register_providers', $callback );

// Modify rendered element output
add_filter( 'bricks/frontend/render_element', $callback, 10, 2 );
```

## WP-CLI

```bash
wp bricks regenerate_assets  # Regenerate CSS files
```

## Documentation

- Official: https://academy.bricksbuilder.io/
- Developer Docs: https://academy.bricksbuilder.io/collection/developer/
