Skip to content

Latest commit

Β 

History

History
343 lines (310 loc) Β· 18.6 KB

project-structure.md

File metadata and controls

343 lines (310 loc) Β· 18.6 KB

Project structure

The project is divided into the following folders:

  • apps - Cross-platform applications and user-facing products.
  • infra - Infrastructure as code for local development and cloud providers.
  • packages - Shared internal packages for use across apps.
  • scripts - Scripts for random tasks, such as syncing the project with the template and graphing dependencies.
  • tooling - Shared development configuration and script helpers. If a configuration is used across workspaces and not related to a specific package, it should go here.

General monorepo structure

root
  β”œβ”€β”€ apps                # Cross-platform applications
  β”‚   β”œβ”€β”€ app               # Next.js web application
  β”‚   β”œβ”€β”€ api               # Hono API with RPC client, deployed on Cloudflare Workers
  β”‚   β”œβ”€β”€ desktop           # Tauri desktop application
  β”‚   β”œβ”€β”€ docs              # Documentation site
  β”‚   β”œβ”€β”€ extensions        # WXT browser extension
  β”‚   β”œβ”€β”€ mobile            # Expo mobile application
  β”‚   └── web               # Next.js marketing site with content collections for blog and other static pages
  β”‚
  β”œβ”€β”€ infra               # Infrastructure as code for cloud providers
  β”‚   └── local             # Docker Compose configuration for local development
  β”‚
  β”œβ”€β”€ packages            # Shared internal packages for use across apps
  β”‚   β”œβ”€β”€ ai                # AI utilities
  β”‚   β”œβ”€β”€ analytics         # Web and product analytics
  β”‚   β”œβ”€β”€ auth              # Authentication utilities
  β”‚   β”œβ”€β”€ db                # Database client and ORM using Drizzle
  β”‚   β”œβ”€β”€ email             # Email templating and sending service using Resend
  β”‚   β”œβ”€β”€ env               # Environment variable management and validation
  β”‚   β”œβ”€β”€ kv                # Redis client and vector database integration using Upstash
  β”‚   β”œβ”€β”€ native-ui         # Reusable UI components for React Native apps
  β”‚   β”œβ”€β”€ observability     # Logging, error tracking, and monitoring using Sentry and Axiom
  β”‚   β”œβ”€β”€ payments          # Payment processing utilities using Stripe
  β”‚   β”œβ”€β”€ queue             # Serverless job queue and workflow management using Upstash
  β”‚   β”œβ”€β”€ security          # Security utilities and best practices using Arcjet
  β”‚   β”œβ”€β”€ storage           # Shared storage utilities using UploadThing
  β”‚   β”œβ”€β”€ ui                # Reusable UI components and design system using Shadcn/UI
  β”‚   └── utils             # Shared helpers and constants for packages and apps
  β”‚
  β”œβ”€β”€ scripts             # Scripts for random tasks
  β”‚
  β”œβ”€β”€ tooling             # Shared development and build tools
  β”‚   β”œβ”€β”€ tsconfig          # TypeScript configuration
  β”‚   └── helpers           # Common utility functions for tooling and scripts
  β”‚
  └── turbo               # Turborepo configuration for monorepo management
      └── generators        # Code generators for packages and tooling

App structure

Each app has a src folder that contains the source code for the app.

Apps are usually organized in three folders:

  • The main router (e.g., app for Next.js and Expo, routes for Vite projects).
    • Some projects, like the browser extension, have an extra folder that can be considered part of the routing logic.
  • A shared folder for shared utilities and components.
  • A features folder for feature-based modules.

We follow a unidirectional import flow between these three folders. The code only flows downwards to the routing folder, never going upwards. What this means is that the features folder can import from the shared folder, but the shared folder cannot import from the features folder. The app/routing folder can import from either the features or the shared folder, but never the other way around. This makes the code more organized and easier to understand.

Feature folders are also vertical slices of the app and do not have any dependencies between them. This keeps the code organized and easier to understand. If you find yourself needing to import something from a different feature, you should first consider if it can be moved to the shared folder.

App

This is a web application using Next.js.

