User Management - Reference Implementation
Complete reference implementation showcasing all module system capabilities
๐ฅ User Management - Reference Implementation
This module is the definitive reference implementation for GoGrab Space modules, demonstrating all capabilities of the module system.
๐ Module Information
| Property | Value |
|---|---|
| ID | user-management |
| Version | 1.0.0 |
| Library | @libs-core/user-management |
| Base Path | /users |
| Status | โ Production Ready |
| Tests | 131 passing (100% coverage) |
๐๏ธ Architecture
Complete Directory Structure
libs/core/user-management/
โโโ src/
โ โโโ lib/
โ โ โโโ components/ # UI Components
โ โ โ โโโ user-list/
โ โ โ โโโ user-card/
โ โ โ โโโ user-detail/
โ โ โ โโโ user-form/
โ โ โ โโโ user-filters/
โ โ โโโ embeddables/ # Embeddable Widgets
โ โ โ โโโ user-list-widget/
โ โ โโโ actions/ # Public Actions
โ โ โ โโโ navigate-to-user.action.ts
โ โ โ โโโ create-user.action.ts
โ โ โ โโโ update-user.action.ts
โ โ โ โโโ delete-user.action.ts
โ โ โ โโโ bulk-update-roles.action.ts
โ โ โโโ services/ # Module Services
โ โ โ โโโ user-api.service.ts
โ โ โ โโโ user.service.ts
โ โ โโโ data/ # Data Layer
โ โ โ โโโ repositories/
โ โ โ โโโ user.repository.ts
โ โ โ โโโ role.repository.ts
โ โ โโโ state/ # State Management (NGXS)
โ โ โ โโโ user.state.ts
โ โ โ โโโ user.actions.ts
โ โ โโโ events/ # Domain Events
โ โ โ โโโ user.events.ts
โ โ โโโ models/ # Types & Interfaces
โ โ โ โโโ user.model.ts
โ โ โ โโโ user-api.model.ts
โ โ โโโ mocks/ # Mock Data
โ โ โ โโโ user-mock-api.ts
โ โ โ โโโ user-mock-data.ts
โ โ โโโ user-management.module.ts
โ โ โโโ user-management.routes.ts
โ โโโ index.ts
โ โโโ test-setup.ts
๐ฏ Key Features
1. Complete CRUD Operations
- Create: Full user creation with role assignment
- Read: List, detail views with filtering
- Update: Individual and bulk updates
- Delete: Soft/hard delete with confirmation
2. Embeddable Widget
UserListWidgetComponent - A compact, reusable widget for embedding in dashboards.
Inputs:
| Input | Type | Default | Description |
|---|---|---|---|
limit |
number | 10 | Max users to display |
roleFilter |
string | undefined | Filter by role |
showAvatar |
boolean | true | Show user avatars |
showStatus |
boolean | true | Show status badges |
Outputs:
| Output | Type | Description |
|---|---|---|
userSelected |
User | Emitted when user clicked |
Usage:
<lib-user-list-widget
[limit]="5"
[roleFilter]="'admin'"
(userSelected)="handleUserSelected($event)"
/>
3. Public Actions (5 Total)
All actions use @PublicAction decorator and implement ExecutableAction<T>:
NavigateToUserAction (
users:navigate-to-user)- Navigate to user detail or edit page
- Category:
navigation
CreateUserAction (
users:create-user)- Create new user with validation
- Category:
crud
UpdateUserAction (
users:update-user)- Update existing user
- Category:
crud
DeleteUserAction (
users:delete-user)- Delete user (soft/hard)
- Category:
crud
BulkUpdateRolesAction (
users:bulk-update-roles)- Batch role assignment
- Category:
workflow
๐ก Implementation Patterns
RxJS-First Architecture
// All actions use Observable-based execution
execute(params: Input, context: ActionContext): Observable<Output> {
return this.validate(params).pipe(
switchMap(isValid => {
if (!isValid) return of({ success: false, error: 'Invalid params' });
return this.userService.createUser(params).pipe(
tap(() => this.logger.info('User created')),
map(user => ({ success: true, userId: user.id })),
catchError(err => of({ success: false, error: err.message }))
);
})
);
}
State Management (NGXS)
@State<UserStateModel>({ name: 'users', defaults: initialState })
export class UserState {
@Action(UserActions.LoadUsers)
loadUsers(ctx: StateContext<UserStateModel>) {
return this.userService.getUsers().pipe(
tap(users => ctx.patchState({ users, loading: false }))
);
}
}
๐งช Testing
Test Coverage
- โ 131 tests passing
- โ 100% action coverage
- โ Integration with NGXS
- โ Mock API functional
Example Test
describe('CreateUserAction', () => {
it('should create user successfully', async () => {
const result = await lastValueFrom(
action.execute({ email: '[email protected]', ... }, context)
);
expect(result.success).toBe(true);
expect(result.userId).toBeDefined();
});
});
๐ Related Documentation
Last Updated: December 3, 2025 Status: โ Production Reference Session ID: 3