# thisiszoaib/angular-dark-mode architecture

> Architecture diagram of the GitHub repository thisiszoaib/angular-dark-mode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thisiszoaib/angular-dark-mode
- Repository: https://github.com/thisiszoaib/angular-dark-mode

## Overview

##### Project type and purpose
- This is a single-page front-end demo app built with Angular and Angular Material.
- Purpose: showcase how to add dark mode using custom Material themes (mat.theme() mixin).

##### File structure
- Top level:
- angular.json, tsconfig*.json, package.json → Angular CLI configuration, TypeScript setup, dependencies
- README.md, LICENSE → documentation
- e2e/ → end-to-end tests (Protractor)
- karma.conf.js, src/test.ts → unit tests (Karma + Jasmine)
- src/
- main.ts, polyfills.ts, index.html → bootstrap and browser setup
- styles.scss, assets/ → global styles and static assets
- environments/ → environment.ts + environment.prod.ts (theme defaults, feature flags)
- app/
– app.component.ts/​.html/​.scss → root component
– components/ (header, content) → UI building blocks
– sample-dialog/ → dialog component demo
– services/theme.service.ts → toggles and applies dark/light themes via Angular Material

##### README for additional insights
- Confirms it’s a companion demo for an article on dark mode in Angular Material.
- No backend or external APIs—pure frontend focus.

a. Main components:
- Angular CLI (build & serve)
- Webpack dev server (via Angular CLI)
- Browser runtime (runs bundle)
- AppModule (NgModule)
- AppComponent (root)
- HeaderComponent, ContentComponent, SampleDialogComponent
- ThemeService (injectable)
- Angular Material theming engine (Sass mixins, mat-theme)
- Environment configurations
- Test harnesses: Karma/Jasmine and Protractor

b. Relationships & interactions:
- index.html → loads main.js bundle → bootstrap AppModule
- AppModule provides ThemeService, Material modules, and declares components
- AppComponent hosts HeaderComponent & ContentComponent
- Components inject ThemeService to read/toggle theme settings
- SampleDialogComponent is instantiated by MatDialog service from a component
- ThemeService updates Angular Material theme at runtime (via CSS variables or Sass-generated classes)

c. Architectural patterns & principles:
- Component-based architecture (each UI piece is a reusable Angular component)
- Dependency Injection (ThemeService injected where needed)
- Single Responsibility (components handle UI; service handles theming logic)
- Environment-based configuration (switch default theme via environment.ts)

d. Key technologies & frameworks:
- Angular (CLI, modules, components, services, DI)
- Angular Material v19 (theming, MatDialog)
- TypeScript, RxJS
- Sass/SCSS for theming (mat.theme() mixin)
- Webpack (via CLI)
- Karma + Jasmine (unit tests)
- Protractor (e2e tests)

##### Important detail reminders
- Key files/settings: angular.json, environment files, main.ts, polyfills, styles.scss
- Where tests plug in: Karma config → unit tests; Protractor config → e2e tests
- Theme flow end-to-end: environment default → ThemeService → Angular Material core → CSS switch

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & Serve Layer
    subgraph "Build & Serve Layer"
        AngularCLI["Angular CLI / Webpack"]:::tools
    end

    %% Browser Runtime Layer
    subgraph "Browser Runtime Layer"
        IndexHTML["index.html"]:::config
        MainTS["main.ts"]:::config
        PolyfillsTS["polyfills.ts"]:::config
    end

    %% Application Layer
    subgraph "Application Layer"
        AppModule["AppModule"]:::frontend
        AppComponent["AppComponent"]:::frontend
        HeaderComponent["HeaderComponent"]:::frontend
        ContentComponent["ContentComponent"]:::frontend
        SampleDialogComponent["SampleDialogComponent"]:::frontend
        ThemeService["ThemeService"]:::service
    end

    %% Styling/Theming Layer
    subgraph "Styling/Theming Layer"
        EnvDev["environment.ts"]:::config
        EnvProd["environment.prod.ts"]:::config
        StylesSCSS["styles.scss"]:::config
        MatTheming["Angular Material theming engine"]:::service
    end

    %% Testing Layer
    subgraph "Testing Layer"
        subgraph "Unit Tests"
            KarmaConf["karma.conf.js"]:::testing
            TestTS["test.ts"]:::testing
            SpecApp["app.component.spec.ts"]:::testing
            SpecDialog["sample-dialog.component.spec.ts"]:::testing
        end
        subgraph "E2E Tests"
            ProtractorConf["protractor.conf.js"]:::testing
            E2ESpec["app.e2e-spec.ts"]:::testing
            E2EPO["app.po.ts"]:::testing
        end
    end

    %% Connections
    AngularCLI --> IndexHTML
    AngularCLI --> MainTS
    AngularCLI --> PolyfillsTS

    IndexHTML --> MainTS
    MainTS -->|"bootstrap"| AppModule

    AppModule -->|"declares"| AppComponent
    AppModule -->|"provides DI"| ThemeService

    AppComponent -->|"hosts"| HeaderComponent
    AppComponent -->|"hosts"| ContentComponent

    ContentComponent -->|"opens"| SampleDialogComponent
    ContentComponent -->|"injects"| ThemeService
    HeaderComponent -->|"injects"| ThemeService
    SampleDialogComponent -->|"injects"| ThemeService

    EnvDev -->|"default theme"| ThemeService
    EnvProd -->|"default theme"| ThemeService

    ThemeService -->|"toggle()"| MatTheming
    StylesSCSS --> MatTheming

    KarmaConf --> SpecApp
    KarmaConf --> SpecDialog
    TestTS --> SpecApp
    TestTS --> SpecDialog

    ProtractorConf --> E2ESpec
    ProtractorConf --> E2EPO

    %% Click Events
    click AngularCLI "https://github.com/thisiszoaib/angular-dark-mode/blob/master/angular.json"
    click IndexHTML "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/index.html"
    click MainTS "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/main.ts"
    click PolyfillsTS "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/polyfills.ts"
    click StylesSCSS "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/styles.scss"
    click EnvDev "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/environments/environment.ts"
    click EnvProd "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/environments/environment.prod.ts"
    click AppComponent "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/app.component.ts"
    click HeaderComponent "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/components/header/header.component.ts"
    click ContentComponent "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/components/content/content.component.ts"
    click SampleDialogComponent "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/sample-dialog/sample-dialog.component.ts"
    click ThemeService "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/services/theme.service.ts"
    click KarmaConf "https://github.com/thisiszoaib/angular-dark-mode/blob/master/karma.conf.js"
    click TestTS "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/test.ts"
    click SpecApp "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/app.component.spec.ts"
    click SpecDialog "https://github.com/thisiszoaib/angular-dark-mode/blob/master/src/app/sample-dialog/sample-dialog.component.spec.ts"
    click ProtractorConf "https://github.com/thisiszoaib/angular-dark-mode/blob/master/e2e/protractor.conf.js"
    click E2ESpec "https://github.com/thisiszoaib/angular-dark-mode/blob/master/e2e/src/app.e2e-spec.ts"
    click E2EPO "https://github.com/thisiszoaib/angular-dark-mode/blob/master/e2e/src/app.po.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef tools fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef testing fill:#f9f,stroke:#333,stroke-width:1px
```
