DEV Community

Alex Spinov
Alex Spinov

Posted on

Encore Has a Free Backend Framework — Type-Safe APIs With Auto-Generated Infrastructure

Define your API in TypeScript. Encore generates the infrastructure — databases, queues, cron jobs, service mesh — automatically.

What is Encore?

Encore is a backend development platform that uses your application code to understand your infrastructure needs. Write TypeScript services, and Encore provisions databases, pub/sub, caching, and deploys to your own cloud account.

Why Encore Is Unique

1. Type-Safe APIs

import { api } from "encore.dev/api";

interface CreateUserRequest {
  name: string;
  email: string;
}

interface User {
  id: string;
  name: string;
  email: string;
}

export const createUser = api(
  { method: "POST", path: "/users", expose: true },
  async (req: CreateUserRequest): Promise<User> => {
    const user = await db.insert(users).values(req).returning();
    return user[0];
  }
);
Enter fullscreen mode Exit fullscreen mode

Full type safety. Auto-generated API docs. Client SDKs generated from types.

2. Declarative Databases

import { SQLDatabase } from "encore.dev/storage/sqldb";

const db = new SQLDatabase("users", {
  migrations: "./migrations",
});

// Use in handlers
export const getUser = api(
  { method: "GET", path: "/users/:id", expose: true },
  async ({ id }: { id: string }): Promise<User> => {
    const row = await db.queryRow`SELECT * FROM users WHERE id = ${id}`;
    return row;
  }
);
Enter fullscreen mode Exit fullscreen mode

Encore provisions the database automatically. Migrations run on deploy.

3. Pub/Sub Built In

import { Topic, Subscription } from "encore.dev/pubsub";

interface OrderEvent {
  orderId: string;
  userId: string;
  total: number;
}

export const orderTopic = new Topic<OrderEvent>("order-events");

// Publish
await orderTopic.publish({ orderId: "123", userId: "abc", total: 99.99 });

// Subscribe
new Subscription(orderTopic, "send-email", {
  handler: async (event) => {
    await sendOrderConfirmation(event.userId, event.orderId);
  },
});
Enter fullscreen mode Exit fullscreen mode

4. Cron Jobs

import { CronJob } from "encore.dev/cron";

new CronJob("cleanup-expired", {
  title: "Clean up expired sessions",
  schedule: "0 * * * *", // Every hour
  endpoint: cleanupSessions,
});

export const cleanupSessions = api(
  { method: "POST", path: "/internal/cleanup" },
  async () => {
    await db.exec`DELETE FROM sessions WHERE expires_at < NOW()`;
  }
);
Enter fullscreen mode Exit fullscreen mode

5. Auto-Generated Architecture Diagram

Encore analyzes your code and generates:

  • Service dependency graph
  • API catalog with docs
  • Database relationships
  • Pub/sub flow visualization
  • Request tracing

6. Deploy to Your Cloud

encore app create my-app
encore run  # Local development
encore deploy --env=production  # Deploys to your AWS/GCP
Enter fullscreen mode Exit fullscreen mode

Encore deploys to YOUR cloud account (AWS or GCP), not a proprietary platform.

Encore vs Express vs NestJS

Encore Express NestJS
Type safety Built-in Manual Decorators
Database Declarative Manual setup Manual setup
Pub/Sub Built-in Manual Manual
Cron Built-in Via packages Via packages
Infra provisioning Automatic Manual Manual
API docs Auto-generated Via Swagger Via decorators
Tracing Built-in Via OpenTelemetry Via interceptors

Free Tier

Feature Free
Services Unlimited
Environments 2
Team members 1
Deploys/month Unlimited
Tracing 14 days

Getting Started

# Install
curl -L https://encore.dev/install.sh | bash

# Create app
encore app create my-app

# Run locally
encore run
Enter fullscreen mode Exit fullscreen mode

The Bottom Line

Encore makes infrastructure disappear. Define APIs in TypeScript, and the framework handles databases, queues, cron, and deployment. Less YAML, more product.


Need data tools? I build scraping solutions. Check my Apify actors or email spinov001@gmail.com.

Top comments (0)