# alghamdima/asfdsgf architecture

> Architecture diagram of the GitHub repository alghamdima/asfdsgf, 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/asfdsgf
- Repository: https://github.com/alghamdima/asfdsgf

## Overview

1. **Repository shape**
   - This is a **pnpm monorepo** organized around three main Next.js applications plus shared packages.
   - The top-level apps are:
     - `apps/marketing`: the public-facing marketing site
     - `apps/saas`: the authenticated SaaS application
     - `apps/docs`: documentation site and content API
     - `apps/mail-preview`: email template preview surface
   - Shared behavior lives in `packages/*`, which act as the main architectural boundary for cross-app capabilities.

2. **Primary product surfaces**
   - `apps/marketing` and `apps/docs` are largely content-driven and public.
   - `apps/saas` is the core product UI with authentication, organizations, billing, settings, onboarding, and admin pages.
   - The SaaS app is split into authenticated and unauthenticated route groups, which is a major boundary in the UI flow.

3. **SaaS application structure**
   - `apps/saas/app` contains route groups for:
     - unauthenticated flows: login, signup, verify, forgot/reset password
     - authenticated flows: onboarding, organization creation/invites, account settings, organization dashboards, admin sections, checkout return
   - The app also has an API proxy route under `app/api/[[...rest]]`, plus an `image-proxy` route, so the frontend communicates with backend procedures through a typed API boundary rather than directly embedding data logic in pages.

4. **Public marketing site architecture**
   - `apps/marketing` is a localized Next.js site with locale-based routing under `[locale]`.
   - It contains:
     - home page
     - blog pages
     - changelog
     - legal pages
     - contact page
   - The marketing app uses content collections and shared modules for homepage sections, blog rendering, legal page loading, locale handling, consent, navigation, and analytics injection.

5. **Documentation site architecture**
   - `apps/docs` is a separate Next.js app focused on docs content and machine-readable outputs.
   - It serves MDX-based documentation pages, plus special routes for:
     - search API
     - `llms.txt` / `llms.mdx` variants
     - Open Graph image generation
   - Docs content is stored in `apps/docs/content` and rendered through `source.config.ts` and MDX components, making docs mostly content + render pipeline rather than application state.

6. **Backend/API boundary**
   - `packages/api` is the central typed backend layer.
   - It is organized by domain modules:
     - `admin`
     - `ai`
     - `notifications`
     - `organizations`
     - `payments`
     - `users`
   - Each module exposes procedures and a router, and the API is served through an oRPC handler with middleware such as locale handling.
   - This package is the main backend contract consumed by the SaaS frontend.

7. **Authentication and session model**
   - `packages/auth` centralizes auth configuration, client/server helpers, organization helpers, and an invitation-only plugin.
   - The SaaS app wraps routes/components with auth/session providers, and the unauthenticated pages are clearly separated from authenticated workspaces.
   - Auth is not just login/logout; it also supports organization membership, invitations, and account-level session management.

8. **Data persistence layer**
   - `packages/database` contains the persistence stack with both **Prisma** and **Drizzle** assets present.
   - It includes:
     - schema definitions
     - query modules for organizations, purchases, and users
     - Zod generation/configuration
   - The architecture suggests a shared domain model for core entities like users, organizations, memberships, and purchases, with the API package using these data access utilities.

9. **Payments and billing flow**
   - `packages/payments` abstracts billing across multiple providers:
     - Stripe
     - Polar
     - Lemon Squeezy
     - Creem
     - Dodo Payments
   - It also contains plan helpers, customer utilities, and provider-specific integrations.
   - `packages/api/modules/payments` exposes procedures for checkout link creation, customer portal links, and purchase listing.
   - In the SaaS UI, billing pages and pricing/plan components consume this backend-backed billing layer.

10. **Notifications, mail, and async user communication**
   - `packages/notifications` manages notification creation, listing, read state, preferences, and welcome notifications.
   - `packages/mail` handles email templates and sending, with provider adapters for services like Resend, Mailgun, Postmark, Plunk, Nodemailer, and a console provider.
   - These packages support user-facing lifecycle events such as verification, password reset, invitations, and notification delivery.

11. **AI and external capabilities**
   - `packages/ai` provides client logic and prompt definitions.
   - `packages/api/modules/ai` exposes a `stream-message` procedure, so AI interaction is routed through the backend rather than directly from the UI.
   - `apps/saas/modules/ai` contains the chat UI that sits on top of that backend procedure.

12. **Shared UI and application utilities**
   - `packages/ui` is the component library used across apps, providing common primitives like buttons, dialogs, forms, tables, toasts, charts, etc.
   - `packages/utils`, `packages/logs`, and `packages/storage` provide cross-cutting helpers for base URLs, validation, logging, and file storage.
   - `packages/storage` currently abstracts S3-style storage, which is used for upload flows like avatars and organization logos.

