# mwickett/blitzer architecture

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

- Interactive diagram: https://gitdiagram.com/mwickett/blitzer
- Repository: https://github.com/mwickett/blitzer

## Overview

##### Project Type and Purpose
- This is a full-stack web application designed to capture and analyze scores for the card game Dutch Blitz. The project uses Next.js for its front-end and API routes, Prisma with Neon for database operations, and incorporates external services like Clerk for authentication, PostHog for analytics, and Sentry for error tracking. The README makes it clear that the primary goal is to create an engaging, personal dataset and analytics experience for Dutch Blitz enthusiasts.

##### Analyzing the File Structure
- Notice the Next.js layout in the “src/app” directory. It contains pages (for home, dashboard, sign-in, etc.), API routes (for rounds, webhooks, games, friends), and shared UI components (in “src/components” and “src/components/ui”).
- The “src/server” directory holds business logic, queries, mutations, and database integrations—including migrations and the Prisma schema. This shows a clear separation where API endpoints in the app directory delegate more complex or secure operations to backend modules.
- Additional configuration files are present (e.g., next.config.mjs, jest.config.js, tailwind.config.ts) alongside Docker and GitHub workflow files, indicating CI/CD and styling considerations.

##### Main Components to be Included
a. Frontend (User Interface):
- Next.js pages in “src/app”: Home, Dashboard, Games, Friends, and Sign-in pages.
- Shared UI components (buttons, cards, dialogs, etc.) in “src/components/ui”.
- Client-side integrations such as PostHog analytics (see PostHogProvider.tsx) and Sentry configurations.
b. API Layer:
- API endpoints within “src/app/api” for handling dynamic actions (e.g., game rounds and webhooks).
- These endpoints act as bridges between the UI and server-side logic.
c. Backend/Server:
- “src/server”: Handles heavier business logic, including database queries, mutations, and utility functions.
- Server-side tests ensuring business rules and validation logic (in “src/lib/__tests__” and “src/server/__tests__”).
d. Database:
- Prisma ORM, indicated by the “schema.prisma”, database migrations in “src/server/db/migrations”, and the database initialization file.
- Neon as the hosting provider for the database.
e. Authentication & Analytics:
- Clerk is used for user authentication, and the integration is configured with Clerk’s API endpoints.
- PostHog for event tracking and analytics.
f. External Tools & Configuration:
- Docker Compose for container orchestration.
- GitHub workflows for continuous integration and deployment.

##### Relationships and Interactions
- The API endpoints, encapsulated in Next.js routes, interface with the backend logic in “src/server” and access the database via Prisma.
- User authentication (Clerk) and analytics (PostHog) are integrated across the application layers, ensuring authentication state and user interactions are tracked.
- Sentry configurations (available as separate config files for client, server, and edge) are integrated to monitor errors throughout the system.
- External services like Vercel (deployment environment) and Neon (hosted database) should be represented as external endpoints linked to their respective components.