apps/app
  β”œβ”€β”€ src/                    # Source code
  β”‚   β”œβ”€β”€ app/                  # App router for Next.js
  β”‚   β”‚   β”œβ”€β”€ (unauthenticated)/ # Unauthenticated routes (sign in, sign up, etc.)
  β”‚   β”‚   β”œβ”€β”€ (authenticated)/   # Authenticated routes (dashboard, settings, etc.)
  β”‚   β”‚   └── api/               # API routes
  β”‚   β”‚
  β”‚   β”œβ”€β”€ shared/               # Shared utilities and helpers
  β”‚   β”‚   β”œβ”€β”€ assets/               # Static assets shared across the app (images, icons, etc.)
  β”‚   β”‚   β”œβ”€β”€ auth/               # Authentication client and helpers
  β”‚   β”‚   β”œβ”€β”€ components/         # Reusable components
  β”‚   β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
  β”‚   β”‚   β”œβ”€β”€ i18n/               # Internationalization setup
  β”‚   β”‚   β”œβ”€β”€ middlewares/        # Global middleware to be imported into middleware.ts
  β”‚   β”‚   β”œβ”€β”€ server/             # Server-side code
  β”‚   β”‚   β”‚   β”œβ”€β”€ data/               # Data access layer (e.g., database queries)
  β”‚   β”‚   β”‚   β”œβ”€β”€ loaders.ts          # Shared data fetching functions for server components
  β”‚   β”‚   β”‚   └── actions.ts          # Shared server actions for handling form submissions and mutations
  β”‚   β”‚   β”œβ”€β”€ stores/             # Global state management stores
  β”‚   β”‚   β”œβ”€β”€ env.ts              # Environment variable configuration
  β”‚   β”‚   β”œβ”€β”€ constants.ts        # Constant values and enums
  β”‚   β”‚   β”œβ”€β”€ safe-action.ts      # Type-safe server actions client and middleware
  β”‚   β”‚   β”œβ”€β”€ types.ts            # TypeScript type definitions
  β”‚   β”‚   β”œβ”€β”€ utils.ts            # General utility functions
  β”‚   β”‚   └── validation.ts       # Form and data validation schemas
  β”‚   β”‚
  β”‚   β”œβ”€β”€ features/             # Feature-based modules
  β”‚   β”‚   └──[feature]/           # Specific feature (e.g., auth, dashboard, settings)
  β”‚   β”‚       β”œβ”€β”€ assets/           # Feature-specific assets
  β”‚   β”‚       β”œβ”€β”€ components/       # Feature-specific components
  β”‚   β”‚       β”œβ”€β”€ actions.ts        # Feature-specific server actions
  β”‚   β”‚       β”œβ”€β”€ hooks.ts          # Feature-specific custom hooks
  β”‚   β”‚       β”œβ”€β”€ loaders.ts        # Feature-specific data loaders
  β”‚   β”‚       β”œβ”€β”€ stores.ts         # Feature-specific state stores
  β”‚   β”‚       β”œβ”€β”€ types.ts          # Feature-specific type definitions
  β”‚   β”‚       β”œβ”€β”€ utils.ts          # Feature-specific utility functions
  β”‚   β”‚       └── validation.ts     # Feature-specific validation schemas
  β”‚   β”‚
  β”‚   β”œβ”€β”€ middleware.ts         # Next.js middleware for request/response modification
  β”‚   └── instrumentation.ts    # Monitoring and analytics instrumentation
  β”‚
  β”œβ”€β”€ translations              # Internationalization translation files
  └── global.d.ts               # Global TypeScript declarations

Mobile

