# qlover/brain-toolkit architecture

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

- Interactive diagram: https://gitdiagram.com/qlover/brain-toolkit
- Repository: https://github.com/qlover/brain-toolkit

## Overview

brain-toolkit is a TypeScript monorepo of reusable frontend and application-support packages, rather than one end-user application. Its documented package capabilities span authentication, UI utilities, localization generation, and Ant Design theming; the tree also contains PAM OAuth and CLI support. The principal runtime patterns visible in the excerpts are service-to-adapter/store composition and authenticated API access. Source inspection is uneven, so unsampled package capabilities are represented from README descriptions and tree paths without inferred internal wiring.

Main entry points: [`packages/brain-user/src/BrainUserService.ts`](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/BrainUserService.ts) (Brain user service), [`packages/bridge/src/imagica-auth/ImagicaAuthService.ts`](https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthService.ts) (Imagica auth service), [`packages/pamenv/src/impls/PamCliApiClient.ts`](https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/impls/PamCliApiClient.ts) (PAM CLI API client), [`packages/brain-user/src/utils/createBrainUserOptions.ts`](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/utils/createBrainUserOptions.ts) (Service setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_auth["Authentication"]
  node_brain_service["Brain user service"]
  node_brain_options["Service setup"]
  node_brain_store_factory["User store factory"]
  node_brain_store["User state store<br/>[BrainUserStore.ts]"]
  node_brain_gateway_contract["Gateway contract"]
  node_imagica_service["Imagica auth service"]
  node_imagica_api["Imagica auth API<br/>[ImagicaAuthApi.ts]"]
  node_imagica_state["Imagica auth state"]
end

subgraph group_pam["PAM tooling"]
  node_pam_cli_client["PAM CLI API client<br/>[PamCliApiClient.ts]"]
  node_pam_cli_contract["CLI API contract"]
  node_pam_auth_store["CLI auth store"]
  node_pam_types["Project and env types<br/>[PamCliTypes.ts]"]
  node_oauth_trust["Consent trust service"]
  node_oauth_grants["Consent grant repository"]
  node_grant_store[("Supabase grant store")]
end

subgraph group_ui["UI utilities"]
  node_element_sizer["Element expand/collapse<br/>[index.ts]"]
  node_antd_theme["Ant Design theming<br/>[index.ts]"]
  node_antd_resource["Resource table events<br/>[ResourceEvent.ts]"]
  node_react_hooks["Async store hooks<br/>[useAsyncStore.ts]"]
end

subgraph group_localization["Localization"]
  node_locale_generator["Locale file generator<br/>[Ts2Locales.ts]"]
  node_locale_vite["Vite integration<br/>[index.ts]"]
end

node_developer(("Application developer"))

node_developer -.->|"uses"| node_brain_service
node_brain_service -->|"creates options"| node_brain_options
node_brain_options -->|"configures store"| node_brain_store_factory
node_brain_store_factory -->|"creates store"| node_brain_store
node_brain_service -->|"uses gateway"| node_brain_gateway_contract
node_imagica_service -->|"constructs API"| node_imagica_api
node_imagica_service -->|"reads state"| node_imagica_state
node_imagica_api -->|"uses state"| node_imagica_state
node_pam_cli_client -->|"reads credentials"| node_pam_auth_store
node_pam_cli_client -->|"implements API"| node_pam_cli_contract
node_pam_cli_contract -->|"uses types"| node_pam_types
node_oauth_trust -->|"reads and updates"| node_oauth_grants
node_oauth_grants -->|"queries"| node_grant_store
node_developer -.->|"uses"| node_element_sizer
node_developer -.->|"uses"| node_antd_theme
node_developer -.->|"uses"| node_locale_generator

click node_brain_service "https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/BrainUserService.ts"
click node_brain_options "https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/utils/createBrainUserOptions.ts"
click node_brain_store_factory "https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/utils/createBrainUserStore.ts"
click node_brain_store "https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/BrainUserStore.ts"
click node_brain_gateway_contract "https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/interface/BrainUserGatewayInterface.ts"
click node_imagica_service "https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthService.ts"
click node_imagica_api "https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthApi.ts"
click node_imagica_state "https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthState.ts"
click node_pam_cli_client "https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/impls/PamCliApiClient.ts"
click node_pam_cli_contract "https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/interfaces/PamCliApiClientInterface.ts"
click node_pam_auth_store "https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/interfaces/PamCliAuthStoreInterface.ts"
click node_pam_types "https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/interfaces/PamCliTypes.ts"
click node_oauth_trust "https://github.com/qlover/brain-toolkit/blob/master/packages/next-app-kit/src/server/oauth/OAuthConsentTrustService.ts"
click node_oauth_grants "https://github.com/qlover/brain-toolkit/blob/master/packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts"
click node_grant_store "https://github.com/qlover/brain-toolkit/blob/master/packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts"
click node_element_sizer "https://github.com/qlover/brain-toolkit/blob/master/packages/element-sizer/src/index.ts"
click node_antd_theme "https://github.com/qlover/brain-toolkit/blob/master/packages/antd-theme-override/src/vite/index.ts"
click node_antd_resource "https://github.com/qlover/brain-toolkit/blob/master/packages/antd-blocks/src/resourceTable/ResourceEvent.ts"
click node_react_hooks "https://github.com/qlover/brain-toolkit/blob/master/packages/react-kit/src/hooks/useAsyncStore.ts"
click node_locale_generator "https://github.com/qlover/brain-toolkit/blob/master/packages/ts2locales/src/lib/Ts2Locales.ts"
click node_locale_vite "https://github.com/qlover/brain-toolkit/blob/master/packages/ts2locales/src/vite/index.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_brain_service,node_brain_options,node_brain_store_factory,node_brain_store,node_brain_gateway_contract,node_imagica_service,node_imagica_api,node_imagica_state toneBlue
class node_pam_cli_client,node_pam_cli_contract,node_pam_auth_store,node_pam_types,node_oauth_trust,node_oauth_grants,node_grant_store toneAmber
class node_element_sizer,node_antd_theme,node_antd_resource,node_react_hooks toneMint
class node_locale_generator,node_locale_vite toneRose
class node_developer toneIndigo
```

## Components

### Authentication

- [Brain user service](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/BrainUserService.ts): `packages/brain-user/src/BrainUserService.ts`
- [Service setup](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/utils/createBrainUserOptions.ts): `packages/brain-user/src/utils/createBrainUserOptions.ts`
- [User store factory](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/utils/createBrainUserStore.ts): `packages/brain-user/src/utils/createBrainUserStore.ts`
- [User state store](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/BrainUserStore.ts): `packages/brain-user/src/BrainUserStore.ts`
- [Gateway contract](https://github.com/qlover/brain-toolkit/blob/master/packages/brain-user/src/interface/BrainUserGatewayInterface.ts): `packages/brain-user/src/interface/BrainUserGatewayInterface.ts`
- [Imagica auth service](https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthService.ts): `packages/bridge/src/imagica-auth/ImagicaAuthService.ts`
- [Imagica auth API](https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthApi.ts): `packages/bridge/src/imagica-auth/ImagicaAuthApi.ts`
- [Imagica auth state](https://github.com/qlover/brain-toolkit/blob/master/packages/bridge/src/imagica-auth/ImagicaAuthState.ts): `packages/bridge/src/imagica-auth/ImagicaAuthState.ts`

### PAM tooling

- [PAM CLI API client](https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/impls/PamCliApiClient.ts): `packages/pamenv/src/impls/PamCliApiClient.ts`
- [CLI API contract](https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/interfaces/PamCliApiClientInterface.ts): `packages/pamenv/src/interfaces/PamCliApiClientInterface.ts`
- [CLI auth store](https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/interfaces/PamCliAuthStoreInterface.ts): `packages/pamenv/src/interfaces/PamCliAuthStoreInterface.ts`
- [Project and env types](https://github.com/qlover/brain-toolkit/blob/master/packages/pamenv/src/interfaces/PamCliTypes.ts): `packages/pamenv/src/interfaces/PamCliTypes.ts`
- [Consent trust service](https://github.com/qlover/brain-toolkit/blob/master/packages/next-app-kit/src/server/oauth/OAuthConsentTrustService.ts): `packages/next-app-kit/src/server/oauth/OAuthConsentTrustService.ts`
- [Consent grant repository](https://github.com/qlover/brain-toolkit/blob/master/packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts): `packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts`
- [Supabase grant store](https://github.com/qlover/brain-toolkit/blob/master/packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts): `packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts`

### UI utilities

- [Element expand/collapse](https://github.com/qlover/brain-toolkit/blob/master/packages/element-sizer/src/index.ts): `packages/element-sizer/src/index.ts`
- [Ant Design theming](https://github.com/qlover/brain-toolkit/blob/master/packages/antd-theme-override/src/vite/index.ts): `packages/antd-theme-override/src/vite/index.ts`
- [Resource table events](https://github.com/qlover/brain-toolkit/blob/master/packages/antd-blocks/src/resourceTable/ResourceEvent.ts): `packages/antd-blocks/src/resourceTable/ResourceEvent.ts`
- [Async store hooks](https://github.com/qlover/brain-toolkit/blob/master/packages/react-kit/src/hooks/useAsyncStore.ts): `packages/react-kit/src/hooks/useAsyncStore.ts`

### Localization

- [Locale file generator](https://github.com/qlover/brain-toolkit/blob/master/packages/ts2locales/src/lib/Ts2Locales.ts): `packages/ts2locales/src/lib/Ts2Locales.ts`
- [Vite integration](https://github.com/qlover/brain-toolkit/blob/master/packages/ts2locales/src/vite/index.ts): `packages/ts2locales/src/vite/index.ts`

### Other components

- **Application developer**

## Connections

- Application developer → Brain user service: uses (evidence: `README.md`)
- Brain user service → Service setup: creates options (evidence: `packages/brain-user/src/BrainUserService.ts`)
- Service setup → User store factory: configures store (evidence: `packages/brain-user/src/utils/createBrainUserOptions.ts`)
- User store factory → User state store: creates store (evidence: `packages/brain-user/src/utils/createBrainUserStore.ts`)
- Brain user service → Gateway contract: uses gateway (evidence: `packages/brain-user/src/BrainUserService.ts`)
- Imagica auth service → Imagica auth API: constructs API (evidence: `packages/bridge/src/imagica-auth/ImagicaAuthService.ts`)
- Imagica auth service → Imagica auth state: reads state (evidence: `packages/bridge/src/imagica-auth/ImagicaAuthService.ts`)
- Imagica auth API → Imagica auth state: uses state (evidence: `packages/bridge/src/imagica-auth/ImagicaAuthApi.ts`)
- PAM CLI API client → CLI auth store: reads credentials (evidence: `packages/pamenv/src/impls/PamCliApiClient.ts`)
- PAM CLI API client → CLI API contract: implements API (evidence: `packages/pamenv/src/impls/PamCliApiClient.ts`)
- CLI API contract → Project and env types: uses types (evidence: `packages/pamenv/src/interfaces/PamCliApiClientInterface.ts`)
- Consent trust service → Consent grant repository: reads and updates (evidence: `packages/next-app-kit/src/server/oauth/OAuthConsentTrustService.ts`)
- Consent grant repository → Supabase grant store: queries (evidence: `packages/next-app-kit/src/server/oauth/OAuthConsentGrantRepository.ts`)
- Application developer → Element expand/collapse: uses (evidence: `README.md`)
- Application developer → Ant Design theming: uses (evidence: `README.md`)
- Application developer → Locale file generator: uses (evidence: `README.md`)
