# betocattani/nfl-rushing architecture

> Architecture diagram of the GitHub repository betocattani/nfl-rushing, 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/betocattani/nfl-rushing
- Repository: https://github.com/betocattani/nfl-rushing

## Overview

- Client/Consumer: Represent users accessing either the GraphiQL Playground (via browser at localhost:4000/graphiql) or other external client applications that issue GraphQL queries and mutations.
- Web Server / Phoenix Endpoint: Include the Phoenix endpoint (lib/the_score_web/endpoint.ex) which receives HTTP requests and manages WebSocket connections (user_socket defined in channels).
- Router: Represent the Phoenix router (lib/the_score_web/router.ex) that dispatches incoming requests to the appropriate controllers or GraphQL schema.
- GraphQL API Layer:
- Schema: Illustrate the GraphQL schema (lib/the_score_web/schema.ex and submodules within lib/the_score_web/schema) where types, queries, and mutations are defined.
- Resolvers: Include the GraphQL resolvers (for example, lib/the_score_web/resolvers/players.ex) that contain the business logic to service GraphQL queries/mutations.
- Middleware: Represent the use of any middleware (lib/the_score_web/schema/middleware), such as changeset error handling.
- Business Logic / Domain Layer: Show the core application logic within the “the_score” context (from files in lib/the_score and lib/the_score/players) that encapsulates player profiles and related operations.
- Data Persistence / Repository Layer: Mark the “Repo” (lib/the_score/repo.ex) which is built with Ecto, and point out the existence of migrations (priv/repo/migrations) that define the PostgreSQL database schema.
- Database: Indicate PostgreSQL as the persistent storage layer.

##### Relationships and Data Flow
- From the Endpoint, indicate request routing through the Router to the GraphQL API layer.
- From the Resolver, show the connection to the Business Logic / Domain components (for instance, modules within lib/the_score and its players subdirectory).
- Development utilities (for example, dev/support/import_data.ex) as auxiliary components used for data seeding and import operations.

##### Architectural Patterns and Design Principles
- Separation of concerns: the presentation layer (Phoenix Web/Endpoint), the API layer (GraphQL schema and resolvers), the business logic (core domain modules), and the persistence layer (Ecto Repo and PostgreSQL).
- That the GraphQL API encapsulates the application’s external interface and provides flexible querying and mutation capabilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client("GraphQL Client / GraphiQL (Browser)"):::external

    %% Web/API Layer
    subgraph "Web/API Layer"
        Endpoint("Phoenix Endpoint"):::web
        Router("Phoenix Router"):::web
        subgraph "GraphQL API"
            Schema("GraphQL Schema"):::api
            PlayerTypes("Player Types"):::api
            Resolvers("Player Resolvers"):::api
            Middleware("GraphQL Middleware"):::api
            Changeset("Changeset Errors"):::api
        end
    end

    %% Domain / Business Logic Layer
    subgraph "Domain / Business Logic"
        Core("Core Domain Logic"):::domain
        Players("Players Domain"):::domain
        Profile("Player Profile"):::domain
    end

    %% Data Persistence Layer
    subgraph "Data Persistence Layer"
        Repo("Ecto Repo"):::repo
        Migrations("Migrations"):::repo
        Database("PostgreSQL Database"):::db
    end

    %% Development Utilities
    subgraph "Development Utilities"
        ImportData("Data Import"):::dev
        Seeds("Data Seeds"):::dev
    end

    %% Connections from External Client to Web/API
    Client -->|"HTTP/WebSocket Request"| Endpoint
    Endpoint -->|"Routing"| Router
    Router -->|"Dispatches to"| Schema

    %% GraphQL API internal flow
    Schema -->|"Defines queries/mutations"| PlayerTypes
    Schema -->|"Sends query to"| Resolvers
    Middleware -->|"Processes errors with"| Changeset

    %% From GraphQL layer to Domain/Business Logic
    Resolvers -->|"Calls"| Core

    %% Domain layer flow
    Core -->|"Delegates to"| Players
    Players -->|"Handles operations"| Profile

    %% Domain to Data Persistence flow
    Profile -->|"Reads/Writes data via"| Repo
    Repo -->|"Executes migrations on"| Migrations
    Repo -->|"Persists data in"| Database

    %% Development Utilities seeding data
    ImportData -->|"Seeds data into"| Repo
    Seeds -->|"Runs seeds on"| Repo

    %% Click Events
    click Endpoint "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score_web/endpoint.ex"
    click Router "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score_web/router.ex"
    click Schema "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score_web/schema.ex"
    click PlayerTypes "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score_web/schema/player_types.ex"
    click Resolvers "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score_web/resolvers/players.ex"
    click Middleware "https://github.com/betocattani/nfl-rushing/tree/main/lib/the_score_web/schema/middleware"
    click Changeset "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score_web/schema/middleware/changeset_errors.ex"
    click Core "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score.ex"
    click Players "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score/players.ex"
    click Profile "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score/players/profile.ex"
    click Repo "https://github.com/betocattani/nfl-rushing/blob/main/lib/the_score/repo.ex"
    click Migrations "https://github.com/betocattani/nfl-rushing/tree/main/priv/repo/migrations"
    click ImportData "https://github.com/betocattani/nfl-rushing/blob/main/dev/support/import_data.ex"
    click Seeds "https://github.com/betocattani/nfl-rushing/blob/main/dev/support/seeds.ex"

    %% Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef web fill:#bbf,stroke:#333,stroke-width:2px;
    classDef api fill:#cfc,stroke:#333,stroke-width:2px;
    classDef domain fill:#fc9,stroke:#333,stroke-width:2px;
    classDef repo fill:#fdd,stroke:#333,stroke-width:2px;
    classDef db fill:#fcc,stroke:#333,stroke-width:2px;
    classDef dev fill:#cff,stroke:#333,stroke-width:2px;
```
