# Code Review Guidelines **Version**: 1.0 **Project**: HTTP Sender Plugin (HSP) **Last Updated**: 2025-11-20 ## Purpose This document defines code review standards and processes for the HSP project, ensuring code quality, maintainability, security, and compliance with hexagonal architecture and TDD methodology. --- ## π― Code Review Objectives 1. **Quality Assurance**: Ensure code meets quality standards and best practices 2. **Knowledge Sharing**: Spread knowledge across the team 3. **Bug Prevention**: Catch defects before they reach production 4. **Architecture Compliance**: Verify hexagonal architecture boundaries 5. **TDD Verification**: Ensure Test-Driven Development methodology followed 6. **Security Review**: Identify potential vulnerabilities 7. **Performance Review**: Spot optimization opportunities 8. **Maintainability**: Ensure code is readable and maintainable --- ## π Review Process Overview ### 1. Pull Request Creation **Developer Responsibilities**: - [ ] Create feature branch from develop - [ ] Implement using TDD (RED-GREEN-REFACTOR) - [ ] Ensure all tests pass locally - [ ] Run coverage analysis (β₯95%/90%) - [ ] Self-review changes before creating PR - [ ] Create PR in Gitea with detailed description **PR Title Format**: ``` [TYPE] Brief description Examples: feat: implement BufferManager with FIFO overflow fix: correct retry logic in HttpPollingAdapter refactor: improve DataCollectionService naming test: add integration tests for gRPC transmission docs: update architecture diagrams ``` **PR Description Template**: ```markdown ## Summary [Brief description of changes] ## Related Requirements - Req-FR-XX: [requirement description] - Req-NFR-XX: [requirement description] ## TDD Compliance - [ ] Tests written before implementation - [ ] Git history shows RED-GREEN-REFACTOR cycles - [ ] All tests passing - [ ] Coverage: XX% line, XX% branch ## Testing - [ ] Unit tests added/updated - [ ] Integration tests added/updated (if applicable) - [ ] Manual testing performed ## Architecture Impact - [ ] Follows hexagonal architecture - [ ] Port interfaces not violated - [ ] Domain models remain pure - [ ] Adapters properly isolated ## Checklist - [ ] Self-reviewed code - [ ] Documentation updated - [ ] No commented-out code - [ ] No debug statements - [ ] Thread safety verified (if applicable) - [ ] CI pipeline passing ``` ### 2. Reviewer Assignment **Assignment Rules**: - At least **2 reviewers required** for all PRs - **1 senior developer** must review architectural changes - **QA engineer** must review test changes - **Security specialist** for security-sensitive code (authentication, data handling) **Review SLA**: - **Initial feedback**: Within 4 hours - **Complete review**: Within 24 hours - **Critical fixes**: Within 2 hours ### 3. Review Checklist Reviewers must verify all items in this checklist before approval. --- ## β Code Review Checklist ### 1. TDD Compliance β οΈ MANDATORY **Git History Verification**: - [ ] **Tests committed BEFORE implementation** (check timestamps) - [ ] Clear RED-GREEN-REFACTOR cycle in commit history - [ ] Commit messages follow TDD pattern (`test:`, `feat:`, `refactor:`) - [ ] Test-to-code commit ratio approximately 1:1 - [ ] No large implementation commits without prior test commits **Test Quality**: - [ ] Tests follow AAA pattern (Arrange-Act-Assert) - [ ] Test names describe behavior: `shouldDoX_whenY()` - [ ] Tests are independent (no shared state) - [ ] Tests are repeatable (deterministic results) - [ ] Edge cases covered (boundary conditions, empty inputs, nulls) - [ ] Error scenarios tested (exceptions, timeouts, failures) - [ ] Both happy path and sad path tested **Coverage Verification**: - [ ] JaCoCo report shows β₯95% line coverage - [ ] JaCoCo report shows β₯90% branch coverage - [ ] New code is covered by new tests (not just existing tests) - [ ] No critical paths left untested - [ ] CI pipeline coverage check passes ### 2. Hexagonal Architecture Compliance β οΈ MANDATORY **Port Boundary Enforcement**: - [ ] **Ports not bypassed**: Application core only depends on port interfaces - [ ] **No adapter imports in core**: Domain services don't import adapters - [ ] **Port interfaces defined**: All external interactions through ports - [ ] **Dependency direction correct**: Core β Ports β Adapters (not Core β Adapters) **Domain Model Purity**: - [ ] **No infrastructure in domain**: No HTTP, gRPC, file I/O in domain models - [ ] **Immutable value objects**: All domain models are immutable (final fields, no setters) - [ ] **Business logic in core**: Not in adapters - [ ] **Domain-specific language used**: Clear, business-focused names **Adapter Isolation**: - [ ] **Adapters implement ports**: Each adapter implements one or more port interfaces - [ ] **Infrastructure isolated**: HTTP, gRPC, file I/O only in adapters - [ ] **Adapters don't talk directly**: Communication through application core - [ ] **Configuration injected**: No hardcoded values in adapters **Package Structure Verification**: ``` β CORRECT: com.siemens.coreshield.hsp. βββ domain/ (models, pure Java) βββ application/ (services, depends on ports) βββ ports/ β βββ inbound/ (primary ports) β βββ outbound/ (secondary ports) βββ adapter/ βββ inbound/ (implements primary ports) βββ outbound/ (implements secondary ports) β WRONG: application.DataCollectionService imports adapter.HttpPollingAdapter domain.DiagnosticData imports io.grpc.stub ``` ### 3. Thread Safety (Concurrency Requirements) **Concurrency Review** (CRITICAL for HSP): - [ ] **Thread-safe where required**: BufferManager, CollectionStatistics - [ ] **Immutability used**: Value objects are thread-safe by design - [ ] **Proper synchronization**: `synchronized`, `Lock`, or concurrent collections - [ ] **Atomic operations**: Use `AtomicLong`, `AtomicInteger` for counters - [ ] **No race conditions**: Shared state properly protected - [ ] **Virtual threads used correctly**: For I/O-bound tasks (HTTP polling) - [ ] **Stress tests exist**: Concurrent tests with 1000+ threads (if applicable) **Common Thread Safety Issues**: ```java β WRONG: public class CollectionStatistics { private int totalPolls = 0; // Not thread-safe! public void incrementPolls() { totalPolls++; // Race condition } } β CORRECT: public class CollectionStatistics { private final AtomicInteger totalPolls = new AtomicInteger(0); public void incrementPolls() { totalPolls.incrementAndGet(); } } ``` ### 4. Code Quality **Readability**: - [ ] Clear, descriptive variable names (not `x`, `tmp`, `data123`) - [ ] Methods are small (<30 lines preferred) - [ ] Classes are focused (Single Responsibility Principle) - [ ] No commented-out code (use Git history instead) - [ ] No debug statements (`System.out.println`, excessive logging) - [ ] Complex logic has explanatory comments **SOLID Principles**: - [ ] **Single Responsibility**: Each class has one reason to change - [ ] **Open/Closed**: Open for extension, closed for modification - [ ] **Liskov Substitution**: Subtypes are substitutable for base types - [ ] **Interface Segregation**: Interfaces are client-specific, not fat - [ ] **Dependency Inversion**: Depend on abstractions (ports), not concretions **DRY (Don't Repeat Yourself)**: - [ ] No duplicated code (extract to methods/utilities) - [ ] No copy-paste programming - [ ] Common logic extracted to reusable components **Error Handling**: - [ ] Exceptions used appropriately (not for control flow) - [ ] Custom exceptions for domain errors - [ ] Resources cleaned up (try-with-resources, finally blocks) - [ ] Error messages are descriptive and actionable - [ ] Logging at appropriate levels (ERROR, WARN, INFO, DEBUG) ### 5. Performance **Algorithm Efficiency**: - [ ] Appropriate data structures used (O(1) for lookups if possible) - [ ] No unnecessary iterations (nested loops reviewed) - [ ] No premature optimization (profile first) - [ ] Database queries optimized (no N+1 queries, though HSP has no DB) **Resource Management**: - [ ] No memory leaks (collections not unbounded) - [ ] Connections properly closed (HTTP clients, gRPC channels) - [ ] Streams closed (try-with-resources) - [ ] Thread pools bounded (use virtual threads or fixed pools) **Caching** (if applicable): - [ ] Appropriate cache eviction strategy - [ ] Thread-safe cache access - [ ] Cache invalidation logic correct ### 6. Security **Input Validation**: - [ ] **All external inputs validated** (HTTP responses, configuration) - [ ] Size limits enforced (Req-FR-21: 1MB limit) - [ ] URL validation (protocol, host, port) - [ ] JSON validation (schema compliance) - [ ] No injection vulnerabilities (though HSP has limited attack surface) **Data Handling**: - [ ] **Sensitive data not logged** (no raw data in logs) - [ ] Base64 encoding used for binary data (Req-FR-22) - [ ] No credentials in code (use configuration) - [ ] Configuration file permissions documented **Error Information Disclosure**: - [ ] Error messages don't expose internals - [ ] Stack traces not sent to external systems - [ ] Logs sanitized (no sensitive data) ### 7. Documentation **Code Documentation**: - [ ] **Javadoc on all public APIs** (classes, methods, interfaces) - [ ] **Requirement traceability in Javadoc**: `@requirement Req-FR-XX` - [ ] Complex algorithms explained (comments or Javadoc) - [ ] Non-obvious behavior documented - [ ] TODOs tracked (with ticket numbers if applicable) **Javadoc Example**: ```java /** * Polls the specified HTTP endpoint and returns the response data. * *
This method implements the HTTP polling logic with retry and backoff
* strategy as specified in requirements Req-FR-17 and Req-FR-18.
*
* @requirement Req-FR-14 HTTP endpoint polling
* @requirement Req-FR-17 Retry mechanism (3 attempts, 5s interval)
* @requirement Req-FR-18 Linear backoff (5s to 300s)
*
* @param url the HTTP endpoint URL to poll
* @return a CompletableFuture containing the response data
* @throws PollingException if all retry attempts fail
*/
CompletableFuture