##### Architectural Patterns and Design Principles
- Component-based architecture typical of Next.js, separating presentation, API, and server layers.
- Emphasis on modularity: clear separation of concerns between frontend pages, UI components, and deeper server logic.
- Layering: Graphically distinguish between client-side (Next.js app and UI), server-side (business logic, queries, mutations), and persistence (database with Prisma).
- Use of migration files and strict test folders indicates a strong focus on version control and reliability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External: User and Deployment
    User["User Browser"]:::external
    Vercel["Vercel Deployment"]:::external
    Neon["Neon Database Host"]:::external

    %% Frontend Layer Subgraph
    subgraph "Frontend Layer"
        FE_Next["Next.js Pages"]:::frontend
        FE_UI["UI Components"]:::frontend
    end

    %% API Layer Subgraph
    subgraph "API Layer"
        API["API Endpoints"]:::api
    end

    %% Backend Layer Subgraph
    subgraph "Backend Layer"
        BE["Business Logic / Server"]:::backend
        subgraph "Testing Infrastructure"
            Tests_Front["Frontend/Lib Tests"]:::backend
            Tests_Server["Server Tests"]:::backend
        end
    end

    %% Database Layer Subgraph
    subgraph "Database Layer"
        DB_Prisma["Prisma Schema"]:::database
        DB_Mig["DB Migrations"]:::database
    end

    %% External Services Subgraph
    subgraph "External Services"
        Clerk["Auth (Clerk)"]:::external
        subgraph "Analytics (PostHog)"
            PH_Provider["PostHog Provider"]:::external
            PH_PageView["PostHog Page View"]:::external
        end
        SentryClient["Sentry Client"]:::external
        SentryServer["Sentry Server"]:::external
        SentryEdge["Sentry Edge"]:::external
        Docker["Docker Compose"]:::external
        CI["GitHub Workflows"]:::external
    end

    %% Arrows: User interactions
    User -->|"visits"| FE_Next
    User -->|"interacts"| FE_UI

    %% Arrows: Frontend to API communication
    FE_Next -->|"calls"| API
    FE_UI -->|"fetches data"| API

    %% Arrows: API to Backend interaction
    API -->|"delegates to"| BE

    %% Arrows: Backend to Database access
    BE -->|"queries/mutates"| DB_Prisma
    BE -->|"uses migrations"| DB_Mig

    %% Arrows: External integrations from Frontend
    FE_Next -->|"auth"| Clerk
    FE_Next -->|"analytics"| PH_Provider
    FE_Next -->|"analytics"| PH_PageView
    FE_Next -->|"error"| SentryClient

    %% Arrows: External integrations from API and Backend
    API -->|"error"| SentryServer
    BE -->|"error"| SentryEdge

    %% Arrows: Deployment & Configuration
    FE_Next --- Vercel
    API --- Vercel
    BE --- Docker
    BE --- CI
    DB_Prisma --- Neon
    DB_Mig --- Neon

    %% Arrows: Testing connection
    BE -->|"tested by"| Tests_Front
    BE -->|"tested by"| Tests_Server
    FE_UI -->|"triggers updates"| BE

    %% Click Events
    click FE_Next "https://github.com/mwickett/blitzer/tree/main/src/app"
    click FE_UI "https://github.com/mwickett/blitzer/tree/main/src/components/ui"
    click API "https://github.com/mwickett/blitzer/tree/main/src/app/api"
    click BE "https://github.com/mwickett/blitzer/tree/main/src/server"
    click DB_Prisma "https://github.com/mwickett/blitzer/blob/main/src/server/db/schema.prisma"
    click DB_Mig "https://github.com/mwickett/blitzer/tree/main/src/server/db/migrations"
    click Clerk "https://github.com/mwickett/blitzer/tree/main/src/app/sign-in"
    click PH_Provider "https://github.com/mwickett/blitzer/blob/main/src/app/PostHogProvider.tsx"
    click PH_PageView "https://github.com/mwickett/blitzer/blob/main/src/app/PostHogPageView.tsx"
    click SentryClient "https://github.com/mwickett/blitzer/blob/main/sentry.client.config.ts"
    click SentryServer "https://github.com/mwickett/blitzer/blob/main/sentry.server.config.ts"
    click SentryEdge "https://github.com/mwickett/blitzer/blob/main/sentry.edge.config.ts"
    click Tests_Front "https://github.com/mwickett/blitzer/tree/main/src/lib/__tests__"
    click Tests_Server "https://github.com/mwickett/blitzer/tree/main/src/server/__tests__"
    click Docker "https://github.com/mwickett/blitzer/blob/main/docker-compose.yml"
    click CI "https://github.com/mwickett/blitzer/tree/main/.github/workflows"

    %% Style Definitions
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef api fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef database fill:#fffacd,stroke:#000,stroke-width:1px;
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px;
```
