mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 07:16:53 +05:00
feat(guardian): add guardian package - code quality analyzer
Add @puaros/guardian package v0.1.0 - code quality guardian for vibe coders and enterprise teams. Features: - Hardcode detection (magic numbers, magic strings) - Circular dependency detection - Naming convention enforcement (Clean Architecture) - Architecture violation detection - CLI tool with comprehensive reporting - 159 tests with 80%+ coverage - Smart suggestions for fixes - Built for AI-assisted development Built with Clean Architecture and DDD principles. Works with Claude, GPT, Copilot, Cursor, and any AI coding assistant.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { Email } from "../../domain/value-objects/Email"
|
||||
import { UserRegistrationService } from "../../domain/services/UserRegistrationService"
|
||||
import { UserMapper } from "../mappers/UserMapper"
|
||||
import { CreateUserRequest } from "../dtos/CreateUserRequest"
|
||||
import { UserResponseDto } from "../dtos/UserResponseDto"
|
||||
|
||||
/**
|
||||
* Use Case: CreateUser
|
||||
*
|
||||
* DDD Pattern: Application Service / Use Case
|
||||
* - Orchestrates domain operations
|
||||
* - Transaction boundary
|
||||
* - Converts DTOs to domain
|
||||
*
|
||||
* SOLID Principles:
|
||||
* - SRP: handles user creation workflow
|
||||
* - DIP: depends on abstractions (UserRegistrationService)
|
||||
* - OCP: can extend without modifying
|
||||
*
|
||||
* Clean Architecture:
|
||||
* - Application layer
|
||||
* - Uses domain services
|
||||
* - Returns DTOs (not domain entities)
|
||||
*
|
||||
* Clean Code:
|
||||
* - Verb+Noun naming: CreateUser
|
||||
* - Single purpose
|
||||
* - No business logic (delegated to domain)
|
||||
*/
|
||||
export class CreateUser {
|
||||
constructor(private readonly userRegistrationService: UserRegistrationService) {}
|
||||
|
||||
public async execute(request: CreateUserRequest): Promise<UserResponseDto> {
|
||||
this.validateRequest(request)
|
||||
|
||||
const email = Email.create(request.email)
|
||||
|
||||
const user = await this.userRegistrationService.registerUser(
|
||||
email,
|
||||
request.firstName,
|
||||
request.lastName,
|
||||
)
|
||||
|
||||
return UserMapper.toDto(user)
|
||||
}
|
||||
|
||||
private validateRequest(request: CreateUserRequest): void {
|
||||
if (!request.email?.trim()) {
|
||||
throw new Error("Email is required")
|
||||
}
|
||||
|
||||
if (!request.firstName?.trim()) {
|
||||
throw new Error("First name is required")
|
||||
}
|
||||
|
||||
if (!request.lastName?.trim()) {
|
||||
throw new Error("Last name is required")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user