Shared

codi-layer

The shared Nuxt layer — composables, plugins, and types used by all frontend apps.

codi-layer is a Nuxt layer consumed by all four frontend apps. It provides shared composables, plugins, types, and base components so they don't need to be duplicated.

How It's Used

Each consuming app extends the layer in its nuxt.config.ts:

// customer-booki-web-app/nuxt.config.ts
export default defineNuxtConfig({
  extends: ['../codi-layer'],   // local path during development
  // or: extends: ['@codi-team/codi-layer']  // when published
})

What It Provides

Composables (auto-imported)

ComposableDescription
useAuth()Login, logout, getCurrentUser, token + currentUser state
useTenant()Subdomain slug extraction into global state
useFormHandler()Validation rules + handleApiAction wrapper
useBooking()All booking API calls + dialog/form state factories
usePayment()Payment API calls
useOrganization()Organization API calls
useService()Service/package API calls
usePage()Pagination state (page, pages, items, search)
useSocket()Reactive Socket.IO connection state
useUtils()alertRef and misc helpers

Plugins (auto-loaded)

PluginEffect
api.tsProvides $api — typed $fetch with auth headers and 401 redirect
auth.client.tsBootstraps currentUser from token cookie on app load
socket.client.tsProvides $socket with room join helpers
phosphor-icons.tsRegisters all Phosphor icon components globally

Types (auto-imported)

All types from codi-layer/app/types/ are available in consuming apps without any import:

// These are all available without import in any consuming app:
const user = ref<TUser | null>(null)
const booking: IBooking = { ... }
const options: TApiActionOptions = { successMessage: 'Done!' }

runtimeConfig Shape

codi-layer/nuxt.config.ts defines the public runtime config shape that all apps share:

runtimeConfig: {
  public: {
    cookieConfig: {
      // Cookie options injected into useCookie calls
      maxAge:   60 * 60 * 24 * 7,   // 7 days
      secure:   true,
      sameSite: 'lax',
    },
    socketUrl:      '',   // overridden per app via env
    googleClientId: '',   // overridden per app via env
  }
}

Local Development Linking

When iterating on codi-layer while running a consuming app:

# 1. In codi-layer/ — build in watch mode
yarn dev

# 2. In the consuming app — use local path in extends
# nuxt.config.ts: extends: ['../codi-layer']

# 3. Run dev server
yarn dev

See codi-layer/DEPENDENCY_LINKING.md for details on symlink vs path-based approaches.

Adding to codi-layer

When adding a new shared composable or component to codi-layer:

  1. Add the file to the appropriate app/composables/ or app/components/ directory.
  2. Nuxt auto-imports handle the rest — no barrel exports needed.
  3. If it's a new plugin, it auto-loads in consuming apps.
  4. If it introduces new types, add them to app/types/ with a matching export in app/types/index.ts.
  5. Test it in one consuming app before marking as stable.