Skip to main content
Version: Next

LMES Backend Coding Standards

1. Naming Conventions​

1.1. Classes and Interfaces​

  • Use PascalCase for class and interface names.
  • Interfaces should start with an I prefix (e.g., IUserService).
  • Service implementations should end with AppService or Service (e.g., UserAppService).

1.2. Methods​

  • Use PascalCase for method names.
  • Async methods should end with the Async suffix (e.g., CreateAsync).

1.3. Variables and Parameters​

  • Use camelCase for local variables and method parameters.

2. Architectural Rules​

2.1. Layering​

  • Domain Layer: Contains entities, value objects, and domain logic. No dependencies on other layers.
  • Application Layer: Orchestrates domain objects to perform use cases. Depends on the Domain Layer.
  • Infrastructure Layer: Implements interfaces defined in the Domain Layer (repositories, external services).
  • API Layer: Exposes functionality via HTTP. Depends on the Application Layer.

2.2. Dependency Injection​

  • Use Constructor Injection for dependencies.
  • Avoid Service Locator pattern.

3. Error Handling​

  • Use exceptions for exceptional conditions, not for flow control.
  • Throw UserFriendlyException for errors that should be displayed to the user.
  • Log all unexpected exceptions at the application boundary.

4. Asynchronous Programming​

  • Use async and await for all I/O-bound operations.
  • Avoid Task.Run in ASP.NET Core applications unless necessary for background work.
  • Use CancellationToken to support request cancellation.

5. Database Access​

  • Use Repositories for data access.
  • Avoid using IQueryable directly in the API layer; project to DTOs in the Application layer.
  • Use AsNoTracking() for read-only queries to improve performance.

6. Documentation​

  • Public classes and methods should have XML documentation comments (///).
  • document complex business logic inline.

Note: Adhering to these standards ensures code maintainability and consistency across the team.