Add module management system for enabling/disabling features

Stores can enable/disable feature modules from Settings. When disabled,
nav links are hidden and API routes return 403. Designed as the
foundation for future license-based gating (licensed + enabled flags).

Core modules (Accounts, Members, Users, Roles, Settings) are always on.

- module_config table with slug, name, description, licensed, enabled
- In-memory cache for fast per-request module checks
- requireModule middleware wraps route groups in main.ts
- Settings page Modules card with toggle switches
- Sidebar hides nav links for disabled modules
- Default modules seeded: inventory, pos, repairs, rentals, lessons,
  files, vault, email, reports
This commit is contained in:
Ryan Moon
2026-03-30 06:52:27 -05:00
parent 1f9297f533
commit e346e072b8
10 changed files with 294 additions and 13 deletions

View File

@@ -0,0 +1,14 @@
import { pgTable, uuid, varchar, text, timestamp, boolean } from 'drizzle-orm/pg-core'
export const moduleConfig = pgTable('module_config', {
id: uuid('id').primaryKey().defaultRandom(),
slug: varchar('slug', { length: 50 }).notNull().unique(),
name: varchar('name', { length: 100 }).notNull(),
description: text('description'),
licensed: boolean('licensed').notNull().default(true),
enabled: boolean('enabled').notNull().default(false),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
})
export type ModuleConfig = typeof moduleConfig.$inferSelect