# prophet-99/ng-conf-rxjs-cache architecture

> Architecture diagram of the GitHub repository prophet-99/ng-conf-rxjs-cache, 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/prophet-99/ng-conf-rxjs-cache
- Repository: https://github.com/prophet-99/ng-conf-rxjs-cache

## Overview

##### Main components
- Frontend (Angular 18)
– App Shell (AppModule + AppComponent)
– HTTP Interceptor (http-security.interceptor.ts)
– Services
- AuthService
- DemoService
– State Services (RxJS stores)
- apiKeyStateService
- accessTokenStateService
- jwtStateService
– UI Components
- AuthComponent
- DemoComponent
- MockComponent
- Backend (NestJS 10)
– Modules
- ApiKeyModule
· api-key.controller.ts
· api-key.service.ts
· api-key.guard.ts
- AuthModule
· auth.controller.ts
· auth.service.ts
· jwt.strategy.ts
· jwt-auth.guard.ts
- DemoModule
· demo.controller.ts
· demo.module.ts
– Application Entry
- main.ts
- AppModule (app.module.ts)
- (Optional) Persistence Layer
– In-memory or external store for API keys/tokens (not explicit in code but represent as “Cache Store / DB”)

##### Relationships and data flow
- Frontend → HTTP Interceptor → AuthService / DemoService → RxJS State Services → API calls
- Interceptor attaches API key or JWT token from the relevant state service before dispatching HTTP requests.
- Backend Controllers receive requests → Guards validate API key or JWT → Services handle business logic → (Cache store) → Return responses
- Demo flow: DemoComponent triggers DemoService → interceptor attaches credentials → demo.controller returns dummy data.

##### Architectural patterns
- Frontend
– Module-component-service pattern
– Centralized state management using RxJS (behavior subjects, shareReplay, retryWhen, etc.)
– Single HTTP interceptor for cross-cutting concerns (security headers, token attachment)
- Backend
– Modular design (API Key / Auth / Demo modules)
– Guard-based authorization (API key guard, JWT guard)
– Strategy pattern for JWT validation (Passport JWT strategy)
– Dependency Injection for controllers and services

