# tendrelhq/graphql architecture

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

- Interactive diagram: https://gitdiagram.com/tendrelhq/graphql
- Repository: https://github.com/tendrelhq/graphql

## Overview

##### Main Components

a) API Layer:
- GraphQL Server (Core)
- Schema Modules:
- Application Domain (/schema/application)
- Platform Domain (/schema/platform)
- System Domain (/schema/system)
- Legacy Domain (/schema/legacy)

b) Data Layer:
- PostgreSQL Database (indicated by postgresql.conf and datasources)
- Data Sources (/lib/datasources):
- User Management
- Organization Management
- Authentication
- Requirements
- Status Management
- Attachments

c) Infrastructure:
- Docker Container Environment
- AWS Copilot Deployment Infrastructure (indicated by /copilot directory)
- Development/Testing/Beta Environments

**[Client Applications]**
- ↓
**[GraphQL API Layer]**
- ↓
**[Data Layer]**

**[Client Applications]**
- ↓
**[GraphQL API Layer]**
- Schema Domains
- Application
- Platform
- System
- Legacy
- Resolvers
- Type Definitions

**[Data Layer]**
- PostgreSQL
- Data Sources
- User
- Organization
- Requirements
- Other Entities

##### Key Elements to Highlight

a) Authentication Flow:
- Auth middleware (lib/auth.ts)
- Connection to user/worker management

b) Data Flow:
- GraphQL query/mutation paths
- Data source interactions
- Entity relationships

c) Infrastructure Components:
- AWS deployment pipeline
- Environment segregation (dev/test/beta)
- Monitoring/Instrumentation (lib/instrument.ts)

##### Architectural Patterns to Emphasize

- GraphQL schema stitching/federation
- Data source abstraction layer
- Domain-driven design (evident in schema organization)
- Infrastructure as Code (AWS Copilot)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Applications]
    end

    subgraph API["GraphQL API Layer"]
        GQL[GraphQL Server]
        
        subgraph Schemas["Schema Domains"]
            APP["Application Domain"]:::schema
            PLAT["Platform Domain"]:::schema
            SYS["System Domain"]:::schema
            LEG["Legacy Domain"]:::schema
        end
        
        subgraph Core["Core Features"]
            AUTH["Authentication"]:::core
            UPLOAD["File Upload"]:::core
            I18N["Internationalization"]:::core
            INSTR["Instrumentation"]:::core
        end
    end

    subgraph Data["Data Layer"]
        PG[(PostgreSQL)]:::db
        
        subgraph DS["Data Sources"]
            USER["User Management"]:::datasource
            ORG["Organization Management"]:::datasource
            WORK["Worker Management"]:::datasource
            REQ["Requirements"]:::datasource
            STATUS["Status Management"]:::datasource
            ATTACH["Attachments"]:::datasource
            AUDIT["Audit Logging"]:::datasource
        end
    end

    subgraph Infra["Infrastructure"]
        DOCKER["Docker Container"]:::infra
        
        subgraph AWS["AWS Copilot"]
            DEV["Development Env"]:::env
            TEST["Testing Env"]:::env
            BETA["Beta Env"]:::env
        end
    end

    C --> GQL
    GQL --> APP & PLAT & SYS & LEG
    GQL --> AUTH & UPLOAD & I18N & INSTR
    AUTH & UPLOAD & I18N & INSTR --> DS
    APP & PLAT & SYS & LEG --> DS
    DS --> PG
    PG -.-> DOCKER
    DOCKER -.-> AWS

    %% Click Events
    click APP "https://github.com/tendrelhq/graphql/tree/main/schema/application/"
    click PLAT "https://github.com/tendrelhq/graphql/tree/main/schema/platform/"
    click SYS "https://github.com/tendrelhq/graphql/tree/main/schema/system/"
    click LEG "https://github.com/tendrelhq/graphql/tree/main/schema/legacy/"
    click USER "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/user.ts"
    click ORG "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/organization.ts"
    click WORK "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/worker.ts"
    click REQ "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/requirement.ts"
    click STATUS "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/status.ts"
    click ATTACH "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/attachment.ts"
    click AUDIT "https://github.com/tendrelhq/graphql/blob/main/lib/datasources/auditable.ts"
    click DOCKER "https://github.com/tendrelhq/graphql/tree/main/Dockerfile"
    click AWS "https://github.com/tendrelhq/graphql/tree/main/copilot/"
    click DEV "https://github.com/tendrelhq/graphql/tree/main/copilot/environments/dev/"
    click TEST "https://github.com/tendrelhq/graphql/tree/main/copilot/environments/test/"
    click BETA "https://github.com/tendrelhq/graphql/tree/main/copilot/environments/beta/"
    click AUTH "https://github.com/tendrelhq/graphql/blob/main/lib/auth.ts"
    click UPLOAD "https://github.com/tendrelhq/graphql/blob/main/lib/upload.ts"
    click I18N "https://github.com/tendrelhq/graphql/blob/main/lib/i18n.ts"
    click INSTR "https://github.com/tendrelhq/graphql/blob/main/lib/instrument.ts"
    click PG "https://github.com/tendrelhq/graphql/blob/main/postgresql.conf"

    %% Styling
    classDef schema fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef datasource fill:#4CAF50,stroke:#388E3C,color:white
    classDef db fill:#FFC107,stroke:#FFA000,color:black
    classDef infra fill:#FF5722,stroke:#E64A19,color:white
    classDef env fill:#795548,stroke:#5D4037,color:white

    %% Legend
    subgraph Legend
        L1["Schema Domain"]:::schema
        L2["Core Feature"]:::core
        L3["Data Source"]:::datasource
        L4["Database"]:::db
        L5["Infrastructure"]:::infra
        L6["Environment"]:::env
    end
```
