2023-05-15 00:51:32 +00:00
# Dify Frontend
2024-06-18 10:33:22 +00:00
2026-03-20 09:23:17 +00:00
This is a [Next.js] project, but you can dev with [vinext].
2023-05-15 00:51:32 +00:00
## Getting Started
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
### Run by source code
2024-06-18 10:33:22 +00:00
2025-04-08 09:12:25 +00:00
Before starting the web frontend service, please make sure the following environment is ready.
2025-08-20 05:49:11 +00:00
2026-03-20 09:23:17 +00:00
- [Node.js]
- [pnpm]
You can also use [Vite+] with the corresponding `vp` commands.
For example, use `vp install` instead of `pnpm install` and `vp test` instead of `pnpm run test` .
2023-05-15 00:51:32 +00:00
2026-01-12 04:44:30 +00:00
> [!TIP]
> It is recommended to install and enable Corepack to manage package manager versions automatically:
>
> ```bash
> npm install -g corepack
> corepack enable
> ```
>
2026-03-20 09:23:17 +00:00
> Learn more: [Corepack]
2026-01-12 04:44:30 +00:00
2023-09-07 01:43:24 +00:00
First, install the dependencies:
```bash
2025-02-17 09:05:13 +00:00
pnpm install
2023-09-07 01:43:24 +00:00
```
2026-03-20 09:23:17 +00:00
Then, configure the environment variables.
Create a file named `.env.local` in the current directory and copy the contents from `.env.example` .
Modify the values of these environment variables according to your requirements:
2024-06-18 10:33:22 +00:00
2024-09-19 02:39:27 +00:00
```bash
cp .env.example .env.local
```
2025-11-18 09:29:54 +00:00
> [!IMPORTANT]
>
> 1. When the frontend and backend run on different subdomains, set NEXT_PUBLIC_COOKIE_DOMAIN=1. The frontend and backend must be under the same top-level domain in order to share authentication cookies.
> 1. It's necessary to set NEXT_PUBLIC_API_PREFIX and NEXT_PUBLIC_PUBLIC_API_PREFIX to the correct backend API URL.
2023-09-07 01:43:24 +00:00
Finally, run the development server:
2023-05-15 00:51:32 +00:00
```bash
2025-02-17 09:05:13 +00:00
pnpm run dev
2026-03-20 09:23:17 +00:00
# or if you are using vinext which provides a better development experience
pnpm run dev:vinext
# (optional) start the dev proxy server so that you can use online API in development
pnpm run dev:proxy
2023-05-15 00:51:32 +00:00
```
2026-03-20 09:23:17 +00:00
Open < http: / / localhost:3000 > with your browser to see the result.
2023-05-15 00:51:32 +00:00
2026-03-20 09:23:17 +00:00
You can start editing the file under folder `app` .
The page auto-updates as you edit the file.
2023-09-07 01:43:24 +00:00
## Deploy
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
### Deploy on server
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
First, build the app for production:
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
```bash
2025-02-17 09:05:13 +00:00
pnpm run build
2023-09-07 01:43:24 +00:00
```
2023-05-15 00:51:32 +00:00
2023-10-19 03:38:03 +00:00
Then, start the server:
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
```bash
2025-02-17 09:05:13 +00:00
pnpm run start
2023-09-07 01:43:24 +00:00
```
2023-05-15 00:51:32 +00:00
2023-10-19 03:38:03 +00:00
If you want to customize the host and port:
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
```bash
2025-02-17 09:05:13 +00:00
pnpm run start --port=3001 --host=0.0.0.0
2023-09-07 01:43:24 +00:00
```
2023-05-15 00:51:32 +00:00
2024-10-16 02:18:48 +00:00
## Storybook
2026-03-20 09:23:17 +00:00
This project uses [Storybook] for UI component development.
2024-10-16 02:18:48 +00:00
To start the storybook server, run:
```bash
2025-02-17 09:05:13 +00:00
pnpm storybook
2024-10-16 02:18:48 +00:00
```
2026-03-20 09:23:17 +00:00
Open < http: / / localhost:6006 > with your browser to see the result.
2024-10-16 02:18:48 +00:00
2023-09-07 01:43:24 +00:00
## Lint Code
2024-06-18 10:33:22 +00:00
2023-09-07 01:43:24 +00:00
If your IDE is VSCode, rename `web/.vscode/settings.example.json` to `web/.vscode/settings.json` for lint code setting.
2023-05-15 00:51:32 +00:00
2026-03-20 09:23:17 +00:00
Then follow the [Lint Documentation] to lint the code.
2026-01-29 09:58:10 +00:00
2024-07-18 09:35:10 +00:00
## Test
2026-03-20 09:23:17 +00:00
We use [Vitest] and [React Testing Library] for Unit Testing.
2024-07-18 09:35:10 +00:00
2026-03-20 09:23:17 +00:00
**📖 Complete Testing Guide**: See [web/docs/test.md] for detailed testing specifications, best practices, and examples.
> [!IMPORTANT]
> As we are using Vite+, the `vitest` command is not available.
> Please make sure to run tests with `vp` commands.
> For example, use `npx vp test` instead of `npx vitest`.
2024-07-18 09:35:10 +00:00
Run test:
```bash
2025-12-22 08:35:22 +00:00
pnpm test
2024-07-18 09:35:10 +00:00
```
2026-03-20 09:23:17 +00:00
> [!NOTE]
> Our test is not fully stable yet, and we are actively working on improving it.
> If you encounter test failures only in CI but not locally, please feel free to ignore them and report the issue to us.
> You can try to re-run the test in CI, and it may pass successfully.
2025-11-26 07:18:07 +00:00
### Example Code
2024-07-18 09:35:10 +00:00
2025-11-26 07:18:07 +00:00
If you are not familiar with writing tests, refer to:
2026-03-20 09:23:17 +00:00
- [classnames.spec.ts] - Utility function test example
- [index.spec.tsx] - Component test example
2025-11-26 07:18:07 +00:00
### Analyze Component Complexity
Before writing tests, use the script to analyze component complexity:
```bash
pnpm analyze-component app/components/your-component/index.tsx
```
2026-03-20 09:23:17 +00:00
This will help you determine the testing strategy. See [web/testing/testing.md] for details.
2024-07-18 09:35:10 +00:00
2023-09-07 01:43:24 +00:00
## Documentation
2024-06-18 10:33:22 +00:00
2026-01-21 08:31:48 +00:00
Visit < https: / / docs . dify . ai > to view the full documentation.
2023-05-15 00:51:32 +00:00
2023-09-07 01:43:24 +00:00
## Community
2024-06-18 10:33:22 +00:00
2026-03-20 09:23:17 +00:00
The Dify community can be found on [Discord community], where you can ask questions, voice ideas, and share your projects.
[Corepack]: https://github.com/nodejs/corepack#readme
[Discord community]: https://discord.gg/5AEfbxcd9k
[Lint Documentation]: ./docs/lint.md
[Next.js]: https://nextjs.org
[Node.js]: https://nodejs.org
[React Testing Library]: https://testing-library.com/docs/react-testing-library/intro
[Storybook]: https://storybook.js.org
[Vite+]: https://viteplus.dev
[Vitest]: https://vitest.dev
[classnames.spec.ts]: ./utils/classnames.spec.ts
[index.spec.tsx]: ./app/components/base/button/index.spec.tsx
[pnpm]: https://pnpm.io
[vinext]: https://github.com/cloudflare/vinext
[web/docs/test.md]: ./docs/test.md