# macjohnny/angular-memory-leak-demo architecture

> Architecture diagram of the GitHub repository macjohnny/angular-memory-leak-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/macjohnny/angular-memory-leak-demo
- Repository: https://github.com/macjohnny/angular-memory-leak-demo

## Overview

##### Project Type Analysis
This is a specialized Angular application designed to demonstrate memory leak scenarios, particularly focusing on Observable subscription patterns. The project structure follows a standard Angular application setup but with a specific educational purpose.

##### Main Components

a. Core Application Layer:
- AppModule (Root module)
- AppComponent (Root component)
- SubComponent (Component demonstrating memory leaks)
- DummyService (Service containing Observable patterns)

b. Runtime Environment:
- Browser Runtime
- Angular Framework Core
- Memory Management Layer

**┌─ Browser Window ─────────────────┐**
- ┌─ Angular Application ──────┐ │
- AppComponent             │ │
- SubComponent         │ │
- ┘ │
- ┘

**┌─ Services Layer ─────┐**
- DummyService        │
- Observables     │
- ┘

**┌─ Memory Heap ────────────────┐**
- Subscription Tracking       │
- Memory Allocation          │
- ┘

##### Key Elements to Highlight

a. Observable Flows:

b. Component Lifecycle:
- NgOnInit and ngOnDestroy hooks
- Subscription creation and cleanup points

c. Memory Impact:
- A side panel showing heap size monitoring
- Warning indicators for leak scenarios

##### Technical Details

- Angular version and key dependencies
- Browser runtime context
- Development server configuration
- Memory profiling integration points

##### Monitoring Integration

Integration with:
- Chrome DevTools
- Angular Debug Tools
- Memory Profiler

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Browser Window"
        BrowserRuntime["Browser Runtime"]
        DevTools["Chrome DevTools"]
        AngularDebug["Angular Debug Tools"]
        MemoryProfiler["Memory Profiler"]
    end

    subgraph "Angular Application"
        AppModule["App Module"]:::angular
        AppComponent["App Component"]:::angular
        SubComponent["Sub Component"]:::angular
        DummyService((Dummy Service)):::service
    end

    subgraph "Memory Management"
        MemoryHeap["Memory Heap"]:::memory
        SubTracking["Subscription Tracking"]:::memory
        MemAlloc["Memory Allocation"]:::memory
    end

    subgraph "Observable Flows"
        ProperSub["Proper Subscription"]:::good
        LeakySub["Leaky Subscription"]:::bad
    end

    subgraph "Environment"
        DevEnv["Development Environment"]:::env
        ProdEnv["Production Environment"]:::env
        E2E["E2E Testing"]:::testing
    end

    %% Relationships
    BrowserRuntime --> AppModule
    AppModule --> AppComponent
    AppComponent --> SubComponent
    SubComponent --> DummyService
    DummyService --> ProperSub
    DummyService --> LeakySub
    ProperSub --> MemoryHeap
    LeakySub -.-> MemoryHeap
    MemoryHeap --> SubTracking
    MemoryHeap --> MemAlloc
    DevTools --> MemoryProfiler
    AngularDebug --> MemoryProfiler
    MemoryProfiler --> MemoryHeap

    %% Click Events
    click AppModule "https://github.com/macjohnny/angular-memory-leak-demo/blob/master/src/app/app.module.ts"
    click AppComponent "https://github.com/macjohnny/angular-memory-leak-demo/blob/master/src/app/app.component.ts"
    click SubComponent "https://github.com/macjohnny/angular-memory-leak-demo/blob/master/src/app/sub.component.ts"
    click DummyService "https://github.com/macjohnny/angular-memory-leak-demo/blob/master/src/app/dummy.service.ts"
    click DevEnv "https://github.com/macjohnny/angular-memory-leak-demo/blob/master/src/environments/environment.ts"
    click ProdEnv "https://github.com/macjohnny/angular-memory-leak-demo/blob/master/src/environments/environment.prod.ts"
    click E2E "https://github.com/macjohnny/angular-memory-leak-demo/tree/master/e2e/"

    %% Styles
    classDef angular fill:#1976D2,color:white
    classDef service fill:#FF4081,color:white
    classDef memory fill:#FFC107,color:black
    classDef good fill:#4CAF50,color:white
    classDef bad fill:#F44336,color:white
    classDef env fill:#9C27B0,color:white
    classDef testing fill:#607D8B,color:white

    %% Legend
    subgraph Legend
        L1["Angular Component"]:::angular
        L2(("Service")):::service
        L3["Memory Element"]:::memory
        L4["Proper Flow"]:::good
        L5["Memory Leak"]:::bad
        L6["Environment"]:::env
        L7["Testing"]:::testing
    end
```
