# mznzgt/quizwiz architecture

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

- Interactive diagram: https://gitdiagram.com/mznzgt/quizwiz
- Repository: https://github.com/mznzgt/quizwiz

## Overview

##### Main Components
- Domain Layer: Represents the core business logic. Include entities like User and models such as LoginResponseModel, QuizResponse, etc. This layer (Directory: Domain/QuizWiz.Domain) is central and independent.
- Application Layer: Contains modules such as QuizWix.Application.Auth and QuizWiz.Application.QuizGenerator. This layer holds use-case implementations, commands (e.g., AddRolesCommand, AddArticleCommand) and queries (e.g., GetArticleQuery). It’s responsible for orchestrating business operations.
- Infrastructure Layer: Contains components for data access and external integrations:
- Data: QuizWix.Infrastructure.Data (with the DbContext, migrations, etc.) for interacting with SQL databases.
- OpenAI Integration: QuizWiz.Infrastructure.OpenAI (providing an abstraction and implementation for integration with OpenAI Chat API).
- Persistence Layer: Offers specialized persistence services such as:
- Cosmos: QuizWiz.Persistence.Cosmos, which handles Azure Cosmos DB interactions.
- Blob Storage: QuizWiz.Persistence.BlobStorage, which handles blob-based storage.
- Presentation Layer: Contains several projects:
- QuizWiz.ApiService: Exposes REST API endpoints with controllers (e.g., BlobController, OpenAIController, etc.) that expose services like user management and roles.
- QuizWiz.AppHost: Likely serves as the hosting orchestrator.
- QuizWiz.Web: Implements the Blazor Server-Side application providing the user interface for students and teachers.
- ServiceDefaults: Provides common extensions or utilities used across services.

##### Relationships and Interactions
- The Presentation layer (API and web projects) acts as the entry point. Users (teachers and students) interact with the web client or REST endpoints.
- API controllers in QuizWiz.ApiService route requests to the Application layer through dependency injection – observe the various “DependencyInjection” classes that set up the service registrations.
- The Application layer commands and queries then coordinate with the Domain layer (for business rules) and invoke infrastructure services.
- Infrastructure components (e.g., the DbContext, migration files, and OpenAI service) facilitate data storage and external calls.
- Persistence provides specialized storage mechanisms: one part handles Cosmos DB for quiz data (partitioned by teacher’s email), and another handles Blob Storage for storing related artifacts.
- The external OpenAI Chat API is integrated via the OpenAI service in the Infrastructure layer.
- Data flows from front-end (Blazor) to API endpoints, then through application services, and further to persistence and external services.

##### Architectural Patterns and Design Principles
- Onion/Clean Architecture: The separation into Domain, Application, Infrastructure, and Presentation layers clearly represents the decoupling of core business logic from external concerns.
- Command-Query Responsibility Segregation (CQRS): Notice the presence of “Commands” (e.g., AddRolesCommand) and “Queries” (e.g., GetArticleQuery) which indicate that operations are split by intent.
- Dependency Injection: Various “DependencyInjection” classes hint at the use of DI for wiring together system components.
- Cloud-Native Design: Emphasis on Azure Cosmos DB, SQL databases, and Docker support reflects a cloud-oriented approach.

##### Relevant Technologies
- .NET 8 (with Aspire’s default template) is the backbone.
- Blazor Server-Side is used for the UI.
- Azure Cosmos DB and Azure SQL Database are part of data storage.
- The OpenAI Chat API is integrated as a service.
- Entity Framework Core is used for data management.
- Docker and container configurations (see .devcontainer and GitHub Actions) support deployment and CI/CD.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        USER("User"):::presentation
        API("REST API Project"):::presentation
        APPHOST("App Hosting"):::presentation
        WEB("Blazor Web Client"):::presentation
        SERVICE("Common Service Extensions"):::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        AUTH("Authentication Module"):::application
        QUIZGEN("Quiz Generation Module"):::application
        SHARED("Shared Model"):::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DOMAIN("Domain Core"):::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        DATA("Data Access"):::infrastructure
        OPENAI("OpenAI Integration"):::infrastructure
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        COSMOS("Cosmos DB"):::persistence
        BLOB("Blob Storage"):::persistence
    end

    %% Data Flow Connections
    USER -->|"uses"| WEB
    WEB -->|"routesTo"| API
    APPHOST -->|"orchestrates"| API
    API -->|"calls"| AUTH
    API -->|"calls"| QUIZGEN
    AUTH -->|"dependsOn"| SHARED
    QUIZGEN -->|"dependsOn"| SHARED
    AUTH -->|"businessLogic"| DOMAIN
    QUIZGEN -->|"businessLogic"| DOMAIN
    AUTH -->|"persistsTo"| DATA
    QUIZGEN -->|"callsAPI"| OPENAI
    DATA -->|"CRUDOperations"| COSMOS
    DATA -->|"CRUDOperations"| BLOB
    SERVICE -->|"supports"| API

    %% Click Events
    click DOMAIN "https://github.com/mznzgt/quizwiz/blob/main/Domain/QuizWiz.Domain"
    click AUTH "https://github.com/mznzgt/quizwiz/blob/main/Application/QuizWix.Application.Auth"
    click QUIZGEN "https://github.com/mznzgt/quizwiz/blob/main/Application/QuizWiz.Application.QuizGenerator"
    click SHARED "https://github.com/mznzgt/quizwiz/blob/main/Application/QuizWiz.Application.SharedModel"
    click DATA "https://github.com/mznzgt/quizwiz/blob/main/Infrastructure/QuizWix.Infrastructure.Data"
    click OPENAI "https://github.com/mznzgt/quizwiz/blob/main/Infrastructure/QuizWiz.Infrastructure.OpenAI"
    click COSMOS "https://github.com/mznzgt/quizwiz/blob/main/Persistence/QuizWiz.Persistence.Cosmos"
    click BLOB "https://github.com/mznzgt/quizwiz/blob/main/Persistence/QuizWiz.Persistence.BlobStorage"
    click API "https://github.com/mznzgt/quizwiz/blob/main/Presentation/QuizWiz.ApiService"
    click APPHOST "https://github.com/mznzgt/quizwiz/blob/main/Presentation/QuizWiz.AppHost"
    click WEB "https://github.com/mznzgt/quizwiz/blob/main/Presentation/QuizWiz.Web"
    click SERVICE "https://github.com/mznzgt/quizwiz/blob/main/Presentation/QuizWiz.ServiceDefaults"

    %% Styles
    classDef presentation fill:#FDEBD0,stroke:#E59866,stroke-width:2px;
    classDef application fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef domain fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef infrastructure fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef persistence fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
```
