How azure/azurite works
Project Type and Purpose
• This is “Azurite,” a stand-alone emulator for Azure Storage services (Blob, Queue, Table).
• Written in TypeScript, it exposes HTTP endpoints that mimic Azure Storage REST APIs for local development and testing.
• Core components: a CLI (and VS Code extension), three service emulators (Blob, Queue, Table), shared common libraries, multiple persistence providers (in-memory, file system, Loki, SQL), and generated request/response middleware from Swagger specs.
File Structure Analysis
• Top-level scripts & config: Dockerfile(s), azure-pipelines.yml, GitHub actions, ESLint/Prettier, package.json, build scripts under scripts/.
• Source code (src/):
• extension.ts & main.ts: VS Code extension and top-level entrypoint.
• azurite.ts: main CLI bootstrap.
• blob/, queue/, table/: each service’s implementation subdivided into:
– Configuration & Environment (*Configuration.ts, *Environment.ts)
– Server & Factory (*Server.ts, *ServerFactory.ts)
– Authentication (SAS, SharedKey, Token, public access)
– Middlewares (authentication, CORS/Preflight, context injection, telemetry, strict-model)
– Generated (Express adapters, handlers, middleware from Swagger)
– Handlers (business logic by operation type)
– Persistence (metadata stores and extent stores with QueryInterpreter)
– GC (garbage-collection managers)
• Shared code (src/common/): interfaces (ILogger, IDataStore, IEnvironment), base classes (ServerBase, ConfigurationBase), persistence abstractions, telemetry, logging strategies, VSC server manager state machines, utility streams, mutex, zero-byte stream.
• Persistence implementations: in-memory, file-system, Loki.js, SQL (via SqlBlob… and SqlExtent… stores).
• Tests covering all layers under tests/.
• Swagger definitions under swagger/ drive code generation.
Architectural Patterns & Design Principles
• Micro-services style: three separate Express apps (Blob, Queue, Table), each on its own port.
• Factory pattern to instantiate servers with pluggable environment/configuration/persistence.
• Middleware pipeline for cross-cutting concerns (auth, CORS, telemetry, context).
• Strategy pattern for persistence and authentication methods.
• Generated code from OpenAPI/Swagger ensuring contract adherence.
• Dependency injection via environment interfaces.
• CQRS-like separation: request parsing → business handler → data store interaction → response serialization.
Components and Interactions
• CLI / VS Code Extension
• Parses command-line args or VS Code commands → chooses in-memory or disk/SQL persistence → invokes ServerFactories.
• ServerFactories (BlobServerFactory, QueueServerFactory, TableServerFactory)
• Build Express apps: mount generated routes & middleware → register custom middlewares & handlers → start listening.
• Express Middleware Pipeline (per service)
1. CORS/Preflight (PreflightMiddlewareFactory)
2. Authentication (shared-key, SAS, token; authenticator implementations)
3. Context injection (BlobStorageContext / QueueStorageContext / TableStorageContext)
4. Strict model validation (enforce request schema)
5. Telemetry logging
6. Generated deserializer → dispatch → handler middleware → serializer → error handling
• Handlers
• Invoke service-specific logic: blob upload/download, queue enqueue/dequeue, table CRUD & query.
• Persistence Layer
• ExtentStore (holds raw data chunks) + MetadataStore (keeps metadata & indexing)
• QueryInterpreter for Table & Blob/Queue query filters
• GCManager cleans expired blobs/messages
• Common Utilities
• Logger & Telemetry (Winston, VSC strategies)
• Mutex, streams, configuration base classes
• External Services / Tools
• Node.js, Express.js, Swagger codegen, Loki.js, SQLite/MySQL drivers (for SQL stores)
• Clear component boundaries and labels
• Notes or callouts for key architectural patterns (Factory, Strategy, Middleware pipeline, Codegen).