# hatena/pull-request-analysis-sample architecture

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

- Interactive diagram: https://gitdiagram.com/hatena/pull-request-analysis-sample
- Repository: https://github.com/hatena/pull-request-analysis-sample

## Overview

- Data Ingestion/Import Scripts:
- Two import scripts (script/import-pull-request.ts and script/import-teams.ts). These scripts are responsible for fetching data from external sources (for example, GitHub pull requests and team data) and loading them into the data warehouse.
- Data Storage and Transformation (BigQuery):
- There are two main directories under “bigquery”:
▪ warehouse: Contains SQL scripts (e.g., teams_repositories_relation.sql, teams_to_show.sql) that likely prepare raw data.
▪ mart: Contains SQL scripts that compute key metrics (like deploy_count and process_time histories) used to measure productivity.
- Infrastructure & Deployment:
- The terraform directory contains the infrastructure configuration (main.tf) and its lock file. This indicates that the project uses Infrastructure as Code (IaC) to provision resources such as BigQuery datasets or compute instances.
- CI/CD and Quality Tools:
- GitHub workflows (in .github/workflows) that include linting, type checking, and import tasks.
- The presence of .eslintrc.js, .prettierrc.js, and tsconfig files confirm that the project enforces coding standards and type safety.

##### Relationships and Interactions
- That the CI/CD pipeline (represented by GitHub workflows) triggers tests, linting, and type checking — ensuring that the scripts and configurations are correctly executed.
- Deployment component managed by Terraform, which sets up the required BigQuery infrastructure and potentially other cloud resources.
- Optionally, add an external “Visualization” component if there is a dashboard or reporting tool (even if it’s only implied), representing the final output of the productivity analysis.

##### Architectural Patterns and Design Principles
- The project exhibits a clear separation of concerns:
- Data ingestion (ETL scripts) is neatly separated from data transformation (SQL in BigQuery).
- Infrastructure configuration is managed independently (Terraform).
- CI/CD practices are applied via GitHub workflows.
- This separation can be roughly seen as a pipeline structure, where data flows from ingestion -> storage -> transformation -> visualization (if extended).
- The modular structure (different directories for mart, warehouse, and scripts) also hints at an architecture that is easily extensible and maintainable.

## Diagram (Mermaid)

```mermaid
graph TD
  %% CI/CD & Quality Tools
  subgraph "CI/CD & Quality Tools"
    CI1["Import PR Workflow"]:::cicd
    CI2["Import Teams Workflow"]:::cicd
    CI3["Lint Workflow"]:::cicd
    CI4["Typecheck Workflow"]:::cicd
    CI5[".eslintrc.js"]:::cicd
    CI6[".prettierrc.js"]:::cicd
    CI7["tsconfig.json"]:::cicd
    CI8["tsconfig.typecheck.json"]:::cicd
  end
  
  %% Data Ingestion / Import Scripts
  subgraph "Data Ingestion / Import Scripts"
    ETL1["Import Pull Request Script"]:::etl
    ETL2["Import Teams Script"]:::etl
  end
  
  %% BigQuery Warehouse
  subgraph "BigQuery Warehouse"
    W1["Teams Repositories Relation"]:::warehouse
    W2["Teams To Show"]:::warehouse
  end
  
  %% BigQuery Mart
  subgraph "BigQuery Mart"
    M1["Deploy Count"]:::mart
    M2["Deploy Count by Team Name"]:::mart
    M3["Process Time by Team Name"]:::mart
    M4["Process Time History"]:::mart
    M5["Process Time History by Team Name"]:::mart
  end
  
  %% Infrastructure & Deployment
  subgraph "Infrastructure & Deployment"
    INF1["Terraform Config"]:::infra
    INF2["Terraform Lock"]:::infra
  end
  
  %% Visualization (Future Extension)
  VIS1["Visualization Dashboard"]:::visual
  
  %% Connections
  CI1 -->|"triggers"| ETL1
  CI2 -->|"triggers"| ETL2

  ETL1 -->|"loads data"| W1
  ETL2 -->|"loads data"| W2

  W1 -->|"transforms to"| M1
  W1 -->|"transforms to"| M2
  W2 -->|"transforms to"| M3
  W2 -->|"transforms to"| M4
  W2 -->|"transforms to"| M5

  INF1 -->|"provisions"| W1
  INF1 -->|"provisions"| W2
  INF2 -->|"locks"| W1
  INF2 -->|"locks"| W2

  M4 -->|"feeds"| VIS1

  %% Click Events for CI/CD & Quality Tools
  click CI1 "https://github.com/hatena/pull-request-analysis-sample/blob/main/script/import-pull-request.ts"
  click CI2 "https://github.com/hatena/pull-request-analysis-sample/blob/main/script/import-teams.ts"
  click CI3 "https://github.com/hatena/pull-request-analysis-sample/blob/main/.github/workflows/lint.yml"
  click CI4 "https://github.com/hatena/pull-request-analysis-sample/blob/main/.github/workflows/typecheck.yml"
  click CI5 "https://github.com/hatena/pull-request-analysis-sample/blob/main/.eslintrc.js"
  click CI6 "https://github.com/hatena/pull-request-analysis-sample/blob/main/.prettierrc.js"
  click CI7 "https://github.com/hatena/pull-request-analysis-sample/blob/main/tsconfig.json"
  click CI8 "https://github.com/hatena/pull-request-analysis-sample/blob/main/tsconfig.typecheck.json"

  %% Click Events for Data Ingestion / Import Scripts
  click ETL1 "https://github.com/hatena/pull-request-analysis-sample/blob/main/script/import-pull-request.ts"
  click ETL2 "https://github.com/hatena/pull-request-analysis-sample/blob/main/script/import-teams.ts"

  %% Click Events for BigQuery Warehouse
  click W1 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/warehouse/teams_repositories_relation.sql"
  click W2 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/warehouse/teams_to_show.sql"

  %% Click Events for BigQuery Mart
  click M1 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/mart/deploy_count.sql"
  click M2 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/mart/deploy_count_by_team_name.sql"
  click M3 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/mart/process_time_by_team_name.sql"
  click M4 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/mart/process_time_history.sql"
  click M5 "https://github.com/hatena/pull-request-analysis-sample/blob/main/bigquery/mart/process_time_history_by_team_name.sql"

  %% Click Events for Infrastructure & Deployment
  click INF1 "https://github.com/hatena/pull-request-analysis-sample/blob/main/terraform/main.tf"
  click INF2 "https://github.com/hatena/pull-request-analysis-sample/blob/main/terraform/.terraform.lock.hcl"

  %% Styles
  classDef cicd fill:#ffeb99,stroke:#d4aa00,stroke-width:2px;
  classDef etl fill:#add8e6,stroke:#00008b,stroke-width:2px;
  classDef warehouse fill:#90ee90,stroke:#006400,stroke-width:2px;
  classDef mart fill:#98fb98,stroke:#2e8b57,stroke-width:2px;
  classDef infra fill:#d3d3d3,stroke:#808080,stroke-width:2px;
  classDef visual fill:#ffc0cb,stroke:#ff69b4,stroke-width:2px;
```