apps/mobile
  β”œβ”€β”€ src/                    # Source code
  β”‚   β”œβ”€β”€ app/                  # App router
  β”‚   β”‚
  β”‚   β”œβ”€β”€ shared/               # Shared utilities and helpers
  β”‚   β”‚   β”œβ”€β”€ assets/            # Static assets shared across the app
  β”‚   β”‚   β”‚   └── styles/          # Global styles
  β”‚   β”‚   β”œβ”€β”€ components/        # Shared components used across the entire app
  β”‚   β”‚   β”œβ”€β”€ auth/             # Authentication client and helpers
  β”‚   β”‚   β”œβ”€β”€ hooks/            # Custom React hooks
  β”‚   β”‚   β”œβ”€β”€ i18n/             # Internationalization setup
  β”‚   β”‚   β”œβ”€β”€ stores/           # Global state stores
  β”‚   β”‚   β”œβ”€β”€ api.ts            # Global API and query client
  β”‚   β”‚   β”œβ”€β”€ constants.ts      # Constant values and enums
  β”‚   β”‚   β”œβ”€β”€ env.ts            # Environment variables
  β”‚   β”‚   β”œβ”€β”€ types.ts          # Shared types
  β”‚   β”‚   β”œβ”€β”€ utils.ts          # Shared utilities for the app
  β”‚   β”‚   └── validation.ts     # Shared validation schemas
  β”‚   β”‚
  β”‚   └── features/             # Feature based modules
  β”‚       └──[feature]/           # Specific feature (e.g. auth, dashboard, settings)
  β”‚           β”œβ”€β”€ assets/          # Feature-specific assets
  β”‚           β”œβ”€β”€ components/      # Feature-specific components
  β”‚           β”œβ”€β”€ hooks.ts         # Feature-specific hooks
  β”‚           β”œβ”€β”€ mutations.ts     # Feature-specific mutations
  β”‚           β”œβ”€β”€ queries.ts       # Feature-specific queries
  β”‚           β”œβ”€β”€ stores.ts        # Feature-specific global state stores
  β”‚           β”œβ”€β”€ types.ts         # Feature-specific types
  β”‚           β”œβ”€β”€ utils.ts         # Feature-specific utilities
  β”‚           └── validation.ts    # Feature-specific validation schemas
  β”‚
  └── translations            # Translations files

API

apps/api
  └── src/                    # Source code
      β”œβ”€β”€ index.ts              # Entry point to the worker
      β”œβ”€β”€ client.ts             # RPC client type to be used in other apps
      β”œβ”€β”€ routes/               # Routing
      β”‚   β”œβ”€β”€ index.tsx           # Router entrypoint
      β”‚   └── ...                 # Other routes
      β”‚
      β”œβ”€β”€ shared/               # Shared utilities and helpers
      β”‚   β”œβ”€β”€ middlewares/        # Global middleware
      β”‚   β”œβ”€β”€ constants.ts        # Constant values and enums
      β”‚   β”œβ”€β”€ env.ts              # Environment variables
      β”‚   β”œβ”€β”€ types.ts            # Shared types
      β”‚   └── utils.ts            # General utility functions
      β”‚
      └── features/             # Feature based modules
          └──[feature]/           # Specific feature (e.g. auth, dashboard, settings)
              β”œβ”€β”€ router.ts         # Feature-specific router
              β”œβ”€β”€ procedures.ts     # Feature-specific procedures
              β”œβ”€β”€ types.ts          # Feature-specific types
              β”œβ”€β”€ utils.ts          # Feature-specific utilities
              └── validation.ts     # Feature-specific validation schemas

Desktop

