Open platform to collect and prioritize feedback
Commercial features - phase 1
Matt Roberts57c1d6567008
diff --git a/COMMERCIAL_MODERATION_PLAN.md b/COMMERCIAL_MODERATION_PLAN.mdnew file mode 100644index 000000000..f00566085--- /dev/null+++ b/COMMERCIAL_MODERATION_PLAN.md@@ -0,0 +1,213 @@+# Commercial Content Moderation Restructure Plan++## Overview++Moving Fider's content moderation feature from open source (AGPL) to commercial licensing using an "open core" model. The commercial code will reside in a `commercial/` folder with a restrictive license, while the open source core provides infrastructure and gracefully degrades when commercial features aren't licensed.++## Key Architectural Decisions++### 1. Webpack Integration (Simple Solution)+- Update `webpack.config.js` to scan both folders:+ ```js+ paths: [+ ...glob.sync(`./public/**/*.{html,tsx}`, { nodir: true }),+ ...glob.sync(`./commercial/**/*.{html,tsx}`, { nodir: true })+ ]+ ```+- Commercial code gets bundled but legal license prevents usage+- No complex conditional compilation needed++### 2. Backend Package Separation Strategy++**Handlers - Dynamic Route Registration**+- Open source: Register stub routes returning "upgrade" messages+- Commercial: Override routes with real handlers via dynamic registration+- License validation controls active routes++**Services - Stub + Override Pattern**+- Open source: Register stub bus handlers returning "not licensed" errors+- Commercial: Override with real implementations via bus registration+- Same command/query types, different implementations++## What Moves to Commercial (Strong Legal Protection)++### Commercial Folder Structure+```+commercial/+├── LICENSE (restrictive commercial license)+├── pages/+│ └── Administration/+│ └── ContentModeration.page.tsx (~300 lines)+├── components/+│ └── ModerationIndicator.tsx+├── handlers/+│ ├── moderation.go (ModerationPage, GetModerationItems, GetModerationCount)+│ └── apiv1/+│ ├── moderation.go (all API endpoints)+│ └── moderation_test.go+├── services/+│ └── moderation.go (approve/decline business logic)+└── init.go (service/route registration)+```++### Frontend (Moves to Commercial)+- Complete moderation admin UI (ContentModeration.page.tsx + styles)+- Moderation indicator component showing pending counts+- All moderation-specific UI components++### Backend (Moves to Commercial)+- All HTTP handlers (`ModerationPage`, `GetModerationItems`, `GetModerationCount`)+- All API endpoints (`/api/v1/admin/moderation/*` routes)+- Business logic implementations (approve/decline/verify/block functions)+- Route registrations for moderation endpoints+- Tests for commercial functionality++## What Stays Open Source (Minimal Infrastructure)++### Database/Models (Cannot Move - Bus System Dependency)+- `app/models/cmd/moderation.go` - Command type definitions+- `app/models/query/moderation.go` - Query type definitions+- Database schema, migrations (`is_moderation_enabled`, `is_approved` columns)+- Entity definitions (`ModerationItem` structs)++### Settings Infrastructure+- Privacy settings toggle (shows "upgrade" message if unlicensed)+- Basic tenant property (`isModerationEnabled`)+- License validation service++### Content Flow Logic+- Logic that marks content as needing approval+- Basic "content requires moderation" checks throughout codebase+- Content queuing when moderation is enabled++### Locale Files+- All `moderation.*` translation strings (used by upgrade messages too)++## Technical Implementation Details++### 1. Handler Registration Pattern+```go+// Open source routes.go - stub routes+ui.Get("/admin/moderation", upgradeHandler("content-moderation"))+ui.Get("/_api/admin/moderation/items", upgradeHandler("content-moderation"))++// Commercial init.go - overrides routes+func init() {+ if license.IsCommercialFeatureEnabled("content-moderation") {+ web.RegisterRoute("GET", "/admin/moderation", handlers.ModerationPage())+ web.RegisterRoute("GET", "/_api/admin/moderation/items", handlers.GetModerationItems())+ // ... all other moderation routes+ }+}+```++### 2. Service Registration Pattern+```go+// Open source postgres.go - register stubs+func (s *Service) Init() {+ bus.AddHandler(approvePostStub) // Returns "feature not licensed"+ bus.AddHandler(declinePostStub)+ bus.AddHandler(getModerationItemsStub)+ // ... other stubs+}++// Commercial service init - override with real handlers+func (cs *CommercialService) Init() {+ if license.IsCommercialFeatureEnabled("content-moderation") {+ bus.AddHandler(approvePost) // Real implementation+ bus.AddHandler(declinePost)+ bus.AddHandler(getModerationItems)+ // ... other real handlers+ }+}+```++### 3. License Validation Service+```go+// app/services/license.go+type LicenseService interface {+ IsCommercialFeatureEnabled(feature string) bool+}++// Implementation checks for valid commercial license+// Controls route registration and service overrides+```++## Implementation Phases++### Phase 1: Setup Commercial Infrastructure+1. Create `commercial/` folder structure+2. Add restrictive LICENSE file to commercial folder+3. Update webpack.config.js to scan commercial folder+4. Create license validation service interface++### Phase 2: Move Frontend Components+1. Move `ContentModeration.page.tsx` to `commercial/pages/Administration/`+2. Move `ModerationIndicator.tsx` to `commercial/components/`+3. Test that webpack builds both locations correctly+4. Add license checks in components to show upgrade messages++### Phase 3: Implement Backend Service Separation+1. Create stub implementations for all moderation commands/queries+2. Register stubs in open source postgres service+3. Move real implementations to `commercial/services/moderation.go`+4. Implement commercial service registration with license checks++### Phase 4: Implement Route Separation+1. Replace direct handler calls with upgrade handlers in routes.go+2. Move real handlers to `commercial/handlers/`+3. Implement dynamic route registration in commercial init+4. Test route overriding works correctly++### Phase 5: Testing & Validation+1. Move tests to commercial folder+2. Test open source build without commercial features+3. Test commercial build with license validation+4. Verify graceful degradation and upgrade messaging+5. Test that forking open source works without commercial parts++## Key Benefits++### Strong Commercial Protection+- Recreating moderation requires rebuilding entire UI + API + business logic+- Substantial engineering effort (days/weeks) to replicate functionality+- Clear legal separation under different licenses++### Clean Architecture+- Open source provides database infrastructure and settings+- Commercial enhances with actual moderation functionality+- No broken states - content flows normally when moderation disabled+- True open core model: commercial builds on open source foundation++### Simple Build Process+- Single repository with clear folder separation+- Standard webpack build process+- License provides protection, not technical hiding+- Easy development workflow++## Migration Considerations++### Existing Moderation Data+- All existing moderation settings and data remain compatible+- Database schema stays in open source (infrastructure)+- Only the management interface becomes commercial++### User Experience+- **With License**: Full moderation functionality as before+- **Without License**: Moderation simply disabled, standard user flow+- **Upgrade Path**: Clear messaging and sales funnel for commercial features++### Development Workflow+- Developers can see all code (legal license controls usage)+- Standard build process works for both open source and commercial+- Clean separation makes it easy to add more commercial features++## Success Metrics++1. **Legal Protection**: Someone forking open source cannot easily recreate moderation+2. **Functional Separation**: Open source works perfectly without moderation+3. **Build Compatibility**: Both open source and commercial versions build successfully+4. **Clean Boundaries**: Clear understanding of what's core vs commercial+5. **Scalability**: Pattern works for future commercial features++This plan provides genuine open core protection while maintaining clean architecture and manageable implementation complexity.\ No newline at end of filediff --git a/app/services/license.go b/app/services/license.gonew file mode 100644index 000000000..3e49f8f3f--- /dev/null+++ b/app/services/license.go@@ -0,0 +1,46 @@+package services++// LicenseService provides license validation for commercial features+type LicenseService interface {+ // IsCommercialFeatureEnabled checks if a specific commercial feature is licensed+ IsCommercialFeatureEnabled(feature string) bool++ // GetLicenseInfo returns information about the current license+ GetLicenseInfo() *LicenseInfo+}++// LicenseInfo contains information about the current license+type LicenseInfo struct {+ IsValid bool `json:"isValid"`+ Features []string `json:"features"`+ ExpiresAt *string `json:"expiresAt,omitempty"`+ LicenseHolder string `json:"licenseHolder"`+}++// Commercial feature constants+const (+ FeatureContentModeration = "content-moderation"+)++// Default implementation that denies all commercial features+type defaultLicenseService struct{}++func (s *defaultLicenseService) IsCommercialFeatureEnabled(feature string) bool {+ return false+}++func (s *defaultLicenseService) GetLicenseInfo() *LicenseInfo {+ return &LicenseInfo{+ IsValid: false,+ Features: []string{},+ LicenseHolder: "Open Source",+ }+}++// Global license service instance - can be overridden by commercial code+var License LicenseService = &defaultLicenseService{}++// Helper function for easy access+func IsCommercialFeatureEnabled(feature string) bool {+ return License.IsCommercialFeatureEnabled(feature)+}\ No newline at end of filediff --git a/commercial/LICENSE b/commercial/LICENSEnew file mode 100644index 000000000..4c4d6f386--- /dev/null+++ b/commercial/LICENSE@@ -0,0 +1,27 @@+Fider Commercial License++Copyright (c) 2025 Fider++This software and associated documentation files (the "Software") contained within this+"commercial" directory are proprietary and confidential to Fider.++RESTRICTIONS:+- You may NOT use, copy, modify, merge, publish, distribute, sublicense, or sell copies+ of this Software without a valid commercial license from Fider.+- You may NOT create derivative works based on this Software.+- You may NOT reverse engineer, decompile, or disassemble this Software.++PERMITTED USES:+- You may view this Software's source code for evaluation purposes only.+- Licensed users with valid commercial agreements may use this Software in accordance+ with their license terms.++NO WARRANTY:+This Software is provided "as is", without warranty of any kind, express or implied,+including but not limited to the warranties of merchantability, fitness for a particular+purpose and noninfringement.++For commercial licensing inquiries, please contact: [LICENSE_EMAIL_TO_BE_SET]++All other code in this repository (outside this "commercial" directory) remains under+the AGPL-3.0 license as specified in the root LICENSE file.\ No newline at end of filediff --git a/commercial/init.go b/commercial/init.gonew file mode 100644index 000000000..eae560743--- /dev/null+++ b/commercial/init.go@@ -0,0 +1,38 @@+package commercial++import (+ "github.com/getfider/fider/app/services"+)++// This file will contain commercial license validation and service registration+// It will be populated in later phases++func init() {+ // TODO: Phase 4 - Register commercial license service+ // TODO: Phase 4 - Register commercial route overrides+ // TODO: Phase 3 - Register commercial service handlers++ // Example (will be implemented later):+ // if isValidCommercialLicense() {+ // services.License = &commercialLicenseService{}+ // registerCommercialRoutes()+ // registerCommercialServices()+ // }+}++// Placeholder for commercial license service (to be implemented)+type commercialLicenseService struct{}++func (s *commercialLicenseService) IsCommercialFeatureEnabled(feature string) bool {+ // TODO: Implement actual license validation+ // For now, return true to enable commercial features during development+ return feature == services.FeatureContentModeration+}++func (s *commercialLicenseService) GetLicenseInfo() *services.LicenseInfo {+ return &services.LicenseInfo{+ IsValid: true,+ Features: []string{services.FeatureContentModeration},+ LicenseHolder: "Commercial License Holder",+ }+}\ No newline at end of filediff --git a/webpack.config.js b/webpack.config.jsindex 42d6a4fe4..e8b0750e0 100755--- a/webpack.config.js+++ b/webpack.config.js@@ -8,6 +8,7 @@ const PurgecssPlugin = require("purgecss-webpack-plugin")const MiniCssExtractPlugin = require("mini-css-extract-plugin")const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPluginconst publicFolder = path.resolve(__dirname, "public")+const commercialFolder = path.resolve(__dirname, "commercial")const localeFolder = path.resolve(__dirname, "locale")const isProduction = process.env.NODE_ENV === "production"@@ -36,7 +37,10 @@ const plugins = [if (isProduction) {plugins.push(new PurgecssPlugin({- paths: glob.sync(`./public/**/*.{html,tsx}`, { nodir: true }),+ paths: [+ ...glob.sync(`./public/**/*.{html,tsx}`, { nodir: true }),+ ...glob.sync(`./commercial/**/*.{html,tsx}`, { nodir: true })+ ],defaultExtractor: (content) => content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || [],safelist: [/--/, /__/, /data-/, /tiptap/],})@@ -62,6 +66,7 @@ module.exports = {extensions: [".mjs", ".ts", ".tsx", ".js", ".svg"],alias: {"@fider": publicFolder,+ "@commercial": commercialFolder,"@locale": localeFolder,},},@@ -78,7 +83,7 @@ module.exports = {},{test: /\.(ts|tsx)$/,- include: [publicFolder, localeFolder],+ include: [publicFolder, commercialFolder, localeFolder],loader: "babel-loader",},{@@ -89,7 +94,7 @@ module.exports = {},{test: /\.svg$/,- include: publicFolder,+ include: [publicFolder, commercialFolder],use: ["svg-sprite-loader", "svgo-loader"],},],