# farazkelhini/stack-pulse architecture

> Architecture diagram of the GitHub repository farazkelhini/stack-pulse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/farazkelhini/stack-pulse
- Repository: https://github.com/farazkelhini/stack-pulse

## Overview

#### Purpose and entry points
StackPulse measures technology adoption and co-occurrence across a rolling, eligible sample of public JavaScript/TypeScript GitHub repositories. It has two operational surfaces: a Next.js analytics site/API and a scheduled data pipeline. Web entry routes are `src/app/page.tsx`, `src/app/search/page.tsx`, and `src/app/technology/[slug]/page.tsx`; automation starts in `.github/workflows/daily-pipeline.yml`.

#### Data model and persistence
PostgreSQL is the system of record for tracked repositories, technology detections, snapshots, trends, and pairings. Prisma centralizes schema, migrations, client lifecycle, and initial technology seeding:
- `prisma/schema.prisma`
- `prisma/migrations/20260618140954_init/migration.sql`
- `prisma/seed.ts`
- `src/lib/prisma.ts`

The technology dictionary is seeded from repository-owned data (`data/technologies.json`), establishing the controlled vocabulary used by matching and analytics.

#### Ingestion: GitHub discovery and detection
The crawler discovers eligible GitHub repositories, reads package metadata, matches dependencies/tools against the technology dictionary, and upserts repository-to-technology links. GitHub GraphQL API access is encapsulated separately from matching and crawl orchestration:
- `src/scripts/crawl.ts`
- `src/lib/github.ts`
- `src/lib/matcher.ts`

A maintenance refresh updates existing repository links so the sample remains a 30-day rolling window:
- `scripts/refresh.ts`
- `src/scripts/crawl.ts`

This boundary requires `GITHUB_TOKEN`; crawl batching, retry, duration, and transaction controls are environment-configured.

#### Analytics pipeline
Post-ingestion stages precompute read models rather than calculating statistics at request time. Pairings use Jaccard co-occurrence; snapshots preserve daily adoption; trends derive change metrics from snapshot history:
- `src/scripts/aggregate.ts`
- `src/scripts/snapshot.ts`
- `src/scripts/trends.ts`

The scheduled workflow applies migrations, crawls, refreshes, runs these stages, then exports. It is intended to be idempotent/resumable, with ingestion/database failures critical and later analytics allowed to degrade:
- `.github/workflows/daily-pipeline.yml`
- `scripts/full_recompute.ts`

#### Dataset publication
Database-derived public artifacts are generated into committed static JSON, enabling consumption without a running app or database:
- `src/scripts/export.ts`
- `public/datasets/technologies.json`
- `public/datasets/repositories.json`
- `public/datasets/pairings.json`

Exports are schema-validated before the workflow commits them; README summary content is also pipeline-updatable through `src/scripts/update-readme.ts`.

#### Serving layer and UI boundary
Next.js 15 Route Handlers are the single data-access interface for both React Server Component pages and external consumers; pages intentionally do not query Prisma directly. Representative API resources include search, trends, technology detail, categories, and pairings:
- `src/app/api/search/route.ts`
- `src/app/api/technology/[slug]/route.ts`
- `src/app/api/trending/route.ts`
- `src/app/api/pairings/top/route.ts`

UI pages compose API-backed dashboards and charts:
- `src/app/technology/[slug]/page.tsx`
- `src/components/tech-detail/TechDashboard.tsx`
- `src/components/TrendChart.tsx`

#### Runtime, deployment, and protections
The runtime is Node.js 20+, TypeScript, Next.js/React, and Tailwind; production targets Vercel with hosted PostgreSQL 16+. GitHub Actions requires database and GitHub credentials. API rate limiting uses Vercel KV/Upstash Redis when configured and no-ops locally:
- `.env.example`
- `src/lib/rate-limit.ts`
- `src/lib/logger.ts`

