|Max Heichling 92a47b2b4a||1 month ago|
|.vscode||4 months ago|
|client||1 month ago|
|server||1 month ago|
|.gitignore||4 months ago|
|README.md||3 months ago|
|docker-compose.yaml||3 months ago|
Please read the following doc carefully to avoid any difficulties and misunderstandings.
This project is a template to build an offline first web application with authentication, that can be ported easily to other platforms (Android, iOS, Electron). It runs on the CAIN Stack which consists of following technologies:
Requirements: Installed Ionic Cli and NodeJS. Install the client dependencies by
cd client and running
npm i . Start the client framework by running
ionic serve .
The heart of the Cain Stack. The
initDatabase function gets initiated when the user logs in. It filters the names and remote addresses of the databases the user has access to and builds an object of PouchDB instances. Afterwards it starts the
initRemoteSync , which starts the synchronisation of the local with the remote databases. The data service includes many document, attachment and database functions, to be used in your own services (see
client/src/app/services ). Visit [pouchdb. com](https://pouchdb.com/api. html) for the full api list.
Querys the superlogin apis and handles the destruction of local databses when logging out. It also checks the locally saved user token and therefore enables offline reauthentication.
Handles all User Doc related functions, like saving the user data locally, editing profile details and getting profile images.
Handles all chat related functions. Mainly the creation of private Chats, the querying of all user chats and the chat messages of one particular conversation. To avoid any conflicts when creating a new private chat database, the
createPrivateChatId function builds a unique conversation Id based on the usernames of the participants. Therefore it is possible to create a chat even when the user is offline.
client/src/app/shared . Consists of components, helpers, modals and services. These can be used in your own pages. A quick overview of what is included:
input doc object arrayand is used by the pages Feed, User-Profile, Me and Notes)
Includes all pages regarding user authentication, registration and password resets.
Handles routing for the tab bar. Namingly the pages Feed, Me and Conversation List. Depending on the client device, it shows the tabbar on the bottom (mobile) or on the top (desktop).
Shows all documents of the shared database, by querying the shared-doc service (
Consists of two pages: Me and User-profile. Me shows the current user doc, User-Profile, the profile of any other user.
Consists of two pages: Chat and Conversations. Chat displays the messages of a single conversation, Conversations displays all chats the user is participating in.
Shows all documents of the private database, by querying the private-doc service (
Handles functions like *change profile, email, password, etc. *. For admin users shows an additional tab for managing users.
Change your app name and id in the
ionic.config.json located in the root folder of
client . For bulding please refer to the official capacitor documentation.
Images are mostly lazyloaded with the help of ng-lazyload-image. If you create a new page, you have to import the
LazyLoadImageModule in your page module. For a nice UI, images will fade in when they are lazyloaded. Have a look at the lazyload section in
client/src/global.css . If you do not want to use lazyload for an
<img> tag, you have to declare your own class and set
opacity: 1 !important in your global. css.
Requirements: Installed NodeJS, NestJS and Docker / Docker-Compose locally. Run
docker-compose up in the root folder. Open Fauxton, the couchdb gui and disable the cors policy in settings and after you edited the credentials in the
Important: When developing always open Fauxton in a private window, as its authentication document conflicts with the user document of the CAIN Stack application.
.env file into the root of the server folder
BASEURL=http://localhost:8100 NESTURL=http://localhost:3000 COUCHDB_HOST=localhost COUCHDB_PORT=5984 COUCHDB_USR=admin COUCHDB_PW=couchdb MAILER_USR=gmailaccountname MAILER_PW=gmailaccountpassword
The setup function (
server/src/core/db-setup.ts )is triggerd on server startup and automatically creates all necessary databases and design documents (can be found in
server/core/design-docs ). For developing it can be useful to purge all databases. Just uncomment the function at the beginning of the setup handler, save, comment again and save again.
Authentication heavily relies on superlogin. Press the link to read the full documentation. Almost all main apis are included in this template.
A confirmation e-mail can be sent when a user signs up or forgot his password. You can use a standard gmail account to send out those mails. Just enter your credentials into the
MAILER_PW sections of the
.env file. You then have to enable access throught less secure apps. You can also use SendMail or any other custom Nodemailer transport. Have a look in the mailer section of the
superlogin-config.ts . If you want to enable the confirmation mails you can change the mailer configuration in the superlogin config file
server/src/core/superlogin-config.ts under the local section. Mailer Templates can be modified in
sendConfirmEmail: false, requireEmailConfirm: false,
User roles can be defined and will be automatically added to the user doc (see
server/src/core/signup-handler.ts on line 30). By default users with the
admin role will have access to all documents. Routes can be guarded by user role (see
server/src/user/user.module.ts on line 23)
Auth service checks if the token of the bearer token corresponds with the token in the user document in couchdb. The stream service converts a buffer into an readable stream for optimized file responses.
The user controller is responsible for getting and edditing profile details and additional settings for admin users. The apis are protected by the superlogin middleware, see
After starting the server, the chat controller starts listening to changes in the
chat-index database and creates the corresponding chat databases and adds the participants to the security document of these databases.