Skip to content

Conversation

@taiphanvan2k3
Copy link
Member

@taiphanvan2k3 taiphanvan2k3 commented Sep 20, 2025

Summary by CodeRabbit

  • New Features

    • JWT-based authentication, health endpoint, DI wiring for infrastructure, token & password services, repository implementation, and configurable email/file storage and caching settings.
  • Refactor

    • Standardized role handling to string-based roles and unified permission derivation; improved API error message extraction.
  • Documentation

    • Added extensive guides: Aggregates, Behaviors, DI behaviors, CI/CD, Commands, Naming Conventions, build/exception guidelines, and README updates.
  • Chores

    • GitHub Actions build workflow, Dependabot enabled, Sonar analyzer activated, and analyzer rule adjustments.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 20, 2025

Walkthrough

Refactors role handling from enum to string constants across domain, application, and web layers; adds infrastructure wiring (DI, EF repository, password hasher, JWT token service, caching, health checks); introduces config classes, many documentation files, CI automation (Dependabot + GitHub Actions), and startup/middleware updates. (48 words)

Changes

Cohort / File(s) Summary
Automation & CI
.github/dependabot.yml, .github/workflows/build.yml
Add Dependabot NuGet config and a .NET 8 GitHub Actions build/test/publish workflow with caching and artifact upload.
Build & Analysis
Directory.Build.props, .editorconfig
Enable/pin SonarAnalyzer.CSharp and adjust analyzer severities.
Documentation
docs/*, BUILD_SCRIPTS.md, EXCEPTION_GUIDELINES.md
Add many new docs (aggregates, behaviors, CI/CD, commands, DI/behaviors examples, naming, build scripts, exception guidelines) and update docs/README.md.
Domain: Role model & related
src/Domain/Enums/UserRole.cs (removed), src/Domain/Constants/UserRoles.cs, src/Domain/Entities/User.cs, src/Domain/Aggregates/User/UserAggregate.cs, src/Domain/Specifications/*, src/Domain/Services/UserDomainService.cs, src/Domain/Events/*, src/Domain/GlobalSuppressions.cs
Remove enum-based UserRole; add UserRoles string constants and helpers; convert role properties/methods from enums/arrays to string/List; update aggregates, specs, services, events, and add a GlobalSuppressions file.
Domain: Conversation aggregate
src/Domain/Aggregates/Conversation/ConversationAggregate.cs
Change method signatures to accept string role(s) and use qualified Entities.MessageType.
Application: Commands, DTOs, Behaviors
src/Application/Features/**, src/Application/Common/Behaviors/*, src/Application/Common/Exceptions/RequestProcessingException.cs
Convert many request/response role arrays to List<string>; update Login/CreateUser handlers to use string roles and UserAggregate.Create; adjust authorization behavior and ICurrentUser to use List<string>; add RequestProcessingException; change logging/transaction error wrapping.
Infrastructure: Config, DI, Services, Repositories
src/Infrastructure/Configuration/*, src/Infrastructure/Extensions/ServiceCollectionExtensions.cs, src/Infrastructure/Services/*, src/Infrastructure/Repositories/UserRepository.cs, src/Infrastructure/Infrastructure.csproj, src/Infrastructure/Exceptions/*, src/Infrastructure/Data/Contexts/DataContext.cs
Add strongly-typed settings (Jwt, Email, FileStorage); add DI extension to register DbContext, repos, services, caching, health checks; implement EF UserRepository; add PBKDF2 PasswordHasher; add TokenService (JWT generation/validation); add domain-event dispatch exception and wrap dispatch errors; remove base.OnConfiguring call.
Web.Api: Startup, controllers, filters, settings
src/Web.Api/Program.cs, src/Web.Api/Web.Api.csproj, src/Web.Api/appsettings.json, src/Web.Api/Controllers/V1/*, src/Web.Api/Filters/ValidateModelFilter.cs, src/Web.Api/Services/CurrentUserService.cs
Wire infrastructure services, JWT auth, health checks, global exception middleware, database ensure on startup; add JWT package and config sections in appsettings; change controller error payloads to use Error.Description; rename ValidateModelFilterValidateModelFilterAttribute; enhance CurrentUserService to expose List Roles and permission mapping.
Examples & Specs
src/Domain/Events/Examples/DomainEventsUsageExamples.cs, src/Domain/Specifications/Examples/SpecificationUsageExamples.cs, src/Domain/Specifications/UserSpecifications.cs
Update examples to use UserAggregate.Create, add logging in spec examples, and switch spec checks to HasRole helpers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant API as Web.Api (AuthController)
  participant App as Application (LoginCommandHandler)
  participant Repo as IUserRepository
  participant Hash as PasswordHasher
  participant Token as TokenService

  Client->>API: POST /api/v1/auth/login
  API->>App: Send LoginCommand
  App->>Repo: GetByEmailAsync(email)
  Repo-->>App: User (Roles: List<string>)
  App->>Hash: VerifyPassword(password, hash)
  alt valid
    App->>Token: GenerateAccessToken(UserInfo with Roles)
    Token-->>App: JWT + refresh token
    App-->>API: Success (tokens, user info)
    API-->>Client: 200 OK
  else invalid
    App-->>API: Failure (error)
    API-->>Client: 400 Bad Request (error.description)
  end
Loading
sequenceDiagram
  autonumber
  participant Host as Program.cs
  participant DI as ServiceCollectionExtensions
  participant DB as DataContext
  participant Auth as JWT Auth
  participant HC as HealthChecks

  Host->>DI: AddInfrastructureServices(configuration)
  DI->>DB: Register DbContext (SQL Server), Repositories, Services
  DI->>HC: AddHealthChecks(SQL, Redis?)
  Host->>Auth: Configure JWT Bearer (settings)
  Host->>Host: EnsureDatabaseCreatedAsync()
  Host->>DB: Database.EnsureCreatedAsync()
  Host->>Host: UseAuthentication/UseAuthorization, Map /health, UseMiddlewares
  Host->>Host: RunAsync()
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

I hop through code with whiskers bright,
Enums turned strings and JWTs take flight.
Health checks hum and caches dream,
Passwords salted like a stream.
CI drums daily — carrots for the team. 🥕


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 35598a8 and b06e76a.

📒 Files selected for processing (26)
  • .editorconfig (1 hunks)
  • BUILD_SCRIPTS.md (1 hunks)
  • EXCEPTION_GUIDELINES.md (1 hunks)
  • src/Application/Common/Behaviors/AuthorizationBehavior.cs (4 hunks)
  • src/Application/Common/Behaviors/LoggingBehavior.cs (2 hunks)
  • src/Application/Common/Behaviors/TransactionBehavior.cs (1 hunks)
  • src/Application/Common/Exceptions/RequestProcessingException.cs (1 hunks)
  • src/Application/Features/Auth/GetProfile/GetProfileQuery.cs (1 hunks)
  • src/Application/Features/Auth/Login/LoginCommand.cs (1 hunks)
  • src/Application/Features/User/CreateUser/CreateUserCommand.cs (1 hunks)
  • src/Application/Features/User/CreateUser/CreateUserCommandValidator.cs (1 hunks)
  • src/Application/Features/User/GetUsers/GetUsersQuery.cs (1 hunks)
  • src/Domain/Aggregates/User/UserAggregate.cs (6 hunks)
  • src/Domain/Entities/User.cs (2 hunks)
  • src/Domain/Events/Examples/DomainEventsUsageExamples.cs (6 hunks)
  • src/Domain/Events/User/UserCreatedEvent.cs (1 hunks)
  • src/Domain/GlobalSuppressions.cs (1 hunks)
  • src/Domain/Specifications/Examples/SpecificationUsageExamples.cs (5 hunks)
  • src/Infrastructure/Data/Contexts/DataContext.cs (0 hunks)
  • src/Infrastructure/Exceptions/DomainEventDispatchException.cs (1 hunks)
  • src/Infrastructure/Services/DomainEventDispatcher.cs (2 hunks)
  • src/Infrastructure/Services/PasswordHasher.cs (1 hunks)
  • src/Infrastructure/Services/TokenService.cs (1 hunks)
  • src/Web.Api/Filters/ValidateModelFilter.cs (1 hunks)
  • src/Web.Api/Program.cs (2 hunks)
  • src/Web.Api/Services/CurrentUserService.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/Infrastructure/Data/Contexts/DataContext.cs
✅ Files skipped from review due to trivial changes (3)
  • BUILD_SCRIPTS.md
  • .editorconfig
  • src/Domain/GlobalSuppressions.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Domain/Specifications/Examples/SpecificationUsageExamples.cs
  • src/Infrastructure/Services/PasswordHasher.cs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@taiphanvan2k3 taiphanvan2k3 merged commit 5cd882a into main Sep 20, 2025
1 check passed
@taiphanvan2k3 taiphanvan2k3 deleted the chore/write-documents-and-refactor-some-codes branch September 20, 2025 10:42
@taiphanvan2k3 taiphanvan2k3 self-assigned this Sep 20, 2025
taiphanvan2k3 added a commit that referenced this pull request Dec 22, 2025
…factor-some-codes

chore: Write document and refactor some codes
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