## Application Layer: Commands, Queries, DTOs and Handlers This document summarizes how commands, queries, DTOs, mapping and handler registration form the Application boundary for ingestion, AI verification, quizzes and sync flows. ```mermaid --- config: flowchart: defaultRenderer: "elk" --- flowchart TD flow_file_nexusreader_application_commands_ai_verifygroundednesscommand_cs_file_1["VerifyGroundednessCommandHandler"] flow_file_nexusreader_application_commands_library_ingestebookcommand_cs_file_1["IngestEbookCommand"] flow_file_nexusreader_application_commands_library_ingestebookcommandhandler_cs_file_1["IngestEbookCommandHandler"] flow_file_nexusreader_application_commands_library_ingestebookrequest_cs_file_1["IngestEbookRequest.cs"] flow_file_nexusreader_application_commands_quiz_submitanswercommand_cs_file_1["SubmitAnswerCommand"] flow_file_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_file_1["SubmitAnswerCommandHandler"] flow_file_nexusreader_application_commands_sync_updatereadingprogresscommand_cs_file_1["UpdateReadingProgressCommand"] flow_file_nexusreader_application_commands_sync_updatereadingprogresscommandhandler_cs_file_1["UpdateReadingProgressCommandHandler"] flow_file_nexusreader_application_dtos_ai_groundedresponsedto_cs_file_1["GroundedResponseDto.cs"] flow_file_nexusreader_application_dtos_ai_semanticsearchresultdto_cs_file_1["SemanticSearchResultDto"] flow_file_nexusreader_application_dtos_user_authordto_cs_file_1["AuthorDto"] flow_type_nexusreader_application_commands_ai_verifygroundednesscommand_cs_verifygroundednesscommand_7[/"VerifyGroundednessCommand"/] flow_type_nexusreader_application_commands_library_ingestebookcommand_cs_ingestebookcommand_15[/"IngestEbookCommand"/] flow_type_nexusreader_application_commands_library_ingestebookrequest_cs_ingestebookrequest_3[/"IngestEbookRequest"/] flow_type_nexusreader_application_commands_quiz_submitanswercommand_cs_submitanswercommand_5[/"SubmitAnswerCommand"/] flow_type_nexusreader_application_commands_sync_updatereadingprogresscommand_cs_updatereadingprogresscommand_6[/"UpdateReadingProgressCommand"/] flow_type_nexusreader_application_commands_sync_updatereadingprogresscommandhandler_cs_updatereadingprogresscommandhandler_13[/"UpdateReadingProgressCommandHandler"/] flow_type_nexusreader_application_dtos_ai_groundedresponsedto_cs_citationdto_11[/"CitationDto"/] flow_type_nexusreader_application_dtos_ai_groundedresponsedto_cs_groundedresponsedto_5[/"GroundedResponseDto"/] flow_type_nexusreader_application_dtos_ai_semanticsearchresultdto_cs_semanticsearchresultdto_3[/"SemanticSearchResultDto"/] flow_file_nexusreader_application_commands_ai_verifygroundednesscommand_cs_file_1 -->|command VerifyGroundednessCommand| flow_type_nexusreader_application_commands_ai_verifygroundednesscommand_cs_verifygroundednesscommand_7 flow_file_nexusreader_application_commands_library_ingestebookcommand_cs_file_1 -->|command IngestEbookCommand| flow_type_nexusreader_application_commands_library_ingestebookcommand_cs_ingestebookcommand_15 flow_file_nexusreader_application_commands_library_ingestebookrequest_cs_file_1 -->|command IngestEbookRequest| flow_type_nexusreader_application_commands_library_ingestebookrequest_cs_ingestebookrequest_3 flow_file_nexusreader_application_commands_quiz_submitanswercommand_cs_file_1 -->|command SubmitAnswerCommand| flow_type_nexusreader_application_commands_quiz_submitanswercommand_cs_submitanswercommand_5 flow_file_nexusreader_application_commands_sync_updatereadingprogresscommand_cs_file_1 -->|command UpdateReadingProgressCommand| flow_type_nexusreader_application_commands_sync_updatereadingprogresscommand_cs_updatereadingprogresscommand_6 flow_file_nexusreader_application_commands_sync_updatereadingprogresscommandhandler_cs_file_1 -->|model UpdateReadingProgressCommandHandler| flow_type_nexusreader_application_commands_sync_updatereadingprogresscommandhandler_cs_updatereadingprogresscommandhandler_13 flow_file_nexusreader_application_dtos_ai_groundedresponsedto_cs_file_1 -->|dto CitationDto| flow_type_nexusreader_application_dtos_ai_groundedresponsedto_cs_citationdto_11 flow_file_nexusreader_application_dtos_ai_groundedresponsedto_cs_file_1 -->|dto GroundedResponseDto| flow_type_nexusreader_application_dtos_ai_groundedresponsedto_cs_groundedresponsedto_5 flow_file_nexusreader_application_dtos_ai_semanticsearchresultdto_cs_file_1 -->|dto SemanticSearchResultDto| flow_type_nexusreader_application_dtos_ai_semanticsearchresultdto_cs_semanticsearchresultdto_3 click flow_file_nexusreader_application_commands_ai_verifygroundednesscommand_cs_file_1 href "vscode://file/NexusReader.Application/Commands/AI/VerifyGroundednessCommand.cs:1:1" "Open source" click flow_type_nexusreader_application_commands_ai_verifygroundednesscommand_cs_verifygroundednesscommand_7 href "vscode://file/NexusReader.Application/Commands/AI/VerifyGroundednessCommand.cs:7:1" "Open source" click flow_file_nexusreader_application_commands_library_ingestebookcommand_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Library/IngestEbookCommand.cs:1:1" "Open source" click flow_type_nexusreader_application_commands_library_ingestebookcommand_cs_ingestebookcommand_15 href "vscode://file/NexusReader.Application/Commands/Library/IngestEbookCommand.cs:15:1" "Open source" click flow_file_nexusreader_application_commands_library_ingestebookcommandhandler_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Library/IngestEbookCommandHandler.cs:1:1" "Open source" click flow_file_nexusreader_application_commands_library_ingestebookrequest_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Library/IngestEbookRequest.cs:1:1" "Open source" click flow_type_nexusreader_application_commands_library_ingestebookrequest_cs_ingestebookrequest_3 href "vscode://file/NexusReader.Application/Commands/Library/IngestEbookRequest.cs:3:1" "Open source" click flow_file_nexusreader_application_commands_quiz_submitanswercommand_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Quiz/SubmitAnswerCommand.cs:1:1" "Open source" click flow_type_nexusreader_application_commands_quiz_submitanswercommand_cs_submitanswercommand_5 href "vscode://file/NexusReader.Application/Commands/Quiz/SubmitAnswerCommand.cs:5:1" "Open source" click flow_file_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Quiz/SubmitAnswerCommandHandler.cs:1:1" "Open source" click flow_file_nexusreader_application_commands_sync_updatereadingprogresscommand_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Sync/UpdateReadingProgressCommand.cs:1:1" "Open source" click flow_type_nexusreader_application_commands_sync_updatereadingprogresscommand_cs_updatereadingprogresscommand_6 href "vscode://file/NexusReader.Application/Commands/Sync/UpdateReadingProgressCommand.cs:6:1" "Open source" click flow_file_nexusreader_application_commands_sync_updatereadingprogresscommandhandler_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Sync/UpdateReadingProgressCommandHandler.cs:1:1" "Open source" click flow_type_nexusreader_application_commands_sync_updatereadingprogresscommandhandler_cs_updatereadingprogresscommandhandler_13 href "vscode://file/NexusReader.Application/Commands/Sync/UpdateReadingProgressCommandHandler.cs:13:1" "Open source" click flow_file_nexusreader_application_dtos_ai_groundedresponsedto_cs_file_1 href "vscode://file/NexusReader.Application/DTOs/AI/GroundedResponseDto.cs:1:1" "Open source" click flow_type_nexusreader_application_dtos_ai_groundedresponsedto_cs_groundedresponsedto_5 href "vscode://file/NexusReader.Application/DTOs/AI/GroundedResponseDto.cs:5:1" "Open source" click flow_type_nexusreader_application_dtos_ai_groundedresponsedto_cs_citationdto_11 href "vscode://file/NexusReader.Application/DTOs/AI/GroundedResponseDto.cs:11:1" "Open source" click flow_file_nexusreader_application_dtos_ai_semanticsearchresultdto_cs_file_1 href "vscode://file/NexusReader.Application/DTOs/AI/SemanticSearchResultDto.cs:1:1" "Open source" click flow_type_nexusreader_application_dtos_ai_semanticsearchresultdto_cs_semanticsearchresultdto_3 href "vscode://file/NexusReader.Application/DTOs/AI/SemanticSearchResultDto.cs:3:1" "Open source" click flow_file_nexusreader_application_dtos_user_authordto_cs_file_1 href "vscode://file/NexusReader.Application/DTOs/User/AuthorDto.cs:1:1" "Open source" ``` This dependency map shows commands, handlers and DTOs in the Application layer and how core command/query types relate to DTO files. It highlights IngestEbook, VerifyGroundedness, SubmitAnswer and UpdateReadingProgress as first-class command types and exposes DTOs used for AI and user data. ```mermaid --- config: flowchart: defaultRenderer: "elk" --- flowchart TD subgraph flow_0_nexusreader_web_program_cs["Program.cs"] end subgraph flow_1_nexusreader_web_client_program_cs["Program.cs"] end flow_file_nexusreader_web_client_program_cs_file_1["Program.cs"] flow_file_nexusreader_web_program_cs_file_1["Program.cs"] flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250["GetEpubContent (GET /api/epub/{ebookId}/{index})"] flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355["GetMyEbooks (GET /api/library/books)"] flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434["HandleSubscriptionCancellation"] flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410["HandleSubscriptionSuccess"] flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453["Identity Login (GET /identity/login/google)"] flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330["IngestEbook (POST /api/library/ingest)"] flow_method_nexusreader_web_program_cs_knowledge_api_group_mappings_261["Knowledge API group mappings"] flow_method_nexusreader_web_program_cs_map_identity_api_mapgroup_identity_451["Map Identity API (MapGroup /identity)"] flow_method_nexusreader_web_program_cs_program_top_level_29["Program (top-level)"] flow_method_nexusreader_web_program_cs_stripewebhook_post_api_stripewebhook_367["StripeWebhook (POST /api/StripeWebhook)"] flow_file_nexusreader_application_mappings_mappingconfig_cs_file_1["MappingConfig"] flow_type_nexusreader_application_mappings_mappingconfig_cs_config_global_typeadapterconfig_19[/"config (global TypeAdapterConfig)"/] flow_type_nexusreader_application_mappings_mappingconfig_cs_servicemapper_20[/"ServiceMapper"/] flow_type_nexusreader_web_client_program_cs_webplatformservice_18[/"WebPlatformService"/] flow_type_nexusreader_web_program_cs_addapplication_78[/"AddApplication()"/] flow_type_nexusreader_web_program_cs_addinfrastructure_iconfiguration_79[/"AddInfrastructure(IConfiguration)"/] flow_type_nexusreader_web_program_cs_framework_34[/"framework"/] flow_type_nexusreader_web_program_cs_named_httpclient_58[/"named HttpClient"/] flow_type_nexusreader_web_program_cs_registerservicesfromassemblies_81[/"RegisterServicesFromAssemblies"/] flow_type_nexusreader_web_program_cs_serveridentityservice_75[/"ServerIdentityService"/] flow_type_nexusreader_web_program_cs_tokenlimithandler_87[/"TokenLimitHandler"/] flow_type_nexusreader_web_program_cs_webplatformservice_47[/"WebPlatformService"/] flow_file_nexusreader_application_mappings_mappingconfig_cs_file_1 -->|TypeAdapterConfig| flow_type_nexusreader_application_mappings_mappingconfig_cs_config_global_typeadapterconfig_19 flow_file_nexusreader_application_mappings_mappingconfig_cs_file_1 -->|IMapper| flow_type_nexusreader_application_mappings_mappingconfig_cs_servicemapper_20 flow_file_nexusreader_web_client_program_cs_file_1 -->|IPlatformService| flow_type_nexusreader_web_client_program_cs_webplatformservice_18 flow_file_nexusreader_web_program_cs_file_1 -->|Application layer| flow_type_nexusreader_web_program_cs_addapplication_78 flow_file_nexusreader_web_program_cs_file_1 -->|Infrastructure layer| flow_type_nexusreader_web_program_cs_addinfrastructure_iconfiguration_79 flow_file_nexusreader_web_program_cs_file_1 -->|Razor / Blazor services| flow_type_nexusreader_web_program_cs_framework_34 flow_file_nexusreader_web_program_cs_file_1 -->|uses| flow_type_nexusreader_web_program_cs_named_httpclient_58 flow_file_nexusreader_web_program_cs_file_1 -->|MediatR handlers| flow_type_nexusreader_web_program_cs_registerservicesfromassemblies_81 flow_file_nexusreader_web_program_cs_file_1 -->|IIdentityService| flow_type_nexusreader_web_program_cs_serveridentityservice_75 flow_file_nexusreader_web_program_cs_file_1 -->|IAuthorizationHandler| flow_type_nexusreader_web_program_cs_tokenlimithandler_87 flow_file_nexusreader_web_program_cs_file_1 -->|IPlatformService| flow_type_nexusreader_web_program_cs_webplatformservice_47 click flow_file_nexusreader_application_mappings_mappingconfig_cs_file_1 href "vscode://file/NexusReader.Application/Mappings/MappingConfig.cs:1:1" "Open source" click flow_type_nexusreader_application_mappings_mappingconfig_cs_config_global_typeadapterconfig_19 href "vscode://file/NexusReader.Application/Mappings/MappingConfig.cs:19:1" "Open source" click flow_type_nexusreader_application_mappings_mappingconfig_cs_servicemapper_20 href "vscode://file/NexusReader.Application/Mappings/MappingConfig.cs:20:1" "Open source" click flow_file_nexusreader_web_client_program_cs_file_1 href "vscode://file/NexusReader.Web.Client/Program.cs:1:1" "Open source" click flow_type_nexusreader_web_client_program_cs_webplatformservice_18 href "vscode://file/NexusReader.Web.Client/Program.cs:18:1" "Open source" click flow_file_nexusreader_web_program_cs_file_1 href "vscode://file/NexusReader.Web/Program.cs:1:1" "Open source" click flow_method_nexusreader_web_program_cs_program_top_level_29 href "vscode://file/NexusReader.Web/Program.cs:29:1" "Open source" click flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250 href "vscode://file/NexusReader.Web/Program.cs:250:1" "Open source" click flow_method_nexusreader_web_program_cs_knowledge_api_group_mappings_261 href "vscode://file/NexusReader.Web/Program.cs:261:1" "Open source" click flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330 href "vscode://file/NexusReader.Web/Program.cs:330:1" "Open source" click flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355 href "vscode://file/NexusReader.Web/Program.cs:355:1" "Open source" click flow_method_nexusreader_web_program_cs_stripewebhook_post_api_stripewebhook_367 href "vscode://file/NexusReader.Web/Program.cs:367:1" "Open source" click flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410 href "vscode://file/NexusReader.Web/Program.cs:410:1" "Open source" click flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434 href "vscode://file/NexusReader.Web/Program.cs:434:1" "Open source" click flow_method_nexusreader_web_program_cs_map_identity_api_mapgroup_identity_451 href "vscode://file/NexusReader.Web/Program.cs:451:1" "Open source" click flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453 href "vscode://file/NexusReader.Web/Program.cs:453:1" "Open source" click flow_type_nexusreader_web_program_cs_framework_34 href "vscode://file/NexusReader.Web/Program.cs:34:1" "Open source" click flow_type_nexusreader_web_program_cs_webplatformservice_47 href "vscode://file/NexusReader.Web/Program.cs:47:1" "Open source" click flow_type_nexusreader_web_program_cs_named_httpclient_58 href "vscode://file/NexusReader.Web/Program.cs:58:1" "Open source" click flow_type_nexusreader_web_program_cs_serveridentityservice_75 href "vscode://file/NexusReader.Web/Program.cs:75:1" "Open source" ``` This startup diagram shows service registration: MappingConfig provides a global TypeAdapterConfig/IMapper and Program.cs registers MediatR handlers and platform services. It documents how handlers are discovered (RegisterServicesFromAssemblies) and mapping is provided centrally. ```mermaid --- config: flowchart: defaultRenderer: "elk" --- flowchart TD subgraph flow_0_nexusreader_web_program_cs["Program.cs"] end flow_file_nexusreader_web_program_cs_file_1["Program.cs"] flow_method_nexusreader_web_program_cs_configure_pipeline_and_run_225["Configure pipeline and run"] flow_method_nexusreader_web_program_cs_database_initialization_and_seeding_with_retries_175["Database initialization and seeding with retries"] flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250["GetEpubContent (GET /api/epub/{ebookId}/{index})"] flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355["GetMyEbooks (GET /api/library/books)"] flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434["HandleSubscriptionCancellation"] flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410["HandleSubscriptionSuccess"] flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453["Identity Login (GET /identity/login/google)"] flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330["IngestEbook (POST /api/library/ingest)"] flow_method_nexusreader_web_program_cs_knowledge_api_group_mappings_261["Knowledge API group mappings"] flow_method_nexusreader_web_program_cs_map_identity_api_mapgroup_identity_451["Map Identity API (MapGroup /identity)"] flow_method_nexusreader_web_program_cs_program_top_level_29["Program (top-level)"] flow_method_nexusreader_web_program_cs_stripewebhook_post_api_stripewebhook_367["StripeWebhook (POST /api/StripeWebhook)"] flow_method_nexusreader_web_program_cs_usehangfiredashboard_163["UseHangfireDashboard"] flow_type_nexusreader_web_program_cs_addapplication_78[/"AddApplication()"/] flow_type_nexusreader_web_program_cs_addinfrastructure_iconfiguration_79[/"AddInfrastructure(IConfiguration)"/] flow_type_nexusreader_web_program_cs_framework_34[/"framework"/] flow_type_nexusreader_web_program_cs_identity_ef_stores_107[/"Identity + EF stores"/] flow_type_nexusreader_web_program_cs_named_httpclient_58[/"named HttpClient"/] flow_type_nexusreader_web_program_cs_nexusreader_infrastructure_services_billingservice_93[/"NexusReader.Infrastructure.Services.BillingService"/] flow_type_nexusreader_web_program_cs_registerservicesfromassemblies_81[/"RegisterServicesFromAssemblies"/] flow_type_nexusreader_web_program_cs_serveridentityservice_75[/"ServerIdentityService"/] flow_type_nexusreader_web_program_cs_tokenlimithandler_87[/"TokenLimitHandler"/] flow_type_nexusreader_web_program_cs_webplatformservice_47[/"WebPlatformService"/] flow_file_nexusreader_web_program_cs_file_1 -->|middleware| flow_method_nexusreader_web_program_cs_configure_pipeline_and_run_225 flow_file_nexusreader_web_program_cs_file_1 -->|unknown| flow_method_nexusreader_web_program_cs_database_initialization_and_seeding_with_retries_175 flow_file_nexusreader_web_program_cs_file_1 -->|GetEpubContent GET / api / epub / ebookId / index| flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250 flow_file_nexusreader_web_program_cs_file_1 -->|GetMyEbooks GET / api / library / books| flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355 flow_file_nexusreader_web_program_cs_file_1 -->|HandleSubscriptionCancellation| flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434 flow_file_nexusreader_web_program_cs_file_1 -->|HandleSubscriptionSuccess| flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410 flow_file_nexusreader_web_program_cs_file_1 -->|Identity Login GET / identity / login / google| flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453 flow_file_nexusreader_web_program_cs_file_1 -->|IngestEbook POST / api / library / ingest| flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330 flow_file_nexusreader_web_program_cs_file_1 -->|Knowledge API group mappings| flow_method_nexusreader_web_program_cs_knowledge_api_group_mappings_261 flow_file_nexusreader_web_program_cs_file_1 -->|Map Identity API MapGroup / identity| flow_method_nexusreader_web_program_cs_map_identity_api_mapgroup_identity_451 flow_file_nexusreader_web_program_cs_file_1 -->|Program top-level| flow_method_nexusreader_web_program_cs_program_top_level_29 flow_file_nexusreader_web_program_cs_file_1 -->|StripeWebhook POST / api / StripeWebhook| flow_method_nexusreader_web_program_cs_stripewebhook_post_api_stripewebhook_367 flow_file_nexusreader_web_program_cs_file_1 -->|middleware| flow_method_nexusreader_web_program_cs_usehangfiredashboard_163 flow_file_nexusreader_web_program_cs_file_1 -->|Application layer| flow_type_nexusreader_web_program_cs_addapplication_78 flow_file_nexusreader_web_program_cs_file_1 -->|Infrastructure layer| flow_type_nexusreader_web_program_cs_addinfrastructure_iconfiguration_79 flow_file_nexusreader_web_program_cs_file_1 -->|Razor / Blazor services| flow_type_nexusreader_web_program_cs_framework_34 flow_file_nexusreader_web_program_cs_file_1 -->|uses| flow_type_nexusreader_web_program_cs_identity_ef_stores_107 flow_file_nexusreader_web_program_cs_file_1 -->|uses| flow_type_nexusreader_web_program_cs_named_httpclient_58 flow_file_nexusreader_web_program_cs_file_1 -->|IBillingService| flow_type_nexusreader_web_program_cs_nexusreader_infrastructure_services_billingservice_93 flow_file_nexusreader_web_program_cs_file_1 -->|MediatR handlers| flow_type_nexusreader_web_program_cs_registerservicesfromassemblies_81 flow_file_nexusreader_web_program_cs_file_1 -->|IIdentityService| flow_type_nexusreader_web_program_cs_serveridentityservice_75 flow_file_nexusreader_web_program_cs_file_1 -->|IAuthorizationHandler| flow_type_nexusreader_web_program_cs_tokenlimithandler_87 flow_file_nexusreader_web_program_cs_file_1 -->|IPlatformService| flow_type_nexusreader_web_program_cs_webplatformservice_47 click flow_file_nexusreader_web_program_cs_file_1 href "vscode://file/NexusReader.Web/Program.cs:1:1" "Open source" click flow_method_nexusreader_web_program_cs_program_top_level_29 href "vscode://file/NexusReader.Web/Program.cs:29:1" "Open source" click flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250 href "vscode://file/NexusReader.Web/Program.cs:250:1" "Open source" click flow_method_nexusreader_web_program_cs_knowledge_api_group_mappings_261 href "vscode://file/NexusReader.Web/Program.cs:261:1" "Open source" click flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330 href "vscode://file/NexusReader.Web/Program.cs:330:1" "Open source" click flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355 href "vscode://file/NexusReader.Web/Program.cs:355:1" "Open source" click flow_method_nexusreader_web_program_cs_stripewebhook_post_api_stripewebhook_367 href "vscode://file/NexusReader.Web/Program.cs:367:1" "Open source" click flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410 href "vscode://file/NexusReader.Web/Program.cs:410:1" "Open source" click flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434 href "vscode://file/NexusReader.Web/Program.cs:434:1" "Open source" click flow_method_nexusreader_web_program_cs_map_identity_api_mapgroup_identity_451 href "vscode://file/NexusReader.Web/Program.cs:451:1" "Open source" click flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453 href "vscode://file/NexusReader.Web/Program.cs:453:1" "Open source" ``` This Program.cs flow emphasizes middleware, endpoint mappings (including the IngestEbook API) and initialization sequencing. It also shows where application and infrastructure extensions are wired into the host. ```mermaid classDiagram class flow_file_nexusreader_web_program_cs_file_1["Program.cs"] class flow_type_nexusreader_web_program_cs_addapplication_78["AddApplication()"] class flow_type_nexusreader_web_program_cs_addinfrastructure_iconfiguration_79["AddInfrastructure(IConfiguration)"] class flow_type_nexusreader_web_program_cs_askquestionrequest_569["AskQuestionRequest"] class flow_type_nexusreader_web_program_cs_framework_34["framework"] class flow_type_nexusreader_web_program_cs_groundednessrequest_567["GroundednessRequest"] class flow_type_nexusreader_web_program_cs_identity_ef_stores_107["Identity + EF stores"] class flow_type_nexusreader_web_program_cs_knowledgerequest_566["KnowledgeRequest"] class flow_type_nexusreader_web_program_cs_named_httpclient_58["named HttpClient"] class flow_type_nexusreader_web_program_cs_nexusreader_infrastructure_services_billingservice_93["NexusReader.Infrastructure.Services.BillingService"] class flow_type_nexusreader_web_program_cs_registerservicesfromassemblies_81["RegisterServicesFromAssemblies"] class flow_type_nexusreader_web_program_cs_semanticsearchrequest_568["SemanticSearchRequest"] class flow_type_nexusreader_web_program_cs_serveridentityservice_75["ServerIdentityService"] class flow_type_nexusreader_web_program_cs_tokenlimithandler_87["TokenLimitHandler"] class flow_type_nexusreader_web_program_cs_webplatformservice_47["WebPlatformService"] flow_file_nexusreader_web_program_cs_file_1 --> flow_type_nexusreader_web_program_cs_askquestionrequest_569 : dto AskQuestionRequest flow_file_nexusreader_web_program_cs_file_1 --> flow_type_nexusreader_web_program_cs_groundednessrequest_567 : dto GroundednessRequest flow_file_nexusreader_web_program_cs_file_1 --> flow_type_nexusreader_web_program_cs_knowledgerequest_566 : dto KnowledgeRequest flow_file_nexusreader_web_program_cs_file_1 --> flow_type_nexusreader_web_program_cs_semanticsearchrequest_568 : dto SemanticSearchRequest click flow_file_nexusreader_web_program_cs_file_1 href "vscode://file/NexusReader.Web/Program.cs:1:1" "Open source" click flow_type_nexusreader_web_program_cs_knowledgerequest_566 href "vscode://file/NexusReader.Web/Program.cs:566:1" "Open source" click flow_type_nexusreader_web_program_cs_groundednessrequest_567 href "vscode://file/NexusReader.Web/Program.cs:567:1" "Open source" click flow_type_nexusreader_web_program_cs_semanticsearchrequest_568 href "vscode://file/NexusReader.Web/Program.cs:568:1" "Open source" click flow_type_nexusreader_web_program_cs_askquestionrequest_569 href "vscode://file/NexusReader.Web/Program.cs:569:1" "Open source" click flow_type_nexusreader_web_program_cs_framework_34 href "vscode://file/NexusReader.Web/Program.cs:34:1" "Open source" click flow_type_nexusreader_web_program_cs_webplatformservice_47 href "vscode://file/NexusReader.Web/Program.cs:47:1" "Open source" click flow_type_nexusreader_web_program_cs_named_httpclient_58 href "vscode://file/NexusReader.Web/Program.cs:58:1" "Open source" click flow_type_nexusreader_web_program_cs_serveridentityservice_75 href "vscode://file/NexusReader.Web/Program.cs:75:1" "Open source" click flow_type_nexusreader_web_program_cs_addapplication_78 href "vscode://file/NexusReader.Web/Program.cs:78:1" "Open source" click flow_type_nexusreader_web_program_cs_addinfrastructure_iconfiguration_79 href "vscode://file/NexusReader.Web/Program.cs:79:1" "Open source" click flow_type_nexusreader_web_program_cs_registerservicesfromassemblies_81 href "vscode://file/NexusReader.Web/Program.cs:81:1" "Open source" click flow_type_nexusreader_web_program_cs_tokenlimithandler_87 href "vscode://file/NexusReader.Web/Program.cs:87:1" "Open source" click flow_type_nexusreader_web_program_cs_nexusreader_infrastructure_services_billingservice_93 href "vscode://file/NexusReader.Web/Program.cs:93:1" "Open source" click flow_type_nexusreader_web_program_cs_identity_ef_stores_107 href "vscode://file/NexusReader.Web/Program.cs:107:1" "Open source" ``` This class diagram enumerates DTO contracts exposed at the Program boundary (AskQuestionRequest, GroundednessRequest, etc.). It clarifies mapping targets and shows MappingConfig/IMapper usage in startup. ```mermaid flowchart TD subgraph NexusReader_Web_Program["Program"] end flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250["GetEpubContent (GET /api/epub/{ebookId}/{index})"] flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355["GetMyEbooks (GET /api/library/books)"] flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434["HandleSubscriptionCancellation"] flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410["HandleSubscriptionSuccess"] flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453["Identity Login (GET /identity/login/google)"] flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330["IngestEbook (POST /api/library/ingest)"] flow_method_nexusreader_web_program_cs_program_top_level_29["Program (top-level)"] flow_action_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_guard_clause_252_252{"Extract userId"} flow_action_nexusreader_web_program_cs_getmyebooks_get_api_library_books_guard_clause_357_357{"Ensure authenticated user"} flow_action_nexusreader_web_program_cs_handlesubscriptioncancellation_guard_clause_439_439{"Guards early exit or rejection path"} flow_action_nexusreader_web_program_cs_handlesubscriptionsuccess_guard_clause_416_416{"Guards early exit or rejection path"} flow_action_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_guard_clause_332_332{"Ensure authenticated user"} flow_action_nexusreader_web_program_cs_program_top_level_branch_62_62{"Evaluates branch condition"} flow_action_nexusreader_web_program_cs_identity_login_get_identity_login_google_return_460_460(["Return Challenge to Google"]) flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250 -->|continue| flow_action_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_guard_clause_252_252 flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355 -->|Unauthorized / continue| flow_action_nexusreader_web_program_cs_getmyebooks_get_api_library_books_guard_clause_357_357 flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434 -->|exit / continue| flow_action_nexusreader_web_program_cs_handlesubscriptioncancellation_guard_clause_439_439 flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410 -->|exit / continue| flow_action_nexusreader_web_program_cs_handlesubscriptionsuccess_guard_clause_416_416 flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453 -->|Return Challenge to Google| flow_action_nexusreader_web_program_cs_identity_login_get_identity_login_google_return_460_460 flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330 -->|Unauthorized / continue| flow_action_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_guard_clause_332_332 flow_method_nexusreader_web_program_cs_program_top_level_29 -->|true / false| flow_action_nexusreader_web_program_cs_program_top_level_branch_62_62 click flow_method_nexusreader_web_program_cs_program_top_level_29 href "vscode://file/NexusReader.Web/Program.cs:29:1" "Open source" click flow_action_nexusreader_web_program_cs_program_top_level_branch_62_62 href "vscode://file/NexusReader.Web/Program.cs:62:1" "Open source" click flow_method_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_250 href "vscode://file/NexusReader.Web/Program.cs:250:1" "Open source" click flow_action_nexusreader_web_program_cs_getepubcontent_get_api_epub_ebookid_index_guard_clause_252_252 href "vscode://file/NexusReader.Web/Program.cs:252:1" "Open source" click flow_method_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_330 href "vscode://file/NexusReader.Web/Program.cs:330:1" "Open source" click flow_action_nexusreader_web_program_cs_ingestebook_post_api_library_ingest_guard_clause_332_332 href "vscode://file/NexusReader.Web/Program.cs:332:1" "Open source" click flow_method_nexusreader_web_program_cs_getmyebooks_get_api_library_books_355 href "vscode://file/NexusReader.Web/Program.cs:355:1" "Open source" click flow_action_nexusreader_web_program_cs_getmyebooks_get_api_library_books_guard_clause_357_357 href "vscode://file/NexusReader.Web/Program.cs:357:1" "Open source" click flow_method_nexusreader_web_program_cs_handlesubscriptionsuccess_410 href "vscode://file/NexusReader.Web/Program.cs:410:1" "Open source" click flow_action_nexusreader_web_program_cs_handlesubscriptionsuccess_guard_clause_416_416 href "vscode://file/NexusReader.Web/Program.cs:416:1" "Open source" click flow_method_nexusreader_web_program_cs_handlesubscriptioncancellation_434 href "vscode://file/NexusReader.Web/Program.cs:434:1" "Open source" click flow_action_nexusreader_web_program_cs_handlesubscriptioncancellation_guard_clause_439_439 href "vscode://file/NexusReader.Web/Program.cs:439:1" "Open source" click flow_method_nexusreader_web_program_cs_identity_login_get_identity_login_google_453 href "vscode://file/NexusReader.Web/Program.cs:453:1" "Open source" click flow_action_nexusreader_web_program_cs_identity_login_get_identity_login_google_return_460_460 href "vscode://file/NexusReader.Web/Program.cs:460:1" "Open source" ``` This control-flow diagram surfaces guard clauses and failure paths at the API boundary (authentication checks, early exits), clarifying validation before commands reach handlers. ```mermaid flowchart TD subgraph NexusReader_Application_Commands_AI_VerifyGroundednessCommand["VerifyGroundednessCommand"] end subgraph NexusReader_Application_Commands_Quiz_SubmitAnswerCommandHandler["SubmitAnswerCommandHandler"] end subgraph NexusReader_Application_Queries_Graph_GetKnowledgeGraphQueryHandler["GetKnowledgeGraphQueryHandler"] end subgraph NexusReader_Application_Queries_Library_AskLibraryQuestionQuery["AskLibraryQuestionQuery"] end subgraph NexusReader_Application_Queries_Library_SearchLibrarySemanticallyQuery["SearchLibrarySemanticallyQuery"] end subgraph NexusReader_Application_Queries_Reader_GetReaderPageQueryHandler["GetReaderPageQueryHandler"] end flow_method_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_18["Handle"] flow_method_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_16["Handle"] flow_method_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_16["Handle"] flow_method_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_23["Handle"] flow_method_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_41["Handle"] flow_method_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_16["Handle"] flow_action_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_guard_clause_18_18{"correct-answer-check"} flow_action_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_guard_clause_18_18{"Empty text returns empty GraphDataDto"} flow_action_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_branch_25_25{"Evaluates branch condition"} flow_action_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_branch_43_43{"Evaluates branch condition"} flow_file_nexusreader_application_commands_ai_verifygroundednesscommand_cs_file_1["VerifyGroundednessCommandHandler"] flow_file_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_file_1["SubmitAnswerCommandHandler"] flow_file_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_file_1["GetKnowledgeGraphQueryHandler"] flow_file_nexusreader_application_queries_library_asklibraryquestionquery_cs_file_1["AskLibraryQuestionQueryHandler"] flow_file_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_file_1["SearchLibrarySemanticallyQueryHandler"] flow_file_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_file_1["GetReaderPageQueryHandler"] flow_action_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_return_20_20(["Returns result"]) flow_action_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_return_18_18(["Return epub reader result"]) flow_action_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_return_18_18 -->|Returns result| flow_action_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_return_18_18 flow_file_nexusreader_application_commands_ai_verifygroundednesscommand_cs_file_1 -->|Handle| flow_method_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_18 flow_file_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_file_1 -->|Handle| flow_method_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_16 flow_file_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_file_1 -->|Handle| flow_method_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_16 flow_file_nexusreader_application_queries_library_asklibraryquestionquery_cs_file_1 -->|Handle| flow_method_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_23 flow_file_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_file_1 -->|Handle| flow_method_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_41 flow_file_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_file_1 -->|Handle| flow_method_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_16 flow_method_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_18 -->|Returns result| flow_action_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_return_20_20 flow_method_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_16 -->|correct -> vibrate and return success / incorrect -> return failure| flow_action_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_guard_clause_18_18 flow_method_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_16 -->|return empty GraphDataDto / continue| flow_action_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_guard_clause_18_18 flow_method_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_23 -->|true / false| flow_action_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_branch_25_25 flow_method_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_41 -->|true / false| flow_action_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_branch_43_43 flow_method_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_16 -->|Return epub reader result| flow_action_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_return_18_18 click flow_file_nexusreader_application_commands_ai_verifygroundednesscommand_cs_file_1 href "vscode://file/NexusReader.Application/Commands/AI/VerifyGroundednessCommand.cs:1:1" "Open source" click flow_method_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_18 href "vscode://file/NexusReader.Application/Commands/AI/VerifyGroundednessCommand.cs:18:1" "Open source" click flow_action_nexusreader_application_commands_ai_verifygroundednesscommand_cs_handle_return_20_20 href "vscode://file/NexusReader.Application/Commands/AI/VerifyGroundednessCommand.cs:20:1" "Open source" click flow_file_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_file_1 href "vscode://file/NexusReader.Application/Commands/Quiz/SubmitAnswerCommandHandler.cs:1:1" "Open source" click flow_method_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_16 href "vscode://file/NexusReader.Application/Commands/Quiz/SubmitAnswerCommandHandler.cs:16:1" "Open source" click flow_action_nexusreader_application_commands_quiz_submitanswercommandhandler_cs_handle_guard_clause_18_18 href "vscode://file/NexusReader.Application/Commands/Quiz/SubmitAnswerCommandHandler.cs:18:1" "Open source" click flow_file_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_file_1 href "vscode://file/NexusReader.Application/Queries/Graph/GetKnowledgeGraphQueryHandler.cs:1:1" "Open source" click flow_method_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_16 href "vscode://file/NexusReader.Application/Queries/Graph/GetKnowledgeGraphQueryHandler.cs:16:1" "Open source" click flow_action_nexusreader_application_queries_graph_getknowledgegraphqueryhandler_cs_handle_guard_clause_18_18 href "vscode://file/NexusReader.Application/Queries/Graph/GetKnowledgeGraphQueryHandler.cs:18:1" "Open source" click flow_file_nexusreader_application_queries_library_asklibraryquestionquery_cs_file_1 href "vscode://file/NexusReader.Application/Queries/Library/AskLibraryQuestionQuery.cs:1:1" "Open source" click flow_method_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_23 href "vscode://file/NexusReader.Application/Queries/Library/AskLibraryQuestionQuery.cs:23:1" "Open source" click flow_action_nexusreader_application_queries_library_asklibraryquestionquery_cs_handle_branch_25_25 href "vscode://file/NexusReader.Application/Queries/Library/AskLibraryQuestionQuery.cs:25:1" "Open source" click flow_file_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_file_1 href "vscode://file/NexusReader.Application/Queries/Library/SearchLibrarySemanticallyQuery.cs:1:1" "Open source" click flow_method_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_41 href "vscode://file/NexusReader.Application/Queries/Library/SearchLibrarySemanticallyQuery.cs:41:1" "Open source" click flow_action_nexusreader_application_queries_library_searchlibrarysemanticallyquery_cs_handle_branch_43_43 href "vscode://file/NexusReader.Application/Queries/Library/SearchLibrarySemanticallyQuery.cs:43:1" "Open source" click flow_file_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_file_1 href "vscode://file/NexusReader.Application/Queries/Reader/GetReaderPageQueryHandler.cs:1:1" "Open source" click flow_method_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_16 href "vscode://file/NexusReader.Application/Queries/Reader/GetReaderPageQueryHandler.cs:16:1" "Open source" click flow_action_nexusreader_application_queries_reader_getreaderpagequeryhandler_cs_handle_return_18_18 href "vscode://file/NexusReader.Application/Queries/Reader/GetReaderPageQueryHandler.cs:18:1" "Open source" ``` The method-flow diagram exposes per-handler behavior: VerifyGroundedness delegates to knowledge services and returns DTOs; SubmitAnswer enforces correctness and side-effects; query handlers return DTOs or early-empty results. ### Key Files - NexusReader.Application/Commands/Library/IngestEbookCommand.cs - NexusReader.Application/Commands/Library/IngestEbookCommandHandler.cs - NexusReader.Application/Commands/Library/IngestEbookRequest.cs - NexusReader.Application/Commands/AI/VerifyGroundednessCommand.cs - NexusReader.Application/Commands/Quiz/SubmitAnswerCommand.cs - NexusReader.Application/Commands/Quiz/SubmitAnswerCommandHandler.cs - NexusReader.Application/Commands/Sync/UpdateReadingProgressCommand.cs - NexusReader.Application/Commands/Sync/UpdateReadingProgressCommandHandler.cs - NexusReader.Application/DTOs/AI/GroundedResponseDto.cs - NexusReader.Application/Mappings/MappingConfig.cs --- ## See Also - [Project Overview and High-level Architecture](../collections/overview.md) - [Web Client (WASM) and Shared UI Components](web-client-and-shared-ui.md) - [Mobile (MAUI) Application Integration](../runtime/mobile-maui.md) - [Infrastructure Services (AI, Epub, Storage, Billing)](../infrastructure/infrastructure-services.md) - [Authentication, Authorization and Account Flows](../flows/authentication-and-account.md) - [Real-time Synchronization and Sync Pipeline](../runtime/realtime-and-sync.md) - [AI Features, Knowledge Graph and UX Integration](../integrations/ai-and-knowledge-ux.md) - [Business Overview](../business/business-overview.md) - [Top Business Flows](../business/top-business-flows.md)