# teamelysium/serve-static architecture

> Architecture diagram of the GitHub repository teamelysium/serve-static, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/teamelysium/serve-static
- Repository: https://github.com/teamelysium/serve-static

## Overview

##### Main Components

a. Core Components:
- ServeStaticModule (Central Component)
- Loaders System
- Configuration Interface
- Utility Services

b. Integration Points:
- Express.js Integration
- Fastify Integration
- NestJS Core Framework
- Static Content Storage

**┌─ Application Layer ─────────────────────┐**

- Your NestJS Application            │

- ServeStaticModule Layer ──────────────┤

- ┌─ Module Configuration ┐             │
- rootPath          │             │
- serveRoot         │  Loaders    │
- renderPath        │   System    │
- exclude           │             │
- ┘             │

- Platform Adapters ───────────────────┤

- Express Loader    Fastify Loader   │

- Static Content Layer ────────────────┤

- Static Files/SPA               │
- ┘

##### Key Relationships to Highlight

a. Module Configuration Flow:
- How ServeStaticModule.forRoot() accepts configuration
- Demonstrate how configuration flows to the appropriate loader

b. Platform Adaptation:
- Abstract loader pattern
- How Express and Fastify implementations extend the base loader

c. Static Content Serving:
- Path from incoming requests to static content delivery
- Excluded paths handling

##### Important Implementation Details

- Path validation flow
- Route exclusion mechanism
- Loader selection logic
- Static file serving options

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Application
        NestApp[NestJS Application]
    end

    subgraph ServeStaticModuleLayer
        SSM[ServeStaticModule]:::core
        click SSM "https://github.com/TeamElysium/serve-static/blob/master/lib/serve-static.module.ts"
        
        subgraph Configuration
            ModConfig[Module Configuration]:::config
            click ModConfig "https://github.com/TeamElysium/serve-static/blob/master/lib/interfaces/serve-static-options.interface.ts"
            Constants[Module Constants]:::config
            click Constants "https://github.com/TeamElysium/serve-static/blob/master/lib/serve-static.constants.ts"
            Providers[Module Providers]:::config
            click Providers "https://github.com/TeamElysium/serve-static/blob/master/lib/serve-static.providers.ts"
        end

        subgraph LoaderSystem
            AbstractLoader[Abstract Loader]:::loader
            click AbstractLoader "https://github.com/TeamElysium/serve-static/blob/master/lib/loaders/abstract.loader.ts"
            NoopLoader[No-Op Loader]:::loader
            click NoopLoader "https://github.com/TeamElysium/serve-static/blob/master/lib/loaders/noop.loader.ts"
        end

        subgraph Utils
            PathValidator[Path Validator]:::util
            click PathValidator "https://github.com/TeamElysium/serve-static/blob/master/lib/utils/validate-path.util.ts"
            RouteExcluder[Route Excluder]:::util
            click RouteExcluder "https://github.com/TeamElysium/serve-static/blob/master/lib/utils/is-route-excluded.util.ts"
        end
    end

    subgraph PlatformAdapters
        ExpressLoader[Express Loader]:::platform
        click ExpressLoader "https://github.com/TeamElysium/serve-static/blob/master/lib/loaders/express.loader.ts"
        FastifyLoader[Fastify Loader]:::platform
        click FastifyLoader "https://github.com/TeamElysium/serve-static/blob/master/lib/loaders/fastify.loader.ts"
    end

    subgraph StaticContent
        StaticFiles[Static Files/SPA]:::content
    end

    %% Relationships
    NestApp --> SSM
    SSM --> ModConfig
    SSM --> Constants
    SSM --> Providers
    
    AbstractLoader --> PathValidator
    AbstractLoader --> RouteExcluder
    
    ExpressLoader --> AbstractLoader
    FastifyLoader --> AbstractLoader
    NoopLoader --> AbstractLoader
    
    ExpressLoader --> StaticFiles
    FastifyLoader --> StaticFiles

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef config fill:#FF9800,stroke:#F57C00,color:white
    classDef loader fill:#4CAF50,stroke:#388E3C,color:white
    classDef platform fill:#009688,stroke:#00796B,color:white
    classDef util fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef content fill:#757575,stroke:#616161,color:white

    %% Legend
    subgraph Legend
        L1[Core Component]:::core
        L2[Configuration]:::config
        L3[Loader System]:::loader
        L4[Platform Adapter]:::platform
        L5[Utility]:::util
        L6[Static Content]:::content
    end

    %% Notes
    note["Note: Not for MVC assets<br/>Use useStaticAssets() instead"]
    style note fill:#fff,stroke:#999
```
