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: ["@codisolutions/codi-layer"], // published npm package
  // or: extends: ['../codi-layer']          // local path when iterating
});

What It Provides

Composables (auto-imported)

ComposableDescription
useAddress()Address lookup and management helpers
useAttachments()File attachment upload and management
useAuth()Login, logout, getCurrentUser, token + currentUser state
useBooking()All booking API calls + dialog/form state factories
useBookingOwner()Owner-side booking management and status transitions
useBusinessHours()Business hours configuration API calls
useContact()Contact form submission helpers
useDefaultRoute()Resolves the default redirect route after login per app
useFaq()FAQ CRUD API calls
useFormHandler()Validation rules + handleApiAction wrapper
useMayaPayment()Maya payment gateway checkout and status polling
useNotificationDrawer()Notification drawer open/close state + unread count
useOrganization()Organization API calls
usePackage()Service/package API calls
usePage()Pagination state (page, pages, items, search)
usePayment()Payment API calls
useRealtime()Real-time event subscription helpers (wraps Socket.IO)
useSocket()Reactive Socket.IO connection state
useSubscription()Subscription plan management + Maya checkout integration
useSubscriptionBillingSettings()Billing settings fetch and update
useTenant()Subdomain slug extraction into global state
useUsers()User listing, invitation, and role management
useUtils()alertRef and misc helpers

Plugins (auto-loaded)

PluginEffect
api.tsProvides $api — typed $fetch with auth + tenant + branch headers and 401 redirect
auth.client.tsBootstraps currentUser from ${cookiePrefix}accessToken cookie on app load
socket.client.tsProvides $socket with room join/leave helpers
phosphor-icons.tsRegisters 16 Phosphor icon components globally
aos.client.tsInitializes AOS (Animate on Scroll) with standard settings
google-identity.client.tsEnsures Google Identity Services script is loaded on the client

Types (auto-imported)

All types live in codi-layer/app/types/ as .d.ts declaration files. There is no barrel export (index.ts) — Nuxt's auto-import picks them all up automatically in every consuming app.

FileKey types
address.d.tsTAddress, TAddressForm
auth.d.tsTRegister, TRegisterOwner, TLogin
booking.d.tsTBooking, TBookingGuest, TBookingId, TReasonEvent
branch.d.tsTBranch, TBranchForm
branch-management.d.tsTBranchInvitation, TBranchMember
business-hours.d.tsTBusinessHours, TBusinessHoursDay
contact.d.tsTContact, TContactForm
invitation.d.tsTInvitation, TInvitationStatus
local.d.tsTStandardResponse, TMenuItem, TApiActionOptions
notification.d.tsTNotification, TNotificationPayload
package.d.tsTPackage, TPackageForm
payment.d.tsTPayment, TPaymentStatus
socket.d.tsTSocketRoom, TSocketPayload
subscription.d.tsTSubscription, TSubscriptionPlan
subscription-billing.d.tsTBillingSettings, TBillingCycle
user.d.tsTUser, TCustomer
// All available without import in any consuming app:
const user = ref<TUser | null>(null);
const booking = ref<TBooking | null>(null);
const options: TApiActionOptions = { successMessage: "Done!" };

runtimeConfig Shape

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

runtimeConfig: {
  public: {
    cookiePrefix: '',     // per-app: 'customer_', 'owner_', 'admin_', 'cms_'
    cookieConfig: {
      domain:  undefined,          // production: '.booki.com'; dev: undefined
      secure:  false,              // true in production
      maxAge:  30 * 24 * 60 * 60, // 30 days
    },
    googleClientId: '',            // NUXT_PUBLIC_GOOGLE_CLIENT_ID
    apiUrl:    'http://localhost:4001',
    socketUrl: 'http://localhost:4001',
    basePlanPrice: '399',
    APP_CMS_BOOKI_WEB_APP:      'http://localhost:3000',
    APP_OWNER_BOOKI_WEB_APP:    'http://localhost:3001',
    APP_CUSTOMER_BOOKI_WEB_APP: 'http://localhost:3002',
  }
}

cookiePrefix is the key field: it scopes cookie names per app so sessions don't collide when running multiple apps on the same localhost (e.g. customer_accessToken vs owner_accessToken). Each consuming app sets this via NUXT_PUBLIC_COOKIE_PREFIX in its .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.