Infraestructure Flashcards

(10 cards)

1
Q

How do you separate logic within your code?

A

I use a layered architecture: Controllers handle HTTP requests/responses, Services contain business logic, and Repositories manage data persistence. Each layer has a single responsibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why should Controllers be thin and free of business logic?

A

Thin controllers ensure better separation of concerns, making code more testable, maintainable, and scalable. Business logic belongs in Services, not Controllers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the role of a Service layer in application architecture?

A

The Service layer holds business rules, coordinates workflows, and orchestrates interactions between Controllers and Repositories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why should data access logic be isolated in Repositories?

A

Repositories abstract data access, ensuring persistence logic is decoupled from business rules and controllers, improving testability and maintainability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does layered separation improve code testability?

A

With logic isolated in Services and Repositories, you can unit test them independently of HTTP layers, ensuring more reliable and faster tests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are NestJS Guards and why are they important for logic separation?

A

Guards handle authorization and role checks outside of Controllers and Services, keeping security logic centralized and reusable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do Pipes help in keeping controllers clean?

A

Pipes handle validation and data transformation before it reaches the Controller or Service, reducing boilerplate and enforcing clean data contracts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s an example of a cross-cutting concern you’d handle with Middleware?

A

Logging, request timing, or global request validation are cross-cutting concerns best handled with Middleware to keep Controllers clean.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When would you introduce a Domain Service or Use Case layer?

A

For large projects with complex business logic, introducing Domain Services or Application Use Cases helps structure workflows clearly beyond simple Services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you explain code organization trade-offs in an interview?

A

I’d explain that layered separation improves code clarity, maintainability, and scalability, but acknowledge that for very small scripts, over-engineering layers could slow down delivery unnecessarily.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly