# maddygoround/nestjs-hasura-starter architecture

> Architecture diagram of the GitHub repository maddygoround/nestjs-hasura-starter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maddygoround/nestjs-hasura-starter
- Repository: https://github.com/maddygoround/nestjs-hasura-starter

## Overview

##### Main Components Identification

a) Core Application Layer:
- Main NestJS Application Module
- GraphQL API Gateway
- Authentication System
- User Management System

b) Supporting Infrastructure:
- Configuration Management
- Guards & Security Layer
- Entity Layer
- Database Layer (implied by entities)

##### Component Relationships

a) External Interface Layer:
- GraphQL API Gateway at the top
- Incoming client requests through GraphQL endpoints

b) Authentication Flow:
- Auth Module to GraphQL Gateway
- Interaction between Auth Service and User Service
- Guard implementations for request protection

c) Data Flow:
- User Entity relationships with the database
- How Services interact with Entities

##### Specific Implementation Details

- Modules (Hexagons): AuthModule, UsersModule, ConfigModule
- Services (Rectangles): AuthService, UsersService, GraphQLService
- Guards (Shields): IdentityGuard, LoginGuard
- Strategies (Diamonds): GraphQLLocalStrategy

##### Architecture Patterns

Following architectural patterns:

- Modular architecture (NestJS modules)
- Dependency injection system
- GraphQL resolver pattern
- Authentication strategy pattern

**Client Layer**
- ↓
**GraphQL API Layer (schema.gql)**
- ↓
**Authentication Layer (auth module, guards)**
- ↓
**Business Logic Layer (services)**
- ↓
**Data Access Layer (entities)**
- ↓
**Database Layer**

##### Important Elements

- GraphQL endpoint handling
- Authentication flow with session serialization
- User management operations
- Security guard implementation points
- Configuration service integration
- Entity relationships

##### Additional Notes

- Public vs. protected endpoints
- Error handling paths

Remember to include version information and any external service dependencies that might be referenced in the configuration files. This will help other developers understand the complete system context.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph "API Gateway"
        GQL["GraphQL API Gateway"]:::gateway
        Schema["GraphQL Schema"]:::schema
    end

    subgraph "Authentication Layer"
        AM["Auth Module"]:::auth
        AS["Auth Service"]:::auth
        AR["Auth Resolver"]:::auth
        SS["Session Serializer"]:::auth
        AO["Auth Output DTO"]:::auth
    end

    subgraph "Security Layer"
        IG["Identity Guard"]:::security
        LG["Login Guard"]:::security
        GLS["GraphQL Local Strategy"]:::security
    end

    subgraph "User Management"
        UM["Users Module"]:::users
        US["Users Service"]:::users
        UE["User Entity"]:::entity
    end

    subgraph "Configuration"
        CM["Config Module"]:::config
        CS["Config Service"]:::config
    end

    subgraph "Core Application"
        AppM["App Module"]:::core
    end

    subgraph "Interfaces"
        GI["GraphQL Interface"]:::interface
        UI["Users Interface"]:::interface
    end

    subgraph "Custom Decorators"
        UD["User Decorator"]:::decorator
    end

    %% Relationships
    CL --> GQL
    GQL --> Schema
    GQL --> AR
    AR --> AS
    AS --> US
    AS --> SS
    IG --> AS
    LG --> AS
    GLS --> AS
    US --> UE
    AppM --> AM
    AppM --> UM
    AppM --> CM
    AS --> GI
    US --> UI
    AR --> AO
    IG --> UD
    CS --> AppM

    %% Click Events
    click AppM "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/app.module.ts"
    click GQL "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/graphql/graphql.service.ts"
    click Schema "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/schema.gql"
    click AM "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/auth/auth.module.ts"
    click AS "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/auth/auth.service.ts"
    click AR "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/auth/auth.resolver.ts"
    click SS "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/auth/session.serializer.ts"
    click UM "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/users/users.module.ts"
    click US "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/users/users.service.ts"
    click CM "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/config/config.module.ts"
    click CS "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/config/config.service.ts"
    click IG "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/guards/identity.guard.ts"
    click LG "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/guards/login.guard.ts"
    click GLS "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/strategies/graphql-local.strategy.ts"
    click UE "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/entities/user.entity.ts"
    click GI "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/interfaces/gql.interface.ts"
    click UI "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/interfaces/users.interface.ts"
    click AO "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/auth/dto/auth.output.ts"
    click UD "https://github.com/maddygoround/nestjs-hasura-starter/blob/master/src/decorators/user.decorator.ts"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef auth fill:#4CAF50,stroke:#2E7D32,color:white
    classDef security fill:#f44336,stroke:#c62828,color:white
    classDef users fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef config fill:#FFC107,stroke:#FFA000,color:black
    classDef entity fill:#795548,stroke:#4E342E,color:white
    classDef interface fill:#607D8B,stroke:#37474F,color:white
    classDef gateway fill:#00BCD4,stroke:#0097A7,color:white
    classDef schema fill:#009688,stroke:#00796B,color:white
    classDef decorator fill:#FF9800,stroke:#F57C00,color:white
```
