How nestjs/azure-storage works
Project Type and Purpose
• This is an open-source NestJS module (“@nestjs/azure-storage”) that plugs into any Nest application and provides Azure Blob Storage integration.
• It offers a Dynamic Module (AzureStorageModule), a service (AzureStorageService), an interceptor (AzureStorageFileInterceptor), a decorator (AzureCredentialsDecorator), and a CLI schematic to automate setup.
High-Level File-Structure Analysis
• Top-level:
• index.ts – re-exports public API
• lib/ – contains core module, service, interceptor, decorator, constants and tests
• schematics/ – contains Nest CLI installation scripts that add config and imports to the user’s project
• config files: tsconfig.json, tslint.json, jest.config.js, CI config, etc.
• Patterns:
• Nest Dynamic Module pattern (withConfig, withConfigAsync)
• Dependency Injection for service and interceptor
• Nest CLI schematics for code generation
System Design Components
a. Components
• NestJS Application (User’s app)
• AzureStorageModule (Dynamic Nest Module)
• Configuration Provider (injects accountName, sasKey, containerName)
• AzureStorageService (wraps Azure Blob Storage SDK calls)
• AzureMulterService (handles multer storage logic)
• AzureStorageFileInterceptor (intercepts file uploads in controllers)
• AzureCredentialsDecorator (injects credential metadata into routes)
• Azure Blob Storage (external service)
• Nest CLI Schematic (external tooling that edits user code)
b. Interactions / Data Flow
1. Developer runs nest add @nestjs/azure-storage → Nest CLI reads schematics/install → updates .env, app.module.ts, .gitignore.
2. At runtime, the Nest Application imports AzureStorageModule.withConfig(...) → Nest’s DI container registers:
– CONFIG token → config factory/provider
– AzureStorageService → depends on CONFIG
– AzureMulterService → depends on CONFIG
– AzureStorageFileInterceptor → injected into controller pipeline
3. Client sends HTTP POST /azure/upload with multipart/form-data →
– Request hits Controller → @UseInterceptors(AzureStorageFileInterceptor) →
– Interceptor uses AzureMulterService to buffer/stream the file →
– Interceptor calls AzureStorageService.upload() →
– Service calls Azure Blob Storage SDK → Blob container receives file → returns a storage URL →
– Interceptor attaches file.storageUrl to the controller handler.
c. Architectural Patterns
• Dynamic Module Pattern (configurable import)
• Dependency Injection (services, interceptors, config)
• Interceptor Pattern (file upload pipeline)
• Decorator Pattern (credentials injection)
• CLI Schematic (code generation plugin)
• Labels showing file locations and key methods