# progwise/timebook architecture

> Architecture diagram of the GitHub repository progwise/timebook, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/progwise/timebook
- Repository: https://github.com/progwise/timebook

## Overview

##### Main Components

a. Applications Layer:
- Web Application (Next.js)
- Stream Deck Plugin
- E2E Testing Suite (Playwright)

b. Package Layer:
- Backend Package (GraphQL + Prisma)
- UI Package (Reusable Components)
- Validations Package (Zod Schemas)
- Infrastructure Package (Pulumi)

c. External Services:
- PostgreSQL Database
- PayPal Integration
- Authentication System (NextAuth.js)

##### Component Relationships

**Web Application**
- Frontend (Next.js)
- Pages
- Components
- API Routes
- Backend (GraphQL)
- Schema
- Resolvers
- Prisma Client
- Database Layer

##### Specific Implementation Details

a. Frontend Architecture:
- Next.js pages structure (/pages directory)
- UI components from the shared UI package
- Demonstrate form validation flow using the validations package

b. Backend Architecture:
- GraphQL API endpoint (/api/graphql)
- Prisma database layer
- Authentication middleware
- PayPal integration services

##### Data Flow Representation

- Client requests → Next.js pages → GraphQL API
- GraphQL resolvers → Prisma → Database
- Authentication flow through NextAuth.js
- Payment processing through PayPal

##### Infrastructure Layer

A section showing:
- Docker containers
- Pulumi infrastructure configuration
- Development vs Production environments

##### Key Elements to Highlight

- GraphQL API as the central communication hub
- Shared package dependencies
- Database schema and migrations
- Authentication and authorization flow
- Stream Deck plugin integration

##### Infrastructure Layer (Docker, Pulumi)

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that matter most for understanding the system's structure and behavior.

- How different parts of the system interact
- Where to find specific functionality
- How data flows through the system
- How to extend or modify the system
- Where to add new features
- How to troubleshoot issues

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef database fill:#f1c40f,color:white
    classDef external fill:#9b59b6,color:white
    classDef package fill:#e67e22,color:white

    %% Applications Layer
    subgraph Applications
        WebApp["Web Application (Next.js)"]
        StreamDeck["Stream Deck Plugin"]
        E2E["E2E Testing Suite"]
    end

    %% Frontend Layer
    subgraph Frontend
        Pages["Pages"]
        Components["Components"]
        APIRoutes["API Routes"]
        Auth["NextAuth.js"]
        PaypalWebhook["PayPal Webhook"]
    end

    %% Backend Layer
    subgraph Backend
        GraphQL["GraphQL API"]
        Resolvers["Resolvers"]
        PrismaClient["Prisma Client"]
        PayPalAPI["PayPal Integration"]
    end

    %% Packages Layer
    subgraph Packages
        UIPackage["UI Package"]
        ValidationPackage["Validations Package"]
        InfraPackage["Infrastructure Package"]
    end

    %% Database Layer
    subgraph Data
        PostgreSQL[(PostgreSQL)]
        Schema["Database Schema"]
        Migrations["Migrations"]
    end

    %% External Services
    PayPal["PayPal Service"]

    %% Relationships
    WebApp --> Pages
    Pages --> Components
    Pages --> APIRoutes
    APIRoutes --> Auth
    APIRoutes --> PaypalWebhook
    APIRoutes --> GraphQL
    StreamDeck --> GraphQL
    Components --> UIPackage
    GraphQL --> Resolvers
    Resolvers --> PrismaClient
    PrismaClient --> PostgreSQL
    PaypalWebhook --> PayPalAPI
    PayPalAPI --> PayPal
    Schema --> PostgreSQL
    Migrations --> PostgreSQL
    E2E --> WebApp

    %% Style Applications
    class WebApp frontend
    class StreamDeck frontend
    class E2E frontend
    class Pages frontend
    class Components frontend
    class APIRoutes frontend
    class Auth frontend
    class PaypalWebhook frontend

    %% Style Backend
    class GraphQL backend
    class Resolvers backend
    class PrismaClient backend
    class PayPalAPI backend

    %% Style Database
    class PostgreSQL database
    class Schema database
    class Migrations database

    %% Style External
    class PayPal external

    %% Style Packages
    class UIPackage package
    class ValidationPackage package
    class InfraPackage package

    %% Click Events
    click WebApp "https://github.com/progwise/timebook/tree/main/apps/web/"
    click StreamDeck "https://github.com/progwise/timebook/tree/main/apps/stream-deck/net.progwise.timebook.sdPlugin/"
    click E2E "https://github.com/progwise/timebook/tree/main/apps/web-e2e/"
    click Pages "https://github.com/progwise/timebook/tree/main/apps/web/pages/"
    click Auth "https://github.com/progwise/timebook/blob/main/apps/web/pages/api/auth/[...nextauth].page.ts"
    click PaypalWebhook "https://github.com/progwise/timebook/blob/main/apps/web/pages/api/paypal-webhook.page.ts"
    click GraphQL "https://github.com/progwise/timebook/tree/main/packages/backend/src/graphql/"
    click UIPackage "https://github.com/progwise/timebook/tree/main/packages/ui/"
    click ValidationPackage "https://github.com/progwise/timebook/tree/main/packages/validations/"
    click InfraPackage "https://github.com/progwise/timebook/tree/main/packages/pulumi/"
    click PayPalAPI "https://github.com/progwise/timebook/tree/main/packages/backend/src/paypalapi/"
    click Schema "https://github.com/progwise/timebook/blob/main/packages/backend/src/prisma/schema.prisma"
    click Migrations "https://github.com/progwise/timebook/tree/main/packages/backend/src/prisma/migrations/"
```
