# alghamdima/asdf architecture

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

- Interactive diagram: https://gitdiagram.com/alghamdima/asdf
- Repository: https://github.com/alghamdima/asdf

## Overview

1. **Monorepo shape**
   - This is a Turborepo-style monorepo with two user-facing apps (`apps/web`, `apps/mobile`) and several shared packages for AI, API, auth, storage, db, i18n, shared utilities, and UI.
   - The repo is organized so feature logic lives in reusable packages and app-specific shells stay thin.

2. **Primary entry points**
   - `apps/web` is the Next.js frontend.
   - `apps/mobile` is the Expo/React Native frontend.
   - `packages/api` is the backend HTTP layer that centralizes auth, AI, and storage routes.
   - `packages/ai/*` contains the domain services for chat, image generation, RAG, text-to-speech, and voice.

3. **Frontend architecture**
   - Both apps are route-driven and split by feature: chat, image, rag, tts, voice, and agent.
   - Each feature has its own `layout`, `composer`, `conversation`, `history`, and `lib` modules, which makes the architecture modular and easy to diagram by domain rather than by screen.
   - The web app uses Next.js App Router with locale-prefixed routes; the mobile app uses Expo Router with nested layouts.

4. **Shared design system**
   - `packages/ui/web`, `packages/ui/mobile`, and `packages/ui/shared` provide the visual and interaction primitives.
   - The web and mobile apps consume platform-specific UI packages, while `packages/ui/shared` holds shared assets, styles, and SVGs.
   - This is a key boundary: feature modules build screens, but reusable controls and visual language come from the UI packages.

5. **Backend/API boundary**
   - `packages/api` is the central server-side API surface.
   - It is split into modules for `auth`, `ai`, and `storage`, with middleware and shared error handling.
   - The web app includes a catch-all API route (`/api/[...route]`) that proxies or forwards requests into this backend layer, so the frontend does not directly embed all server logic.

6. **AI domain services**
   - `packages/ai/chat`, `packages/ai/image`, `packages/ai/rag`, `packages/ai/tts`, and `packages/ai/voice` isolate each AI capability behind its own API, schema, provider, and utility code.
   - Chat also has a dedicated tools subsystem for web search, with multiple provider strategies such as Brave, Exa, Firecrawl, and Tavily.
   - This creates a clean separation between UI concerns, orchestration logic, and third-party AI/provider integrations.

7. **Feature-level data flow**
   - For most experiences, the flow is: user action in a feature module → composer/history/conversation UI → app API client → `packages/api` route → relevant `packages/ai/*` service → external AI provider or storage/db dependency → response back to the UI.
   - The feature folders in web/mobile mirror this flow, so an architect can draw each domain as a vertical slice from input to result.

8. **Persistence and documents**
   - `packages/db` holds the Drizzle schema, migrations, and scripts, covering persistent entities for auth, chat, image, customer, and RAG.
   - `packages/storage` abstracts file/object storage, with an S3 provider implementation.
   - These packages are used by the backend and AI flows for uploads, history, and persisted artifacts such as documents or generated media.

9. **Auth and identity**
   - `packages/auth` is a shared authentication layer with separate client/server entry points and mobile/web clients.
   - `packages/api/src/modules/auth` exposes auth-related backend routes.
   - Auth is therefore a cross-cutting subsystem used by both frontends and server modules, not embedded inside a single app.

10. **Internationalization and app shell concerns**
   - `packages/i18n` provides shared translation resources and server/client helpers.
   - Web wraps pages in locale-aware routes and `with-i18n` style server helpers, while shared app shells handle theme, header/sidebar/drawer, credits, toast, and layout concerns.
   - This means localization and shell UI are handled as infrastructure around feature modules, not inside them.

11. **Voice as a special runtime**
   - Voice is the most stateful subsystem: the UI includes session providers, transcripts, visualizers, and controls, while `packages/ai/voice` includes an agent plus a deployment package.
   - That suggests a separate conversational/real-time runtime boundary beyond standard request/response API calls.
   - In the architecture diagram, voice should be shown as a client session connected to a dedicated voice service/agent, not just a normal CRUD endpoint.

12. **Tooling and deployment**
   - Turborepo, pnpm workspaces, shared TypeScript configs, and repo-wide lint/format tooling support the multi-package architecture.
   - GitHub workflows cover tests and separate publish pipelines for web, mobile, and database artifacts; mobile also has EAS config.
   - The repo is therefore designed for independent delivery of web, mobile, and backend/data changes while sharing most domain logic.