13. **Internationalization and content localization**
   - `packages/i18n` is shared across apps and provides translations for `en`, `de`, `es`, and `fr`.
   - Marketing and SaaS each have their own i18n modules, but both rely on the shared translations package and locale update/request utilities.
   - Localization affects routing, content rendering, and some user preferences such as language selection.

14. **Important UI/data flow boundaries**
   - Public content flows:
     - MDX/content collections or filesystem content → Next.js pages/components
   - Authenticated product flows:
     - UI form/page → shared client/provider → oRPC procedure → domain package → persistence/provider
   - Outbound service flows:
     - API/domain logic → payment/mail/storage/notification/AI provider adapters
   - This separation between presentation, typed API, and provider-backed infrastructure is the core architectural pattern in the repo.

15. **Tooling and quality gates**
   - The repository uses TypeScript throughout, Next.js app router, Playwright for end-to-end tests, Vitest for unit tests, and GitHub Actions for PR validation.
   - There is also shared tooling for Tailwind and TypeScript configs, indicating a standardized multi-app setup rather than isolated projects.

Main entry points: [`apps/saas/app/layout.tsx`](https://github.com/alghamdima/asfdsgf/blob/main/apps/saas/app/layout.tsx) (SaaS), [`packages/api/orpc/handler.ts`](https://github.com/alghamdima/asfdsgf/blob/main/packages/api/orpc/handler.ts) (API), [`apps/marketing/app/layout.tsx`](https://github.com/alghamdima/asfdsgf/blob/main/apps/marketing/app/layout.tsx) (Marketing), [`packages/auth/auth.ts`](https://github.com/alghamdima/asfdsgf/blob/main/packages/auth/auth.ts) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_apps_marketing["Marketing<br/>Next.js site<br/>[layout.tsx]"]
  node_apps_docs["Docs<br/>[layout.tsx]"]
  node_apps_saas["SaaS<br/>Next.js app<br/>[layout.tsx]"]
  node_apps_mail_preview["Mail Preview<br/>Preview app<br/>[package.json]"]
end

subgraph group_packages["Packages"]
  node_pkg_api["API<br/>oRPC backend<br/>[handler.ts]"]
  node_pkg_auth["Auth<br/>[auth.ts]"]
  node_pkg_db[("Database<br/>persistence layer<br/>[index.ts]")]
  node_pkg_payments["Payments<br/>billing layer<br/>[index.ts]"]
  node_pkg_mail["Mail<br/>[index.ts]"]
  node_pkg_notifications["Notifications<br/>notification engine<br/>[index.ts]"]
  node_pkg_ai["AI<br/>prompt client<br/>[index.ts]"]
  node_pkg_i18n["i18n<br/>translation set<br/>[index.ts]"]
  node_pkg_ui["UI<br/>component library<br/>[index.ts]"]
  node_pkg_storage["Storage<br/>[index.ts]"]
  node_pkg_utils["Utils<br/>helpers<br/>[index.ts]"]
  node_pkg_logs["Logs<br/>logging<br/>[index.ts]"]
end

subgraph group_tooling["Tooling"]
  node_tooling_ts["TypeScript<br/>workspace config<br/>[base.json]"]
  node_tooling_tailwind["Tailwind<br/>workspace config<br/>[theme.css]"]
  node_tooling_scripts["Scripts<br/>[create-user.ts]"]
end

node_apps_marketing -->|"translations"| node_pkg_i18n
node_apps_marketing -->|"components"| node_pkg_ui
node_apps_marketing -->|"helpers"| node_pkg_utils
node_apps_marketing -->|"logging"| node_pkg_logs
node_apps_docs -->|"mdx ui"| node_pkg_ui
node_apps_docs -->|"locale"| node_pkg_i18n
node_apps_saas -->|"backend"| node_pkg_api
node_apps_saas -->|"sessions"| node_pkg_auth
node_apps_saas -->|"billing"| node_pkg_payments
node_apps_saas -->|"notifications"| node_pkg_notifications
node_apps_saas -->|"emails"| node_pkg_mail
node_apps_saas -->|"ai ui"| node_pkg_ai
node_apps_saas -->|"uploads"| node_pkg_storage
node_apps_saas -->|"components"| node_pkg_ui
node_apps_saas -->|"translations"| node_pkg_i18n
node_pkg_api -->|"data access"| node_pkg_db
node_pkg_api -->|"auth checks"| node_pkg_auth
node_pkg_api -->|"billing ops"| node_pkg_payments
node_pkg_api -->|"notification ops"| node_pkg_notifications
node_pkg_api -->|"ai procedures"| node_pkg_ai
node_pkg_mail -->|"email text"| node_pkg_i18n
node_pkg_notifications -->|"welcome mail"| node_pkg_mail
node_pkg_payments -->|"purchase data"| node_pkg_db
node_pkg_auth -->|"identity data"| node_pkg_db
node_pkg_auth -->|"verification mail"| node_pkg_mail
node_pkg_ai -->|"tracing"| node_pkg_logs
node_apps_saas -.->|"config"| node_tooling_ts
node_apps_marketing -.->|"theme"| node_tooling_tailwind
node_apps_docs -.->|"config"| node_tooling_ts
node_apps_saas -.->|"ops"| node_tooling_scripts

click node_apps_marketing "https://github.com/alghamdima/asfdsgf/blob/main/apps/marketing/app/layout.tsx"
click node_apps_docs "https://github.com/alghamdima/asfdsgf/blob/main/apps/docs/app/layout.tsx"
click node_apps_saas "https://github.com/alghamdima/asfdsgf/blob/main/apps/saas/app/layout.tsx"
click node_apps_mail_preview "https://github.com/alghamdima/asfdsgf/blob/main/apps/mail-preview/package.json"
click node_pkg_api "https://github.com/alghamdima/asfdsgf/blob/main/packages/api/orpc/handler.ts"
click node_pkg_auth "https://github.com/alghamdima/asfdsgf/blob/main/packages/auth/auth.ts"
click node_pkg_db "https://github.com/alghamdima/asfdsgf/blob/main/packages/database/index.ts"
click node_pkg_payments "https://github.com/alghamdima/asfdsgf/blob/main/packages/payments/index.ts"
click node_pkg_mail "https://github.com/alghamdima/asfdsgf/blob/main/packages/mail/index.ts"
click node_pkg_notifications "https://github.com/alghamdima/asfdsgf/blob/main/packages/notifications/src/index.ts"
click node_pkg_ai "https://github.com/alghamdima/asfdsgf/blob/main/packages/ai/index.ts"
click node_pkg_i18n "https://github.com/alghamdima/asfdsgf/blob/main/packages/i18n/index.ts"
click node_pkg_ui "https://github.com/alghamdima/asfdsgf/blob/main/packages/ui/index.ts"
click node_pkg_storage "https://github.com/alghamdima/asfdsgf/blob/main/packages/storage/index.ts"
click node_pkg_utils "https://github.com/alghamdima/asfdsgf/blob/main/packages/utils/index.ts"
click node_pkg_logs "https://github.com/alghamdima/asfdsgf/blob/main/packages/logs/index.ts"
click node_tooling_ts "https://github.com/alghamdima/asfdsgf/blob/main/tooling/typescript/base.json"
click node_tooling_tailwind "https://github.com/alghamdima/asfdsgf/blob/main/tooling/tailwind/theme.css"
click node_tooling_scripts "https://github.com/alghamdima/asfdsgf/blob/main/tooling/scripts/src/create-user.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_apps_marketing,node_apps_docs,node_apps_saas,node_apps_mail_preview toneBlue
class node_pkg_api,node_pkg_auth,node_pkg_db,node_pkg_payments,node_pkg_mail,node_pkg_notifications,node_pkg_ai,node_pkg_i18n,node_pkg_ui,node_pkg_storage,node_pkg_utils,node_pkg_logs toneAmber
class node_tooling_ts,node_tooling_tailwind,node_tooling_scripts toneMint
```

## Components

### Apps

Next.js product surfaces and previews

- [Marketing](https://github.com/alghamdima/asfdsgf/blob/main/apps/marketing/app/layout.tsx): Next.js site · Public localized marketing site with content-driven pages and shared presentation modules. · `apps/marketing/app/layout.tsx`
- [Docs](https://github.com/alghamdima/asfdsgf/blob/main/apps/docs/app/layout.tsx): Next.js docs site · Documentation app with MDX content, search, machine-readable outputs, and OG image routes. · `apps/docs/app/layout.tsx`
- [SaaS](https://github.com/alghamdima/asfdsgf/blob/main/apps/saas/app/layout.tsx): Next.js app · Authenticated product surface with auth, organizations, billing, settings, onboarding, admin, and API proxy routes. · `apps/saas/app/layout.tsx`
- [Mail Preview](https://github.com/alghamdima/asfdsgf/blob/main/apps/mail-preview/package.json): Preview app · Standalone surface for previewing email templates. · `apps/mail-preview/package.json`

### Packages

Shared domain, infrastructure, and UI libraries

- [API](https://github.com/alghamdima/asfdsgf/blob/main/packages/api/orpc/handler.ts): oRPC backend · Central typed backend contract organized by domain routers and procedures. · `packages/api/orpc/handler.ts`
- [Auth](https://github.com/alghamdima/asfdsgf/blob/main/packages/auth/auth.ts): auth core · Shared authentication, session, organization, and invitation logic. · `packages/auth/auth.ts`
- [Database](https://github.com/alghamdima/asfdsgf/blob/main/packages/database/index.ts): persistence layer · Shared Prisma/Drizzle persistence stack and generated query/schema assets. · `packages/database/index.ts`
- [Payments](https://github.com/alghamdima/asfdsgf/blob/main/packages/payments/index.ts): billing layer · Provider-agnostic billing abstractions for plans, customers, and price mappings. · `packages/payments/index.ts`
- [Mail](https://github.com/alghamdima/asfdsgf/blob/main/packages/mail/index.ts): email system · Email templates, rendering, sending, and provider adapters. · `packages/mail/index.ts`
- [Notifications](https://github.com/alghamdima/asfdsgf/blob/main/packages/notifications/src/index.ts): notification engine · Notification creation, listing, read state, preferences, and welcome flows. · `packages/notifications/src/index.ts`
- [AI](https://github.com/alghamdima/asfdsgf/blob/main/packages/ai/index.ts): prompt client · Shared AI client and prompt definitions. · `packages/ai/index.ts`
- [i18n](https://github.com/alghamdima/asfdsgf/blob/main/packages/i18n/index.ts): translation set · Shared translations and locale message loading for all apps. · `packages/i18n/index.ts`
- [UI](https://github.com/alghamdima/asfdsgf/blob/main/packages/ui/index.ts): component library · Shared design-system primitives and reusable UI components. · `packages/ui/index.ts`
- [Storage](https://github.com/alghamdima/asfdsgf/blob/main/packages/storage/index.ts): file storage · Shared S3-style storage abstraction for uploads and assets. · `packages/storage/index.ts`
- [Utils](https://github.com/alghamdima/asfdsgf/blob/main/packages/utils/index.ts): helpers · Cross-cutting utilities such as base URL and validation helpers. · `packages/utils/index.ts`
- [Logs](https://github.com/alghamdima/asfdsgf/blob/main/packages/logs/index.ts): logging · Shared logger utilities used across the workspace. · `packages/logs/index.ts`

### Tooling

Workspace-wide build and developer tooling

- [TypeScript](https://github.com/alghamdima/asfdsgf/blob/main/tooling/typescript/base.json): workspace config · Shared TypeScript base configurations for apps and packages. · `tooling/typescript/base.json`
- [Tailwind](https://github.com/alghamdima/asfdsgf/blob/main/tooling/tailwind/theme.css): workspace config · Shared Tailwind configuration and theme assets. · `tooling/tailwind/theme.css`
- [Scripts](https://github.com/alghamdima/asfdsgf/blob/main/tooling/scripts/src/create-user.ts): dev scripts · Workspace utility scripts such as user creation helpers. · `tooling/scripts/src/create-user.ts`

## Connections

- Marketing → i18n: translations · Localized content and UI strings.
- Marketing → UI: components · Shared UI primitives and layout elements.
- Marketing → Utils: helpers · Base URL and common utility helpers.
- Marketing → Logs: logging · Client/server logging support.
- Docs → UI: mdx ui · Shared rendering components for docs and MDX.
- Docs → i18n: locale · Shared locale/message loading where needed.
- SaaS → API: backend · Primary typed API boundary for product data and actions.
- SaaS → Auth: sessions · Authentication, session, and organization access.
- SaaS → Payments: billing · Plan and subscription UI backed by billing providers.
- SaaS → Notifications: notifications · Notification center and preferences flows.
- SaaS → Mail: emails · Lifecycle email templates and sending support.
- SaaS → AI: ai ui · Chat experience backed by shared AI prompts/client.
- SaaS → Storage: uploads · Avatar and organization logo upload flows.
- SaaS → UI: components · Shared UI primitives and widgets.
- SaaS → i18n: translations · Localized routes, labels, and preferences.
- API → Database: data access · Reads and writes through shared persistence queries.
- API → Auth: auth checks · Uses auth context and organization helpers.
- API → Payments: billing ops · Delegates checkout and customer portal logic.
- API → Notifications: notification ops · Notification listing, read state, and preferences.
- API → AI: ai procedures · Streams AI messages through backend procedures.
- Mail → i18n: email text · Localized email templates and messages.
- Notifications → Mail: welcome mail · Notification workflows trigger email delivery.
- Payments → Database: purchase data · Persists and queries customers, purchases, and plans.
- Auth → Database: identity data · Stores and queries users, sessions, memberships, and invitations.
- Auth → Mail: verification mail · Sends verification, reset, and invitation emails.
- AI → Logs: tracing · Logging for prompts and client interactions.
- SaaS → TypeScript: config · Workspace TypeScript setup.
- Marketing → Tailwind: theme · Shared styling and theme configuration.
- Docs → TypeScript: config · Workspace TypeScript setup.
- SaaS → Scripts: ops · Developer and admin utility scripts.
