Skip to content

Latest commit

ย 

History

History
95 lines (77 loc) ยท 4.73 KB

AGENTS.md

File metadata and controls

95 lines (77 loc) ยท 4.73 KB

AGENTS.md

This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.

Build Commands

# Set JDK 21 (required โ€” record syntax, virtual threads)
export JAVA_HOME="D:\Develop\DevelopTool\StudyEnvironment\PhpWebStudy-Data\app\openjdk-21.0.9"

# Compile
cd Argus-backend && ./mvnw clean compile

# Run tests
./mvnw test

# Run single test
./mvnw test -Dtest=ClassName#methodName

# Package
./mvnw clean package -DskipTests

# Run app (local profile by default)
./mvnw spring-boot:run

Tech Stack

  • Java 21 with Spring Boot 3.5.0, Spring MVC (no WebFlux)
  • MyBatis-Plus 3.5.15 (not JdbcTemplate) for all DB access
  • PostgreSQL as the database (driver already in pom)
  • Maven with wrapper (mvnw)
  • Lombok 1.18.34 (available but currently unused โ€” entity getters/setters are hand-written)
  • JJWT 0.12.6 for JWT access tokens
  • Spring Security Crypto (BCrypt) for password hashing
  • Knife4j 4.5.0 for API documentation

Architecture

com.argus.rag
โ”œโ”€โ”€ ArgusBackendApplication        # @SpringBootApplication entry point
โ”œโ”€โ”€ common/                        # Shared infrastructure
โ”‚   โ”œโ”€โ”€ api/ApiResponse            # Unified response record: {success, data, message}
โ”‚   โ”œโ”€โ”€ enums/                     # SystemRole, UserStatus, GroupRole, etc.
โ”‚   โ””โ”€โ”€ exception/                 # BusinessException(400), ForbiddenException(403),
โ”‚                                  # UnauthorizedException(401), GlobalExceptionHandler
โ”œโ”€โ”€ auth/                          # Authentication & authorization
โ”‚   โ”œโ”€โ”€ config/                    # AuthProperties (@ConfigurationProperties prefix: argus.rag.auth),
โ”‚   โ”‚                              # AuthConfiguration (PasswordHasher bean, Clock bean),
โ”‚   โ”‚                              # DevAdminInitializer (@Profile("dev") seeds admin account)
โ”‚   โ”œโ”€โ”€ controller/AuthController  # /api/auth/{login,register,refresh,logout,me}
โ”‚   โ”œโ”€โ”€ service/                   # AuthService (login/register/refresh logic),
โ”‚   โ”‚                              # PasswordHasher interface, RefreshTokenRecord
โ”‚   โ”œโ”€โ”€ security/                  # JwtAuthenticationFilter (OncePerRequestFilter),
โ”‚   โ”‚                              # JwtAccessTokenService (issue/parse JWT),
โ”‚   โ”‚                              # RefreshTokenService (refresh token CRUD),
โ”‚   โ”‚                              # AuthCookieSupport (refresh token cookie)
โ”‚   โ”œโ”€โ”€ model/entity/UserRefreshToken  # MyBatis-Plus entity โ†’ user_refresh_tokens table
โ”‚   โ”œโ”€โ”€ mapper/UserRefreshTokenMapper  # MyBatis-Plus BaseMapper
โ”‚   โ””โ”€โ”€ CurrentUserService         # Extracts authenticated user from request attribute
โ””โ”€โ”€ user/                          # User management
    โ”œโ”€โ”€ controller/                # AccountController (/api/account/change-password),
    โ”‚                              # AdminUserController (/api/admin/users CRUD)
    โ”œโ”€โ”€ service/                   # AccountService, AdminUserService, UserQueryService
    โ”œโ”€โ”€ model/entity/User          # MyBatis-Plus entity โ†’ users table
    โ”œโ”€โ”€ model/dto/                 # Request records (ChangePassword, UpdateUserStatus, etc.)
    โ”œโ”€โ”€ model/vo/                  # Response records (AdminUserItemResponse)
    โ””โ”€โ”€ mapper/UserMapper          # MyBatis-Plus BaseMapper + custom XML methods

Key Conventions

MyBatis-Plus Pattern

  • All DB access uses BaseMapper + LambdaQueryWrapper, never JdbcTemplate
  • Entities extend nothing but use @TableName / @TableId(type = IdType.AUTO)
  • Complex queries with FOR UPDATE row locking go in src/main/resources/mappers/*.xml
  • Enums use default-enum-type-handler: org.apache.ibatis.type.EnumTypeHandler (stored as name() strings)

API Response Pattern

  • Every controller method returns ApiResponse<T> โ€” a record with success(), data(), message()
  • Never throw raw exceptions; throw BusinessException/ForbiddenException/UnauthorizedException which GlobalExceptionHandler maps to HTTP status codes

Auth Flow

  • JwtAuthenticationFilter extracts Bearer token โ†’ sets AuthenticatedUser as request attribute
  • CurrentUserService reads that attribute to provide CurrentUser record
  • Controllers call currentUserService.getRequiredCurrentUser(request) or requireSystemAdmin(request)
  • Refresh tokens stored in user_refresh_tokens table, sent as httpOnly cookie

Configuration

  • Active profile: local (default in application.yml)
  • Auth properties prefix: argus.rag.auth (maps to AuthProperties class)
  • MyBatis-Plus XML mappers: classpath*:/mappers/**/*.xml
  • Enum handling: Stored as VARCHAR using enum .name() values