Main entry points: [`packages/api`](https://github.com/alghamdima/asdf/tree/main/packages/api) (API layer), [`packages/ai/core`](https://github.com/alghamdima/asdf/tree/main/packages/ai/core) (AI core), [`apps/web`](https://github.com/alghamdima/asdf/tree/main/apps/web) (Web app), [`apps/mobile`](https://github.com/alghamdima/asdf/tree/main/apps/mobile) (Mobile app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_web["Web app<br/>nextjs frontend"]
  node_mobile["Mobile app<br/>expo frontend"]
  node_web_modules["Web features<br/>route modules"]
  node_mobile_modules["Mobile features<br/>route modules"]
  node_web_shell["Web shell<br/>routing + layout"]
  node_mobile_shell["Mobile shell<br/>routing + providers"]
end

subgraph group_packages["Packages"]
  node_api["API layer<br/>http backend"]
  node_ai_core["AI core<br/>shared ai helpers"]
  node_ai_chat["Chat AI<br/>llm orchestration"]
  node_ai_image["Image AI<br/>image generation"]
  node_ai_rag["RAG AI<br/>retrieval service"]
  node_ai_tts["TTS AI<br/>speech synthesis"]
  node_ai_voice["Voice AI<br/>realtime agent"]
  node_auth["Auth<br/>identity layer"]
  node_db[("Database<br/>drizzle schema")]
  node_storage[("Storage")]
  node_i18n["i18n<br/>translations"]
  node_ui_web["Web UI<br/>component library"]
  node_ui_mobile["Mobile UI<br/>component library"]
  node_ui_shared["Shared UI<br/>assets + styles"]
  node_shared["Shared utils<br/>common toolkit"]
end

subgraph group_tooling["Tooling"]
  node_tooling{{"Tooling<br/>build + lint"}}
end

node_repo{{"Monorepo<br/>turborepo workspace"}}

node_repo -->|"contains"| node_web
node_repo -->|"contains"| node_mobile
node_repo -->|"contains"| node_api
node_repo -->|"contains"| node_ai_core
node_repo -->|"contains"| node_auth
node_repo -->|"contains"| node_db
node_repo -->|"contains"| node_storage
node_repo -->|"contains"| node_i18n
node_repo -->|"contains"| node_ui_web
node_repo -->|"contains"| node_ui_mobile
node_repo -->|"contains"| node_ui_shared
node_repo -->|"contains"| node_shared
node_repo -->|"contains"| node_tooling
node_web -->|"shell"| node_web_shell
node_web -->|"features"| node_web_modules
node_mobile -->|"shell"| node_mobile_shell
node_mobile -->|"features"| node_mobile_modules
node_web_shell -->|"calls"| node_api
node_mobile_shell -->|"calls"| node_api
node_api -->|"routes to"| node_ai_chat
node_api -->|"routes to"| node_ai_image
node_api -->|"routes to"| node_ai_rag
node_api -->|"routes to"| node_ai_tts
node_api -->|"routes to"| node_ai_voice
node_ai_chat -->|"uses"| node_ai_core
node_ai_image -->|"uses"| node_ai_core
node_ai_rag -->|"uses"| node_ai_core
node_ai_tts -->|"uses"| node_ai_core
node_ai_voice -->|"uses"| node_ai_core
node_api -->|"uses"| node_auth
node_api -->|"uses"| node_storage
node_api -->|"persists"| node_db
node_web_shell -->|"localizes"| node_i18n
node_mobile_shell -->|"localizes"| node_i18n
node_web -->|"renders with"| node_ui_web
node_mobile -->|"renders with"| node_ui_mobile
node_web -->|"shares assets"| node_ui_shared
node_mobile -->|"shares assets"| node_ui_shared
node_web_modules -->|"depends on"| node_shared
node_mobile_modules -->|"depends on"| node_shared

click node_web "https://github.com/alghamdima/asdf/tree/main/apps/web"
click node_mobile "https://github.com/alghamdima/asdf/tree/main/apps/mobile"
click node_web_modules "https://github.com/alghamdima/asdf/tree/main/apps/web/src/modules"
click node_mobile_modules "https://github.com/alghamdima/asdf/tree/main/apps/mobile/src/modules"
click node_web_shell "https://github.com/alghamdima/asdf/tree/main/apps/web/src/app"
click node_mobile_shell "https://github.com/alghamdima/asdf/tree/main/apps/mobile/src/app"
click node_api "https://github.com/alghamdima/asdf/tree/main/packages/api"
click node_ai_core "https://github.com/alghamdima/asdf/tree/main/packages/ai/core"
click node_ai_chat "https://github.com/alghamdima/asdf/tree/main/packages/ai/chat"
click node_ai_image "https://github.com/alghamdima/asdf/tree/main/packages/ai/image"
click node_ai_rag "https://github.com/alghamdima/asdf/tree/main/packages/ai/rag"
click node_ai_tts "https://github.com/alghamdima/asdf/tree/main/packages/ai/tts"
click node_ai_voice "https://github.com/alghamdima/asdf/tree/main/packages/ai/voice"
click node_auth "https://github.com/alghamdima/asdf/tree/main/packages/auth"
click node_db "https://github.com/alghamdima/asdf/tree/main/packages/db"
click node_storage "https://github.com/alghamdima/asdf/tree/main/packages/storage"
click node_i18n "https://github.com/alghamdima/asdf/tree/main/packages/i18n"
click node_ui_web "https://github.com/alghamdima/asdf/tree/main/packages/ui/web"
click node_ui_mobile "https://github.com/alghamdima/asdf/tree/main/packages/ui/mobile"
click node_ui_shared "https://github.com/alghamdima/asdf/tree/main/packages/ui/shared"
click node_shared "https://github.com/alghamdima/asdf/tree/main/packages/shared"
click node_tooling "https://github.com/alghamdima/asdf/tree/main/tooling"

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,node_mobile,node_web_modules,node_mobile_modules,node_web_shell,node_mobile_shell toneBlue
class node_api,node_ai_core,node_ai_chat,node_ai_image,node_ai_rag,node_ai_tts,node_ai_voice,node_auth,node_db,node_storage,node_i18n,node_ui_web,node_ui_mobile,node_ui_shared,node_shared toneAmber
class node_tooling toneMint
class node_repo toneNeutral
```

## Components

### Apps

User-facing web and mobile shells.

- [Web app](https://github.com/alghamdima/asdf/tree/main/apps/web): nextjs frontend · Locale-aware Next.js app shell with feature routes and a proxy API layer. · `apps/web`
- [Mobile app](https://github.com/alghamdima/asdf/tree/main/apps/mobile): expo frontend · Expo/React Native app shell with nested routes and feature modules. · `apps/mobile`
- [Web features](https://github.com/alghamdima/asdf/tree/main/apps/web/src/modules): route modules · Domain slices for chat, image, rag, tts, voice, agent, and shared shell concerns. · `apps/web/src/modules`
- [Mobile features](https://github.com/alghamdima/asdf/tree/main/apps/mobile/src/modules): route modules · Domain slices for chat, image, rag, tts, voice, agent, and shared shell concerns. · `apps/mobile/src/modules`
- [Web shell](https://github.com/alghamdima/asdf/tree/main/apps/web/src/app): routing + layout · Locale routes, app layout, API proxy, auth/query clients, and shared page chrome. · `apps/web/src/app`
- [Mobile shell](https://github.com/alghamdima/asdf/tree/main/apps/mobile/src/app): routing + providers · Expo Router layouts, app config, providers, and platform bootstrap. · `apps/mobile/src/app`

### Packages

Shared domain, platform, and infrastructure packages.

- [API layer](https://github.com/alghamdima/asdf/tree/main/packages/api): http backend · Central server-side HTTP surface for auth, AI, and storage routes with shared error handling. · `packages/api`
- [AI core](https://github.com/alghamdima/asdf/tree/main/packages/ai/core): shared ai helpers · Common AI utilities, credits, and server helpers used across AI services. · `packages/ai/core`
- [Chat AI](https://github.com/alghamdima/asdf/tree/main/packages/ai/chat): llm orchestration · Chat domain service with models, schemas, prompts, and web-search tool integrations. · `packages/ai/chat`
- [Image AI](https://github.com/alghamdima/asdf/tree/main/packages/ai/image): image generation · Image generation service with provider, schema, and API surface. · `packages/ai/image`
- [RAG AI](https://github.com/alghamdima/asdf/tree/main/packages/ai/rag): retrieval service · RAG service with embeddings, provider logic, schema, and API surface. · `packages/ai/rag`
- [TTS AI](https://github.com/alghamdima/asdf/tree/main/packages/ai/tts): speech synthesis · Text-to-speech service with client, API, schema, and utilities. · `packages/ai/tts`
- [Voice AI](https://github.com/alghamdima/asdf/tree/main/packages/ai/voice): realtime agent · Dedicated voice agent runtime and deployment package for real-time conversation flows. · `packages/ai/voice`
- [Auth](https://github.com/alghamdima/asdf/tree/main/packages/auth): identity layer · Shared authentication clients and server entry points for web and mobile. · `packages/auth`
- [Database](https://github.com/alghamdima/asdf/tree/main/packages/db): drizzle schema · Persistent schema, migrations, and database scripts for auth, chat, image, customer, and RAG data. · `packages/db`
- [Storage](https://github.com/alghamdima/asdf/tree/main/packages/storage): object storage · Shared file/object storage abstraction with S3 provider implementation. · `packages/storage`
- [i18n](https://github.com/alghamdima/asdf/tree/main/packages/i18n): translations · Shared translation resources and server/client localization helpers. · `packages/i18n`
- [Web UI](https://github.com/alghamdima/asdf/tree/main/packages/ui/web): component library · Platform UI primitives and AI elements for the web app. · `packages/ui/web`
- [Mobile UI](https://github.com/alghamdima/asdf/tree/main/packages/ui/mobile): component library · Platform UI primitives and AI elements for the mobile app. · `packages/ui/mobile`
- [Shared UI](https://github.com/alghamdima/asdf/tree/main/packages/ui/shared): assets + styles · Cross-platform assets, SVGs, styles, and shared visual tokens. · `packages/ui/shared`
- [Shared utils](https://github.com/alghamdima/asdf/tree/main/packages/shared): common toolkit · Repo-wide constants, hooks, logging, ids, URL helpers, and error utilities. · `packages/shared`

### Tooling

Repo-wide build, lint, and workflow support.

- [Tooling](https://github.com/alghamdima/asdf/tree/main/tooling): build + lint · TypeScript, lint, formatting, generators, and repository scripts. · `tooling`

### Other components

- **Monorepo**: turborepo workspace · Root workspace that ties together apps, shared packages, and deployment tooling.

## Connections

- Monorepo → Web app: contains · Workspace includes the web application.
- Monorepo → Mobile app: contains · Workspace includes the mobile application.
- Monorepo → API layer: contains · Workspace includes the shared backend API.
- Monorepo → AI core: contains · Workspace includes shared AI infrastructure.
- Monorepo → Auth: contains · Workspace includes shared auth.
- Monorepo → Database: contains · Workspace includes database schema and migrations.
- Monorepo → Storage: contains · Workspace includes storage abstraction.
- Monorepo → i18n: contains · Workspace includes localization resources.
- Monorepo → Web UI: contains · Workspace includes web UI primitives.
- Monorepo → Mobile UI: contains · Workspace includes mobile UI primitives.
- Monorepo → Shared UI: contains · Workspace includes shared design assets.
- Monorepo → Shared utils: contains · Workspace includes shared utilities.
- Monorepo → Tooling: contains · Workspace includes repo tooling.
- Web app → Web shell: shell · Routing and shell infra wrap feature modules.
- Web app → Web features: features · Feature modules implement domain screens and flows.
- Mobile app → Mobile shell: shell · Routing and provider setup wrap feature modules.
- Mobile app → Mobile features: features · Feature modules implement domain screens and flows.
- Web shell → API layer: calls · Web API routes and clients forward into the central backend layer.
- Mobile shell → API layer: calls · Mobile modules use shared API clients against the backend layer.
- API layer → Chat AI: routes to · API AI module dispatches chat requests to chat service.
- API layer → Image AI: routes to · API AI module dispatches image requests to image service.
- API layer → RAG AI: routes to · API AI module dispatches RAG requests to retrieval service.
- API layer → TTS AI: routes to · API AI module dispatches TTS requests to speech service.
- API layer → Voice AI: routes to · API exposes voice integration for the dedicated runtime.
- Chat AI → AI core: uses · Chat service shares AI helpers and credits logic.
- Image AI → AI core: uses · Image service shares AI helpers and credits logic.
- RAG AI → AI core: uses · RAG service shares AI helpers and credits logic.
- TTS AI → AI core: uses · TTS service shares AI helpers and credits logic.
- Voice AI → AI core: uses · Voice runtime shares AI helpers and server utilities.
- API layer → Auth: uses · Backend auth routes rely on the shared auth layer.
- API layer → Storage: uses · Backend storage routes rely on the shared storage layer.
- API layer → Database: persists · Backend and AI flows persist to the database schema.
- Web shell → i18n: localizes · Web app uses locale routing and server/client translation helpers.
- Mobile shell → i18n: localizes · Mobile app uses shared translation resources and helpers.
- Web app → Web UI: renders with · Web features consume platform-specific UI components.
- Mobile app → Mobile UI: renders with · Mobile features consume platform-specific UI components.
- Web app → Shared UI: shares assets · Web app uses shared icons, SVGs, and styles.
- Mobile app → Shared UI: shares assets · Mobile app uses shared icons, SVGs, and styles.
- Web features → Shared utils: depends on · Web feature logic uses common utilities and hooks.
- Mobile features → Shared utils: depends on · Mobile feature logic uses common utilities and hooks.
