Code Conventions Skill
Java / Backend Conventions
User Identity Type
User identity is always String throughout the codebase. This covers:
- Authentication and authorization
- API parameters and responses
- Permission checks
- Audit logs
- Resource owner, creator, reviewer, actor, submittedBy fields
Never introduce int, long, or bigint as user identifiers. The platform needs to support
external SSO/OIDC/SCIM identity sources whose UIDs are typically stable strings.
Exception Handling
- Use
LocalizedDomainException for user-facing error messages (supports i18n)
- Use
DomainBadRequestException for invalid client input
- Use
DomainNotFoundException for missing resources
- Use
DomainForbiddenException for authorization failures
- Exception classes live in
skillhub-domain/shared/exception/
Domain Services
- Return domain objects, not DTOs
- Contain business rules and state transitions
- Use domain events for cross-cutting side effects (publishing, notifications)
- Located in
domain/{submodule}/service/
Controllers
- Transport only: extract auth context, bind request params, wrap responses
- No business logic in controllers
- Located in
com.iflytek.skillhub.controller/
Query Repositories
- Handle read-model joins and presentation projection
- Return DTOs or presentation models
- Located in
com.iflytek.skillhub.repository/
- Named like
*QueryRepository (e.g., GovernanceQueryRepository, MySkillQueryRepository)
App Services
- Workflow orchestration: coordinate domain services and query repositories
- Should express "what this endpoint does", not "how it assembles DTOs"
- Located in
com.iflytek.skillhub.service/
Logging
- Use SLF4J with structured logging
- Use MDC for request tracing
- Log at appropriate levels: INFO for business events, DEBUG for troubleshooting, ERROR for failures
TypeScript / Frontend Conventions
Type Safety
- Strict TypeScript mode. No
any types.
- Use generated OpenAPI types from
web/src/api/generated/schema.d.ts for all API interactions.
- Additional types in
web/src/types/
Data Fetching
- Always use TanStack Query (
@tanstack/react-query) for server state
- Never use
useEffect for data fetching
- Use
openapi-fetch client for type-safe API calls
Component Composition
- Radix UI primitives:
@radix-ui/react-dropdown-menu, @radix-ui/react-select
- class-variance-authority (cva) for component variants
- clsx + tailwind-merge for class merging
cn() utility: web/src/shared/lib/utils.ts
- shadcn/ui is NOT used as a library
State Management
- TanStack Query for server state (API data, caching, invalidation)
- Zustand for local/UI state (theme, sidebar, modals, form state)
Feature-Sliced Design
| Layer |
Path |
Purpose |
| Pages |
web/src/pages/ |
Route-level page components |
| Features |
web/src/features/ |
Self-contained business features |
| Entities |
web/src/entities/ |
Domain entity display logic |
| Shared |
web/src/shared/ |
Reusable UI components, hooks, utilities |
Place code at the lowest appropriate layer. Do not put page-level logic in shared.
Styling
- Tailwind CSS for all styling
- Follow existing component patterns
- Use
cn() for conditional class merging
Internationalization
- Use i18next + react-i18next
- All user-facing text must be translatable
- Translation keys in
web/src/i18n/
Testing Philosophy
Backend
- JUnit 5 + Mockito + AssertJ
- Use Spring Boot test slices where possible (
@WebMvcTest, @DataJpaTest)
- Test behaviors, not implementations
- Use
make test-backend-app (includes -am for dependent modules)
- Never run
./mvnw -pl skillhub-app clean test directly — stale Maven cache causes misleading errors
Frontend
- Vitest for unit tests
- Playwright for E2E tests
- Test component behavior and user interactions
Common Pitfalls
- Maven multi-module: Always use
-am flag or Makefile targets to include dependent modules
- OpenAPI types: Must regenerate and commit after API contract changes
- String identity: Never use numeric types for user identifiers
- Controller business logic: Move to domain service or app service
- Complex read-models in app service: Extract to query repository
1---2name: code-conventions3description: Code style, logging, and testing conventions for SkillHub backend (Java) and frontend (TypeScript). Use when writing or reviewing code.4license: Apache-2.05---67# Code Conventions Skill89## Java / Backend Conventions1011### User Identity Type1213User identity is **always `String`** throughout the codebase. This covers:14- Authentication and authorization15- API parameters and responses16- Permission checks17- Audit logs18- Resource owner, creator, reviewer, actor, submittedBy fields1920Never introduce `int`, `long`, or `bigint` as user identifiers. The platform needs to support21external SSO/OIDC/SCIM identity sources whose UIDs are typically stable strings.2223### Exception Handling2425- Use `LocalizedDomainException` for user-facing error messages (supports i18n)26- Use `DomainBadRequestException` for invalid client input27- Use `DomainNotFoundException` for missing resources28- Use `DomainForbiddenException` for authorization failures29- Exception classes live in `skillhub-domain/shared/exception/`3031### Domain Services3233- Return domain objects, not DTOs34- Contain business rules and state transitions35- Use domain events for cross-cutting side effects (publishing, notifications)36- Located in `domain/{submodule}/service/`3738### Controllers3940- Transport only: extract auth context, bind request params, wrap responses41- No business logic in controllers42- Located in `com.iflytek.skillhub.controller/`4344### Query Repositories4546- Handle read-model joins and presentation projection47- Return DTOs or presentation models48- Located in `com.iflytek.skillhub.repository/`49- Named like `*QueryRepository` (e.g., `GovernanceQueryRepository`, `MySkillQueryRepository`)5051### App Services5253- Workflow orchestration: coordinate domain services and query repositories54- Should express "what this endpoint does", not "how it assembles DTOs"55- Located in `com.iflytek.skillhub.service/`5657### Logging5859- Use SLF4J with structured logging60- Use MDC for request tracing61- Log at appropriate levels: INFO for business events, DEBUG for troubleshooting, ERROR for failures6263## TypeScript / Frontend Conventions6465### Type Safety6667- Strict TypeScript mode. No `any` types.68- Use generated OpenAPI types from `web/src/api/generated/schema.d.ts` for all API interactions.69- Additional types in `web/src/types/`7071### Data Fetching7273- **Always use TanStack Query** (`@tanstack/react-query`) for server state74- **Never use `useEffect`** for data fetching75- Use `openapi-fetch` client for type-safe API calls7677### Component Composition7879- **Radix UI** primitives: `@radix-ui/react-dropdown-menu`, `@radix-ui/react-select`80- **class-variance-authority** (cva) for component variants81- **clsx** + **tailwind-merge** for class merging82- **`cn()` utility**: `web/src/shared/lib/utils.ts`83- shadcn/ui is NOT used as a library8485### State Management8687- **TanStack Query** for server state (API data, caching, invalidation)88- **Zustand** for local/UI state (theme, sidebar, modals, form state)8990### Feature-Sliced Design9192| Layer | Path | Purpose |93|-------|------|---------|94| Pages | `web/src/pages/` | Route-level page components |95| Features | `web/src/features/` | Self-contained business features |96| Entities | `web/src/entities/` | Domain entity display logic |97| Shared | `web/src/shared/` | Reusable UI components, hooks, utilities |9899Place code at the lowest appropriate layer. Do not put page-level logic in shared.100101### Styling102103- Tailwind CSS for all styling104- Follow existing component patterns105- Use `cn()` for conditional class merging106107### Internationalization108109- Use i18next + react-i18next110- All user-facing text must be translatable111- Translation keys in `web/src/i18n/`112113## Testing Philosophy114115### Backend116117- JUnit 5 + Mockito + AssertJ118- Use Spring Boot test slices where possible (`@WebMvcTest`, `@DataJpaTest`)119- Test behaviors, not implementations120- Use `make test-backend-app` (includes `-am` for dependent modules)121- Never run `./mvnw -pl skillhub-app clean test` directly — stale Maven cache causes misleading errors122123### Frontend124125- Vitest for unit tests126- Playwright for E2E tests127- Test component behavior and user interactions128129## Common Pitfalls130131- **Maven multi-module**: Always use `-am` flag or Makefile targets to include dependent modules132- **OpenAPI types**: Must regenerate and commit after API contract changes133- **String identity**: Never use numeric types for user identifiers134- **Controller business logic**: Move to domain service or app service135- **Complex read-models in app service**: Extract to query repository