# marcelinojrg/microstock-copilot architecture

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

- Interactive diagram: https://gitdiagram.com/marcelinojrg/microstock-copilot
- Repository: https://github.com/marcelinojrg/microstock-copilot

## Overview

Microstock Copilot is a creator-focused workspace for accounts, teams, stock assets, metadata, AI assistance, exports, and privacy operations. The user-facing flow runs from sign-in and workspace setup through collaborative asset/task work and optional AI assistance to exports; account and workspace privacy actions form a separate lifecycle. A background worker handles queued exports, asset verification, and deletion/retention work. The README documents these capabilities, while the excerpts and source index verify selected server and worker calls; links for unsampled domain routes are documented product relationships, not claims about inspected implementation.

Main entry points: [`packages/db/src/client.ts`](https://github.com/marcelinojrg/microstock-copilot/blob/main/packages/db/src/client.ts) (PostgreSQL database), [`apps/worker/src/services/run-worker-once.ts`](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/services/run-worker-once.ts) (Job dispatcher), [`apps/web/server/auth/auth.ts`](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/auth/auth.ts) (Authentication service), [`apps/web/features/workspace/workspace-app.tsx`](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/workspace/workspace-app.tsx) (Workspace UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_web_app["Web app routes"]
  node_auth_ui["Account screens<br/>[auth-forms.tsx]"]
end

subgraph group_identity["Identity and access"]
  node_auth_service["Authentication service<br/>[auth.ts]"]
  node_auth_email["Auth email<br/>[auth-email.ts]"]
  node_team_access["Team authorization<br/>[team.ts]"]
  node_privacy_api["Privacy actions<br/>[route.ts]"]
  node_account_privacy["Account privacy<br/>[privacy.ts]"]
end

subgraph group_collaboration["Workspace collaboration"]
  node_workspace_ui["Workspace UI<br/>[workspace-app.tsx]"]
  node_workspace_api["Workspace APIs<br/>[route.ts]"]
  node_workspace_service["Workspace services<br/>[workspace.ts]"]
  node_task_graph["Task dependencies<br/>[task-graph.ts]"]
end

subgraph group_asset_ops["AI and exports"]
  node_ai_ui["AI asset assistance<br/>[asset-ai-panel.tsx]"]
  node_ai_api["AI request API<br/>[route.ts]"]
  node_ai_provider["AI provider client"]
  node_export_ui["Export controls<br/>[export-panel.tsx]"]
  node_export_service["Export services<br/>[commands.ts]"]
end

subgraph group_operations["Background operations"]
  node_worker["Job dispatcher<br/>[run-worker-once.ts]"]
  node_export_job["Export jobs<br/>[export-csv.ts]"]
  node_account_export_job["Account export job<br/>[account-export.ts]"]
  node_asset_verify_job["Asset verification"]
  node_workspace_purge_job["Workspace deletion<br/>[workspace-purge.ts]"]
end

node_creator(("Creator"))
node_database[("PostgreSQL database<br/>[client.ts]")]
node_object_storage[("Object storage<br/>[index.ts]")]

node_creator -->|"uses"| node_web_app
node_web_app -.->|"serves"| node_auth_ui
node_auth_ui -.->|"authenticates"| node_auth_service
node_auth_service -->|"sends mail"| node_auth_email
node_auth_service -->|"stores identity"| node_database
node_auth_service -->|"provisions workspace"| node_workspace_service
node_web_app -.->|"serves"| node_workspace_ui
node_workspace_ui -.->|"requests tasks"| node_workspace_api
node_workspace_api -->|"authorizes"| node_team_access
node_workspace_api -->|"reads and writes"| node_database
node_workspace_api -->|"uses dependencies"| node_task_graph
node_workspace_ui -.->|"offers assistance"| node_ai_ui
node_ai_ui -.->|"requests drafts"| node_ai_api
node_ai_api -->|"authorizes"| node_team_access
node_ai_api -.->|"requests generation"| node_ai_provider
node_ai_api -->|"stores request state"| node_database
node_workspace_ui -.->|"offers exports"| node_export_ui
node_export_ui -.->|"requests export"| node_export_service
node_export_service -.->|"records commands"| node_database
node_creator -.->|"manages privacy"| node_privacy_api
node_privacy_api -->|"checks workspace state"| node_account_privacy
node_privacy_api -->|"reads privacy records"| node_database
node_worker -->|"dispatches"| node_export_job
node_worker -->|"dispatches"| node_account_export_job
node_worker -->|"dispatches"| node_asset_verify_job
node_worker -->|"dispatches"| node_workspace_purge_job
node_export_job -->|"reads and writes"| node_database
node_export_job -->|"stores artifacts"| node_object_storage
node_account_export_job -->|"reads and writes"| node_database
node_account_export_job -->|"stores exports"| node_object_storage
node_asset_verify_job -->|"updates verification"| node_database
node_asset_verify_job -->|"reads assets"| node_object_storage
node_workspace_purge_job -->|"purges records"| node_database
node_workspace_purge_job -->|"deletes objects"| node_object_storage

click node_web_app "https://github.com/marcelinojrg/microstock-copilot/tree/main/apps/web/app"
click node_auth_ui "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/auth/auth-forms.tsx"
click node_auth_service "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/auth/auth.ts"
click node_auth_email "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/auth/auth-email.ts"
click node_workspace_ui "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/workspace/workspace-app.tsx"
click node_workspace_api "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/app/api/v1/workspaces/%5BworkspaceId%5D/tasks/route.ts"
click node_team_access "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/workspace/team.ts"
click node_workspace_service "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/workspace/workspace.ts"
click node_task_graph "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/workspace/task-graph.ts"
click node_ai_ui "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/ai/asset-ai-panel.tsx"
click node_ai_api "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/app/api/v1/workspaces/%5BworkspaceId%5D/ai/route.ts"
click node_ai_provider "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/ai/openai-responses.ts"
click node_export_ui "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/exports/export-panel.tsx"
click node_export_service "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/exports/commands.ts"
click node_privacy_api "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/app/api/v1/account/privacy/route.ts"
click node_account_privacy "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/account/privacy.ts"
click node_worker "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/services/run-worker-once.ts"
click node_export_job "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/export-csv.ts"
click node_account_export_job "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/account-export.ts"
click node_asset_verify_job "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/asset-verification.ts"
click node_workspace_purge_job "https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/workspace-purge.ts"
click node_database "https://github.com/marcelinojrg/microstock-copilot/blob/main/packages/db/src/client.ts"
click node_object_storage "https://github.com/marcelinojrg/microstock-copilot/blob/main/packages/storage/src/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_web_app,node_auth_ui toneBlue
class node_auth_service,node_auth_email,node_team_access,node_privacy_api,node_account_privacy,node_database,node_object_storage toneAmber
class node_workspace_ui,node_workspace_api,node_workspace_service,node_task_graph toneMint
class node_ai_ui,node_ai_api,node_ai_provider,node_export_ui,node_export_service toneRose
class node_worker,node_export_job,node_account_export_job,node_asset_verify_job,node_workspace_purge_job,node_creator toneIndigo
```

## Components

### Web experience

- [Web app routes](https://github.com/marcelinojrg/microstock-copilot/tree/main/apps/web/app): `apps/web/app`
- [Account screens](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/auth/auth-forms.tsx): `apps/web/features/auth/auth-forms.tsx`

### Identity and access

- [Authentication service](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/auth/auth.ts): `apps/web/server/auth/auth.ts`
- [Auth email](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/auth/auth-email.ts): `apps/web/server/auth/auth-email.ts`
- [Team authorization](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/workspace/team.ts): `apps/web/server/workspace/team.ts`
- [Privacy actions](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/app/api/v1/account/privacy/route.ts): `apps/web/app/api/v1/account/privacy/route.ts`
- [Account privacy](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/account/privacy.ts): `apps/web/server/account/privacy.ts`

### Workspace collaboration

- [Workspace UI](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/workspace/workspace-app.tsx): `apps/web/features/workspace/workspace-app.tsx`
- [Workspace APIs](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/app/api/v1/workspaces/%5BworkspaceId%5D/tasks/route.ts): `apps/web/app/api/v1/workspaces/[workspaceId]/tasks/route.ts`
- [Workspace services](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/workspace/workspace.ts): `apps/web/server/workspace/workspace.ts`
- [Task dependencies](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/workspace/task-graph.ts): `apps/web/features/workspace/task-graph.ts`

### AI and exports

- [AI asset assistance](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/ai/asset-ai-panel.tsx): `apps/web/features/ai/asset-ai-panel.tsx`
- [AI request API](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/app/api/v1/workspaces/%5BworkspaceId%5D/ai/route.ts): `apps/web/app/api/v1/workspaces/[workspaceId]/ai/route.ts`
- [AI provider client](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/ai/openai-responses.ts): `apps/web/server/ai/openai-responses.ts`
- [Export controls](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/features/exports/export-panel.tsx): `apps/web/features/exports/export-panel.tsx`
- [Export services](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/web/server/exports/commands.ts): `apps/web/server/exports/commands.ts`

### Background operations

- [Job dispatcher](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/services/run-worker-once.ts): `apps/worker/src/services/run-worker-once.ts`
- [Export jobs](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/export-csv.ts): `apps/worker/src/jobs/export-csv.ts`
- [Account export job](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/account-export.ts): `apps/worker/src/jobs/account-export.ts`
- [Asset verification](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/asset-verification.ts): `apps/worker/src/jobs/asset-verification.ts`
- [Workspace deletion](https://github.com/marcelinojrg/microstock-copilot/blob/main/apps/worker/src/jobs/workspace-purge.ts): `apps/worker/src/jobs/workspace-purge.ts`

### Other components

- **Creator**
- [PostgreSQL database](https://github.com/marcelinojrg/microstock-copilot/blob/main/packages/db/src/client.ts): `packages/db/src/client.ts`
- [Object storage](https://github.com/marcelinojrg/microstock-copilot/blob/main/packages/storage/src/index.ts): `packages/storage/src/index.ts`

## Connections

- Creator → Web app routes: uses (evidence: `README.md`)
- Web app routes → Account screens: serves
- Account screens → Authentication service: authenticates
- Authentication service → Auth email: sends mail (evidence: `apps/web/server/auth/auth.ts`)
- Authentication service → PostgreSQL database: stores identity (evidence: `apps/web/server/auth/auth.ts`)
- Authentication service → Workspace services: provisions workspace (evidence: `apps/web/server/auth/auth.ts`)
- Web app routes → Workspace UI: serves
- Workspace UI → Workspace APIs: requests tasks
- Workspace APIs → Team authorization: authorizes (evidence: `apps/web/app/api/v1/workspaces/[workspaceId]/tasks/route.ts`)
- Workspace APIs → PostgreSQL database: reads and writes (evidence: `apps/web/app/api/v1/workspaces/[workspaceId]/tasks/route.ts`)
- Workspace APIs → Task dependencies: uses dependencies
- Workspace UI → AI asset assistance: offers assistance
- AI asset assistance → AI request API: requests drafts
- AI request API → Team authorization: authorizes (evidence: `apps/web/app/api/v1/workspaces/[workspaceId]/ai/route.ts`)
- AI request API → AI provider client: requests generation (evidence: `apps/web/app/api/v1/workspaces/[workspaceId]/ai/route.ts`)
- AI request API → PostgreSQL database: stores request state (evidence: `apps/web/app/api/v1/workspaces/[workspaceId]/ai/route.ts`)
- Workspace UI → Export controls: offers exports
- Export controls → Export services: requests export
- Export services → PostgreSQL database: records commands
- Creator → Privacy actions: manages privacy
- Privacy actions → Account privacy: checks workspace state (evidence: `apps/web/app/api/v1/account/privacy/route.ts`)
- Privacy actions → PostgreSQL database: reads privacy records (evidence: `apps/web/app/api/v1/account/privacy/route.ts`)
- Job dispatcher → Export jobs: dispatches (evidence: `apps/worker/src/services/run-worker-once.ts`)
- Job dispatcher → Account export job: dispatches (evidence: `apps/worker/src/services/run-worker-once.ts`)
- Job dispatcher → Asset verification: dispatches (evidence: `apps/worker/src/services/run-worker-once.ts`)
- Job dispatcher → Workspace deletion: dispatches (evidence: `apps/worker/src/services/run-worker-once.ts`)
- Export jobs → PostgreSQL database: reads and writes (evidence: `apps/worker/src/jobs/export-csv.ts`)
- Export jobs → Object storage: stores artifacts (evidence: `apps/worker/src/jobs/export-csv.ts`)
- Account export job → PostgreSQL database: reads and writes (evidence: `apps/worker/src/jobs/account-export.ts`)
- Account export job → Object storage: stores exports (evidence: `apps/worker/src/jobs/account-export.ts`)
- Asset verification → PostgreSQL database: updates verification (evidence: `apps/worker/src/jobs/asset-verification.ts`)
- Asset verification → Object storage: reads assets (evidence: `apps/worker/src/jobs/asset-verification.ts`)
- Workspace deletion → PostgreSQL database: purges records (evidence: `apps/worker/src/jobs/workspace-purge.ts`)
- Workspace deletion → Object storage: deletes objects (evidence: `apps/worker/src/jobs/workspace-purge.ts`)
