How alghamdima/asfdsgf works
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: app/layout.tsx SaaS · handler.ts API · app/layout.tsx Marketing · auth.ts Auth
Components 19
Apps
Next.js product surfaces and previews
- Marketing · Public localized marketing site with content-driven pages and shared presentation modules.
apps/marketing/app/layout.tsx - Docs · Documentation app with MDX content, search, machine-readable outputs, and OG image routes.
apps/docs/app/layout.tsx - SaaS · Authenticated product surface with auth, organizations, billing, settings, onboarding, admin, and API proxy routes.
apps/saas/app/layout.tsx - Mail Preview · Standalone surface for previewing email templates.
apps/mail-preview/package.json
Packages
Shared domain, infrastructure, and UI libraries
- API · Central typed backend contract organized by domain routers and procedures.
packages/api/orpc/handler.ts - Auth · Shared authentication, session, organization, and invitation logic.
packages/auth/auth.ts - Database · Shared Prisma/Drizzle persistence stack and generated query/schema assets.
packages/database/index.ts - Payments · Provider-agnostic billing abstractions for plans, customers, and price mappings.
packages/payments/index.ts - Mail · Email templates, rendering, sending, and provider adapters.
packages/mail/index.ts - Notifications · Notification creation, listing, read state, preferences, and welcome flows.
packages/notifications/src/index.ts - AI · Shared AI client and prompt definitions.
packages/ai/index.ts - i18n · Shared translations and locale message loading for all apps.
packages/i18n/index.ts - UI · Shared design-system primitives and reusable UI components.
packages/ui/index.ts - Storage · Shared S3-style storage abstraction for uploads and assets.
packages/storage/index.ts - Utils · Cross-cutting utilities such as base URL and validation helpers.
packages/utils/index.ts - Logs · Shared logger utilities used across the workspace.
packages/logs/index.ts
Tooling
Workspace-wide build and developer tooling
- TypeScript · Shared TypeScript base configurations for apps and packages.
tooling/typescript/base.json - Tailwind · Shared Tailwind configuration and theme assets.
tooling/tailwind/theme.css - Scripts · Workspace utility scripts such as user creation helpers.
tooling/scripts/src/create-user.ts
Connections 30
- 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.