# danishbilalansari/graphqlhotchocolatewithnetcore architecture

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

- Interactive diagram: https://gitdiagram.com/danishbilalansari/graphqlhotchocolatewithnetcore
- Repository: https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore

## Overview

##### Project type and purpose
- This is a .NET Core GraphQL API built with HotChocolate.
- Its purpose is to expose courses, instructors, students and user data via GraphQL. It supports queries, mutations, subscriptions, filtering, sorting, pagination, projection, DataLoader batching, JWT authentication, and Firebase login.

##### File structure
- Top-level project: GraphQL.Demo.API
- Program.cs & launchSettings.json – hosts the GraphQL HTTP endpoint and middleware
- appsettings*.json – configuration, including DB connection and JWT/Firebase settings
- Migrations & school.db – EF Core SQLite database and schema history
- Schema folder
- Queries (CourseQuery, Query root types, ISearchResultType, etc.)
- Mutations (CourseInputType, Mutation root)
- Subscriptions (Subscription root)
- Filters & Sorting – custom filter/sort types
- DTOs – data transfer objects for Course, Instructor, Student
- DataLoaders – batching resolvers for Instructor and User
- Services
- SchoolDbContext – EF Core DbContext
- Repositories (CoursesRepository, InstructorsRepository)
- Models – domain entities (Subject, etc.)

##### Extract insights from README
- Implements core GraphQL concepts: queries, mutations, subscriptions, DataLoader, pagination, filtering, sorting, projection
- JWT Authentication & Authorization, Firebase login integration

##### Main components
a. Client Layer
– GraphQL client (e.g., GraphQL Playground, Apollo Client, custom UI)
b. API / GraphQL Server
– .NET Core Web Host (Program.cs)
– HotChocolate middleware pipeline
- HTTP request → JWT/Firebase auth middleware → GraphQL endpoint
- Schema execution: Query / Mutation / Subscription roots
- Resolver layer
· DataLoaders for batching
· Filter, sort & paginate logic
· Projection of DTOs
– Services layer
- Repositories for courses/instructors
- EF Core DbContext
c. Persistence
– SQLite database (school.db) + EF Core Migrations
d. External Services
– Firebase Authentication service (verify tokens, user login)
– JWT issuer or identity provider
e. Real-time Subscriptions
– In-memory or external PubSub engine (HotChocolate’s built-in or Redis)

##### Relationships and interactions
- Client → HTTP(S) → GraphQL Endpoint
- Auth middleware validates JWT or Firebase token → attaches user context
- GraphQL engine parses and routes operation to Query/Mutation/Subscription
- Resolvers call DataLoaders or Repositories → EF Core → SQLite
- Subscription publish/subscribe pipeline pushes events to subscribed clients

##### Architectural patterns and design principles
- Layered architecture: Presentation (GraphQL) → Business (Services/Repositories) → Data (EF Core/DB)
- CQRS-like separation: Query types vs Mutations vs Subscriptions
- DataLoader pattern for N+1 batching
- Custom filtering/sorting/pagination for scalable data access
- Dependency injection for DbContext, repositories, DataLoaders, auth services
- Configuration-as-code via appsettings and launchSettings.json

