Skip to content

Conversation

@rokuosan
Copy link
Member

Summary

Complete refactor of the backend from layered architecture to clean architecture with comprehensive test coverage and CI/CD pipeline.

🏗️ Architecture Changes

  • Clean Architecture: Domain → Usecase → Adapter → Infrastructure layers
  • Dependency Injection: Google Wire for automatic DI container generation
  • Interface-based Design: All dependencies are interfaces for better testability

🧪 Testing Implementation

  • Unit Tests: All layers covered with comprehensive test suites
  • Mock Repositories: Testify-based mocks for isolation
  • Database Tests: sqlmock for repository layer testing
  • HTTP Tests: Handler layer testing with httptest

🚀 CI/CD Pipeline

  • GitHub Actions: Automated testing on push/PR
  • MariaDB Service: Database container for integration tests
  • Code Coverage: Built-in coverage reporting
  • Code Quality: Linting, formatting, and build verification

📊 Test Results

✅ entity     - PASS (business logic tests)
✅ repository - PASS (database layer tests)  
✅ usecase    - PASS (business workflow tests)
✅ handler    - PASS (HTTP API tests)
✅ config     - PASS (configuration tests)

🔧 Key Features

  • N+1 Problem Solved: Batch queries for related data
  • Transaction Management: Proper transaction boundaries in usecase layer
  • Error Handling: Unified error types and HTTP status mapping
  • Type Safety: Strong typing throughout all layers

📦 Breaking Changes

  • Complete API handler rewrite (same endpoints, new implementation)
  • Database initialization moved to infrastructure layer
  • Configuration system enhanced with test environment support

🛠️ Development Workflow

# Run tests locally
make test

# Run with coverage
make test-coverage

# Docker-based testing
make docker-test

# Linting
make lint

Test Plan

  • All existing functionality preserved
  • API endpoints maintain compatibility
  • Database schema unchanged
  • CI pipeline validates all changes
  • No breaking changes to frontend integration

This refactor significantly improves code maintainability, testability, and development velocity while maintaining full backward compatibility.

rokuosan added 3 commits June 24, 2025 02:11
…ounts

- Removed old service implementations for posts, post_tags, products, tags, and user accounts.
- Introduced new use case layer for posts and user accounts, encapsulating business logic.
- Added DTOs for creating and updating posts and user accounts.
- Implemented dependency injection using Wire for better modularity and testability.
- Updated main application entry point to initialize the server with dependency injection.
- Upgraded Go version in Dockerfile to 1.24.
…ries, and update Docker configuration

- Created unit tests for Annotation, Post, Tag, and UserAccount entities.
- Implemented Post and UserAccount use cases with corresponding tests.
- Added mock repositories for testing purposes.
- Introduced fixture functions for creating test data.
- Updated Docker Compose configuration to comment out Traefik service and expose app on port 8080.
## Features
- **GitHub Actions**: Automated testing on push/PR
- **Test Environment**: Docker Compose setup for isolated testing
- **Database Migration**: Auto-migration in CI
- **Coverage Reports**: Built-in coverage analysis
- **Code Quality**: Linting and formatting checks

## CI Pipeline
- Test job: MariaDB service + migration + full test suite
- Lint job: golangci-lint + go fmt + go vet
- Build job: Binary compilation verification

## Local Development
- `make test`: Run tests
- `make test-coverage`: Generate coverage report
- `make docker-test`: Run tests in Docker environment

Ensures code quality and prevents regressions in the new clean architecture.
@rokuosan rokuosan changed the base branch from main to refactor/all-backend June 24, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants