Giter Club home page Giter Club logo

effect-remix-stream's Introduction

Using Effect with Remix

Project Goals

Prototype an integration of Remix + Effect in such a way that the Effect runtime is only ever executed in the backend while keeping the frontend code minimal and fully type safe.

This project aims to demonstrate integration of Effect in one typical setup where the user is not in control of the program entrypoints that are delegated to frameworks, similar scenarios are for example the usage of Next.js or equivalent frameworks.

Development

From your terminal:

pnpm run dev

This starts your app in development mode, rebuilding assets on file changes.

Deployment

First, build your app for production:

pnpm run build

Then run the app in production mode:

pnpm run start

Now you'll need to pick a host to deploy it to.

Telemetry

If you want to see telemetry data this project is configured to work with https://www.honeycomb.io/, create an account if you don't have one (they have a very nice free tier) and write your project name & api key in a file called .env, follow the template .env.template

Note: if you want to change the backend you use for tracing, for example using your own grafana tempo you'll need to edit /services/Tracing.ts accordingly (see https://github.com/Effect-TS/opentelemetry).

Project Setup

This project uses a nightly build of remix in order to use it together with vite. Apart from that it looks like a normal vite project.

The key configurations for vite are found in the vite.config.ts file that looks like:

import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import babel from "vite-plugin-babel";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    babel({
      filter: new RegExp(/\.tsx?$/),
    }),
    remix(),
    tsconfigPaths(),
  ],
  build: {
    outDir: "build",
    copyPublicDir: false,
    minify: "terser",
  },
  publicDir: "./public",
});

Namely here we are setting up Remix together with babel, in babel we use a plugin to annotate pure calls so that we can tree-shake loaders and actions that use higher order functions.

In short this setup enables us to use and tree-shake the following pattern:

export const loader = effectLoader(effect);
export const action = effectAction(effect);

export default function Component() {
  // plain component
}

Code Structure

The project uses 4 main libraries of the effect ecosystem:

  • effect to handle all effectful operations
  • @effect/schema to define data models and handle serialization
  • @effect/opentelemetry to integrate with a telemetry dashboard
  • @sqlfx/sqlite to integrate with sqlite

As of telemetry for simplicity we are using https://www.honeycomb.io/ but any open telemetry compatible service will work with minor changes to the code

The directories are structured in the following way:

  • /app contains all the app code
    • /lib contains integration code with effect (and a temporary hack to load opentelemetry from esm due to improper es modules)
    • /migrations contains all the database migration code, those are automatically loaded by the sql client
    • /routes contains the remix routes, loaders and actions
    • /services contains the business logic encapsulated in effect services
  • /database contains the sqlite files

effect-remix-stream's People

Contributors

mikearnaldi avatar

Stargazers

 avatar  avatar BillMo avatar Supachai Suwanthip avatar ryoppippi avatar Milad Vafaeifard avatar Hyunjoon KIM avatar Victor Korzunin avatar Gavri (Gabriel) Guy avatar Andrejs Agejevs avatar  avatar Nikita avatar Antoine Coulon avatar Kinane avatar Patrick Roza avatar Akash Tripathy avatar Arek Mazurkiewicz avatar Marcelo Dias avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.