##### Essential details to capture
- Distinct boundaries between client, API layers, data layer, and external services
- The GraphQL schema roots and how they tie to services
- DataLoader’s role in batching and caching
- Authentication flow (JWT vs Firebase) before schema execution
- Real-time subscription pipeline

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Client["GraphQL Client"]:::client
    end

    subgraph "External Services"
        Firebase["Firebase Auth"]:::external
        JWTIssuer["JWT Issuer"]:::external
    end

    subgraph "API / GraphQL Server"
        subgraph "HTTP Host"
            Host[".NET Core Web Host / GraphQL HTTP Endpoint"]:::host
            AppSettings["appsettings*.json"]:::config
            Launch["launchSettings.json"]:::config
        end

        subgraph "Middleware"
            AuthMW["JWT/Firebase Auth Middleware"]:::auth
        end

        subgraph "GraphQL Pipeline"
            SchemaExec["HotChocolate Schema Execution"]:::schema

            subgraph "Schema Roots"
                QRoot["Query.cs"]:::schema
                CourseQueryN["CourseQuery.cs"]:::schema
                CourseTypeN["CourseType.cs"]:::schema
                InstructorTypeN["InstructorType.cs"]:::schema
                StudentTypeN["StudentType.cs"]:::schema
                UserTypeN["UserType.cs"]:::schema
                ISearchResultTypeN["ISearchResultType.cs"]:::schema

                MutationRoot["Mutation.cs"]:::schema
                CourseInputTypeN["CourseInputType.cs"]:::schema
                CourseResultN["CourseResult.cs"]:::schema

                SubscriptionRoot["Subscription.cs"]:::schema

                CourseFilterTypeN["CourseFilterType.cs"]:::schema
                CourseSortTypeN["CourseSortType.cs"]:::schema
            end

            subgraph "Resolvers & DataLoader"
                ResolversNode["Resolver Layer"]:::resolver
                subgraph "DataLoaders"
                    InstructorDL["InstructorDataLoader.cs"]:::dataloader
                    UserDL["UserDataLoader.cs"]:::dataloader
                end
            end
        end

        subgraph "Services & Data Access"
            RepoCourses["CoursesRepository.cs"]:::service
            RepoInst["InstructorsRepository.cs"]:::service
            DbContext["SchoolDbContext.cs"]:::service
            ModelsDTOs["Domain Models & DTOs"]:::service
        end
    end

    subgraph "Persistence"
        Migrations["EF Core Migrations"]:::db
        SQLite["SQLite Database (school.db)"]:::db
    end

    subgraph "Subscriptions Pipeline"
        PubSub["PubSub Engine"]:::pubsub
    end

    %% Connections
    Client -->|"GraphQL Query/Mutation/Subscription"| Host
    Host -->|reads config| AppSettings
    Host -->|reads config| Launch
    Host -->|requests JWT validation| Firebase
    Host -->|requests JWT validation| JWTIssuer
    Host -->|"HTTP Request"| AuthMW
    AuthMW -->|"Authenticated Context"| SchemaExec

    SchemaExec --> QRoot
    SchemaExec --> MutationRoot
    SchemaExec --> SubscriptionRoot

    QRoot --> ResolversNode
    MutationRoot --> ResolversNode
    SubscriptionRoot --> PubSub

    ResolversNode --> InstructorDL
    ResolversNode --> UserDL

    InstructorDL --> RepoInst
    UserDL --> RepoCourses

    RepoInst --> DbContext
    RepoCourses --> DbContext
    DbContext --> SQLite

    DbContext --> Migrations

    PubSub -->|push subscription events| Client

    %% Click Events
    click Host "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Program.cs"
    click AppSettings "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/appsettings.json"
    click Launch "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Properties/launchSettings.json"
    click DbContext "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Services/SchoolDbContext.cs"
    click Migrations "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/tree/master/GraphQL.Demo.API/Migrations/"
    click SQLite "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/school.db"
    click RepoCourses "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Services/Courses/CoursesRepository.cs"
    click RepoInst "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Services/Instructors/InstructorsRepository.cs"
    click QRoot "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/Query.cs"
    click CourseQueryN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/CourseQuery.cs"
    click CourseTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/CourseType.cs"
    click InstructorTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/InstructorType.cs"
    click StudentTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/StudentType.cs"
    click UserTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/UserType.cs"
    click ISearchResultTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Queries/ISearchResultType.cs"
    click MutationRoot "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Mutations/Mutation.cs"
    click CourseInputTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Mutations/CourseInputType.cs"
    click CourseResultN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Mutations/CourseResult.cs"
    click SubscriptionRoot "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Subscriptions/Subscription.cs"
    click CourseFilterTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Filters/CourseFilterType.cs"
    click CourseSortTypeN "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Schema/Sorting/CourseSortType.cs"
    click InstructorDL "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/DataLoaders/InstructorDataLoader.cs"
    click UserDL "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/DataLoaders/UserDataLoader.cs"
    click ModelsDTOs "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/Models/Subject.cs"
    click ModelsDTOs "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/DTOs/CourseDTO.cs"
    click ModelsDTOs "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/DTOs/InstructorDTO.cs"
    click ModelsDTOs "https://github.com/danishbilalansari/graphqlhotchocolatewithnetcore/blob/master/GraphQL.Demo.API/DTOs/StudentDTO.cs"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#1E90FF,color:#000
    classDef external fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef host fill:#DFF2BF,stroke:#4F8A10,color:#000
    classDef config fill:#F0F0F0,stroke:#888888,color:#000
    classDef auth fill:#FFF2CC,stroke:#D6B656,color:#000
    classDef schema fill:#E2F0D9,stroke:#92D050,color:#000
    classDef resolver fill:#D9EAD3,stroke:#6AA84F,color:#000
    classDef dataloader fill:#C9DAF8,stroke:#6D9EEB,color:#000
    classDef service fill:#F4CCCC,stroke:#CC0000,color:#000
    classDef db fill:#E7E6E6,stroke:#8A8A8A,color:#000
    classDef pubsub fill:#ECE5FF,stroke:#7F00FF,color:#000
```
