# insight-services-apac/tokenscope-public architecture

> Architecture diagram of the GitHub repository insight-services-apac/tokenscope-public, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/insight-services-apac/tokenscope-public
- Repository: https://github.com/insight-services-apac/tokenscope-public

## Overview

TokenScope is an AI-engineering usage attribution and budget-management product. Developers connect Claude Code or Copilot CLI, emit usage, and see it attributed to teammates, sessions, and projects; managers govern project budgets and top-ups, while finance and admins reconcile provider billing and manage organizational policy. The graph separates ingestion and attribution, reconciliation, project administration, and reporting/usage views. README statements support the major product flows; sampled source confirms selected UI calls, policy persistence, reconciliation, and worker behavior, but not every route-level connection.

Main entry points: [`drizzle/schema/index.ts`](https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/index.ts) (PostgreSQL), [`app/pages/index.vue`](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/index.vue) (Developer dashboard), [`app/pages/reporting/index.vue`](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/reporting/index.vue) (Finance and reports), [`drizzle/schema/attribution.ts`](https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/attribution.ts) (Usage attribution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Usage capture"]
  node_clients["Claude and Copilot<br/>[session-start.mjs]"]
  node_connect["Connect guidance<br/>[connect-guides.ts]"]
  node_telemetry["Telemetry receiver"]
  node_provider["Provider APIs"]
end

subgraph group_governance["Attribution and governance"]
  node_attribution["Usage attribution<br/>[attribution.ts]"]
  node_identity["Identity and org<br/>[identity.ts]"]
  node_governance["Governance rules<br/>[governance.ts]"]
  node_reconciliation["Billing reconciliation<br/>[engine.ts]"]
  node_placement["Directory placement"]
  node_tagging["Session tagging"]
  node_overage["Copilot overage allocation"]
  node_mitigation["Telemetry gap detection"]
end

subgraph group_operations["Project operations"]
  node_projects["Project budgets<br/>[&#91;code&#93;.vue]"]
  node_requests["Project requests<br/>[index.get.ts]"]
  node_allocations["Budget allocations<br/>[append-topup.ts]"]
  node_adminui["Admin operations<br/>[org-setup.vue]"]
end

subgraph group_insight["Usage and reporting"]
  node_home["Developer dashboard<br/>[index.vue]"]
  node_personal["Personal usage<br/>[ActivityCard.vue]"]
  node_reporting["Finance and reports<br/>[index.vue]"]
  node_reportengine["Reporting engine<br/>[usage-coverage.ts]"]
  node_rag["Budget pace logic<br/>[useRagState.ts]"]
end

subgraph group_platform["Identity and storage"]
  node_database[("PostgreSQL<br/>[index.ts]")]
  node_session["Session and auth<br/>[useSession.ts]"]
end

node_developer(("Developer"))
node_manager(("Project manager"))
node_admin(("Administrator"))

node_developer -->|"gets setup guidance"| node_connect
node_connect -->|"configures clients"| node_clients
node_clients -->|"emits usage"| node_telemetry
node_provider -->|"supplies billing truth"| node_reconciliation
node_telemetry -->|"feeds usage attribution"| node_attribution
node_attribution -.->|"records usage"| node_database
node_identity -.->|"stores identities"| node_database
node_reconciliation -->|"writes deltas"| node_database
node_reconciliation -->|"reads provider usage"| node_provider
node_attribution -->|"attributes project claims"| node_projects
node_placement -.->|"resolves directory placement"| node_identity
node_manager -->|"manages budgets"| node_projects
node_manager -->|"reviews requests"| node_requests
node_requests -.->|"may extend budget"| node_allocations
node_admin -->|"configures organization"| node_adminui
node_adminui -->|"persists connection policy"| node_database
node_developer -->|"views spend and burn"| node_home
node_home -->|"renders activity"| node_personal
node_home -->|"opens tagging dialog"| node_tagging
node_home -->|"computes budget pace"| node_rag
node_reporting -.->|"requests reporting data"| node_reportengine
node_reportengine -.->|"queries usage coverage"| node_database
node_reporting -->|"shows budget reporting"| node_manager
node_reporting -->|"shows finance chargeback"| node_admin
node_overage -.->|"persists allocations"| node_database
node_mitigation -->|"checks attribution gaps"| node_database
node_session -.->|"supports signed-in view"| node_home

click node_clients "https://github.com/insight-services-apac/tokenscope-public/blob/main/plugin/hooks/session-start.mjs"
click node_connect "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/components/connect/connect-guides.ts"
click node_telemetry "https://github.com/insight-services-apac/tokenscope-public/tree/main/server"
click node_attribution "https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/attribution.ts"
click node_identity "https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/identity.ts"
click node_governance "https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/governance.ts"
click node_reconciliation "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/reconciliation/engine.ts"
click node_placement "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/reconciliation/placement-service.ts"
click node_projects "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/projects/%5Bcode%5D.vue"
click node_requests "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/api/v1/admin/project-requests/index.get.ts"
click node_allocations "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/allocations/append-topup.ts"
click node_adminui "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/admin/org-setup.vue"
click node_home "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/index.vue"
click node_personal "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/components/me/ActivityCard.vue"
click node_reporting "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/reporting/index.vue"
click node_reportengine "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/reporting/engine/usage-coverage.ts"
click node_database "https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/index.ts"
click node_session "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/composables/useSession.ts"
click node_tagging "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/components/home/TagSessionDialog.vue"
click node_rag "https://github.com/insight-services-apac/tokenscope-public/blob/main/app/composables/useRagState.ts"
click node_overage "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/governance/copilot-overage-allocation.ts"
click node_mitigation "https://github.com/insight-services-apac/tokenscope-public/blob/main/server/workers/mitigation-query.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_clients,node_connect,node_telemetry,node_provider toneBlue
class node_attribution,node_identity,node_governance,node_reconciliation,node_placement,node_tagging,node_overage,node_mitigation toneAmber
class node_projects,node_requests,node_allocations,node_adminui toneMint
class node_home,node_personal,node_reporting,node_reportengine,node_rag toneRose
class node_database,node_session,node_developer,node_manager,node_admin toneIndigo
```

## Components

### Usage capture

- [Claude and Copilot](https://github.com/insight-services-apac/tokenscope-public/blob/main/plugin/hooks/session-start.mjs): `plugin/hooks/session-start.mjs`
- [Connect guidance](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/components/connect/connect-guides.ts): `app/components/connect/connect-guides.ts`
- [Telemetry receiver](https://github.com/insight-services-apac/tokenscope-public/tree/main/server): `server`
- **Provider APIs**

### Attribution and governance

- [Usage attribution](https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/attribution.ts): `drizzle/schema/attribution.ts`
- [Identity and org](https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/identity.ts): `drizzle/schema/identity.ts`
- [Governance rules](https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/governance.ts): `drizzle/schema/governance.ts`
- [Billing reconciliation](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/reconciliation/engine.ts): `server/reconciliation/engine.ts`
- [Directory placement](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/reconciliation/placement-service.ts): `server/reconciliation/placement-service.ts`
- [Session tagging](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/components/home/TagSessionDialog.vue): `app/components/home/TagSessionDialog.vue`
- [Copilot overage allocation](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/governance/copilot-overage-allocation.ts): `server/governance/copilot-overage-allocation.ts`
- [Telemetry gap detection](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/workers/mitigation-query.ts): `server/workers/mitigation-query.ts`

### Project operations

- [Project budgets](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/projects/%5Bcode%5D.vue): `app/pages/projects/[code].vue`
- [Project requests](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/api/v1/admin/project-requests/index.get.ts): `server/api/v1/admin/project-requests/index.get.ts`
- [Budget allocations](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/allocations/append-topup.ts): `server/allocations/append-topup.ts`
- [Admin operations](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/admin/org-setup.vue): `app/pages/admin/org-setup.vue`

### Usage and reporting

- [Developer dashboard](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/index.vue): `app/pages/index.vue`
- [Personal usage](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/components/me/ActivityCard.vue): `app/components/me/ActivityCard.vue`
- [Finance and reports](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/pages/reporting/index.vue): `app/pages/reporting/index.vue`
- [Reporting engine](https://github.com/insight-services-apac/tokenscope-public/blob/main/server/reporting/engine/usage-coverage.ts): `server/reporting/engine/usage-coverage.ts`
- [Budget pace logic](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/composables/useRagState.ts): `app/composables/useRagState.ts`

### Identity and storage

- [PostgreSQL](https://github.com/insight-services-apac/tokenscope-public/blob/main/drizzle/schema/index.ts): `drizzle/schema/index.ts`
- [Session and auth](https://github.com/insight-services-apac/tokenscope-public/blob/main/app/composables/useSession.ts): `app/composables/useSession.ts`

### Other components

- **Developer**
- **Project manager**
- **Administrator**

## Connections

- Developer → Connect guidance: gets setup guidance (evidence: `README.md`)
- Connect guidance → Claude and Copilot: configures clients (evidence: `README.md`)
- Claude and Copilot → Telemetry receiver: emits usage (evidence: `README.md`)
- Provider APIs → Billing reconciliation: supplies billing truth (evidence: `README.md`)
- Telemetry receiver → Usage attribution: feeds usage attribution (evidence: `README.md`)
- Usage attribution → PostgreSQL: records usage (evidence: `drizzle/schema/index.ts`)
- Identity and org → PostgreSQL: stores identities (evidence: `drizzle/schema/index.ts`)
- Billing reconciliation → PostgreSQL: writes deltas (evidence: `server/reconciliation/engine.ts`)
- Billing reconciliation → Provider APIs: reads provider usage (evidence: `README.md`)
- Usage attribution → Project budgets: attributes project claims (evidence: `README.md`)
- Directory placement → Identity and org: resolves directory placement
- Project manager → Project budgets: manages budgets (evidence: `README.md`)
- Project manager → Project requests: reviews requests (evidence: `README.md`)
- Project requests → Budget allocations: may extend budget
- Administrator → Admin operations: configures organization (evidence: `README.md`)
- Admin operations → PostgreSQL: persists connection policy
- Developer → Developer dashboard: views spend and burn (evidence: `README.md`)
- Developer dashboard → Personal usage: renders activity (evidence: `app/pages/index.vue`)
- Developer dashboard → Session tagging: opens tagging dialog (evidence: `app/pages/index.vue`)
- Developer dashboard → Budget pace logic: computes budget pace (evidence: `app/pages/index.vue`)
- Finance and reports → Reporting engine: requests reporting data
- Reporting engine → PostgreSQL: queries usage coverage
- Finance and reports → Project manager: shows budget reporting (evidence: `README.md`)
- Finance and reports → Administrator: shows finance chargeback (evidence: `README.md`)
- Copilot overage allocation → PostgreSQL: persists allocations
- Telemetry gap detection → PostgreSQL: checks attribution gaps (evidence: `server/workers/mitigation-query.ts`)
- Session and auth → Developer dashboard: supports signed-in view
