"CloakVision" is a .NET 8 Web API designed as an image service. Its primary function is to manage and serve images, leveraging Azure for cloud storage and a relational database for metadata. The API is built with a clean architecture, separating concerns into distinct layers: Core (domain logic), Infrastructure (data access and external services), and the Web API (presentation).
- Image Management: The API provides endpoints to manage images, including:
- Retrieving all images.
- Fetching a specific image by its unique identifier (GUID).
- (Future) Creating new images.
- Dynamic Image URLs: Instead of storing static, publicly accessible URLs, the service generates Shared Access Signature (SAS) URLs for images stored in Azure Blob Storage. This enhances security by providing temporary, permission-based access to the image files.
- Database Integration: Image metadata (name, path, description, etc.) is stored in a SQL Server database, accessed via Entity Framework Core. This allows for efficient querying and management of image information.
- Configuration Management: The application utilizes Azure Key Vault to securely store and manage sensitive configuration data like database connection strings, separating them from the application's source code.
- .NET 8 and ASP.NET Core: The project is built on the latest long-term support (LTS) version of .NET, providing a modern, high-performance foundation for the web API.
- Clean Architecture: The codebase is structured into three main projects:
- CloakVision (Web API): The entry point of the application, responsible for handling HTTP requests, controllers, and dependency injection setup.
- Core: Contains the application's business logic, including domain entities, interfaces for services and repositories, and Data Transfer Objects (DTOs). This layer has no dependencies on external frameworks like Entity Framework or Azure SDKs.
- Infrastructure: Implements the interfaces defined in the Core layer. This includes the database context, repositories that interact with the database, and any other external service integrations.
- Repository Pattern: The project uses a generic repository pattern to abstract the data access logic, making the application more testable and maintainable. A
BaseRepositoryprovides common CRUD (Create, Read, Update, Delete) operations, which can be extended by specific repositories like theImageRepository. - Dependency Injection: The application makes extensive use of dependency injection to manage the lifetime and dependencies of services, repositories, and other components. This promotes loose coupling and testability.
- Azure Integration:
- Azure Blob Storage: Used for storing the actual image files. The
BlobServiceClientis registered to useDefaultAzureCredentialfor authentication, allowing the application to securely access the storage account without hardcoding credentials. - Azure Key Vault: As mentioned, this is used for secure configuration management.
- Azure Blob Storage: Used for storing the actual image files. The
- API Documentation: The project integrates Swagger (OpenAPI) to provide interactive API documentation. This includes detailed information about the API endpoints, request/response models, and contact information. The API also supports Scalar API references for an alternative documentation UI.
- CORS: Cross-Origin Resource Sharing (CORS) is configured to allow requests from any origin, which is useful for development and for allowing web applications hosted on different domains to interact with the API.
- Error Handling: A centralized
ApiResponseHelperis used to create consistent and structured API responses for success and error scenarios, following REST best practices and the RFC 7807 problem details standard.
- A client sends an HTTP request to an
ImageControllerendpoint. - The controller calls the appropriate method on the
IImageService. - The
ImageServiceretrieves the image metadata from theImageRepository. - The
ImageRepository, using Entity Framework Core, queries the SQL Server database for the image information. - If the image path stored in the database is a relative path (not a full URL), the
ImageServiceuses theBlobServiceClientto generate a secure, time-limited SAS URL for the image in Azure Blob Storage. - The
ImageServicereturns the image data (including the potentially generated SAS URL) to the controller. - The controller, with the help of
ApiResponseHelper, formats the data into a standard HTTP response and sends it back to the client.