# envoyx/envoy-mindpalace architecture

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

- Interactive diagram: https://gitdiagram.com/envoyx/envoy-mindpalace
- Repository: https://github.com/envoyx/envoy-mindpalace

## Overview

1. **Overall shape**
   - This is a full-stack TanStack app built around **file-based routing** in `src/routes`, with both UI routes and API routes in the same repository.
   - It mixes **static/content-driven pages**, **database-backed features**, **authenticated dashboard/admin tooling**, **AI chat endpoints**, and **media upload workflows**.

2. **Routing and layout boundaries**
   - `src/router.tsx`, `src/routeTree.gen.ts`, and `src/routes/__root.tsx` define the app shell.
   - Route groups such as `_general`, `_auth`, `_chat`, and `dashboard` separate public pages, auth flows, chat experiences, and protected product/admin areas.
   - The root layout likely owns global providers, nav, theme, and shared error/pending handling via components like `DefaultErrorComponent` and `DefaultPendingComponent`.

3. **Public content and blog system**
   - Blog/article content is source-managed in `src/blog` as markdown files and described by `src/collections/*.ts`.
   - `content-collections.ts` plus `.content-collections/generated/*` indicate build-time generation of typed content indexes and collection accessors.
   - Public content routes like `src/routes/blog/$slug.index.tsx` and `src/routes/article/$slug.tsx` render this generated content rather than querying the database.

4. **Database layer and Prisma**
   - Persistent application data is modeled with **Prisma** in `prisma/schema.prisma`, with generated client code under `src/generated/prisma`.
   - The schema supports multiple domains: users, auth sessions/accounts, posts/comments/likes, albums/images, chats/messages, follows, tasks/task lists, and Quran tracking.
   - `src/db.ts` and `src/lib/db.ts` are the likely DB access entry points used by data-layer modules in `src/data/*`.

5. **Feature-oriented data layer**
   - `src/data/*` is the main server-side domain layer, separating route components from database and service logic.
   - Modules such as `blog.ts`, `post.ts`, `album.ts`, `image.ts`, `user.ts`, `session.ts`, `follow.ts`, and `task-tracker.ts` organize CRUD and query logic by feature.
   - `src/data/query-options/*` suggests TanStack Query-style query definitions are centralized for reuse across pages and dashboards.

6. **Authentication and route protection**
   - Authentication is split between `src/lib/auth.ts`, `src/lib/auth-client.ts`, and middleware in `src/middlewares/auth.ts`.
   - `src/routes/_auth/*` handles login flows, while dashboard and other protected routes likely depend on middleware or server checks.
   - The Prisma models for `Session`, `Account`, `Verification`, and `User` imply a full auth system with persisted sessions and external provider accounts.

7. **Dashboard and admin surface**
   - `src/routes/dashboard/*` is a large internal workspace for managing blog posts, images, albums, profile/settings, task tracking, and admin views.
   - Components under `src/components/web/dashboard`, `src/components/web/admin`, `src/components/web/image`, and `src/components/web/album` are the UI layer for those operations.
   - The dashboard appears to be the primary “back office” for editing content and managing platform data stored in Prisma.

8. **AI chat subsystem**
   - The `_chat` route group and `src/routes/api/chat-gemini`, `chat-groq`, and `chat-openrouter` expose chat experiences backed by different model providers.
   - `src/data/chat-ai.ts` and components like `src/components/ai-elements/*` indicate a reusable chat UI coupled to provider-specific server routes.
   - The path structure under `_chat/chat/_chatbox` suggests per-chat or per-adapter routing, with provider selection as an architectural boundary.

9. **Media upload and image handling**
   - Upload and media management run through `src/server/uploadthing.ts`, `src/server/uploadthing.action.ts`, `src/server/utapi.ts`, and `src/utils/uploadthing.ts`.
   - Routes such as `src/routes/api/uploadthing.ts`, `src/routes/api/proxy-image.ts`, and dashboard image pages coordinate upload, proxying, import, and album assignment.
   - Image-related UI is split across dialogs, dropzones, galleries, lightboxes, and bulk-edit tools, showing that media is a first-class domain.

10. **State, query, and client-side interaction**
   - `src/components/web/query-provider.tsx` plus `src/data/query-options/*` suggest TanStack Query is used for client/server data synchronization.
   - Local interaction state is handled with TanStack Store in `src/store/*` for UI concerns like sidebar, blog editor, image upload, photo gallery, and profile settings.
   - This separates durable server data from ephemeral client state, which is important for understanding render/update flows.

