Skip to content

Commit 70426b6

Browse files
authored
Migrates plugins to module federation (#64)
* Migrates to use module federation for plugins (#61) * Adds module federation support for distributor + transformer plugins (#55) * adds memory bank and plugin loader * adds plugin service * wip * working distributor plugins w/ module federation, some TOODs * working, nice, clean plugin service * fmt * addresses comments * set the correct remotes * update memory bank and documentation * implements transform plugins * update memories * fmt * fmt * fix docs for ai-transform * fmt * remove broken link * fix docs * fmt * passing tests * adds tests * adds multi item error * add necessary dependencies for better-sqlite-3 * remove libsql and copy over frontend dist * install @libsql/client * adds externals * fmt * use node for building * convert to better-sqlite-3 * improve docker image * fmt * Revert "Migrates to use module federation for plugins (#61)" (#62) This reverts commit 6c48325. * Migrates plugins to use module federation (#63) * Adds module federation support for distributor + transformer plugins (#55) * adds memory bank and plugin loader * adds plugin service * wip * working distributor plugins w/ module federation, some TOODs * working, nice, clean plugin service * fmt * addresses comments * set the correct remotes * update memory bank and documentation * implements transform plugins * update memories * fmt * fmt * fix docs for ai-transform * fmt * remove broken link * fix docs * fmt * passing tests * adds tests * adds multi item error * add necessary dependencies for better-sqlite-3 * remove libsql and copy over frontend dist * install @libsql/client * adds externals * fmt * use node for building * convert to better-sqlite-3 * improve docker image * fmt * migrate to hono and node * clean up * nodemon * fmt * replace bun * fix bun command * fix npm command * fix scripts * npx * correct command * node module hoisting * fix packages * fmt * package.json * wip for good deploy * fmt * normalizes db async * fmt * fix dist * working plugins * fmt
1 parent 00ee01f commit 70426b6

Some content is hidden

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

75 files changed

+7429
-1834
lines changed

Dockerfile

+51-44
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,85 @@
1-
## NOTE
2-
# This Dockerfile builds the frontend and backend separately,
3-
# frontend uses npm and backend requires bun.
4-
# This separation is a temporary solution for a Bun issue with rsbuild,
5-
# see: https://github.com/oven-sh/bun/issues/11628
6-
7-
# Frontend deps & build stage
8-
FROM node:20 as frontend-builder
1+
# Build stage
2+
FROM node:20 AS builder
93
WORKDIR /app
104

11-
# Copy frontend package files
12-
COPY frontend/package.json ./frontend/
13-
14-
# Install frontend dependencies
15-
RUN cd frontend && npm install
16-
17-
# Copy frontend source code
18-
COPY frontend ./frontend
19-
20-
# Build frontend
21-
RUN cd frontend && npm run build
22-
23-
# Backend deps & build stage
24-
FROM oven/bun as backend-builder
25-
WORKDIR /app
5+
# Install build dependencies
6+
RUN apt-get update && \
7+
apt-get install -y --no-install-recommends \
8+
python3 \
9+
make \
10+
g++ \
11+
&& rm -rf /var/lib/apt/lists/* && \
12+
apt-get clean
2613

27-
# Copy backend package files
14+
# Copy package files for dependency installation
2815
COPY package.json ./
16+
COPY frontend/package.json ./frontend/
2917
COPY backend/package.json ./backend/
3018
COPY backend/drizzle.config.ts ./backend/
3119

32-
# Install backend dependencies
33-
RUN cd backend && bun install
20+
# Install dependencies
21+
RUN cd frontend && npm install
22+
RUN cd backend && npm install
3423

35-
# Copy backend source code
24+
# Copy source code after dependency installation
25+
COPY frontend ./frontend
3626
COPY backend ./backend
27+
COPY curate.config.json ./
3728

29+
# Build backend (rspack will copy frontend dist to backend/dist/public)
3830
ENV NODE_ENV="production"
39-
40-
# Build backend
41-
RUN cd backend && bun run build
31+
# Build frontend first since backend depends on it
32+
RUN cd frontend && npm run build
33+
# Then build backend which will copy frontend dist
34+
RUN cd backend && npm run build
4235

4336
# Production stage
44-
FROM oven/bun as production
37+
FROM node:20-slim AS production
4538
WORKDIR /app
4639

47-
# Install LiteFS dependencies
48-
RUN apt-get update -y && apt-get install -y ca-certificates fuse3 sqlite3
40+
# Install LiteFS and runtime dependencies
41+
RUN apt-get update -y && \
42+
apt-get install -y --no-install-recommends \
43+
ca-certificates \
44+
curl \
45+
fuse3 \
46+
sqlite3 \
47+
python3 \
48+
make \
49+
g++ \
50+
&& rm -rf /var/lib/apt/lists/* && \
51+
apt-get clean
4952

5053
# Copy LiteFS binary
5154
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
5255

5356
# Create directories for mounts with correct permissions
5457
RUN mkdir -p /litefs /var/lib/litefs && \
55-
chown -R bun:bun /litefs /var/lib/litefs
58+
chown -R node:node /litefs /var/lib/litefs
5659

5760
# Create volume mount points
58-
# Set environment variables first
5961
ENV DATABASE_URL="file:/litefs/db"
60-
ENV FRONTEND_DIST_PATH="/app/frontend/dist"
6162

62-
# Copy only necessary files from builders
63-
COPY --from=backend-builder --chown=bun:bun /app/package.json ./
64-
COPY --chown=bun:bun curate.config.json ./
63+
# Copy application files
64+
COPY --from=builder --chown=node:node /app/backend/dist ./backend/dist
65+
COPY --from=builder --chown=node:node /app/backend/package.json ./backend/package.json
66+
COPY --from=builder --chown=node:node /app/backend/drizzle.config.ts ./backend/drizzle.config.ts
67+
COPY --from=builder --chown=node:node /app/backend/src ./backend/src
68+
COPY --chown=node:node curate.config.json ./
69+
COPY --chown=node:node package.json ./
6570

66-
COPY --from=frontend-builder --chown=bun:bun /app/frontend/dist ./frontend/dist
67-
COPY --from=backend-builder --chown=bun:bun /app/backend ./backend
71+
# Install production dependencies
72+
RUN cd backend && npm install && npm rebuild better-sqlite3
6873

69-
RUN cd backend && bun install
74+
# Copy LiteFS configuration
75+
COPY --chown=node:node litefs.yml /etc/litefs.yml
7076

7177
# Expose the port
7278
EXPOSE 3000
7379

74-
# Copy LiteFS configuration
75-
COPY --chown=bun:bun litefs.yml /etc/litefs.yml
80+
# Set secure environment defaults
81+
ENV NODE_ENV=production \
82+
NPM_CONFIG_LOGLEVEL=warn
7683

7784
# Start LiteFS (runs app with distributed file system for SQLite)
7885
ENTRYPOINT ["litefs", "mount"]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ bun run dev
120120

121121
This will launch:
122122

123-
- Frontend at http://localhost:5173
124-
- Backend at http://localhost:3000
123+
- Frontend at <http://localhost:5173>
124+
- Backend at <http://localhost:3000>
125125

126126
### Building for production
127127

backend/bun.lock

+1,855
Large diffs are not rendered by default.

backend/bun.lockb

-191 KB
Binary file not shown.

backend/package.json

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
{
22
"name": "@curatedotfun/backend",
33
"version": "0.0.1",
4-
"packageManager": "bun@1.0.27",
5-
"type": "module",
64
"scripts": {
7-
"build": "bun build ./src/index.ts --target=bun --outdir=dist --format=esm --external './src/external' && cp -r src/external dist/external/",
8-
"start": "bun run dist/index.js",
9-
"dev": "bun run --watch src/index.ts",
5+
"build": "rspack build",
6+
"start": "node dist/main.js",
7+
"dev": "NODE_ENV=development nodemon --exec \"rspack build && node dist/main.js\" --watch src",
108
"test": "bun test",
11-
"test:watch": "bun test --watch",
12-
"db:generate": "bun drizzle-kit generate",
13-
"db:migrate": "bun drizzle-kit migrate",
14-
"db:push": "bun drizzle-kit push",
15-
"db:pull": "bun drizzle-kit pull",
16-
"db:check": "bun drizzle-kit check",
17-
"db:up": "bun drizzle-kit up",
18-
"db:studio": "bun drizzle-kit studio"
9+
"test:watch": "npm test --watch",
10+
"db:generate": "drizzle-kit generate",
11+
"db:migrate": "drizzle-kit migrate",
12+
"db:push": "drizzle-kit push",
13+
"db:pull": "drizzle-kit pull",
14+
"db:check": "drizzle-kit check",
15+
"db:up": "drizzle-kit up",
16+
"db:studio": "drizzle-kit studio"
1917
},
2018
"browserslist": {
2119
"production": [
@@ -30,29 +28,33 @@
3028
]
3129
},
3230
"devDependencies": {
31+
"@curatedotfun/types": "^0.0.5",
32+
"@module-federation/node": "^2.6.22",
33+
"@rspack/cli": "latest",
34+
"@types/better-sqlite3": "^7.6.9",
35+
"@types/node": "^20.17.19",
3336
"@types/ora": "^3.2.0",
34-
"bun-types": "^1.1.43",
35-
"drizzle-kit": "^0.30.1",
37+
"concurrently": "^9.1.2",
3638
"jest": "^29.7.0",
3739
"jest-mock-extended": "^4.0.0-beta1",
40+
"nodemon": "^3.1.9",
3841
"ts-jest": "^29.2.5",
3942
"ts-node": "^10.9.1",
40-
"typescript": "^5.3.3"
43+
"typescript": "^5.3.3",
44+
"wait-on": "^8.0.2",
45+
"zod": "^3.22.4"
4146
},
4247
"dependencies": {
43-
"@elysiajs/cors": "^1.2.0",
44-
"@elysiajs/static": "^1.2.0",
45-
"@elysiajs/swagger": "^1.2.0",
46-
"@libsql/client": "^0.14.0",
48+
"@hono/node-server": "^1.8.2",
49+
"@hono/zod-openapi": "^0.9.5",
50+
"@hono/zod-validator": "^0.1.11",
4751
"@notionhq/client": "^2.2.15",
48-
"@types/cors": "^2.8.17",
4952
"agent-twitter-client": "^0.0.16",
50-
"cors": "^2.8.5",
51-
"dotenv": "^16.0.3",
53+
"better-sqlite3": "11.8.1",
54+
"dotenv": "^16.4.7",
55+
"drizzle-kit": "^0.30.1",
5256
"drizzle-orm": "^0.38.3",
53-
"elysia": "^1.2.10",
54-
"elysia-helmet": "^2.0.0",
55-
"express": "^4.18.2",
57+
"hono": "^4.0.5",
5658
"ora": "^8.1.1",
5759
"winston": "^3.17.0",
5860
"winston-console-format": "^1.0.8"

backend/rspack.config.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require("dotenv").config();
2+
const path = require("path");
3+
const { rspack } = require("@rspack/core");
4+
5+
const isProduction = process.env.NODE_ENV === "production";
6+
7+
module.exports = {
8+
entry: "./src/index",
9+
mode: isProduction ? "production" : "development",
10+
target: "async-node",
11+
devtool: "source-map",
12+
externals: {
13+
"better-sqlite3": "commonjs better-sqlite3",
14+
bufferutil: "commonjs bufferutil",
15+
},
16+
output: {
17+
path: path.resolve(__dirname, "dist"),
18+
clean: true,
19+
},
20+
module: {
21+
rules: [
22+
{
23+
test: /\.tsx?$/,
24+
use: "builtin:swc-loader",
25+
exclude: /node_modules/,
26+
},
27+
{
28+
test: /\.md$/,
29+
type: "asset/source",
30+
},
31+
],
32+
},
33+
resolve: {
34+
extensions: [".tsx", ".ts", ".js"],
35+
},
36+
plugins: [
37+
new rspack.CopyRspackPlugin({
38+
patterns: [
39+
{
40+
from: "../frontend/dist",
41+
to: "public",
42+
noErrorOnMissing: true, // Don't error in development when dist doesn't exist
43+
},
44+
],
45+
}),
46+
// new rspack.container.ModuleFederationPlugin({
47+
// name: "host",
48+
// runtimePlugins: [
49+
// require.resolve("@module-federation/node/runtimePlugin"),
50+
// ],
51+
// shared: {
52+
// "@curatedotfun/types": {
53+
// singleton: true,
54+
// eager: true
55+
// },
56+
// }
57+
// })
58+
],
59+
};

0 commit comments

Comments
 (0)