> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/pocketbase/pocketbase/llms.txt
> Use this file to discover all available pages before exploring further.

# Extensibility overview

> Learn how to extend PocketBase using Go, JavaScript, or event hooks

PocketBase is designed to be extended and customized to fit your specific needs. You can extend it in three primary ways:

## Extension methods

<CardGroup cols={3}>
  <Card title="Go framework" icon="code" href="/extending/go-framework">
    Use PocketBase as a Go framework for full control
  </Card>

  <Card title="JavaScript hooks" icon="js" href="/extending/javascript-hooks">
    Write hooks in JavaScript for quick customization
  </Card>

  <Card title="Event hooks" icon="webhook" href="/extending/event-hooks">
    React to application events with Go handlers
  </Card>
</CardGroup>

## When to use each approach

### Go framework

Use PocketBase as a Go framework when you need:

* Full control over the application lifecycle
* Maximum performance for custom logic
* Access to the complete Go ecosystem
* Custom commands and CLI tools
* Complex business logic that benefits from strong typing

### JavaScript hooks

Use JavaScript hooks when you need:

* Rapid prototyping and iteration
* Dynamic code reloading during development
* Simpler deployment (no recompilation required)
* Access to npm packages and the JavaScript ecosystem
* Quick customization without Go knowledge

### Event hooks

Use event hooks (in Go) when you need:

* To intercept and modify default behavior
* To add validation or business logic
* To trigger side effects (emails, webhooks, etc.)
* To integrate with external services
* To customize API responses

## Common use cases

<AccordionGroup>
  <Accordion title="Custom routes and APIs">
    Add custom endpoints to your PocketBase server:

    * **Go**: Use `app.OnServe()` to register routes with full control
    * **JavaScript**: Use `routerAdd()` to quickly add endpoints

    See [Custom routes](/extending/custom-routes) for details.
  </Accordion>

  <Accordion title="Data validation and transformation">
    Validate or transform data before it's saved:

    * **Go**: Use `app.OnRecordCreate()`, `app.OnRecordUpdate()` hooks
    * **JavaScript**: Use `onRecordCreate()`, `onRecordUpdate()` hooks

    See [Event hooks](/extending/event-hooks) for all available events.
  </Accordion>

  <Accordion title="External integrations">
    Integrate with external services and APIs:

    * **Go**: Full HTTP client control with the standard library
    * **JavaScript**: Use `$http.send()` for HTTP requests

    Both approaches support webhooks, email notifications, and third-party integrations.
  </Accordion>

  <Accordion title="Custom authentication">
    Implement custom authentication logic:

    * Intercept auth events with `OnRecordAuthRequest`
    * Add custom OAuth2 providers
    * Implement multi-factor authentication
    * Create custom password policies
  </Accordion>

  <Accordion title="Scheduled tasks">
    Run background jobs on a schedule:

    * **Go**: Use `app.Cron()` to register cron jobs
    * **JavaScript**: Use `cronAdd()` for scheduled tasks

    Perfect for data cleanup, report generation, and periodic syncs.
  </Accordion>
</AccordionGroup>

## Architecture overview

PocketBase's extensibility is built on a hook-based architecture:

```mermaid theme={null}
graph LR
    A[Request] --> B[Router]
    B --> C[Middlewares]
    C --> D[Event Hooks]
    D --> E[Core Logic]
    E --> F[Database]
    F --> E
    E --> D
    D --> G[Response]
```

At each stage, you can inject custom logic:

1. **Router level**: Add custom routes and endpoints
2. **Middleware level**: Process requests before they reach handlers
3. **Event hooks**: React to or modify core operations
4. **Database level**: Execute custom queries and transactions

## Development workflow

<Steps>
  <Step title="Choose your approach">
    Decide whether to use Go, JavaScript, or both based on your requirements.
  </Step>

  <Step title="Set up your environment">
    * For Go: Set up a Go project with PocketBase as a dependency
    * For JavaScript: Create a `pb_hooks` directory in your project
  </Step>

  <Step title="Implement your extensions">
    Write your custom code using the appropriate APIs and hooks.
  </Step>

  <Step title="Test your changes">
    Use PocketBase's built-in development mode to test your extensions.
  </Step>

  <Step title="Deploy">
    * Go: Compile to a binary and deploy
    * JavaScript: Deploy the `pb_hooks` directory alongside your executable
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Go framework guide" icon="code" href="/extending/go-framework">
    Learn how to use PocketBase as a Go framework
  </Card>

  <Card title="JavaScript hooks guide" icon="js" href="/extending/javascript-hooks">
    Get started with JavaScript hooks
  </Card>

  <Card title="Event hooks reference" icon="book" href="/extending/event-hooks">
    Explore all available event hooks
  </Card>

  <Card title="Custom routes" icon="route" href="/extending/custom-routes">
    Add custom API endpoints
  </Card>
</CardGroup>
