Skip to content
maheryyPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Monocle

Monocle is a web analytics tool that allows you to track user interactions on your website.

Architecture

Monocle is split into multiple packages

Server packages (The ones you will always need)

@monocle/api handles requests from the different clients and stores data in the database.

@monocle/ui allows you to view analytics data.

Client packages (The ones you may need)

@monocle/browser focuses on tracking interactions and collecting data that may occur in a browser.

@monocle/node focuses on tracking interactions and collecting data that may occur in a node environment.

@monocle/react built on top of @monocle/browser for react support.

Local demo

To run the local demo, run the following commands:

docker compose -f docker-compose.demo.yml up -d

docker compose -f docker-compose.demo.yml exec mongo mongosh --eval 'rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "mongo:27017" }] })'

docker compose -f docker-compose.demo.yml exec monocle-api pnpm prisma db seed

Go to http://localhost:8080 to view the blop example app.

Go to http://localhost:8081 to access the analytics back-office.

You can use the following credentials to login to the back-office:

email: blog@demo.com
password: password

Installation

As a dependency

npm install @ekezoh/monocle.api
yarn add @ekezoh/monocle.api
pnpm add @ekezoh/monocle.api

Usage

Use the createMonocleServer function to create an express server that you can extend.

import { createMonocleServer } from "@ekezoh/monocle.api";

const server = createMonocleServer({
  corsOrigin: "https://example.com",
});

server.listen(3000);

As a standalone server

Make sure to set the following environment variables:

MONOCLE_DATABASE_URL is the url of the database to use. (no default)

MONOCLE_CORS_ORIGIN is the origin to allow cors from. (default: *)

JWT_SECRET is the secret to use for signing jwt tokens. (no default)

Example using docker

docker run -p 3000:3000 --env-file .env -d @ekezoh/monocle.api

Contributing

Requirements

Setup

At the root of the repository, run the following command to install all dependencies:

pnpm install

Development

Database

Copy all .env.example files to .env files.

# Linux based systems
find . -type f -name ".env.example" -exec sh -c 'cp "$1" "${1%.example}"' _ {} \;

To start the development database, run the following command:

docker compose up -d

docker compose exec mongo mongosh --eval 'rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27017" }] })'

To seed the database, run the following commands in the packages/api directory:

pnpm exec prisma generate
pnpm exec prisma db seed

To view the data, you can use prisma studio.

pnpm exec prisma studio

Or use mongo-express running on port 8888.

Packages

api and ui has a dev script that you can run to start the development server.

pnpm dev

Other packages can be built using nx

pnpm exec nx build <package>

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages