# thdk/team-timesheets architecture

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

- Interactive diagram: https://gitdiagram.com/thdk/team-timesheets
- Repository: https://github.com/thdk/team-timesheets

## Overview

##### Main Components
- Frontend Application:
- Represented by the src directory which contains pages, components, containers, routes, contexts, and state management stores.
- Use of React (with .tsx files), webpack configuration, and custom hooks.
- Backend (Cloud Functions):
- Found in the functions directory, which handles business logic (e.g., CSV exports, Firestore data import/export, OAuth integrations, BigQuery syncing).
- Shared/ Common Layer:
- The “common” directory stores shared TypeScript interfaces and utility functions that maintain consistency across both frontend and backend.
- Database & Firebase Services:
- Firebase is used as a backend service: Firestore, and the project contains firebase.json, firestore.rules, and Firestore indexes.
- Deployment & Build Containers:
- The build-containers directory (with separate configurations for the “app” and “firebase”) plus Cloud Build configurations indicate automated builds and deployments.
- External Integrations:
- External systems integrated include Google Calendar (for event-based suggestions), GitHub (for OAuth and registration suggestions), Jira, and BigQuery (for advanced reporting).

##### Relationships and Interactions
- The Frontend interacts with Firebase (either directly via Firebase SDK or through cloud functions) to read and update timesheet data.
- The Cloud Functions serve as an intermediary for more complex operations such as CSV generation and BigQuery exports, processing inputs coming from the frontend.
- The shared “common” modules enable both layers to use the same data models and interfaces.
- OAuth and other external integrations (Google Calendar, GitHub, etc.) interact with the frontend and cloud functions to fetch user-specific data for timesheet suggestions and reporting.

##### Important Architectural Patterns/Design Principles
- Separation of Concerns:
- Frontend presentation logic is decoupled from backend business logic.
- Modularization:
- Clear separation between components, containers, contexts, and routes in the frontend.
- Independent cloud functions for distinct tasks.
- Reusable Shared Code:
- Using a common directory to encapsulate shared interfaces and serialization logic across layers.
- Cloud-Native Deployment:
- Deployment scripts and container definitions suggest containerized builds with Cloud Build integration.

- “Frontend Application (React)” with details like “Pages, Components, Routes, Contexts, and Stores.”
- “Firebase Cloud Functions” with sub-components such as “CSV Generation”, “OAuth Logic”, “Firestore Processing”, and “BigQuery Integration.”
- “Firebase Services & Firestore Database” with annotations for “firestore.rules” and security settings.
- “Shared Common Library” for data interfaces and serialization.
- “Build & Deployment” including “Cloud Build” and “Containerized Deployments” as represented in build-containers and cloudbuild configuration files.
- Notes on integration points:
- For instance, annotate OAuth providers and Google Calendar as external sources that feed data into the app.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    FE["Frontend Application (React)\n(Pages, Components, Routes, Contexts, Stores)"]:::frontend

    %% Backend Layer
    BE["Firebase Cloud Functions\n(CSV, OAuth, Firestore Processing, BigQuery)"]:::backend

    %% Shared Common Layer
    Shared["Shared Common Library\n(TypeScript interfaces, utilities, serializers)"]:::common

    %% Firebase Services & Database Configuration
    subgraph "Firebase Services & Database"
        DB["Firebase & Firestore"]:::database
        Fjson["firebase.json"]:::database
        Frules["firestore.rules"]:::database
        Findexes["firestore.indexes.json"]:::database
    end

    %% Deployment & Build Containers
    subgraph "Deployment & Build Containers"
        Deploy["Deployment & Build"]:::deployment
        subgraph "Build Containers"
            AppC["App Container"]:::deployment
            FirebaseC["Firebase Container"]:::deployment
        end
        CB_Build["Cloud Build (Build)"]:::deployment
        CB_Deploy["Cloud Build (Deploy)"]:::deployment
    end

    %% External Integrations
    subgraph "External Integrations"
        GCal["Google Calendar"]:::external
        Git["GitHub"]:::external
        Jira["Jira"]:::external
        BigQuery["BigQuery"]:::external
    end

    %% OAuth Components
    OAuth_BE["Backend OAuth Logic"]:::backend
    OAuth_FE["Frontend OAuth Providers"]:::frontend

    %% Relationships
    FE -->|"calls"| BE
    FE -->|"uses"| DB
    BE -->|"reads/writes"| DB

    FE -->|"shares"| Shared
    BE -->|"shares"| Shared

    Deploy -->|"deploys"| FE
    Deploy -->|"deploys"| BE

    OAuth_BE -->|"manages"| BE
    OAuth_FE -->|"manages"| FE

    OAuth_FE -->|"integrates"| GCal
    OAuth_FE -->|"integrates"| Git
    OAuth_FE -->|"integrates"| Jira
    OAuth_BE -->|"integrates"| BigQuery

    %% Click Events
    click FE "https://github.com/thdk/team-timesheets/tree/master/src"
    click BE "https://github.com/thdk/team-timesheets/tree/master/functions"
    click Shared "https://github.com/thdk/team-timesheets/tree/master/common"
    click Fjson "https://github.com/thdk/team-timesheets/blob/master/firebase.json"
    click Frules "https://github.com/thdk/team-timesheets/blob/master/firestore.rules"
    click Findexes "https://github.com/thdk/team-timesheets/blob/master/firestore.indexes.json"
    click AppC "https://github.com/thdk/team-timesheets/tree/master/build-containers/app"
    click FirebaseC "https://github.com/thdk/team-timesheets/tree/master/build-containers/firebase"
    click CB_Build "https://github.com/thdk/team-timesheets/blob/master/cloudbuild.build.yaml"
    click CB_Deploy "https://github.com/thdk/team-timesheets/blob/master/cloudbuild.deploy.yaml"
    click OAuth_BE "https://github.com/thdk/team-timesheets/blob/master/functions/src/oauth.ts"
    click OAuth_FE "https://github.com/thdk/team-timesheets/tree/master/src/oauth-providers"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef common fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef deployment fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#FFDEAD,stroke:#000,stroke-width:2px;
```
