This provides a comprehensive webapp interface for LAION's Open Assistant project. Initially it will support:
- User registration using either Discord or Email.
- Adding responses to incomplete Open Assistant tasks.
- Rating or Ranking responses to Open Assistant tasks.
- Viewing an activity leaderboard.
- Tracking community wide updates.
This interface compliments the Discord bot and will give access to the same underlying tasks.
This website is built using:
- npm: The node package manager for building.
- React: The core frontend framework.
- Next.js: A React scaffolding framework to streamline development.
- Prisma: An ORM to interact with a web specific Postgres database.
- NextAuth.js: A user authentication framework to ensure we handle accounts with best practices.
- TailwindCSS: A general purpose framework for styling any component.
- Chakra-UI: A wide collection of pre-built UI components that generally look pretty good.
To contribute to the website, make sure you have the following setup and installed:
- NVM: The Node Version Manager makes it easy
to ensure you have the right NodeJS version installed. Once installed, run
nvm use 16
to use Node 16.x. The website is known to be stable with NodeJS version 16.x. This will install both Node and NPM. - Docker: We use docker to simplify running dependent services.
If you're doing active development we suggest the following workflow:
- In one tab, navigate to the project root.
- Run
docker compose up frontend-dev --build --attach-dependencies
. You can optionally include-d
to detach and later track the logs if desired. - In another tab navigate to
${OPEN_ASSISTANT_ROOT/website
. - Run
npm install
- Run
npx prisma db push
(This is also needed when you restart the docker stack from scratch). - Run
npm run dev
. Now the website is up and running locally athttp://localhost:3000
. - To create an account, login via the user using email authentication and
navigate to
http://localhost:1080
. Check the email listed and click the log in link. You're now logged in and authenticated.
You can use the debug credentials provider to log in without fancy emails or OAuth.
- This feature is automatically on in development mode, i.e. when you run
npm run dev
. In case you want to do the same with a production build (for example, the docker image), then run the website with environment variableDEBUG_LOGIN=true
. - Use the
Login
button in the top right to go to the login page. - You should see a section for debug credentials. Enter any username you wish, you will be logged in as that user.
To develop components using Storybook run
npm run storybook
. Then navigate to in your browser to
http://localhost:6006
.
To create a new story create a file named [componentName].stories.js
. An
example how such a story could look like, see Header.stories.jsx
.
All react code is under src/
with a few sub directories:
pages/
: All pages a user could navigate too and API URLs which are underpages/api/
.components/
: All re-usable React components. If something gets used twice we should create a component and put it here.lib/
: A generic place to store library files that are used anywhere. This doesn't have much structure yet.
NOTE: styles/
can be ignored for now.
All database configurations are stored in prisma/schema.prisma
.
All static images, fonts, svgs, etc are stored in public/
.
We're not really using CSS styles. styles/
can be ignored.
Cypress is used for end-to-end (e2e) and component testing and is configured in
./cypress.config.ts
. The ./cypress
folder is used for supporting
configuration files etc.
- Store e2e tests in the
./cypress/e2e
folder. - Store component tests adjacent to the component being tested. If you want to
wriite a test for
./src/components/Layout.tsx
then store the test file at./src/components/Layout.cy.tsx
.
A few npm scripts are available for convenience:
npm run cypress
: Useful for development, it opens Cypress and allows you to explore, run and debug tests. It assumes you have the NextJS site running atlocalhost:3000
.npm run cypress:run
: Runs all tests. Useful for a quick sanity check before sending a PR or to run in CI pipelines.npm run cypress:image-baseline
: If you have tests failing because of visual changes that was expected, this command will update the baseline images stored in./cypress-visual-screenshots/baseline
with those from the adjacent comparison folder. More can be found in the docs ofuktrade/cypress-image-diff
.
Read more in the ./cypress README.
When writing code for the website, we have a few best practices:
- When importing packages import external dependencies first then local dependencies. Order them alphabetically according to the package name.
- When trying to implement something new, check if Chakra-UI has components that are close enough to your need. For example Sliders, Radio Buttons, Progress indicators, etc. They have a lot and we can save time by re-using what they have and tweaking the style as needed.
- Format everything with Prettier. This is done by default with pre-submits. We currently don't have any custom settings.
- Define functional React components (with types for all properties when feasible).
To use stable and consistent URL paths, we recommend the following strategy for new tasks:
- For any task that involves writing a free-form response, put the page under
website/src/pages/create
with a page name matching the task type, such assummarize_story.tsx
. - For any task that evaluates, rates, or ranks content, put the page under
website/src/pages/evaluate
with a page name matching the task type such asrate_summary.tsx
.
With this we'll be able to ensure these contribution pages are hidden from logged out users but accessible to logged in users.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.