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

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>:

  1. NavigateToUserAction (users:navigate-to-user)

    • Navigate to user detail or edit page
    • Category: navigation
  2. CreateUserAction (users:create-user)

    • Create new user with validation
    • Category: crud
  3. UpdateUserAction (users:update-user)

    • Update existing user
    • Category: crud
  4. DeleteUserAction (users:delete-user)

    • Delete user (soft/hard)
    • Category: crud
  5. 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

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