> ## 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.

# Go SDK overview

> Complete guide to using PocketBase as a Go framework

PocketBase is a Go framework that you can use as a standalone library in your Go application. You can leverage all of PocketBase's features while maintaining full control over your application's architecture.

## Installation

Install PocketBase as a Go module:

```bash theme={null}
go get github.com/pocketbase/pocketbase
```

## Quick start

Create a basic PocketBase application:

```go main.go theme={null}
package main

import (
    "log"
    "github.com/pocketbase/pocketbase"
)

func main() {
    app := pocketbase.New()

    if err := app.Start(); err != nil {
        log.Fatal(err)
    }
}
```

Run your application:

```bash theme={null}
go run main.go serve
```

## Core concepts

### App instance

The `core.App` interface is the backbone of PocketBase. It provides access to all core functionality including database operations, file storage, event hooks, and more.

```go theme={null}
app := pocketbase.New()
```

### Event hooks

PocketBase uses an event-driven architecture. You can register hooks to execute custom logic at specific points:

```go theme={null}
app.OnRecordCreate().BindFunc(func(e *core.RecordEvent) error {
    // Your custom logic here
    return e.Next()
})
```

### Collections and records

Collections define the schema for your data. Records are instances of collection data:

```go theme={null}
record := core.NewRecord(collection)
record.Set("name", "John Doe")
app.Save(record)
```

## Configuration

Customize your PocketBase instance with configuration options:

```go theme={null}
app := pocketbase.NewWithConfig(pocketbase.Config{
    DefaultDataDir: "./pb_data",
    DefaultDev: true,
    HideStartBanner: false,
})
```

### Configuration options

<ParamField path="HideStartBanner" type="bool">
  Hide the default console server info on app startup.
</ParamField>

<ParamField path="DefaultDev" type="bool">
  Enable development mode (logs SQL statements to stderr).
</ParamField>

<ParamField path="DefaultDataDir" type="string">
  The data directory path (defaults to `./pb_data`).
</ParamField>

<ParamField path="DefaultEncryptionEnv" type="string">
  Environment variable name for encryption key.
</ParamField>

<ParamField path="DefaultQueryTimeout" type="time.Duration">
  Default timeout for database queries.
</ParamField>

## Running the application

### Start method

The `Start()` method registers default system commands and executes the root command:

```go theme={null}
if err := app.Start(); err != nil {
    log.Fatal(err)
}
```

### Bootstrap

Manually initialize the application before starting:

```go theme={null}
if err := app.Bootstrap(); err != nil {
    log.Fatal(err)
}

// Your custom initialization code here

if err := app.Start(); err != nil {
    log.Fatal(err)
}
```

## Custom commands

Add custom CLI commands to your application:

```go theme={null}
app.RootCmd.AddCommand(&cobra.Command{
    Use: "hello",
    Run: func(cmd *cobra.Command, args []string) {
        log.Println("Hello, PocketBase!")
    },
})
```

## Next steps

<CardGroup cols={2}>
  <Card title="App interface" icon="code" href="/go/app">
    Learn about the core App interface and its methods
  </Card>

  <Card title="Collections" icon="database" href="/go/collections">
    Work with collections and schema definitions
  </Card>

  <Card title="Records" icon="table" href="/go/records">
    Create, read, update, and delete records
  </Card>

  <Card title="Events" icon="bolt" href="/go/events">
    Register event hooks for custom logic
  </Card>
</CardGroup>