##### Technologies & frameworks to annotate
- Angular 18 (TypeScript, RxJS)
- NestJS 10 (TypeScript, Express under the hood, Passport for JWT)
- RxJS operators (shareReplay, switchMap, catchError, retry)
- JWT for authentication
- In-memory caching or external cache (represent generically)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer (Browser)"
        direction TB
        subgraph "App Shell"
            direction TB
            AppModuleFE["AppModule"]:::module
            AppComponentFE["AppComponent"]:::ui
        end
        subgraph "UI Components"
            direction TB
            AuthComponent["AuthComponent"]:::ui
            DemoComponent["DemoComponent"]:::ui
            MockComponent["MockComponent"]:::ui
        end
        subgraph "Service Layer"
            direction TB
            AuthServiceFE["AuthService"]:::service
            DemoServiceFE["DemoService"]:::service
            HttpInterceptor["HTTP Interceptor"]:::interceptor
        end
        subgraph "State Layer"
            direction TB
            ApiKeyStateService["apiKeyStateService"]:::state
            AccessTokenStateService["accessTokenStateService"]:::state
            JwtStateService["jwtStateService"]:::state
        end
    end

    %% Backend Layer
    subgraph "Backend Layer (API Server)"
        direction TB
        MainEntry["main.ts"]:::module
        AppModuleBE["AppModule"]:::module
        subgraph "API Key Module"
            direction TB
            ApiKeyModule["ApiKeyModule"]:::module
            ApiKeyController["ApiKeyController"]:::backendService
            ApiKeyGuard["ApiKeyGuard"]:::guard
            ApiKeyServiceBE["ApiKeyService"]:::backendService
        end
        subgraph "Auth Module"
            direction TB
            AuthModuleBE["AuthModule"]:::module
            AuthControllerBE["AuthController"]:::backendService
            JwtAuthGuard["JwtAuthGuard"]:::guard
            JwtStrategy["JwtStrategy"]:::backendService
            AuthServiceBE["AuthService"]:::backendService
        end
        subgraph "Demo Module"
            direction TB
            DemoModuleBE["DemoModule"]:::module
            DemoController["DemoController"]:::backendService
        end
        CacheStore["Cache Store / DB"]:::db
    end

    %% Frontend Flow
    AuthComponent -->|uses| AuthServiceFE
    DemoComponent -->|uses| DemoServiceFE
    MockComponent -->|uses| DemoServiceFE

    AuthServiceFE -->|calls| HttpInterceptor
    DemoServiceFE -->|calls| HttpInterceptor

    HttpInterceptor -->|attaches key/token from apiKeyStateService| ApiKeyStateService
    HttpInterceptor -->|attaches token from accessTokenStateService| AccessTokenStateService
    HttpInterceptor -->|attaches JWT from jwtStateService| JwtStateService

    HttpInterceptor -->|GET /api/api-key| ApiKeyController
    HttpInterceptor -->|POST /api/auth| AuthControllerBE
    HttpInterceptor -->|GET /api/demo| DemoController

    %% Backend Flow - API Key
    ApiKeyController -->|protected by| ApiKeyGuard
    ApiKeyGuard -->|uses| ApiKeyServiceBE
    ApiKeyServiceBE -->|reads/writes| CacheStore
    ApiKeyServiceBE -->|responds| ApiKeyController

    %% Backend Flow - Auth
    AuthControllerBE -->|protected by| JwtAuthGuard
    JwtAuthGuard -->|validates via| JwtStrategy
    JwtStrategy -->|uses| AuthServiceBE
    AuthServiceBE -->|reads/writes| CacheStore
    AuthServiceBE -->|responses| AuthControllerBE

    %% Backend Flow - Demo
    DemoController -->|returns data| HttpInterceptor

    %% Response Flow
    HttpInterceptor -->|response| DemoServiceFE
    DemoServiceFE -->|updates| DemoComponent
    HttpInterceptor -->|response| AuthServiceFE
    AuthServiceFE -->|updates| AuthComponent

    %% Click Events - Frontend
    click AppModuleFE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/app.module.ts"
    click AppComponentFE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/app.component.ts"
    click HttpInterceptor "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/interceptors/http-security.interceptor.ts"
    click AuthServiceFE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/services/auth.service.ts"
    click DemoServiceFE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/services/demo.service.ts"
    click ApiKeyStateService "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/state/api-key-state.service.ts"
    click AccessTokenStateService "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/state/access-token-state.service.ts"
    click JwtStateService "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/state/jwt-state.service.ts"
    click AuthComponent "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/components/auth/auth.component.ts"
    click DemoComponent "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/components/demo/demo.component.ts"
    click MockComponent "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-frontend/src/app/components/mock/mock.component.ts"

    %% Click Events - Backend
    click ApiKeyModule "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/api-key/api-key.module.ts"
    click ApiKeyController "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/api-key/api-key.controller.ts"
    click ApiKeyServiceBE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/api-key/api-key.service.ts"
    click ApiKeyGuard "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/api-key/api-key.guard.ts"
    click AuthModuleBE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/auth/auth.module.ts"
    click AuthControllerBE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/auth/auth.controller.ts"
    click AuthServiceBE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/auth/auth.service.ts"
    click JwtStrategy "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/auth/jwt.strategy.ts"
    click JwtAuthGuard "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/auth/jwt-auth.guard.ts"
    click DemoModuleBE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/demo/demo.module.ts"
    click DemoController "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/demo/demo.controller.ts"
    click MainEntry "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/main.ts"
    click AppModuleBE "https://github.com/prophet-99/ng-conf-rxjs-cache/blob/main/rxjs-cache-backend/src/app.module.ts"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000
    classDef service fill:#DDA0DD,stroke:#000
    classDef state fill:#90EE90,stroke:#000
    classDef interceptor fill:#FFA500,stroke:#000
    classDef guard fill:#FF6347,stroke:#000
    classDef backendService fill:#9370DB,stroke:#000
    classDef module fill:#F0E68C,stroke:#000
    classDef db fill:#D3D3D3,stroke:#000
```
