Skip to content

Commit 5e6ed49

Browse files
authored
feat: nextjs migration (#33)
1 parent f6fb956 commit 5e6ed49

File tree

100 files changed

+2809
-2448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2809
-2448
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ lerna-debug.log*
1010
node_modules
1111
dist
1212
dist-ssr
13+
.next
14+
next-env.d.ts
1315
*.local
1416

1517
# Editor directories and files
@@ -30,4 +32,6 @@ scripts/deploy-vercel.sh
3032
# Env files
3133
.env
3234

33-
tsconfig.app.tsbuildinfo
35+
tsconfig.app.tsbuildinfo
36+
tsconfig.tsbuildinfo
37+
certificates

AGENTS.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
# Repository Guidelines
22

33
## Project Structure & Module Organization
4-
The Vite + React app lives in `src/` with `main.tsx` mounting `App.tsx`. Feature-specific UI is grouped under `src/components` (e.g., `create-project`, `deeploys`), while route screens sit in `src/pages`. Shared hooks/utilities are in `src/lib` and `src/shared`, smart-contract adapters in `src/blockchain`, and schema/types in `src/schemas`, `src/data`, and `src/typedefs`. Static assets live in `public/` and `src/assets/`; builds land in `dist/`.
4+
5+
This is a Next.js App Router project. Routes and layouts live in `app/` (file-based routing via `page.tsx`, `layout.tsx`, `not-found.tsx`, and dynamic segments like `[id]`). The codebase uses route groups for organization, e.g. `app/(public)` and `app/(protected)` (the protected group is gated by `app/(protected)/protected-layout.tsx`).
6+
7+
Most feature UI remains in `src/`: feature-specific components are grouped under `src/components` (e.g., `create-project`, `deeploys`, `tunnels`), shared UI/logic in `src/shared`, hooks/utilities/contexts/providers in `src/lib`, smart-contract adapters in `src/blockchain`, and schema/types in `src/schemas`, `src/data`, and `src/typedefs`. Static assets live in `public/` and `src/assets/`. Next build output is `.next/` (a legacy `dist/` directory may exist from pre-Next builds and should not be treated as the Next build output).
58

69
## Build, Test, and Development Commands
10+
711
Run all commands from the repo root:
8-
- `npm run dev` launches the Vite dev server with HMR.
9-
- `npm run dev:logs` adds verbose Vite diagnostics for debugging config issues.
10-
- `npm run build` type-checks through `tsc -b` then emits a production bundle to `dist/`.
12+
13+
- `npm run dev` launches the Next.js dev server (`next dev --turbo --experimental-https`).
14+
- `npm run dev:logs` enables verbose Next.js diagnostics (`NEXT_DEBUG=1 next dev --turbo --experimental-https`).
15+
- `npm run build` creates a production build (`next build`, outputs to `.next/`).
16+
- `npm run start` serves the production build locally (`next start`).
1117
- `npm run lint` executes ESLint with the project’s React/TypeScript rules.
12-
- `npm run preview` serves the last build for local production smoke tests.
1318

1419
## Deeploy API Integration
15-
Deeploy workflows talk to the [edge_node](https://github.com/Ratio1/edge_node) API through wrappers in `src/lib/api/deeploy.ts`. Configure the base URL by setting `VITE_API_URL` and `VITE_ENVIRONMENT` in your `.env`; `src/lib/config.ts` routes requests across devnet/testnet/mainnet. Local storage must expose `accessToken`/`refreshToken` to satisfy the Axios interceptors. When working against a local edge node, run its server first, then point `VITE_API_URL` to the exposed port (e.g., `http://localhost:5000`). Mock responses for offline work by stubbing the helpers (`createPipeline`, `getApps`, etc.) instead of bypassing the provider.
20+
21+
Deeploy workflows talk to the [edge_node](https://github.com/Ratio1/edge_node) API through wrappers in `src/lib/api/deeploy.ts`. Configure the base URL by setting `NEXT_PUBLIC_API_URL` and `NEXT_PUBLIC_ENVIRONMENT` (and optionally `NEXT_PUBLIC_DEV_ADDRESS`) in your env file (prefer `.env.local`); `src/lib/config.ts` routes requests across devnet/testnet/mainnet. Local storage must expose `accessToken`/`refreshToken` to satisfy the Axios interceptors. When working against a local edge node, run its server first, then point `NEXT_PUBLIC_API_URL` to the exposed port (e.g., `http://localhost:5000`).
22+
23+
Because this is Next.js, be mindful of client/server boundaries: modules that access `localStorage` (like `src/lib/api/deeploy.ts`) must only run in client components/hooks (files with `'use client'`) and should not be imported/executed from server components.
1624

1725
## Coding Style & Naming Conventions
18-
Prettier (`.prettierrc`) enforces four-space indentation, single quotes, semicolons, and Tailwind class sorting—format before committing. Use PascalCase for components, camelCase for functions and state, and kebab-case for feature folders. Respect path aliases from `tsconfig.app.json` (such as `@components/...`) to avoid brittle relative imports. ESLint relaxes certain hook rules; still supply explicit dependency arrays and delete unused code paths.
26+
27+
Prettier (`.prettierrc`) enforces four-space indentation, single quotes, semicolons, and Tailwind class sorting—format before committing. Use PascalCase for components, camelCase for functions and state, and kebab-case for feature folders. Respect path aliases from `tsconfig.json` (such as `@components/...`) to avoid brittle relative imports. In the `app/` router, add `'use client'` to components that use hooks, browser APIs, or context providers.
1928

2029
## Testing Guidelines
21-
Automated tests are not yet wired into `package.json`. Prefer Vitest plus React Testing Library when adding coverage; place specs alongside source as `*.test.ts(x)` or under `src/__tests__/`. Stub Deeploy API calls and blockchain providers to keep tests deterministic, and document manual QA steps in your PR until the suite matures.
30+
31+
Automated tests are not yet wired into `package.json`. Place specs alongside source as `*.test.ts(x)` or under `src/__tests__/`. Stub Deeploy API calls and blockchain providers to keep tests deterministic, and document manual QA steps in your PR until the suite matures.
2232

2333
## Commit & Pull Request Guidelines
34+
2435
History follows Conventional Commit prefixes (`fix:`, `feat:`, etc.); keep summaries concise and imperative (<72 chars). Separate logical changes—UI tweaks, contract bindings, and config updates should ship in distinct commits. PRs need a clear problem statement, bullet summary of changes, evidence for UI updates (screenshots/GIFs), linked work items, and callouts for required env/config shifts.

Dockerfile_devnet

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
# ---- Build stage ---------
2-
FROM node:18-slim AS builder
3-
ARG VERSION
1+
FROM node:20-alpine AS base
42
WORKDIR /app
53

6-
# Build arguments for configuration
7-
ARG API_URL=https://devnet-deeploy-api.ratio1.ai
8-
ARG ENVIRONMENT=devnet
4+
ENV NEXT_TELEMETRY_DISABLED=1
5+
RUN apk add --no-cache python3 make g++ libc6-compat
6+
7+
ARG NEXT_PUBLIC_API_URL=https://devnet-deeploy-api.ratio1.ai
8+
ARG NEXT_PUBLIC_ENVIRONMENT=devnet
9+
ARG NEXT_PUBLIC_DEV_ADDRESS
10+
ARG VERSION
911

10-
# Set environment variables for the build process
11-
ENV VITE_API_URL=${API_URL}
12-
ENV VITE_ENVIRONMENT=${ENVIRONMENT}
12+
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
13+
ENV NEXT_PUBLIC_ENVIRONMENT=${NEXT_PUBLIC_ENVIRONMENT}
14+
ENV NEXT_PUBLIC_DEV_ADDRESS=${NEXT_PUBLIC_DEV_ADDRESS}
15+
ENV NEXT_PUBLIC_APP_VERSION=${VERSION}
1316

17+
FROM base AS deps
1418
COPY package*.json ./
1519
RUN npm ci
1620

21+
FROM base AS builder
22+
COPY --from=deps /app/node_modules ./node_modules
1723
COPY . .
18-
ENV VITE_APP_VERSION=${VERSION}
19-
RUN npm run build # produces static files in /app/dist
24+
RUN npm run build
25+
RUN npm prune --omit=dev
2026

21-
# ---- Runtime stage ---------
22-
FROM nginx:alpine
27+
FROM node:20-alpine AS runner
28+
WORKDIR /app
29+
ENV NODE_ENV=production \
30+
HOST=0.0.0.0 \
31+
PORT=80 \
32+
NEXT_TELEMETRY_DISABLED=1
2333

24-
COPY --from=builder /app/dist /usr/share/nginx/html
34+
RUN apk add --no-cache libc6-compat
2535

26-
RUN sed -i '/index index\.html index\.htm;/a\ try_files \$uri \$uri/ /index.html;' \
27-
/etc/nginx/conf.d/default.conf
36+
COPY --from=builder /app/.next/standalone ./
37+
COPY --from=builder /app/.next/static ./.next/static
38+
COPY --from=builder /app/public ./public
2839

2940
EXPOSE 80
30-
CMD ["nginx", "-g", "daemon off;"]
41+
CMD ["node", "server.js"]

Dockerfile_mainnet

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
# ---- Build stage ---------
2-
FROM node:18-slim AS builder
3-
ARG VERSION
1+
FROM node:20-alpine AS base
42
WORKDIR /app
53

6-
# Build arguments for configuration
7-
ARG API_URL=https://deeploy-api.ratio1.ai
8-
ARG ENVIRONMENT=mainnet
4+
ENV NEXT_TELEMETRY_DISABLED=1
5+
RUN apk add --no-cache python3 make g++ libc6-compat
6+
7+
ARG NEXT_PUBLIC_API_URL=https://deeploy-api.ratio1.ai
8+
ARG NEXT_PUBLIC_ENVIRONMENT=mainnet
9+
ARG NEXT_PUBLIC_DEV_ADDRESS
10+
ARG VERSION
911

10-
# Set environment variables for the build process
11-
ENV VITE_API_URL=${API_URL}
12-
ENV VITE_ENVIRONMENT=${ENVIRONMENT}
12+
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
13+
ENV NEXT_PUBLIC_ENVIRONMENT=${NEXT_PUBLIC_ENVIRONMENT}
14+
ENV NEXT_PUBLIC_DEV_ADDRESS=${NEXT_PUBLIC_DEV_ADDRESS}
15+
ENV NEXT_PUBLIC_APP_VERSION=${VERSION}
1316

17+
FROM base AS deps
1418
COPY package*.json ./
1519
RUN npm ci
1620

21+
FROM base AS builder
22+
COPY --from=deps /app/node_modules ./node_modules
1723
COPY . .
18-
ENV VITE_APP_VERSION=${VERSION}
19-
RUN npm run build # produces static files in /app/dist
24+
RUN npm run build
25+
RUN npm prune --omit=dev
2026

21-
# ---- Runtime stage ---------
22-
FROM nginx:alpine
27+
FROM node:20-alpine AS runner
28+
WORKDIR /app
29+
ENV NODE_ENV=production \
30+
HOST=0.0.0.0 \
31+
PORT=80 \
32+
NEXT_TELEMETRY_DISABLED=1
2333

24-
COPY --from=builder /app/dist /usr/share/nginx/html
34+
RUN apk add --no-cache libc6-compat
2535

26-
RUN sed -i '/index index\.html index\.htm;/a\ try_files \$uri \$uri/ /index.html;' \
27-
/etc/nginx/conf.d/default.conf
36+
COPY --from=builder /app/.next/standalone ./
37+
COPY --from=builder /app/.next/static ./.next/static
38+
COPY --from=builder /app/public ./public
2839

2940
EXPOSE 80
30-
CMD ["nginx", "-g", "daemon off;"]
41+
CMD ["node", "server.js"]

Dockerfile_testnet

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
# ---- Build stage ---------
2-
FROM node:18-slim AS builder
3-
ARG VERSION
1+
FROM node:20-alpine AS base
42
WORKDIR /app
53

6-
# Build arguments for configuration
7-
ARG API_URL=https://testnet-deeploy-api.ratio1.ai
8-
ARG ENVIRONMENT=testnet
4+
ENV NEXT_TELEMETRY_DISABLED=1
5+
RUN apk add --no-cache python3 make g++ libc6-compat
6+
7+
ARG NEXT_PUBLIC_API_URL=https://testnet-deeploy-api.ratio1.ai
8+
ARG NEXT_PUBLIC_ENVIRONMENT=testnet
9+
ARG NEXT_PUBLIC_DEV_ADDRESS
10+
ARG VERSION
911

10-
# Set environment variables for the build process
11-
ENV VITE_API_URL=${API_URL}
12-
ENV VITE_ENVIRONMENT=${ENVIRONMENT}
12+
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
13+
ENV NEXT_PUBLIC_ENVIRONMENT=${NEXT_PUBLIC_ENVIRONMENT}
14+
ENV NEXT_PUBLIC_DEV_ADDRESS=${NEXT_PUBLIC_DEV_ADDRESS}
15+
ENV NEXT_PUBLIC_APP_VERSION=${VERSION}
1316

17+
FROM base AS deps
1418
COPY package*.json ./
1519
RUN npm ci
1620

21+
FROM base AS builder
22+
COPY --from=deps /app/node_modules ./node_modules
1723
COPY . .
18-
ENV VITE_APP_VERSION=${VERSION}
19-
RUN npm run build # produces static files in /app/dist
24+
RUN npm run build
25+
RUN npm prune --omit=dev
2026

21-
# ---- Runtime stage ---------
22-
FROM nginx:alpine
27+
FROM node:20-alpine AS runner
28+
WORKDIR /app
29+
ENV NODE_ENV=production \
30+
HOST=0.0.0.0 \
31+
PORT=80 \
32+
NEXT_TELEMETRY_DISABLED=1
2333

24-
COPY --from=builder /app/dist /usr/share/nginx/html
34+
RUN apk add --no-cache libc6-compat
2535

26-
RUN sed -i '/index index\.html index\.htm;/a\ try_files \$uri \$uri/ /index.html;' \
27-
/etc/nginx/conf.d/default.conf
36+
COPY --from=builder /app/.next/standalone ./
37+
COPY --from=builder /app/.next/static ./.next/static
38+
COPY --from=builder /app/public ./public
2839

2940
EXPOSE 80
30-
CMD ["nginx", "-g", "daemon off;"]
41+
CMD ["node", "server.js"]

README.md

Lines changed: 73 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,76 @@
1-
# React + TypeScript + Vite
2-
3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4-
5-
Currently, two official plugins are available:
6-
7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9-
10-
## Expanding the ESLint configuration
11-
12-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13-
14-
```js
15-
export default tseslint.config({
16-
extends: [
17-
// Remove ...tseslint.configs.recommended and replace with this
18-
...tseslint.configs.recommendedTypeChecked,
19-
// Alternatively, use this for stricter rules
20-
...tseslint.configs.strictTypeChecked,
21-
// Optionally, add this for stylistic rules
22-
...tseslint.configs.stylisticTypeChecked,
23-
],
24-
languageOptions: {
25-
// other options...
26-
parserOptions: {
27-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
28-
tsconfigRootDir: import.meta.dirname,
29-
},
30-
},
31-
})
1+
# Deeploy dApp
2+
3+
Ratio1's Deeploy front-end for deploying and operating services on the Ratio1 network. The app is built with Next.js (App Router) and provides wallet-based authentication, Deeploy job management, tunneling setup, and project drafting tools.
4+
5+
## Features
6+
7+
- Wallet sign-in with SIWE via ConnectKit/Wagmi (Base & Base Sepolia networks pulled from `src/lib/config.ts`).
8+
- Create and manage Deeploy jobs and projects; drafts are stored locally with Dexie for offline-friendly editing.
9+
- Monitor running deployments, resend commands, scale workers, and review Deeploy API responses.
10+
- Cloudflare tunnel management with signed messages to fetch and store secrets securely.
11+
- Service catalog with scripted additions (`npm run add-service`) and validation (`npm run validate-services`).
12+
- Shared contexts for authentication, blockchain state, tunneling, and deployment data (`src/lib/contexts`).
13+
14+
## Getting Started
15+
16+
Prerequisites: Node.js 20+ and npm.
17+
18+
1. Install dependencies:
19+
3220
```
21+
npm install
22+
```
23+
24+
2. Create `.env.local` (prefer this over `.env`):
25+
26+
```
27+
NEXT_PUBLIC_ENVIRONMENT=devnet # devnet | testnet | mainnet
28+
NEXT_PUBLIC_API_URL=http://localhost:5000 # Deeploy edge_node base URL
29+
NEXT_PUBLIC_DEV_ADDRESS=0xYourDevWallet # optional; forces this address in dev
30+
NEXT_PUBLIC_APP_VERSION=local # optional; shown in the UI footer
31+
```
32+
33+
- `NEXT_PUBLIC_API_URL` should point to your running [edge_node](https://github.com/Ratio1/edge_node) instance or the hosted Deeploy API.
34+
- `NEXT_PUBLIC_ENVIRONMENT` selects the chain and backend/oracle endpoints defined in `src/lib/config.ts`.
3335

34-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
35-
36-
```js
37-
// eslint.config.js
38-
import reactX from 'eslint-plugin-react-x'
39-
import reactDom from 'eslint-plugin-react-dom'
40-
41-
export default tseslint.config({
42-
plugins: {
43-
// Add the react-x and react-dom plugins
44-
'react-x': reactX,
45-
'react-dom': reactDom,
46-
},
47-
rules: {
48-
// other rules...
49-
// Enable its recommended typescript rules
50-
...reactX.configs['recommended-typescript'].rules,
51-
...reactDom.configs.recommended.rules,
52-
},
53-
})
36+
3. Start the dev server (HTTPS by default):
37+
38+
```
39+
npm run dev
5440
```
41+
42+
Visit https://localhost:3000 and trust the local certificate if prompted.
43+
44+
## Usage Notes
45+
46+
- Authentication uses SIWE; tokens (`accessToken`, `refreshToken`) are kept in `localStorage` and reused by the Axios interceptors in `src/lib/api`.
47+
- Most protected routes live under `app/(protected)/…`; the public login screen is under `app/(public)/login`.
48+
- Draft projects/jobs are stored in IndexedDB (`src/lib/storage/db.ts`); clearing browser storage removes drafts.
49+
- When pointing to a local edge_node, start that server first, then set `NEXT_PUBLIC_API_URL` to its port (e.g., `http://localhost:5000`).
50+
51+
## Scripts
52+
53+
- `npm run dev` – Next.js dev server (`next dev --turbo --experimental-https`).
54+
- `npm run build` / `npm run start` – production build and serve.
55+
- `npm run lint` – ESLint with the project rules.
56+
- `npm run add-service` – interactive wizard to append a service to `src/data/services.ts`.
57+
- `npm run validate-services` – checks service definitions, color variants, and dynamic env types.
58+
59+
## Project Structure
60+
61+
- `app/` – Next.js App Router entrypoints (`(public)` and `(protected)` route groups, layouts, error pages).
62+
- `src/components/` – feature components (auth, create-job, deeploys, tunnels, etc.).
63+
- `src/shared/` – shared UI primitives and layout helpers.
64+
- `src/lib/` – configs, API clients (Deeploy, backend, oracles, tunnels), providers, contexts, hooks, utilities.
65+
- `src/data/` – static data (services catalog, color types, dynamic env types) and scripts targets.
66+
- `src/blockchain/` – contract helpers and wagmi/viem bindings.
67+
- `public/` – static assets and manifest; `certificates/` holds local HTTPS certs for dev.
68+
- `scripts/` – maintenance scripts for services and data validation.
69+
70+
## Deployment
71+
72+
Dockerfiles are provided per environment (`Dockerfile_devnet`, `_testnet`, `_mainnet`) and expect build args `NEXT_PUBLIC_API_URL`, `NEXT_PUBLIC_ENVIRONMENT`, and `VERSION` (mapped to `NEXT_PUBLIC_APP_VERSION`).
73+
74+
## Testing
75+
76+
Automated tests are not wired up yet; use `npm run lint` locally and document manual QA steps when making changes.

0 commit comments

Comments
 (0)