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

# Encore Services

> How encore.service.ts files work to define APIs, databases, and business logic with automatic infrastructure

The core of any Leap-generated app is built with **Encore.ts services**. Each `encore.service.ts` file defines a microservice with its APIs, database connections, and business logic.

## How services work

```typescript theme={null}
// users/encore.service.ts
import { api } from "encore.dev/api";
import { SQLDatabase } from "encore.dev/storage/sqldb";

// This creates a database for this service
const db = new SQLDatabase("users", {
  migrations: "./migrations",
});

// This creates an HTTP API endpoint
export const createUser = api(
  { method: "POST", path: "/users" },
  async (data: CreateUserRequest): Promise<User> => {
    // Your business logic here
    return await db.queryRow`
      INSERT INTO users (email, name)
      VALUES (${data.email}, ${data.name})
      RETURNING *
    `;
  }
);
```

## What makes this special

* **Automatic infrastructure**: Encore creates the database, HTTP endpoints, and connections
* **Type safety**: Full TypeScript support across services with automatic validation
* **Service communication**: Services can call each other with type-safe RPC
* **Built-in observability**: Automatic tracing, metrics, and logging

<Info>
  **Learn more**: Encore.ts handles all the infrastructure complexity so you can focus on business logic. [See how services work →](https://encore.dev/docs/primitives/services-and-apis)
</Info>
