Skip to content

Overview

CMS stands for Content Management System

The CMS (Content for short) is a flagship extension provided by the Vyuh Framework. It allows you to integrate with any headless-CMS and have it control the App Experience. By default we provide support for Sanity.io 🔗, a popular headless-CMS that works well for the kind of scenarios that we expect in App Development.

The Vyuh Framework supports extensions that allow you to extend the capabilities of the framework in new directions. The Content extension is supported by two types of classes: ContentExtensionDescriptor and ContentExtensionBuilder. These two work in conjunction to extract the content-extensions by various features and use that to render content in the final App.

CMS Setup

In order to work well with the headless CMS, we need two counterparties to work together. On the CMS side, we have to export the schemas that are used to configure the content types. This is done by using the FeatureDescriptor for the CMS that collects the schemas exported by individual features.

Most headless CMS-es are TypeScript based, including Sanity.io (our default supported CMS). The Sanity Studio supports creating custom plugins to simplify the setup of schemas. We do this with our plugin, aptly named the vyuh plugin, which takes in a list of features and builds the master schema for Sanity. Here is the typical sanity.config.ts file for a Vyuh project:

sanity.config.ts
1
import { defineConfig } from 'sanity'
2
import { vyuh } from '@vyuh/sanity-plugin-structure'
3
import { system } from '@vyuh/sanity-schema-system'
4
import { firebaseAuth } from '@vyuh/sanity-schema-firebase-auth'
5
import { onboarding } from '@vyuh/sanity-schema-onboarding'
6
import { forms } from '@vyuh/sanity-schema-forms'
7
8
export default defineConfig([
9
{
10
name: 'default',
11
title: 'My Vyuh Studio',
12
basePath: '/',
13
14
projectId: '<project-id>',
15
dataset: 'production',
16
17
plugins: [
18
vyuh({
19
features: [
20
system,
21
firebaseAuth,
22
onboarding,
23
forms,
24
// ... other features ... //
25
],
26
}),
27
],
28
},
29
])

Notice the use of the vyuh() plugin in the highlighted line. We pass in the array of features, where each feature is an instance of the FeatureDescriptor. A feature-descriptor can export multiple types of content. You can see it in its definition:

class FeatureDescriptor {
name: string
title: string
description: string
contents: ContentDescriptor[]
contentSchemaBuilders: ContentSchemaBuilder[]
contentSchemaModifiers: ContentSchemaModifier[]
actions: SchemaTypeDefinition[]
conditions: SchemaTypeDefinition[]
// ... other properties and methods ... //
}

Flutter Setup

A similar setup exists on the Flutter side, where we bootstrap the counterpart-features of the content schemas. Here is the Dart code that will help in rendering the Vyuh App with the previously mentioned features from the CMS setup:

lib/main.dart
1
import 'package:vyuh_core/vyuh_core.dart' as vc;
2
import 'package:vyuh_extension_content/vyuh_extension_content.dart';
3
import 'package:vyuh_feature_system/vyuh_feature_system.dart' as system;
4
5
// ... various imports of the features, plugins and libraries ... //
6
7
void main() async {
8
final plugins = await _getPlugins();
9
10
vc.runApp(
11
initialLocation: '/chakra',
12
features: () => [
13
system.feature,
14
developer.feature,
15
onboarding.feature,
16
firebase_auth.feature(),
17
forms.feature,
18
],
19
plugins: plugins,
20
);
21
}
22
23
_getPlugins() async {
24
WidgetsFlutterBinding.ensureInitialized();
25
26
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
27
28
final contentProvider = SanityContentProvider.withConfig(
29
config: SanityConfig(
30
projectId: '<your-project-id>',
31
dataset: 'production',
32
perspective: Perspective.previewDrafts,
33
useCdn: false,
34
token: '<your-token>',
35
),
36
cacheDuration: const Duration(seconds: 5),
37
);
38
39
return PluginDescriptor(
40
content: DefaultContentPlugin(
41
provider: contentProvider,
42
// provider: localContentProvider,
43
),
44
analytics: vc.AnalyticsPlugin(providers: [
45
FirebaseAnalyticsProvider(),
46
SentryAnalyticsProvider(
47
config: SentryProviderConfig(
48
sampleRate: 0.2,
49
dsn: '<your-sentry-dsn>',
50
)),
51
]),
52
auth: FirebaseAuthPlugin(),
53
others: [
54
vc.ConsoleLoggerPlugin(),
55
FirebaseFeatureFlagPlugin(
56
settings: RemoteConfigSettings(
57
fetchTimeout: const Duration(seconds: 10),
58
minimumFetchInterval: const Duration(seconds: 10),
59
),
60
),
61
],
62
);
63
}

The main entry point is on the highlighted line, where we call runApp() from the vyuh_core library. As expected, it takes in an array of features and plugins and bootstraps the Vyuh App to life.

Continue exploring the various aspects of Vyuh for a flexible system of building, evolving a Flutter App, configured from a CMS.