Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Components Overview

This section provides detailed information about each layer of the Locky architecture.

Layer Summary

LayerPurposeKey Components
Client LayerUser interfaces and CLI toolsAdmin CLI, App CLI, Anonymous CLI
API LayerHTTP routing and middlewareGin Router, JWT Auth, Casbin RBAC, Logger
Controller LayerRequest handling and validationPublic, Internal, Private Controllers
Business Logic LayerUse cases and business rulesUser, Group, Member, Role Usecases
Repository LayerData access abstractionUser, Group, Member, Role Repositories
Data LayerPersistent storageMySQL/TiDB, Redis, Casbin Policies

Component Interaction

Each layer communicates with adjacent layers through well-defined interfaces:

Client → API → Controller → Business Logic → Repository → Data

Dependency Flow

  • Downward Dependencies: Each layer depends only on the layer directly below it
  • Interface-Based: Layers communicate through interfaces, not concrete implementations
  • Testability: Each layer can be tested independently with mocks

Common Patterns

Repository Pattern

All data access goes through repositories, providing:

  • Abstraction from underlying storage
  • Consistent error handling
  • Transaction management
  • Query optimization

Use Case Pattern

Business logic is encapsulated in use cases:

  • Single responsibility per use case
  • Orchestration of multiple repositories
  • Business rule validation
  • Domain logic isolation

Middleware Pattern

Cross-cutting concerns are handled by middleware:

  • Authentication
  • Authorization
  • Logging
  • Error handling

Next Steps

Explore each layer in detail: