All skills
encoredev avatar

/service

@741d95a official
by Encoreencoredev/skills28 stars
5

Implement Encore.ts services and lay out an application using `encore.service.ts`, service directories, systems, and `~encore/clients`. For service boundaries and architecture decisions, use `encore-architecture`.

  • 1 file
  • 3.1 KB
  • Updated 4 weeks ago
  • GitHub

Use this Skill: https://skilld.dev/gh/encoredev/skills/service

This session only. Nothing lands on disk.

SKILL.md

โ‰ˆ56 tokens always: the name and description. โ‰ˆ632 when used: this file.

Encore Service Structure

Instructions

Creating a Service

Every Encore service needs an encore.service.ts file:

// encore.service.ts
import { Service } from "encore.dev/service";

export default new Service("my-service");

Minimal Service Structure

my-service/
โ”œโ”€โ”€ encore.service.ts    # Service definition (required)
โ”œโ”€โ”€ api.ts               # API endpoints
โ””โ”€โ”€ db.ts                # Database (if needed)

Application Patterns

Single Service

A service can be defined at the application root:

my-app/
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ encore.app
โ”œโ”€โ”€ encore.service.ts
โ”œโ”€โ”€ api.ts
โ”œโ”€โ”€ db.ts
โ””โ”€โ”€ migrations/
    โ””โ”€โ”€ 001_initial.up.sql

Multi-Service

Each service lives in its own directory:

my-app/
โ”œโ”€โ”€ encore.app
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ user/
โ”‚   โ”œโ”€โ”€ encore.service.ts
โ”‚   โ”œโ”€โ”€ api.ts
โ”‚   โ””โ”€โ”€ db.ts
โ”œโ”€โ”€ order/
โ”‚   โ”œโ”€โ”€ encore.service.ts
โ”‚   โ”œโ”€โ”€ api.ts
โ”‚   โ””โ”€โ”€ db.ts
โ””โ”€โ”€ notification/
    โ”œโ”€โ”€ encore.service.ts
    โ””โ”€โ”€ api.ts

Large Application (System-based)

Group related services into systems:

my-app/
โ”œโ”€โ”€ encore.app
โ”œโ”€โ”€ commerce/
โ”‚   โ”œโ”€โ”€ order/
โ”‚   โ”‚   โ””โ”€โ”€ encore.service.ts
โ”‚   โ”œโ”€โ”€ cart/
โ”‚   โ”‚   โ””โ”€โ”€ encore.service.ts
โ”‚   โ””โ”€โ”€ payment/
โ”‚       โ””โ”€โ”€ encore.service.ts
โ”œโ”€โ”€ identity/
โ”‚   โ”œโ”€โ”€ user/
โ”‚   โ”‚   โ””โ”€โ”€ encore.service.ts
โ”‚   โ””โ”€โ”€ auth/
โ”‚       โ””โ”€โ”€ encore.service.ts
โ””โ”€โ”€ comms/
    โ”œโ”€โ”€ email/
    โ”‚   โ””โ”€โ”€ encore.service.ts
    โ””โ”€โ”€ push/
        โ””โ”€โ”€ encore.service.ts

Service-to-Service Calls

Import other services from ~encore/clients:

import { user } from "~encore/clients";

export const getOrderWithUser = api(
  { method: "GET", path: "/orders/:id", expose: true },
  async ({ id }): Promise<OrderWithUser> => {
    const order = await getOrder(id);
    const orderUser = await user.get({ id: order.userId });
    return { ...order, user: orderUser };
  }
);

Guidelines

  • Services cannot be nested within other services
  • Use ~encore/clients for cross-service calls (never direct imports)
  • Each service can have its own database
  • Service names should be lowercase, descriptive
  • Don't create services just for code organization - use folders instead
  • Use encore-architecture when the service boundaries have not been decided

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 741d95a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 weeks ago
Other metadata
when_to_use
User wants to add or modify an Encore.ts service or microservice, implement an already-chosen service layout, organize service files and directories, group services into system folders, or call another service. Trigger phrases: "add a service", "create a service", "add a microservice", "encore.service.ts", "lay out these services", "service directory", "systems folder", "~encore/clients".
  • TypeScript
  • encore
  • microservices
  • service-architecture
  • directory-structure
  • domain-driven-design
  • monolith
  • service-boundaries
  • system-design

README badge

README badge for encoredev/skills/service

Helps architects plan Encore.ts application structure by defining service boundaries, directory layouts, and multi-service patterns. Covers single-service setups, multi-service decomposition with domain boundaries, system-based hierarchies, and service-to-service communication via the `~encore/clients` pattern.

Generated from the current SKILL.md.

When should I split my Encore app into multiple services?
Split when services have different scaling needs, different deployment cycles, or clear domain boundaries. Keep services together if they share database tables or have tightly coupled logic. Use folders instead of services if you're just organizing code.
Can services be nested within other services?
No. Services cannot be nested within other services in Encore.
How do services communicate with each other?
Import other services from the `~encore/clients` generated package and call their exported APIs directly. Never use direct imports between services.
Do I need a database for every service?
No. Each service can have its own database if needed, but it's optional. Services can be API-only.
What's the minimum required file for an Encore service?
An `encore.service.ts` file that exports a Service instance. You can add `api.ts` and `db.ts` as needed.

Generated from the current SKILL.md. These answers refresh after source changes.