apps/desktop
  β”œβ”€β”€ src/                    # Source code
  β”‚   β”œβ”€β”€ main.tsx              # Entry point to the desktop app
  β”‚   β”œβ”€β”€ routes/               # Routing
  β”‚   β”‚
  β”‚   β”œβ”€β”€ shared/               # Shared utilities and helpers
  β”‚   β”‚   β”œβ”€β”€ assets/            # Static assets shared across the app
  β”‚   β”‚   β”‚   └── styles/          # Global styles
  β”‚   β”‚   β”œβ”€β”€ components/        # Shared components used across the entire app
  β”‚   β”‚   β”œβ”€β”€ auth/             # Authentication client and helpers
  β”‚   β”‚   β”œβ”€β”€ hooks/            # Custom React hooks
  β”‚   β”‚   β”œβ”€β”€ i18n/             # Internationalization setup
  β”‚   β”‚   β”œβ”€β”€ stores/           # Global state stores
  β”‚   β”‚   β”œβ”€β”€ api.ts            # Global API and query client
  β”‚   β”‚   β”œβ”€β”€ constants.ts      # Constant values and enums
  β”‚   β”‚   β”œβ”€β”€ env.ts            # Environment variables
  β”‚   β”‚   β”œβ”€β”€ types.ts          # Shared types
  β”‚   β”‚   β”œβ”€β”€ utils.ts          # Shared utilities for the app
  β”‚   β”‚   └── validation.ts     # Shared validation schemas
  β”‚   β”‚
  β”‚   └── features/             # Feature based modules
  β”‚       └──[feature]/           # Specific feature (e.g. auth, dashboard, settings)
  β”‚           β”œβ”€β”€ assets/          # Feature-specific assets
  β”‚           β”œβ”€β”€ components/      # Feature-specific components
  β”‚           β”œβ”€β”€ hooks.ts         # Feature-specific hooks
  β”‚           β”œβ”€β”€ mutations.ts     # Feature-specific mutations
  β”‚           β”œβ”€β”€ queries.ts       # Feature-specific queries
  β”‚           β”œβ”€β”€ stores.ts        # Feature-specific global state stores
  β”‚           β”œβ”€β”€ types.ts         # Feature-specific types
  β”‚           β”œβ”€β”€ utils.ts         # Feature-specific utilities
  β”‚           └── validation.ts    # Feature-specific validation schemas
  β”‚
  β”œβ”€β”€ translations            # Translations files
  └── content                 # Blog and other static content

Extensions

apps/extensions
  β”œβ”€β”€ src/                    # Source code
  β”‚   β”œβ”€β”€ entrypoints/          # Entrypoints
  β”‚   β”‚   β”œβ”€β”€ popup/              # Popup entrypoint
  β”‚   β”‚   β”œβ”€β”€ background/         # Background script entrypoint
  β”‚   β”‚   └── ...                 # Other entrypoints
  β”‚   β”‚
  β”‚   β”œβ”€β”€ shared/               # Shared utilities and helpers
  β”‚   β”‚   β”œβ”€β”€ assets/            # Assets processed by WXT
  β”‚   β”‚   β”‚   └── styles/          # Global styles
  β”‚   β”‚   β”œβ”€β”€ components/        # Shared components used across the entire extension
  β”‚   β”‚   β”œβ”€β”€ services/          # Shared services
  β”‚   β”‚   β”œβ”€β”€ stores/            # Global state stores
  β”‚   β”‚   β”œβ”€β”€ api.ts            # Global API and query client
  β”‚   β”‚   β”œβ”€β”€ auth.ts           # Authentication client and helpers
  β”‚   β”‚   β”œβ”€β”€ constants.ts      # Constant values and enums
  β”‚   β”‚   β”œβ”€β”€ env.ts            # Environment variables
  β”‚   β”‚   β”œβ”€β”€ hooks.ts          # Shared hooks
  β”‚   β”‚   β”œβ”€β”€ i18n.ts           # Internationalization
  β”‚   β”‚   β”œβ”€β”€ types.ts          # Shared types
  β”‚   β”‚   β”œβ”€β”€ utils.ts          # Shared utilities for the app
  β”‚   β”‚   └── validation.ts     # Shared validation schemas
  β”‚   β”‚
  β”‚   β”œβ”€β”€ features/             # Feature based modules
  β”‚   β”‚   └──[feature]/           # Specific feature (e.g. auth, dashboard, settings)
  β”‚   β”‚       β”œβ”€β”€ assets/          # Feature-specific assets
  β”‚   β”‚       β”œβ”€β”€ components/      # Feature-specific components
  β”‚   β”‚       β”œβ”€β”€ hooks.ts         # Feature-specific hooks
  β”‚   β”‚       β”œβ”€β”€ mutations.ts     # Feature-specific mutations
  β”‚   β”‚       β”œβ”€β”€ queries.ts       # Feature-specific queries
  β”‚   β”‚       β”œβ”€β”€ services.ts      # Feature-specific services
  β”‚   β”‚       β”œβ”€β”€ stores.ts        # Feature-specific global state stores
  β”‚   β”‚       β”œβ”€β”€ types.ts         # Feature-specific types
  β”‚   β”‚       β”œβ”€β”€ utils.ts         # Feature-specific utilities
  β”‚   β”‚       └── validation.ts    # Feature-specific validation schemas
  β”‚   β”‚
  β”‚   β”œβ”€β”€ routes/               # Routing shared by all entrypoints
  β”‚   β”‚   β”œβ”€β”€ __root.tsx          # Root route
  β”‚   β”‚   └── ...                 # Other routes
  β”‚   β”‚
  β”‚   β”œβ”€β”€ static/               # Static assets not processed by WXT. Includes the extension icon.
  β”‚   β”‚
  β”‚   β”œβ”€β”€ router.ts             # Router instance
  β”‚   └── routeTree.gen.ts      # Auto-generated route tree
  β”‚
  └── wxt.config.ts           # WXT configuration

