Home Projects Portfolio Dashboard Export PDF Log in

Refining Reactive Architectures in EasySign_web

The Challenge of Complexity

When scaling a web application, technical debt often manifests as "spaghetti state" where business logic, UI concerns, and asynchronous streams become inextricably linked. In the EasySign_web project, we recently undertook a major refactoring effort to untangle these dependencies, aiming for a cleaner separation of concerns using Hexagonal Architecture principles combined with RxJS for reactive data flow.

The Approach

Our primary goal was to isolate our domain logic from external side effects. By treating our application as a core protected by ports and adapters, we ensured that the UI layer (HTML/CSS) doesn't know about the implementation details of our services.

Reactive Data Flow

We moved toward a centralized store pattern managed by RxJS, which allows components to subscribe to state changes without triggering global re-renders. This acts like a radio station: the state is the broadcast, and individual UI components are tuned in to only the frequencies they need.

import { BehaviorSubject, Observable } from 'rxjs';

export class StateManager<T> {
  private state$ = new BehaviorSubject<T>(this.initialState);

  getState(): Observable<T> {
    return this.state$.asObservable();
  }

  update(newState: Partial<T>): void {
    this.state$.next({ ...this.state$.getValue(), ...newState });
  }
}

This pattern ensures that when our data changes, subscribers are notified immediately and efficiently, preventing inconsistent UI states during complex operations.

Hexagonal Decoupling

By separating our Domain layer from the Infrastructure, we can swap out our UI implementation—or even our data providers—without rewriting business rules. Think of this like a household power outlet; it doesn't matter what appliance you plug in, as long as it conforms to the standard socket interface.

// Domain Port
interface SignRepository {
  save(data: Document): Observable<boolean>;
}

// Infrastructure Adapter
class ApiSignRepository implements SignRepository {
  save(data: Document): Observable<boolean> {
    return this.httpClient.post('/api/sign', data);
  }
}

Key Insight

Refactoring is not just about writing better code; it is about reducing the cognitive load required to maintain that code. By enforcing architectural boundaries, we allow developers to work on UI components without fear of breaking core domain logic, ultimately leading to a more resilient and scalable application.


Generated with Gitvlg.com

Refining Reactive Architectures in EasySign_web
ALI MAR NGOM

ALI MAR NGOM

Author

Share: