Skip to content

Application Layer (contexts/{context}/application/)

The sections below present the main package components for working with the application layer.

Expected folder structure:

application/
├── services/             # Application services
│   ├── AuthService.ts
│   └── index.ts
├── providers/            # Application providers
│   ├── ApplicationProvider.ts
│   └── index.ts
└── index.ts

For working with the application layer, you should:

  1. Prepare the infrastructure layer and provide the repositories we need through providers.
  2. Write our services (scenario logic and repository method implementation).
  3. Add services to ApplicationProvider and inject repositories from infrastructure into them.

Working with boundary providers was described in the infrastructure section, so here we will touch on this topic only in a general context.

When we have the infrastructure ready, we can write the service layer in the application/services folder. Most of the scenario logic is written by you, so there will be almost no ready-made components in this layer.

Basic service example

typescript
import { AuthRepository } from '${ContextName}/infrastructure/http/repositories';
import type { ILoginRequest } from '${ContextName}/domain/auth';

export class AuthService {
	constructor(private authRepository: AuthRepository) {}

	async login(request: ILoginRequest) {
        // Here you can place some login scenario (scenario logic, if any), or simply proxy the repository method
        return this.authRepository.login(request);
    }

	async current() {
		return this.authRepository.current().catch(() => undefined);
	}

    async logout() {
        return this.authRepository.logout();
    }
}