Docs

apps/docs
  β”œβ”€β”€ src/                    # Source code
  β”‚   β”œβ”€β”€ app/                  # App router for Next.js
  β”‚   β”‚
  β”‚   β”œβ”€β”€ shared/               # Shared utilities and helpers
  β”‚   β”‚   β”œβ”€β”€ assets/            # Static assets shared across the app
  β”‚   β”‚   β”œβ”€β”€ components/        # Shared components
  β”‚   β”‚   β”œβ”€β”€ constants.ts       # Constant values and enums
  β”‚   β”‚   β”œβ”€β”€ env.ts             # Environment variables
  β”‚   β”‚   β”œβ”€β”€ middlewares/       # Global middleware
  β”‚   β”‚   β”œβ”€β”€ source.ts          # Documentation source
  β”‚   β”‚   └── utils.ts           # Shared utilities for the app
  β”‚   β”‚
  β”‚   └── instrumentation.ts    # Monitoring and analytics instrumentation
  β”‚
  └── content/                # Documentation content in MDX format

Web

Similar to the app, but focusing on static content like marketing pages. This leads to have a simpler structure, as it doesn't need to support authentication or server actions.

It uses content collections to manage the blog and other static pages, and has i18n support through routing.

apps/web
  β”œβ”€β”€ src/                    # Source code
  β”‚   β”œβ”€β”€ app/                  # App router for Next.js
  β”‚   β”‚   └── [locale]/          # Localized routes
  β”‚   β”‚
  β”‚   β”œβ”€β”€ shared/               # Shared utilities and helpers
  β”‚   β”‚   β”œβ”€β”€ assets/               # Static assets shared across the app (images, icons, etc.)
  β”‚   β”‚   β”œβ”€β”€ components/         # Reusable components
  β”‚   β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
  β”‚   β”‚   β”œβ”€β”€ i18n/               # Internationalization setup
  β”‚   β”‚   β”œβ”€β”€ middlewares/        # Global middleware to be imported into middleware.ts
  β”‚   β”‚   β”œβ”€β”€ stores/             # Global state management stores
  β”‚   β”‚   β”œβ”€β”€ env.ts              # Environment variable configuration
  β”‚   β”‚   β”œβ”€β”€ constants.ts        # Constant values and enums
  β”‚   β”‚   β”œβ”€β”€ safe-action.ts      # Type-safe server actions client and middleware
  β”‚   β”‚   β”œβ”€β”€ types.ts            # TypeScript type definitions
  β”‚   β”‚   β”œβ”€β”€ utils.ts            # General utility functions
  β”‚   β”‚   └── validation.ts       # Form and data validation schemas
  β”‚   β”‚
  β”‚   β”œβ”€β”€ middleware.ts         # Next.js middleware for request/response modification
  β”‚   └── instrumentation.ts    # Monitoring and analytics instrumentation
  β”‚
  β”œβ”€β”€ translations              # Internationalization translation files
  └── global.d.ts               # Global TypeScript declarations

Package structure

Packages don't have an strict structure. A general guideline is that all runtime code should be in the src folder, while scripts should be in the scripts folder.

packages/package-name
  β”œβ”€β”€ src/                    # Source code
  └── scripts/                # Scripts

You can create a new package using the following command:

pnpm generate

And then selecting the internal-package option.