> ## Documentation Index
> Fetch the complete documentation index at: https://forst-lang.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Language overview

> Aligned with Go, structural typing, and explicit control flow.

Forst extends familiar Go syntax with **structural typing**, constraints, and narrowing. Most `.ft` files look like Go. Where they differ, types behave like validated API schemas.

## Aligned with Go

Ordinary Forst programs look like Go. A minimal executable is identical on both sides:

<Tabs>
  <Tab title="Forst">
    ```ft theme={"languages":{"custom":["/languages/forst.json"]}}
    package main

    import "fmt"

    func main() {
    	fmt.Println("Hello World!")
    }
    ```
  </Tab>

  <Tab title="Generated Go">
    ```go theme={"languages":{"custom":["/languages/forst.json"]}}
    // forst build
    package main

    import "fmt"

    func main() {
    	fmt.Println("Hello World!")
    }
    ```
  </Tab>
</Tabs>

Use **`.ft`** files with the Forst CLI. The plain Go subset builds with `go build`. Forst extensions transpile to Go for production.

## Structural typing

Forst types are defined by **shape**. Inheritance trees are not used. Function parameters and return values use record syntax:

<Tabs>
  <Tab title="Forst">
    ```ft theme={"languages":{"custom":["/languages/forst.json"]}}
    type User = {
    	name: String,
    	email: String,
    }

    func greet(u: User): String {
    	return "Hello, " + u.name
    }
    ```
  </Tab>

  <Tab title="Generated Go">
    ```go theme={"languages":{"custom":["/languages/forst.json"]}}
    // forst build
    type User struct {
    	name  string
    	email string
    }

    func greet(u User) string {
    	return "Hello, " + u.name
    }
    ```
  </Tab>
</Tabs>

Anonymous records work at call sites:

<Tabs>
  <Tab title="Forst">
    ```ft theme={"languages":{"custom":["/languages/forst.json"]}}
    placeOrder({
    	stockKeepingUnit: "ITEM-1",
    	quantity:         2,
    })
    ```
  </Tab>

  <Tab title="Generated Go">
    ```go theme={"languages":{"custom":["/languages/forst.json"]}}
    // forst build
    placeOrder(PlaceOrderInput{
    	stockKeepingUnit: "ITEM-1",
    	quantity:         2,
    })
    ```
  </Tab>
</Tabs>

## Explicit where it matters

Forst embraces inference in clear cases (return types, obvious locals) but requires explicit annotations where ambiguity would hurt reliability:

* Function **parameters** always declare types
* Struct **fields** always declare types
* **Nil** initializations need an explicit type

## Control flow you can trace

Forst steers away from exceptions and implicit jumps. Errors are **values**. Validation uses **`ensure`** and **`is`**. Success and failure paths stay explicit. See [Ensure and narrowing](/docs/language/ensure-and-narrowing) and [Errors and Result](/docs/language/errors-and-result).

## Packages and imports

Forst uses Go style **packages** and **`import`** paths. You can also **import Go packages** and call qualified functions (`fmt.Println`, etc.). See [Go interop](/docs/interop/go) for current limits.

## File layout in a typical backend

A mixed Forst and Go service often looks like this:

```text theme={"languages":{"custom":["/languages/forst.json"]}}
my-service/
├── go.mod
├── handlers/
│   ├── orders.ft      # validated API handlers
│   └── catalog.ft
├── internal/
│   └── legacy.go      # existing Go code
├── ftconfig.json      # generate / dev discovery
└── generated/         # forst generate output (often gitignored)
    └── types.d.ts
```

## Caveats

Forst is not a full Go clone. Several areas are experimental or intentionally different.

* **No `panic` / `recover` / `try` / `catch`** as language features. Generated Go may still call panicking third party code.
* **Go import loading** is partial. See [Mix with Go packages § Caveats](/docs/interop/go#caveats).
* **Validation and narrowing** have real limits. See [Shapes and constraints](/docs/language/shapes-and-constraints#caveats), [Ensure and narrowing](/docs/language/ensure-and-narrowing#caveats), and [Errors and Result](/docs/language/errors-and-result#caveats).

## What to read next

<CardGroup cols={2}>
  <Card title="Shapes and constraints" icon="table-columns" href="/docs/language/shapes-and-constraints">
    Types as schemas with validation and less boilerplate.
  </Card>

  <Card title="Ensure and narrowing" icon="filter" href="/docs/language/ensure-and-narrowing">
    Runtime checks tied to the type system.
  </Card>

  <Card title="Providers (DI)" icon="plug" href="/docs/language/providers">
    Declare shared services with `use` and wire them at entry points.
  </Card>
</CardGroup>
