# leamsigc/magicsync architecture

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

- Interactive diagram: https://gitdiagram.com/leamsigc/magicsync
- Repository: https://github.com/leamsigc/magicsync

## Overview

#### Purpose and Entry Points
MagicSync is a Nuxt 4/pnpm monorepo for multi-platform social-media management: business/account connection, media, AI-assisted content, post scheduling, publishing, and analytics. The primary application merge point is `packages/site/`, started with `pnpm site:dev`; its Nuxt configuration composes feature packages into one app. A separate optional FastAPI service runs AI/agent capabilities on port 8000.
- `packages/site/nuxt.config.ts`
- `packages/site/app/pages/app/index.vue`
- `packages/python-backend/app/main.py`

#### Layered Nuxt Feature Modules
Most product domains are independently structured Nuxt layers containing Vue pages/composables plus Nitro server routes. The shared UI layer provides base layouts/components, while `site` supplies dashboard and admin surfaces. This is a modular monolith at runtime rather than separately deployed frontend applications.
- `packages/ui/app/components/BaseSidebarNavigation.vue`
- `packages/scheduler/nuxt.config.ts`
- `packages/site/app/pages/app/admin/index.vue`

#### Identity, Tenancy, and Social Connections
Authentication is implemented through Better Auth routes and global middleware. Users operate in business contexts; the Connect module manages businesses, memberships, active business selection, and OAuth/API-key-backed social accounts. These identity and connection records are a boundary between user-facing workflows and third-party platforms.
- `packages/auth/server/api/auth/[...all].ts`
- `packages/auth/server/middleware/001.auth.ts`
- `packages/connect/server/api/v1/social-accounts/callback/[platform].get.ts`

#### Persistence and Domain Services
`packages/db` is the central persistence layer, using Drizzle ORM with Turso/libSQL and migrations. Its schemas cover authentication, businesses, posts, social accounts, assets, templates, skills, LLM configuration, and RAG; server services encapsulate database operations for consuming modules. Native vector support enables knowledge retrieval.
- `packages/db/db/schema.ts`
- `packages/db/config/drizzle.config.ts`
- `packages/db/server/services/post.service.ts`

#### Content Creation, Scheduling, and Publishing
The Scheduler module is the core post lifecycle: create/update/validate posts, render calendar/feed views, and publish through platform-specific plugins. Scheduled execution and token-health work are represented as server tasks; publishing adapters isolate platform APIs and rate limiting from post management. Bulk Scheduler feeds this lifecycle through CSV import or AI batch generation.
- `packages/scheduler/server/api/v1/posts/index.post.ts`
- `packages/scheduler/server/services/AutoPost.service.ts`
- `packages/scheduler/server/services/plugins/x.plugin.ts`
- `packages/bulk-scheduler/server/services/bulkScheduler.service.ts`

#### AI, Agent, and Knowledge Boundaries
The TypeScript AI-tools layer exposes chat, LLM configuration, documents, retrieval, skills, tool calls, social generation, and agent streaming to the Nuxt UI. It currently includes an `aiToolsFacade` service boundary. The Python backend contains the deeper implementation: LLM/Ollama access, agent orchestration/subagents, RAG parsing-chunking-embedding-reranking, PII pipeline, MCP client, tool registry/execution, and harness evaluation. Requests cross an HTTP boundary rather than directly sharing runtime code.
- `packages/ai-tools/server/services/aiToolsFacade.service.ts`
- `packages/ai-tools/server/api/ai-tools/retrieve.post.ts`
- `packages/python-backend/app/services/agent/orchestrator.py`
- `packages/python-backend/app/services/rag/embeddings.py`

