earthworm README

The project's README from github.com/cuixueshe/earthworm. As one markdown file: README.md.

Earthworm

Earthworm

English | 中文

Featured|HelloGitHub

⚡ Introduction

By constructing sentences with conjunctions, it helps you learn English better~ 😊

🚀 How To Start?

The mentioned operations below are based on the root directory of the current project, please be attentive to ensure there are no errors!

Requirements

docker --version # Docker version 24.0.7, build afdd53b

node --version # v20+

pnpm -v # 8+

Editor

VSCode

1. Install Dependencies

pnpm install

2. Configure the .env File

You can choose to copy the contents of ./apps/api/.env.example to./apps/api/.env. note that the' example' file contains sample configuration. the main storage system's environment variable information, such as database connection address, user name, password, port, key, etc. the back-end service will read the configuration from this file, of course you can also change it to your own configuration information.

Windows users recommend shortcut keys to copy and paste, Linux users can operate through the following command.

Server

cp ./apps/api/.env.example ./apps/api/.env

Client

cp ./apps/client/.env.example ./apps/client/.env

3. Restore Data Of Logto

Uncompress logto_db_init_data.zip to .volumes/

unzip logto_db_init_data.zip -d .volumes/

if you want to Manual Configuration Logto

4. Start Docker Compose Service

The backend relies on Postgres and Redis services. Start and stop these services using the commands configured in package.json below.

# start
pnpm docker:start

# When needed, execute the following command
# stop
pnpm docker:stop
# delete
pnpm docker:delete
# Complete deletion (including Volume data)
pnpm docker:down

If you prefer manual, you can use the commands below.

docker compose up -d
docker compose stop
docker compose down

# commands compatible with older versions of Docker
docker-compose up -d

5. Initialize Database Schema

When executing this command, try to keep a little time from the previous command, because the -d parameter just used will suspend its service execution in the background. At this time, the docker service may still be running. If an error is found, execute it again.

pnpm db:init

6. Create and Upload Course Data

Only Execute This During the Initial Database Initialization.

pnpm db:upload

7. Start the Backend Service

pnpm dev:serve

8. Start the Frontend Service

pnpm dev:client

🛠️ About testing

Run the test before submitting the commit, and submit the code after the test passes, so as to avoid multiple commits to solve the test problem.

Front-end Testing

The main is the single test of Vitest and the automated test of cypress, execute the following command:

# Enter the front-end project directory
cd apps/client

# vitest
pnpm test:unit:run
# cypress
pnpm test:e2e:run

# monitor vitest, convenient hot update to see test results
pnpm test:unit:watch

Backend Testing

Mainly Jest single test and end-to-end test, but need to access the test database, so you need to ensure that:

  1. testdb and testRedis services in Docker Compose started normally.
  2. The configuration information in the .env.test file is correct. If there is no such file, you can copy the contents of the apps/api/.env.test.example file to the apps/api/.env.test file. The following command is provided to directly use.

Execute the following command:

# Enter Backend Project Directory
cd apps/api

# If you have an.env.test file, you don't need to run this step
cp .env.test.example .env.test

# Single test
pnpm test:unit
# End-to-end testing
pnpm test:e2e
# Single test and end-to-end test run together
pnpm test

Docs Project

Project based on Vitepress documentation,execute the following command:

# Local Development
pnpm docs:dev

❓ FAQ

Database connection failed

My Docker and the database inside are running normally, but when I run the db:init command, I still report an error, indicating that the database connection failed.

You can check whether the database configuration in the .env file is correct, or even whether this file has it! 😠

How To Correctly Update Course Data?

when you identify incorrect course data and make modifications, you should use the following command to update the course data in the database.

pnpm db:update

pnpm Install Error?

Some dependencies require compilation during installation, necessitating the presence of relevant build environments. If these environments are not available, the compilation process may fail. Additionally, different modules may require different build environments, so specific issues need to be analyzed individually. Below are specific problems encountered along with their solutions.

First try the following command to update pnpm.

pnpm i -g
# or
pnpm i -g pnpm
# or
npx pnpm i -g pnpm@latest

Error Installing the argon2 Module On Windows

Docker Permission Denied in Docker?

When using WSL2 as a development environment in Windows, the following error occurs when starting Docker with docker compose up -d :

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

Solution

Add the current user to the docker group

# Add docker user group
sudo groupadd docker
# Add the logged-in user to the docker user group
sudo gpasswd -a $USER docker
# Update user group
newgrp docker
# Test if docker command is working properly
docker images

🤝 Frontend Development Guideline

  1. Do not Destructure Pinia store.

    • The readability will be better when using store
    • Destructuring can lead to reactivity loss and using storeToRefs is also quite cumbersome
  2. Avoid including UI logic in composables.

    • Such as toast.info()
    • We categorize the router as UI logic, and for ease of testing, avoid including routerrelated logic in there

🚀 Star History

Stargazers over time

🌟 Contributing

Thanks to everyone who has already contributed to Earthworm! 🎉

earthworm (cuixueshe/earthworm)

Searching Database…

11.1K ·GitHub
这是什么?Earthworm 是一个开源的网页应用,通过连词造句来学英语——你是一步一步地把句子搭建出来,而不是死背单词表。
它是在线托管的服务,还是需要我自己部署?需要自己部署:这是一个包含前端和 API 的全栈 monorepo,通过 Docker Compose 启动 Postgres、Redis 和 Logto 认证服务,之后就可以在浏览器里使用这个应用了。
把它跑起来需要做哪些事?一共八步:用 pnpm 安装依赖,把 apps/api/.env.example 复制为 .env,把 Logto 初始化数据解压到 .volumes/,启动 Docker Compose,运行 db:init,上传课程数据,然后分别启动后端和前端。
开始之前我需要装好哪些东西?pnpm >= 8、Node.js >= v20、已安装并正在运行的 Docker,还有 Postgres >= 14 和 Redis >= 5——README 把这五项都列为开始前的必备要求。
安装过程中大家通常容易卡在哪里?有些依赖(比如 argon2)需要 C++ 工具链——在 Windows 上要装 Visual Studio 2015 或更高版本,并勾选“使用 C++ 的桌面开发”;WSL2 用户可能遇到 Docker 权限报错;如果 Docker 还没启动完,db:init 可能需要重新跑一次。
它自带现成的课程吗?有——课程数据会在数据库初始化阶段一次性创建并上传;之后如果课程内容有修正,还可以用专门的命令把改动更新到数据库里。
需要注册账号吗?我的数据会到哪里去?登录走的是内置的 Logto 实例,它自带默认管理员账号;由于 Logto、Postgres 和 Redis 全都通过 Docker Compose 在本地运行,你的数据只留在你自己的电脑上。
Logto 是什么?为什么安装要用到它?Logto 是 Earthworm 用来做登录的开源认证服务。仓库里打包了它的初始化数据和默认管理员账号,它和 Postgres、Redis 一起在 Docker Compose 里运行。
它对中文使用者友好吗?这个项目从一开始就是双语的:README 开头就是“Earthworm English | 中文”,连 Windows 故障排查部分都专门讲了编译时中文字符显示的问题。
Creator
cuixueshe
Size
219.1 MB
Stars
11.1K
Updated
CommitAug 19
Age
2y
Commits · 90 Days