Understand the modular architecture of ScreenPulse
ScreenPulse follows a feature-based modular architecture using Angular best practices. The application is organized into distinct modules with clear responsibilities and boundaries.
The root module bootstraps the application and imports core infrastructure:
src/app/app.module.ts
import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { BrowserAnimationsModule } from '@angular/platform-browser/animations';import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'import { AppRoutingModule } from './app-routing.module';import { CoreModule } from './core/core.module';import { LayoutModule } from './layout/layout.module';import { AppComponent } from './app.component';import { ToastrModule } from 'ngx-toastr';import { ErrorInterceptor } from './core/interceptors/error.interceptor';import { AuthInterceptor } from './core/interceptors/auth.interceptor';@NgModule({ declarations: [AppComponent], imports: [ BrowserModule, AppRoutingModule, CoreModule, LayoutModule, BrowserAnimationsModule, HttpClientModule, ToastrModule.forRoot() ], providers: [ { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true, }, { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true, } ], bootstrap: [AppComponent]})export class AppModule { }
Notice how interceptors are registered using the HTTP_INTERCEPTORS token with multi: true. This allows multiple interceptors to process HTTP requests in sequence.
Angular’s dependency injection system manages service instances and component dependencies:
src/app/core/services/auth.service.ts
@Injectable({ providedIn: 'root' // Singleton service available application-wide})export class AuthService { private userMailSubject = new BehaviorSubject<string | null>(null); private userLoggedInSubject = new BehaviorSubject<boolean>(false); // Service logic...}
The providedIn: 'root' option creates a singleton service instance that’s available throughout the application without needing to add it to a module’s providers array.