Main entry points: [`.github/workflows/daily-pipeline.yml`](https://github.com/farazkelhini/stack-pulse/blob/main/.github/workflows/daily-pipeline.yml) (Daily pipeline), [`src/scripts/crawl.ts`](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/crawl.ts) (Crawl orchestration), [`src/app/api/search/route.ts`](https://github.com/farazkelhini/stack-pulse/blob/main/src/app/api/search/route.ts) (Route Handlers), [`src/scripts/export.ts`](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/export.ts) (Dataset export)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pipeline["Scheduled pipeline"]
  node_workflow["Daily pipeline<br/>GitHub Actions workflow<br/>[daily-pipeline.yml]"]
  node_crawler["Crawl orchestration<br/>ingestion script<br/>[crawl.ts]"]
  node_refresh["Rolling-window refresh<br/>maintenance script<br/>[refresh.ts]"]
  node_github["GitHub GraphQL<br/>external API client<br/>[github.ts]"]
  node_matcher["Technology matcher<br/>matching library<br/>[matcher.ts]"]
end

subgraph group_data["Data and analytics"]
  node_dictionary["Technology dictionary<br/>seed data<br/>[technologies.json]"]
  node_prisma["Prisma data layer<br/>ORM and schema<br/>[schema.prisma]"]
  node_database[("PostgreSQL<br/>system of record")]
  node_aggregate["Pairing aggregation<br/>analytics script<br/>[aggregate.ts]"]
  node_snapshot["Daily snapshots<br/>analytics script<br/>[snapshot.ts]"]
  node_trends["Trend derivation<br/>analytics script<br/>[trends.ts]"]
  node_export["Dataset export<br/>publication script<br/>[export.ts]"]
  node_datasets["Published datasets<br/>static JSON artifacts<br/>[technologies.json]"]
end

subgraph group_serving["Serving and UI"]
  node_api["Route Handlers<br/>Next.js API boundary<br/>[route.ts]"]
  node_pages["Analytics pages<br/>Next.js server pages<br/>[page.tsx]"]
  node_dashboard["Technology dashboard<br/>React UI<br/>[TechDashboard.tsx]"]
  node_rate_limit["API rate limiting<br/>[rate-limit.ts]"]
  node_vercel{{"Vercel runtime<br/>production deployment"}}
end

node_workflow -->|"migrates and seeds"| node_prisma
node_workflow -->|"runs"| node_crawler
node_workflow -->|"runs"| node_refresh
node_workflow -->|"runs"| node_aggregate
node_workflow -->|"runs"| node_snapshot
node_workflow -->|"runs"| node_trends
node_workflow -->|"runs"| node_export
node_prisma -->|"maps and connects"| node_database
node_dictionary -->|"seeds technologies"| node_prisma
node_crawler -->|"fetches metadata"| node_github
node_crawler -->|"detects technologies"| node_matcher
node_dictionary -->|"defines vocabulary"| node_matcher
node_crawler -->|"upserts repositories and links"| node_database
node_refresh -->|"reuses crawl logic"| node_crawler
node_aggregate -->|"reads detections; writes pairings"| node_database
node_snapshot -->|"writes adoption history"| node_database
node_trends -->|"reads snapshots; writes trends"| node_database
node_export -->|"reads derived data"| node_database
node_export -->|"writes validated JSON"| node_datasets
node_api -->|"queries read models"| node_database
node_pages -->|"consumes"| node_api
node_dashboard -->|"uses API-backed data"| node_api
node_pages -->|"renders"| node_dashboard
node_api -->|"guards requests"| node_rate_limit
node_vercel -->|"hosts"| node_api
node_vercel -->|"hosts"| node_pages

click node_workflow "https://github.com/farazkelhini/stack-pulse/blob/main/.github/workflows/daily-pipeline.yml"
click node_crawler "https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/crawl.ts"
click node_refresh "https://github.com/farazkelhini/stack-pulse/blob/main/scripts/refresh.ts"
click node_github "https://github.com/farazkelhini/stack-pulse/blob/main/src/lib/github.ts"
click node_matcher "https://github.com/farazkelhini/stack-pulse/blob/main/src/lib/matcher.ts"
click node_dictionary "https://github.com/farazkelhini/stack-pulse/blob/main/data/technologies.json"
click node_prisma "https://github.com/farazkelhini/stack-pulse/blob/main/prisma/schema.prisma"
click node_aggregate "https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/aggregate.ts"
click node_snapshot "https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/snapshot.ts"
click node_trends "https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/trends.ts"
click node_export "https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/export.ts"
click node_datasets "https://github.com/farazkelhini/stack-pulse/blob/main/public/datasets/technologies.json"
click node_api "https://github.com/farazkelhini/stack-pulse/blob/main/src/app/api/search/route.ts"
click node_pages "https://github.com/farazkelhini/stack-pulse/blob/main/src/app/technology/%5Bslug%5D/page.tsx"
click node_dashboard "https://github.com/farazkelhini/stack-pulse/blob/main/src/components/tech-detail/TechDashboard.tsx"
click node_rate_limit "https://github.com/farazkelhini/stack-pulse/blob/main/src/lib/rate-limit.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_workflow,node_crawler,node_refresh,node_github,node_matcher toneBlue
class node_dictionary,node_prisma,node_database,node_aggregate,node_snapshot,node_trends,node_export,node_datasets toneAmber
class node_api,node_pages,node_dashboard,node_rate_limit,node_vercel toneMint
```

## Components

### Scheduled pipeline

Daily GitHub Actions workflow refreshes the dataset.

- [Daily pipeline](https://github.com/farazkelhini/stack-pulse/blob/main/.github/workflows/daily-pipeline.yml): GitHub Actions workflow · Orchestrates migration, ingestion, analytics, and export. · `.github/workflows/daily-pipeline.yml`
- [Crawl orchestration](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/crawl.ts): ingestion script · Discovers eligible repositories and upserts detections. · `src/scripts/crawl.ts`
- [Rolling-window refresh](https://github.com/farazkelhini/stack-pulse/blob/main/scripts/refresh.ts): maintenance script · Refreshes existing repository links for the 30-day sample. · `scripts/refresh.ts`
- [GitHub GraphQL](https://github.com/farazkelhini/stack-pulse/blob/main/src/lib/github.ts): external API client · Uses GITHUB_TOKEN to fetch repositories and package metadata. · `src/lib/github.ts`
- [Technology matcher](https://github.com/farazkelhini/stack-pulse/blob/main/src/lib/matcher.ts): matching library · Matches package tools and dependencies to the controlled vocabulary. · `src/lib/matcher.ts`

### Data and analytics

PostgreSQL is the authoritative operational store.

- [Technology dictionary](https://github.com/farazkelhini/stack-pulse/blob/main/data/technologies.json): seed data · Controlled vocabulary for matching and analytics. · `data/technologies.json`
- [Prisma data layer](https://github.com/farazkelhini/stack-pulse/blob/main/prisma/schema.prisma): ORM and schema · Owns schema, migrations, client lifecycle, and seeding. · `prisma/schema.prisma`
- **PostgreSQL**: system of record · Stores repositories, detections, snapshots, trends, and pairings.
- [Pairing aggregation](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/aggregate.ts): analytics script · Precomputes Jaccard technology co-occurrence. · `src/scripts/aggregate.ts`
- [Daily snapshots](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/snapshot.ts): analytics script · Preserves daily adoption values. · `src/scripts/snapshot.ts`
- [Trend derivation](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/trends.ts): analytics script · Derives change metrics from snapshot history. · `src/scripts/trends.ts`
- [Dataset export](https://github.com/farazkelhini/stack-pulse/blob/main/src/scripts/export.ts): publication script · Validates and generates public database-derived JSON. · `src/scripts/export.ts`
- [Published datasets](https://github.com/farazkelhini/stack-pulse/blob/main/public/datasets/technologies.json): static JSON artifacts · Committed technology, repository, and pairing datasets. · `public/datasets/technologies.json`

### Serving and UI

Route Handlers isolate pages from Prisma.

- [Route Handlers](https://github.com/farazkelhini/stack-pulse/blob/main/src/app/api/search/route.ts): Next.js API boundary · Single data-access interface for pages and external consumers. · `src/app/api/search/route.ts`
- [Analytics pages](https://github.com/farazkelhini/stack-pulse/blob/main/src/app/technology/%5Bslug%5D/page.tsx): Next.js server pages · Dashboard, search, and technology-detail routes. · `src/app/technology/[slug]/page.tsx`
- [Technology dashboard](https://github.com/farazkelhini/stack-pulse/blob/main/src/components/tech-detail/TechDashboard.tsx): React UI · Composes technology detail and trend visualizations. · `src/components/tech-detail/TechDashboard.tsx`
- [API rate limiting](https://github.com/farazkelhini/stack-pulse/blob/main/src/lib/rate-limit.ts): Vercel KV / Upstash Redis · No-ops locally when Redis is not configured. · `src/lib/rate-limit.ts`
- **Vercel runtime**: production deployment · Runs the Node.js Next.js application.

## Connections

- Daily pipeline → Prisma data layer: migrates and seeds
- Daily pipeline → Crawl orchestration: runs
- Daily pipeline → Rolling-window refresh: runs
- Daily pipeline → Pairing aggregation: runs
- Daily pipeline → Daily snapshots: runs
- Daily pipeline → Trend derivation: runs
- Daily pipeline → Dataset export: runs
- Prisma data layer → PostgreSQL: maps and connects
- Technology dictionary → Prisma data layer: seeds technologies
- Crawl orchestration → GitHub GraphQL: fetches metadata
- Crawl orchestration → Technology matcher: detects technologies
- Technology dictionary → Technology matcher: defines vocabulary
- Crawl orchestration → PostgreSQL: upserts repositories and links
- Rolling-window refresh → Crawl orchestration: reuses crawl logic
- Pairing aggregation → PostgreSQL: reads detections; writes pairings
- Daily snapshots → PostgreSQL: writes adoption history
- Trend derivation → PostgreSQL: reads snapshots; writes trends
- Dataset export → PostgreSQL: reads derived data
- Dataset export → Published datasets: writes validated JSON
- Route Handlers → PostgreSQL: queries read models
- Analytics pages → Route Handlers: consumes
- Technology dashboard → Route Handlers: uses API-backed data
- Analytics pages → Technology dashboard: renders
- Route Handlers → API rate limiting: guards requests
- Vercel runtime → Route Handlers: hosts
- Vercel runtime → Analytics pages: hosts
