How alghamdima/asdf works
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: api API layer · core AI core · web Web app · mobile Mobile app
Components 23
Apps
User-facing web and mobile shells.
- Web app · Locale-aware Next.js app shell with feature routes and a proxy API layer.
apps/web - Mobile app · Expo/React Native app shell with nested routes and feature modules.
apps/mobile - Web features · Domain slices for chat, image, rag, tts, voice, agent, and shared shell concerns.
apps/web/src/modules - Mobile features · Domain slices for chat, image, rag, tts, voice, agent, and shared shell concerns.
apps/mobile/src/modules - Web shell · Locale routes, app layout, API proxy, auth/query clients, and shared page chrome.
apps/web/src/app - Mobile shell · Expo Router layouts, app config, providers, and platform bootstrap.
apps/mobile/src/app
Packages
Shared domain, platform, and infrastructure packages.
- API layer · Central server-side HTTP surface for auth, AI, and storage routes with shared error handling.
packages/api - AI core · Common AI utilities, credits, and server helpers used across AI services.
packages/ai/core - Chat AI · Chat domain service with models, schemas, prompts, and web-search tool integrations.
packages/ai/chat - Image AI · Image generation service with provider, schema, and API surface.
packages/ai/image - RAG AI · RAG service with embeddings, provider logic, schema, and API surface.
packages/ai/rag - TTS AI · Text-to-speech service with client, API, schema, and utilities.
packages/ai/tts - Voice AI · Dedicated voice agent runtime and deployment package for real-time conversation flows.
packages/ai/voice - Auth · Shared authentication clients and server entry points for web and mobile.
packages/auth - Database · Persistent schema, migrations, and database scripts for auth, chat, image, customer, and RAG data.
packages/db - Storage · Shared file/object storage abstraction with S3 provider implementation.
packages/storage - i18n · Shared translation resources and server/client localization helpers.
packages/i18n - Web UI · Platform UI primitives and AI elements for the web app.
packages/ui/web - Mobile UI · Platform UI primitives and AI elements for the mobile app.
packages/ui/mobile - Shared UI · Cross-platform assets, SVGs, styles, and shared visual tokens.
packages/ui/shared - Shared utils · Repo-wide constants, hooks, logging, ids, URL helpers, and error utilities.
packages/shared
Tooling
Repo-wide build, lint, and workflow support.
- Tooling · TypeScript, lint, formatting, generators, and repository scripts.
tooling
Other components
- Monorepo · Root workspace that ties together apps, shared packages, and deployment tooling.
Connections 40
- 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.