#### Media, Templates, and External Integrations
Assets are uploaded, stored/served, and optionally imported from Canva, Google Drive, and Pexels. Templates provide reusable variable and chat/post structures. Scheduler and Connect integrate external social networks, Google Business, and provider OAuth; AI workflows can use configured LLMs and web search. Docker Compose files provide local containerized infrastructure.
- `packages/assets/server/services/asset.service.ts`
- `packages/templates/server/api/v1/templates/index.post.ts`
- `packages/scheduler/server/api/v1/gmb/reviews/sync.post.ts`
- `docker-compose.yml`

Main entry points: [`packages/site/nuxt.config.ts`](https://github.com/leamsigc/magicsync/blob/main/packages/site/nuxt.config.ts) (Site dashboard), [`packages/db/db/schema.ts`](https://github.com/leamsigc/magicsync/blob/main/packages/db/db/schema.ts) (Domain database), [`packages/scheduler/server/api/v1/posts/index.post.ts`](https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/api/v1/posts/index.post.ts) (Post scheduler), [`packages/connect/server/api/v1/social-accounts/callback/[platform].get.ts`](https://github.com/leamsigc/magicsync/blob/main/packages/connect/server/api/v1/social-accounts/callback/%5Bplatform%5D.get.ts) (Business connections)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_nuxt["Nuxt modular monolith"]
  node_site["Site dashboard<br/>Nuxt app<br/>[nuxt.config.ts]"]
  node_ui["Shared UI<br/>Nuxt layer"]
  node_auth["Authentication<br/>Nuxt auth layer<br/>[&#91;...all&#93;.ts]"]
end

subgraph group_core["Core domain services"]
  node_connect["Business connections<br/>Nuxt domain layer<br/>[&#91;platform&#93;.get.ts]"]
  node_database[("Domain database<br/>Drizzle + libSQL<br/>[schema.ts]")]
  node_assets["Media assets<br/>Nuxt domain layer<br/>[asset.service.ts]"]
  node_templates["Templates<br/>Nuxt domain layer<br/>[index.post.ts]"]
  node_scheduler["Post scheduler<br/>Nuxt domain layer<br/>[index.post.ts]"]
  node_scheduler_tasks["Scheduled post tasks<br/>server tasks"]
  node_publisher{{"Platform publishers<br/>plugin adapters<br/>[x.plugin.ts]"}}
  node_bulk_scheduler["Bulk scheduling<br/>Nuxt domain layer"]
end

subgraph group_ai["AI runtime boundary"]
  node_ai_facade["AI tools facade<br/>Nuxt service"]
  node_python_api["Python AI API<br/>FastAPI service<br/>[main.py]"]
  node_agent["Agent orchestration<br/>Python service<br/>[orchestrator.py]"]
  node_rag["RAG pipeline<br/>Python service<br/>[embeddings.py]"]
end

subgraph group_external["External systems"]
  node_social_platforms{{"Social platforms<br/>third-party APIs"}}
  node_content_providers{{"Media providers<br/>third-party APIs"}}
  node_llm_services{{"LLM and web services<br/>external AI APIs"}}
end

node_site -->|"renders shared components"| node_ui
node_site -->|"uses identity middleware"| node_auth
node_site -->|"manages business context"| node_connect
node_site -->|"manages posts"| node_scheduler
node_site -->|"manages media"| node_assets
node_site -->|"uses reusable content"| node_templates
node_site -->|"invokes AI workflows"| node_ai_facade
node_auth -->|"stores identities"| node_database
node_connect -->|"stores businesses and accounts"| node_database
node_connect -->|"OAuth and account APIs"| node_social_platforms
node_assets -->|"stores asset records"| node_database
node_assets -->|"imports media"| node_content_providers
node_templates -->|"stores templates"| node_database
node_scheduler -->|"stores posts"| node_database
node_bulk_scheduler -->|"creates batch posts"| node_scheduler
node_scheduler_tasks -->|"processes scheduled posts"| node_scheduler
node_scheduler_tasks -->|"dispatches publishing"| node_publisher
node_publisher -->|"publishes and syncs"| node_social_platforms
node_ai_facade -->|"HTTP requests"| node_python_api
node_python_api -->|"runs agents"| node_agent
node_python_api -->|"runs retrieval"| node_rag
node_agent -->|"uses knowledge retrieval"| node_rag
node_agent -->|"calls models and tools"| node_llm_services
node_rag -->|"uses vector knowledge"| node_database

click node_site "https://github.com/leamsigc/magicsync/blob/main/packages/site/nuxt.config.ts"
click node_ui "https://github.com/leamsigc/magicsync/blob/main/packages/ui/app/components/BaseSidebarNavigation.vue"
click node_auth "https://github.com/leamsigc/magicsync/blob/main/packages/auth/server/api/auth/%5B...all%5D.ts"
click node_connect "https://github.com/leamsigc/magicsync/blob/main/packages/connect/server/api/v1/social-accounts/callback/%5Bplatform%5D.get.ts"
click node_database "https://github.com/leamsigc/magicsync/blob/main/packages/db/db/schema.ts"
click node_assets "https://github.com/leamsigc/magicsync/blob/main/packages/assets/server/services/asset.service.ts"
click node_templates "https://github.com/leamsigc/magicsync/blob/main/packages/templates/server/api/v1/templates/index.post.ts"
click node_scheduler "https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/api/v1/posts/index.post.ts"
click node_scheduler_tasks "https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/services/AutoPost.service.ts"
click node_publisher "https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/services/plugins/x.plugin.ts"
click node_bulk_scheduler "https://github.com/leamsigc/magicsync/blob/main/packages/bulk-scheduler/server/services/bulkScheduler.service.ts"
click node_ai_facade "https://github.com/leamsigc/magicsync/blob/main/packages/ai-tools/server/services/aiToolsFacade.service.ts"
click node_python_api "https://github.com/leamsigc/magicsync/blob/main/packages/python-backend/app/main.py"
click node_agent "https://github.com/leamsigc/magicsync/blob/main/packages/python-backend/app/services/agent/orchestrator.py"
click node_rag "https://github.com/leamsigc/magicsync/blob/main/packages/python-backend/app/services/rag/embeddings.py"

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_site,node_ui,node_auth toneBlue
class node_connect,node_database,node_assets,node_templates,node_scheduler,node_scheduler_tasks,node_publisher,node_bulk_scheduler toneAmber
class node_ai_facade,node_python_api,node_agent,node_rag toneMint
class node_social_platforms,node_content_providers,node_llm_services toneRose
```

## Components

### Nuxt modular monolith

Feature layers compose into the site runtime.

- [Site dashboard](https://github.com/leamsigc/magicsync/blob/main/packages/site/nuxt.config.ts): Nuxt app · Primary application merge point and dashboard surface. · `packages/site/nuxt.config.ts`
- [Shared UI](https://github.com/leamsigc/magicsync/blob/main/packages/ui/app/components/BaseSidebarNavigation.vue): Nuxt layer · `packages/ui/app/components/BaseSidebarNavigation.vue`
- [Authentication](https://github.com/leamsigc/magicsync/blob/main/packages/auth/server/api/auth/%5B...all%5D.ts): Nuxt auth layer · Better Auth routes and global request middleware. · `packages/auth/server/api/auth/[...all].ts`

### Core domain services

- [Business connections](https://github.com/leamsigc/magicsync/blob/main/packages/connect/server/api/v1/social-accounts/callback/%5Bplatform%5D.get.ts): Nuxt domain layer · Business tenancy, memberships, and social-account OAuth. · `packages/connect/server/api/v1/social-accounts/callback/[platform].get.ts`
- [Domain database](https://github.com/leamsigc/magicsync/blob/main/packages/db/db/schema.ts): Drizzle + libSQL · Central schemas and server persistence services. · `packages/db/db/schema.ts`
- [Media assets](https://github.com/leamsigc/magicsync/blob/main/packages/assets/server/services/asset.service.ts): Nuxt domain layer · Asset upload, storage, serving, and imports. · `packages/assets/server/services/asset.service.ts`
- [Templates](https://github.com/leamsigc/magicsync/blob/main/packages/templates/server/api/v1/templates/index.post.ts): Nuxt domain layer · Reusable variable and post/chat structures. · `packages/templates/server/api/v1/templates/index.post.ts`
- [Post scheduler](https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/api/v1/posts/index.post.ts): Nuxt domain layer · Post lifecycle, calendar/feed views, validation, and publishing. · `packages/scheduler/server/api/v1/posts/index.post.ts`
- [Scheduled post tasks](https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/services/AutoPost.service.ts): server tasks · Executes scheduled publishing and token-health work. · `packages/scheduler/server/services/AutoPost.service.ts`
- [Platform publishers](https://github.com/leamsigc/magicsync/blob/main/packages/scheduler/server/services/plugins/x.plugin.ts): plugin adapters · Platform API and rate-limit isolation. · `packages/scheduler/server/services/plugins/x.plugin.ts`
- [Bulk scheduling](https://github.com/leamsigc/magicsync/blob/main/packages/bulk-scheduler/server/services/bulkScheduler.service.ts): Nuxt domain layer · CSV import and AI batch generation into post lifecycle. · `packages/bulk-scheduler/server/services/bulkScheduler.service.ts`

### AI runtime boundary

Python capabilities are reached over HTTP.

- [AI tools facade](https://github.com/leamsigc/magicsync/blob/main/packages/ai-tools/server/services/aiToolsFacade.service.ts): Nuxt service · TypeScript boundary for chat, retrieval, skills, tools, and streaming. · `packages/ai-tools/server/services/aiToolsFacade.service.ts`
- [Python AI API](https://github.com/leamsigc/magicsync/blob/main/packages/python-backend/app/main.py): FastAPI service · Optional AI and agent service on port 8000. · `packages/python-backend/app/main.py`
- [Agent orchestration](https://github.com/leamsigc/magicsync/blob/main/packages/python-backend/app/services/agent/orchestrator.py): Python service · Coordinates agents, subagents, tools, and execution. · `packages/python-backend/app/services/agent/orchestrator.py`
- [RAG pipeline](https://github.com/leamsigc/magicsync/blob/main/packages/python-backend/app/services/rag/embeddings.py): Python service · Embedding and retrieval implementation. · `packages/python-backend/app/services/rag/embeddings.py`

### External systems

- **Social platforms**: third-party APIs · OAuth-connected publishing and Google Business services.
- **Media providers**: third-party APIs · Canva, Google Drive, and Pexels imports.
- **LLM and web services**: external AI APIs · Configured LLM, Ollama, and web-search providers.

## Connections

- Site dashboard → Shared UI: renders shared components
- Site dashboard → Authentication: uses identity middleware
- Site dashboard → Business connections: manages business context
- Site dashboard → Post scheduler: manages posts
- Site dashboard → Media assets: manages media
- Site dashboard → Templates: uses reusable content
- Site dashboard → AI tools facade: invokes AI workflows
- Authentication → Domain database: stores identities
- Business connections → Domain database: stores businesses and accounts
- Business connections → Social platforms: OAuth and account APIs
- Media assets → Domain database: stores asset records
- Media assets → Media providers: imports media
- Templates → Domain database: stores templates
- Post scheduler → Domain database: stores posts
- Bulk scheduling → Post scheduler: creates batch posts
- Scheduled post tasks → Post scheduler: processes scheduled posts
- Scheduled post tasks → Platform publishers: dispatches publishing
- Platform publishers → Social platforms: publishes and syncs
- AI tools facade → Python AI API: HTTP requests
- Python AI API → Agent orchestration: runs agents
- Python AI API → RAG pipeline: runs retrieval
- Agent orchestration → RAG pipeline: uses knowledge retrieval
- Agent orchestration → LLM and web services: calls models and tools
- RAG pipeline → Domain database: uses vector knowledge
