package ocsigen-start
Ocsigen Start
Ocsigen Start is a ready-to-use application skeleton for building client-server web and mobile applications with Eliom and Ocsigen Toolkit. It ships with user management, notifications, a database schema and many code examples, so you can focus on your own features from day one.
Use it to learn Ocsigen or to quickly create your own Minimum Viable Product. The application is cross-platform: it works as a Web app or as a mobile app for iOS or Android (via Cordova).
Ocsigen Start is part of the Ocsigen project.
Demo
If you want to test the demo application before installing Ocsigen Start, a live version is running here.
You can also download the mobile app on Google Play store (for Android) or download the APK for Android or the iOS version (to be installed using XCode).
Ocsigen Start is composed of two main parts:
- The generated code which gives a default behaviour to your application. Adapt it to your needs and remove the parts you don't need. Feel free to redistribute it as you wish.
It includes a demo of many features from Eliom, Js_of_ocaml, Tyxml, Ocsigen Toolkit. Use it to learn quickly the main principles of multi-tier programming.
- A library with user management (authentication, registration of new users with activation links sent by email, recovery of lost passwords, a page to update settings, etc.), tips for new users, notifications to send information to other users, and more.
Getting started
Read this page to learn how to build your first Ocsigen Start app in 5 minutes.
Implementation overview
Template
The library portion of Ocsigen Start contains core functionality that is common across Ocsigen Start applications, while the template can be customized for the specific application at hand.
The template additionally contains a demonstration of relevant Ocsigen Toolkit widgets. The demo portion can easily be removed.
Database
For implementing users, a database is needed. Specifically, we use PostgreSQL via the PGOCaml library. The template and the library make common assumptions about the database schema. The tables of Ocsigen Start are defined in the file ocsigen_start.sql of the template, and the tables of the application in PROJECT_NAME.sql. make db-update applies both: it creates the tables on a new database, and brings them up to date on an existing one. ocsigen_start.sql can be applied again and again, and PROJECT_NAME.sql must stay so (see its header). After an upgrade of Ocsigen Start, back up the database, replace ocsigen_start.sql with the one of the new template ($(opam var lib)/eliom/templates/os/ocsigen_start.sql), and run make db-update again.
The same database can be used for the specific needs of the application at hand. For that, add new tables to PROJECT_NAME.sql, keeping it replayable. The tables of Ocsigen Start should remain in place for it to work correctly.
Internationalization (i18n)
The template is available in multiple languages (English and French) using ocsigen-i18n. The translations used in the template are defined in the files assets/PROJECT_NAME_i18n.tsv and, for the demo, assets/PROJECT_NAME_Demo_i18n.tsv. Dune rules in lib/dune generate the Eliom modules PROJECT_NAME_i18n and PROJECT_NAME_Demo_i18n, and generate them again whenever a TSV file changes.
To add a language, add it to --languages in both rules, and add a column for it to each TSV file. --default-language sets the default language.
Managing e-mails
The template application keeps track of users' e-mails and implements e-mail validation. For that, sendmail (or another mail transfer agent compatible with it) needs to be installed on the host.
Style
The application provides a standard style matching contemporary aesthetics. For this, we use SASS. The style can be customized by modifying the SASS files that are part of the template.
Installation
Ocsigen Start can be installed via OPAM. The package name is ocsigen-start. The template application can be instantiated via eliom-distillery:
eliom-distillery -name $APP_NAME -template os(Replace $APP_NAME by the name of your application).
Then install the opam packages that the generated project depends on, from its directory:
opam install --deps-only .For details on creating the database and launching the application, refer to the template's README.
Migrating from version 8
Since version 9, the modules of Ocsigen Start are submodules of Os: write Os.Session, Os.User or Os.Email instead of Os_session, Os_user or Os_email. Ocsigen Start 9 also requires Eliom 13, Ocsigen Server 8 and Ocsigen Toolkit 5, which rename their modules the same way (Eliom.Content.Html instead of Eliom_content.Html, Ocsigen.Server instead of Ocsigen_server, Ot.Popup instead of Ot_popup).
To migrate progressively, install the ocsigen-start-compat package and add the libraries ocsigen-start-compat.server and ocsigen-start-compat.client to the server and client parts of your application, respectively. They define the old Os_xxx modules, each of which includes the new module, so that existing code keeps compiling while you rename the references. Other packages do the same for the rest of the stack: eliom-compat (libraries eliom-compat.server and eliom-compat.client), ocsigenserver-compat (library ocsigenserver-compat) and ocsigen-toolkit-compat (libraries ocsigen-toolkit-compat.server and ocsigen-toolkit-compat.client).
The tables of Ocsigen Start are now in ocsigen_start.sql, separate from those of the application (see the Database section above). To move an existing project to this layout:
- copy
ocsigen_start.sqlfrom the new template; - take the target
db-update, which replacesdb-schema, and the variableOS_PSQL_FILEfrom theMakefile.dbandMakefile.optionsof the new template; - remove the tables of Ocsigen Start from
PROJECT_NAME.sql, and make the rest replayable, as the header of the newPROJECT_NAME.sqlexplains; - back up the database, then run
make db-update.
The dune rules of the template are now generated by ocsigen-dune-rules (instead of tools/gen_dune.ml), with the code of the application in lib/ and its entry point in app/. Generating a new project with eliom-distillery and comparing it with yours is the simplest way to see what changed.
Library overview
We provide a tour of the Ocsigen Start library. Most modules have server- and client-side versions. (In the API documentation, there are links near the top of each module page for selecting the side.)
The template uses all these modules, and can thus act as a good starting guide. Look around!
User interface
Various modules for producing icons, messages, custom pages, tips, connection forms, etc.
Os.Icons: manage CSS icons.Os.Msg: display messages to the user, such as error messages.Os.Page: utilities for building HTML pages that follow the standard Ocsigen Start layout.Os.Tips: display tips to the user.Os.User_view: functions for creating password forms and other common UI elements appearing in applications and for managing the user connection box.Os.Uploader: ImageMagick-based tools for manipulating avatars.
Users and groups
Os.User,Os.Current_user,Os.Group: manage users and groups thereof.
Os.Connect_phone: register and connect users with their phone number, through codes sent by SMS.
Os.Db: directly access the database. In many cases, it is a better idea to use higher-level modules (e.g.,Os.User).
Communication
Os.Notif: send notifications to connected users.
Os.Email: send e-mails.
Os.Fcm_notif: send push notifications to mobile devices.
Os.Comet: manage the bi-directional communication channel between client and server. This is a low-level module that you probably don't need.
Services, handlers, sessions
Os.Services: Eliom services pre-defined by Ocsigen Start. These produce the default user interface of the template. See the Eliom manual page on services for a general introduction to Eliom services.
Os.Handlers: The handlers (functions) that implement the services inOs.Services. The Eliom manual page on service handlers explains how to implement handlers.
Os.Session: manage user sessions, e.g., execute actions when users connect or disconnect.
Other utilities
Os.Date: utilities for manipulating date and time values.
Os.Platform: obtain information about the platform we are on (Android, iOS, ...).
Os.Request_cache,Os.User_proxy: different forms of caching data.
The template also uses ocsigen-ppx-rpc, a ppx syntax extension to call server-side functions from the client (let%rpc).