11. **Shared UI system**
   - `src/components/ui/*` is a reusable design-system layer, likely built from shadcn-style primitives on top of Tailwind CSS.
   - Feature components in `src/components/web/*` compose those primitives into app-specific experiences: nav, sidebar, cards, dialogs, markdown rendering, comments, and profile flows.
   - `src/lib/theme-provider.tsx` and `src/components/web/theme-toggle.tsx` indicate theme state is handled globally at the client boundary.

12. **Supporting infrastructure and deployment**
   - The app is built with **Vite**, **TanStack Router**, **TanStack Query**, **Prisma**, **Tailwind CSS**, and is configured for **Netlify** deployment via `netlify.toml`.
   - Validation and typed configuration are centralized in `src/schemas/*` and `src/env.ts`, while utility code lives in `src/utils/*` and `src/lib/*`.
   - For an architecture diagram, the key external integrations to show are the database, auth providers/sessions, upload service, AI model providers, and the Netlify-hosted app/API surface.

Main entry points: [`src/routes/dashboard/route.tsx`](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/route.tsx) (Dashboard Shell), [`src/data/blog.ts`](https://github.com/envoyx/envoy-mindpalace/blob/main/src/data/blog.ts) (Domain Data), [`src/routes/__root.tsx`](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/__root.tsx) (Root Layout), [`src/routes/_general/route.tsx`](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_general/route.tsx) (General Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app_shell["App Shell"]
  node_router["Router<br/>[router.tsx]"]
  node_root_route["Root Layout<br/>route-shell<br/>[__root.tsx]"]
end

subgraph group_public_content["Public Content"]
  node_general_group["General Routes<br/>route-group<br/>[route.tsx]"]
  node_blog_page["Blog Index<br/>content-route<br/>[blog.index.tsx]"]
  node_blog_slug["Blog Post<br/>content-route<br/>[$slug.index.tsx]"]
  node_article_page["Article Page<br/>content-route<br/>[$slug.tsx]"]
  node_content_cfg["Collections<br/>content-config"]
  node_blog_content["Blog MD<br/>markdown-content"]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_route["Dashboard Shell<br/>protected-route<br/>[route.tsx]"]
  node_dashboard_home["Dashboard Home<br/>workspace-route<br/>[index.tsx]"]
  node_dashboard_blog["Blog Admin<br/>workspace-module<br/>[index.tsx]"]
  node_dashboard_images["Image Admin<br/>workspace-module<br/>[index.tsx]"]
  node_dashboard_albums["Album Admin<br/>workspace-module<br/>[index.tsx]"]
end

subgraph group_chat_ai["AI Chat"]
  node_chat_group["Chat Routes<br/>route-group<br/>[index.tsx]"]
  node_chat_api["Chat APIs<br/>api-surface<br/>[route.ts]"]
  node_chat_ui["Chat UI<br/>ui-module<br/>[Chat.tsx]"]
end

subgraph group_data_layer["Data Layer"]
  node_db_client[("DB Client<br/>persistence-entry<br/>[db.ts]")]
  node_prisma_schema["Prisma Schema<br/>data-model<br/>[schema.prisma]"]
  node_domain_data["Domain Data<br/>service-layer<br/>[blog.ts]"]
  node_auth_lib["Auth<br/>[auth.ts]"]
  node_upload_srv["Uploads<br/>upload-service<br/>[uploadthing.ts]"]
end

subgraph group_shared_ui["Shared UI"]
  node_query_store["Query State<br/>client-state<br/>[query-provider.tsx]"]
  node_web_components["Web UI<br/>ui-system<br/>[navbar.tsx]"]
end

node_router -->|"loads"| node_root_route
node_root_route -->|"hosts"| node_general_group
node_root_route -->|"hosts"| node_dashboard_route
node_root_route -->|"hosts"| node_chat_group
node_general_group -->|"routes"| node_blog_page
node_general_group -->|"routes"| node_blog_slug
node_general_group -->|"routes"| node_article_page
node_blog_page -->|"reads"| node_content_cfg
node_blog_slug -->|"renders"| node_blog_content
node_article_page -->|"reads"| node_content_cfg
node_dashboard_route -->|"contains"| node_dashboard_home
node_dashboard_route -->|"contains"| node_dashboard_blog
node_dashboard_route -->|"contains"| node_dashboard_images
node_dashboard_route -->|"contains"| node_dashboard_albums
node_dashboard_blog -->|"uses"| node_domain_data
node_dashboard_images -->|"uploads"| node_upload_srv
node_dashboard_albums -->|"uses"| node_domain_data
node_chat_group -->|"composes"| node_chat_ui
node_chat_group -->|"calls"| node_chat_api
node_chat_api -->|"uses"| node_domain_data
node_domain_data -->|"queries"| node_db_client
node_db_client -->|"generated from"| node_prisma_schema
node_auth_lib -->|"stores"| node_db_client
node_upload_srv -->|"records"| node_db_client
node_query_store -->|"supports"| node_web_components
node_web_components -->|"queries"| node_domain_data
node_web_components -->|"guards"| node_auth_lib

click node_router "https://github.com/envoyx/envoy-mindpalace/blob/main/src/router.tsx"
click node_root_route "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/__root.tsx"
click node_general_group "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_general/route.tsx"
click node_blog_page "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_general/blog.index.tsx"
click node_blog_slug "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/blog/$slug.index.tsx"
click node_article_page "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/article/$slug.tsx"
click node_content_cfg "https://github.com/envoyx/envoy-mindpalace/blob/main/content-collections.ts"
click node_blog_content "https://github.com/envoyx/envoy-mindpalace/blob/main/src/blog/announcing-tanstack-form-v1.md"
click node_dashboard_route "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/route.tsx"
click node_dashboard_home "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/index.tsx"
click node_dashboard_blog "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/blog/index.tsx"
click node_dashboard_images "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/images/index.tsx"
click node_dashboard_albums "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/albums/index.tsx"
click node_chat_group "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_chat/chat/index.tsx"
click node_chat_api "https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/api/chat-gemini/route.ts"
click node_chat_ui "https://github.com/envoyx/envoy-mindpalace/blob/main/src/components/ai-elements/Chat.tsx"
click node_db_client "https://github.com/envoyx/envoy-mindpalace/blob/main/src/db.ts"
click node_prisma_schema "https://github.com/envoyx/envoy-mindpalace/blob/main/prisma/schema.prisma"
click node_domain_data "https://github.com/envoyx/envoy-mindpalace/blob/main/src/data/blog.ts"
click node_auth_lib "https://github.com/envoyx/envoy-mindpalace/blob/main/src/lib/auth.ts"
click node_upload_srv "https://github.com/envoyx/envoy-mindpalace/blob/main/src/server/uploadthing.ts"
click node_query_store "https://github.com/envoyx/envoy-mindpalace/blob/main/src/components/web/query-provider.tsx"
click node_web_components "https://github.com/envoyx/envoy-mindpalace/blob/main/src/components/web/navbar.tsx"

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_router,node_root_route toneBlue
class node_general_group,node_blog_page,node_blog_slug,node_article_page,node_content_cfg,node_blog_content toneAmber
class node_dashboard_route,node_dashboard_home,node_dashboard_blog,node_dashboard_images,node_dashboard_albums toneMint
class node_chat_group,node_chat_api,node_chat_ui toneRose
class node_db_client,node_prisma_schema,node_domain_data,node_auth_lib,node_upload_srv toneIndigo
class node_query_store,node_web_components toneTeal
```

## Components

### App Shell

Routing, providers, and global layout boundaries.

- [Router](https://github.com/envoyx/envoy-mindpalace/blob/main/src/router.tsx): tanstack-router · App router entry and route registration. · `src/router.tsx`
- [Root Layout](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/__root.tsx): route-shell · Global app shell, providers, and shared boundaries. · `src/routes/__root.tsx`

### Public Content

Public pages, blog/article rendering, and shared content presentation.

- [General Routes](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_general/route.tsx): route-group · Public site routes for content and profiles. · `src/routes/_general/route.tsx`
- [Blog Index](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_general/blog.index.tsx): content-route · Public blog listing page. · `src/routes/_general/blog.index.tsx`
- [Blog Post](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/blog/$slug.index.tsx): content-route · Rendered blog article by slug. · `src/routes/blog/$slug.index.tsx`
- [Article Page](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/article/$slug.tsx): content-route · Public article/content route. · `src/routes/article/$slug.tsx`
- [Collections](https://github.com/envoyx/envoy-mindpalace/blob/main/content-collections.ts): content-config · Collection definitions for generated markdown content. · `content-collections.ts`
- [Blog MD](https://github.com/envoyx/envoy-mindpalace/blob/main/src/blog/announcing-tanstack-form-v1.md): markdown-content · Source-managed blog articles. · `src/blog/announcing-tanstack-form-v1.md`

### Dashboard

Protected back-office workspace for managing app data.

- [Dashboard Shell](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/route.tsx): protected-route · Protected dashboard layout and navigation boundary. · `src/routes/dashboard/route.tsx`
- [Dashboard Home](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/index.tsx): workspace-route · Main internal workspace landing page. · `src/routes/dashboard/index.tsx`
- [Blog Admin](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/blog/index.tsx): workspace-module · Blog management and editor routes. · `src/routes/dashboard/blog/index.tsx`
- [Image Admin](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/images/index.tsx): workspace-module · Image management and upload routes. · `src/routes/dashboard/images/index.tsx`
- [Album Admin](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/dashboard/albums/index.tsx): workspace-module · Album management routes. · `src/routes/dashboard/albums/index.tsx`

### AI Chat

Chat routes, provider adapters, and shared chat UI.

- [Chat Routes](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/_chat/chat/index.tsx): route-group · Chat experience boundary with nested adapters. · `src/routes/_chat/chat/index.tsx`
- [Chat APIs](https://github.com/envoyx/envoy-mindpalace/blob/main/src/routes/api/chat-gemini/route.ts): api-surface · Provider-specific chat endpoints. · `src/routes/api/chat-gemini/route.ts`
- [Chat UI](https://github.com/envoyx/envoy-mindpalace/blob/main/src/components/ai-elements/Chat.tsx): ui-module · Reusable chat conversation and input components. · `src/components/ai-elements/Chat.tsx`

### Data Layer

Domain services, persistence, and generated client access.

- [DB Client](https://github.com/envoyx/envoy-mindpalace/blob/main/src/db.ts): persistence-entry · Database access entry point. · `src/db.ts`
- [Prisma Schema](https://github.com/envoyx/envoy-mindpalace/blob/main/prisma/schema.prisma): data-model · Persistence schema for users, content, media, chat, and tasks. · `prisma/schema.prisma`
- [Domain Data](https://github.com/envoyx/envoy-mindpalace/blob/main/src/data/blog.ts): service-layer · Feature-oriented server-side data modules. · `src/data/blog.ts`
- [Auth](https://github.com/envoyx/envoy-mindpalace/blob/main/src/lib/auth.ts): auth-layer · Authentication and session integration. · `src/lib/auth.ts`
- [Uploads](https://github.com/envoyx/envoy-mindpalace/blob/main/src/server/uploadthing.ts): upload-service · UploadThing/UT API integration for media workflows. · `src/server/uploadthing.ts`

### Shared UI

Reusable components, stores, and client-side interaction primitives.

- [Query State](https://github.com/envoyx/envoy-mindpalace/blob/main/src/components/web/query-provider.tsx): client-state · Client query and store coordination. · `src/components/web/query-provider.tsx`
- [Web UI](https://github.com/envoyx/envoy-mindpalace/blob/main/src/components/web/navbar.tsx): ui-system · Feature UI built on shared primitives. · `src/components/web/navbar.tsx`

## Connections

- Router → Root Layout: loads · Router bootstraps the root layout and nested routes.
- Root Layout → General Routes: hosts · Root layout provides the public route group.
- Root Layout → Dashboard Shell: hosts · Root layout includes protected dashboard boundaries.
- Root Layout → Chat Routes: hosts · Root layout includes nested chat flows.
- General Routes → Blog Index: routes · Public blog listing is part of the general route group.
- General Routes → Blog Post: routes · General routes render individual blog posts.
- General Routes → Article Page: routes · General routes render article pages.
- Blog Index → Collections: reads · Blog listing is driven by generated content collections.
- Blog Post → Blog MD: renders · Blog slug page renders markdown-backed content.
- Article Page → Collections: reads · Article pages rely on content collection metadata.
- Dashboard Shell → Dashboard Home: contains · Dashboard shell contains workspace entry pages.
- Dashboard Shell → Blog Admin: contains · Dashboard shell exposes blog management.
- Dashboard Shell → Image Admin: contains · Dashboard shell exposes image management.
- Dashboard Shell → Album Admin: contains · Dashboard shell exposes album management.
- Blog Admin → Domain Data: uses · Blog admin relies on domain data services.
- Image Admin → Uploads: uploads · Image admin coordinates upload workflows.
- Album Admin → Domain Data: uses · Album admin uses feature data services.
- Chat Routes → Chat UI: composes · Chat routes compose reusable chat UI.
- Chat Routes → Chat APIs: calls · Chat experiences connect to provider API routes.
- Chat APIs → Domain Data: uses · Chat endpoints may persist or query app data.
- Domain Data → DB Client: queries · Feature services access the shared database client.
- DB Client → Prisma Schema: generated from · Database client is generated from Prisma schema.
- Auth → DB Client: stores · Auth persists sessions and accounts through the database.
- Uploads → DB Client: records · Upload workflows persist media metadata in the database.
- Query State → Web UI: supports · Client state feeds interactive web components.
- Web UI → Domain Data: queries · Feature UI is backed by domain services and queries.
- Web UI → Auth: guards · Some UI surfaces depend on authenticated user state.
