Skip to content

Commit e95f1d9

Browse files
authored
Merge pull request #5 from arunavo4/ray/migrate-project-to-bun-with-redis-and-sqlite
Migrate project to Bun runtime
2 parents 38206e7 + 94aff30 commit e95f1d9

File tree

7 files changed

+56
-54
lines changed

7 files changed

+56
-54
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ Easily configure your GitHub and Gitea connections, set up automatic mirroring s
6363

6464
See the [Quick Start Guide](docs/quickstart.md) for detailed instructions on getting up and running quickly.
6565

66-
### Prerequisites
66+
-### Prerequisites
6767

68-
- Node.js 22 or later
68+
- Bun 1.2.9 or later
6969
- A GitHub account with a personal access token
7070
- A Gitea instance with an access token
7171

@@ -359,7 +359,7 @@ docker compose -f docker-compose.dev.yml up -d
359359
## Technologies Used
360360
361361
- **Frontend**: Astro, React, Shadcn UI, Tailwind CSS v4
362-
- **Backend**: Node.js
362+
- **Backend**: Bun
363363
- **Database**: SQLite (default) or PostgreSQL
364364
- **Caching/Queue**: Redis
365365
- **API Integration**: GitHub API (Octokit), Gitea API

package.json

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@
33
"type": "module",
44
"version": "1.0.0",
55
"engines": {
6-
"node": ">=22.0.0"
6+
"bun": ">=1.2.9"
77
},
88
"scripts": {
99
"setup": "pnpm install && pnpm manage-db init",
10-
"dev": "astro dev",
11-
"dev:clean": "pnpm cleanup-db && pnpm manage-db init && astro dev",
12-
"build": "astro build",
10+
"dev": "bunx astro dev",
11+
"dev:clean": "pnpm cleanup-db && pnpm manage-db init && bunx astro dev",
12+
"build": "bunx astro build",
1313
"cleanup-db": "rm -f gitea-mirror.db data/gitea-mirror.db",
14-
"manage-db": "tsx scripts/manage-db.ts",
15-
"init-db": "tsx scripts/manage-db.ts init",
16-
"check-db": "tsx scripts/manage-db.ts check",
17-
"fix-db": "tsx scripts/manage-db.ts fix",
18-
"reset-users": "tsx scripts/manage-db.ts reset-users",
19-
"preview": "astro preview",
20-
"start": "node dist/server/entry.mjs",
21-
"start:fresh": "pnpm cleanup-db && pnpm manage-db init && node dist/server/entry.mjs",
22-
"test": "vitest run",
23-
"test:watch": "vitest",
24-
"astro": "astro"
14+
"manage-db": "bun scripts/manage-db.ts",
15+
"init-db": "bun scripts/manage-db.ts init",
16+
"check-db": "bun scripts/manage-db.ts check",
17+
"fix-db": "bun scripts/manage-db.ts fix",
18+
"reset-users": "bun scripts/manage-db.ts reset-users",
19+
"preview": "bunx astro preview",
20+
"start": "bun dist/server/entry.mjs",
21+
"start:fresh": "pnpm cleanup-db && pnpm manage-db init && bun dist/server/entry.mjs",
22+
"test": "bunx vitest run",
23+
"test:watch": "bunx vitest",
24+
"astro": "bunx astro"
2525
},
2626
"dependencies": {
2727
"@astrojs/mdx": "^4.2.6",
2828
"@astrojs/node": "^9.2.1",
2929
"@astrojs/react": "^4.2.7",
30-
"@libsql/client": "^0.15.4",
3130
"@octokit/rest": "^21.1.1",
3231
"@radix-ui/react-avatar": "^1.1.4",
3332
"@radix-ui/react-checkbox": "^1.1.5",
@@ -54,7 +53,6 @@
5453
"cmdk": "^1.1.1",
5554
"drizzle-orm": "^0.41.0",
5655
"fuse.js": "^7.1.0",
57-
"ioredis": "^5.6.1",
5856
"jsonwebtoken": "^9.0.2",
5957
"lucide-react": "^0.488.0",
6058
"next-themes": "^0.4.6",
@@ -73,12 +71,10 @@
7371
"@testing-library/jest-dom": "^6.6.3",
7472
"@testing-library/react": "^16.3.0",
7573
"@types/bcryptjs": "^3.0.0",
76-
"@types/better-sqlite3": "^7.6.13",
7774
"@types/jsonwebtoken": "^9.0.9",
7875
"@types/superagent": "^8.1.9",
7976
"@types/uuid": "^10.0.0",
8077
"@vitejs/plugin-react": "^4.4.0",
81-
"better-sqlite3": "^9.6.0",
8278
"jsdom": "^26.1.0",
8379
"tsx": "^4.19.3",
8480
"vitest": "^3.1.1"

src/content/docs/architecture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ The application is built using:
2222
- <span class="font-semibold text-foreground">React</span>: Component library for interactive UI elements
2323
- <span class="font-semibold text-foreground">Shadcn UI</span>: UI component library built on Tailwind CSS
2424
- <span class="font-semibold text-foreground">SQLite</span>: Database for storing configuration and state
25-
- <span class="font-semibold text-foreground">Node.js</span>: Runtime environment for the backend
25+
- <span class="font-semibold text-foreground">Bun</span>: Runtime environment for the backend
2626

2727
## Architecture Diagram
2828

2929
```mermaid
3030
graph TD
3131
subgraph "Gitea Mirror"
3232
Frontend["Frontend<br/>(Astro)"]
33-
Backend["Backend<br/>(Node.js)"]
33+
Backend["Backend<br/>(Bun)"]
3434
Database["Database<br/>(SQLite)"]
3535
3636
Frontend <--> Backend
@@ -60,9 +60,9 @@ Key frontend components:
6060
- **Configuration**: Settings for GitHub and Gitea connections
6161
- **Activity Log**: Detailed log of mirroring operations
6262

63-
### Backend (Node.js)
63+
### Backend (Bun)
6464

65-
The backend is built with Node.js and provides API endpoints for the frontend to interact with. It handles:
65+
The backend is built with Bun and provides API endpoints for the frontend to interact with. It handles:
6666

6767
- Authentication and user management
6868
- GitHub API integration

src/content/docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following environment variables can be used to configure Gitea Mirror:
2323

2424
| Variable | Description | Default Value | Example |
2525
|----------|-------------|---------------|---------|
26-
| `NODE_ENV` | Node environment (development, production, test) | `development` | `production` |
26+
| `NODE_ENV` | Runtime environment (development, production, test) | `development` | `production` |
2727
| `DATABASE_URL` | SQLite database URL | `sqlite://data/gitea-mirror.db` | `sqlite://path/to/your/database.db` |
2828
| `JWT_SECRET` | Secret key for JWT authentication | `your-secret-key-change-this-in-production` | `your-secure-random-string` |
2929
| `HOST` | Server host | `localhost` | `0.0.0.0` |

src/content/docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Before you begin, make sure you have:
1616

1717
1. <span class="font-semibold text-foreground">A GitHub account with a personal access token</span>
1818
2. <span class="font-semibold text-foreground">A Gitea instance with an access token</span>
19-
3. <span class="font-semibold text-foreground">Docker and docker-compose (recommended) or Node.js 18+ installed</span>
19+
3. <span class="font-semibold text-foreground">Docker and docker-compose (recommended) or Bun 1.2.9+ installed</span>
2020

2121
## Installation Options
2222

src/lib/db/index.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod";
2-
import { createClient } from "@libsql/client";
3-
import { drizzle } from "drizzle-orm/libsql";
2+
import { Database } from "bun:sqlite";
3+
import { drizzle } from "drizzle-orm/bun-sqlite";
44
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
55

66
import path from "path";
@@ -11,11 +11,24 @@ const dataDir = path.join(process.cwd(), "data");
1111
const dbUrl =
1212
process.env.DATABASE_URL || `file:${path.join(dataDir, "gitea-mirror.db")}`;
1313

14-
// Create a client connection to the database
15-
export const client = createClient({ url: dbUrl });
14+
// Create a SQLite database instance using Bun's native driver
15+
export const sqlite = new Database(dbUrl);
16+
17+
// Simple async wrapper around Bun's SQLite API for compatibility
18+
export const client = {
19+
async execute(sql: string, params?: any[]) {
20+
const stmt = sqlite.query(sql);
21+
if (/^\s*select/i.test(sql)) {
22+
const rows = stmt.all(params ?? []);
23+
return { rows } as { rows: any[] };
24+
}
25+
stmt.run(params ?? []);
26+
return { rows: [] } as { rows: any[] };
27+
},
28+
};
1629

1730
// Create a drizzle instance
18-
export const db = drizzle(client);
31+
export const db = drizzle(sqlite);
1932

2033
// Define the tables
2134
export const users = sqliteTable("users", {

src/lib/redis.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
import Redis from "ioredis";
1+
import { RedisClient } from "bun";
22

33
// Connect to Redis using REDIS_URL environment variable or default to redis://redis:6379
44
// This ensures we have a fallback URL when running with Docker Compose
5-
const redisUrl = process.env.REDIS_URL ?? 'redis://redis:6379';
5+
const redisUrl = process.env.REDIS_URL ?? "redis://redis:6379";
66

77
console.log(`Connecting to Redis at: ${redisUrl}`);
88

99
// Configure Redis client with connection options
10-
const redisOptions = {
11-
retryStrategy: (times: number) => {
12-
// Retry with exponential backoff up to 30 seconds
13-
const delay = Math.min(times * 100, 3000);
14-
console.log(`Redis connection attempt ${times} failed. Retrying in ${delay}ms...`);
15-
return delay;
16-
},
17-
maxRetriesPerRequest: 5,
18-
enableReadyCheck: true,
19-
connectTimeout: 10000,
20-
};
10+
function createClient() {
11+
return new RedisClient(redisUrl, {
12+
autoReconnect: true,
13+
});
14+
}
2115

22-
export const redis = new Redis(redisUrl, redisOptions);
23-
export const redisPublisher = new Redis(redisUrl, redisOptions); // For publishing
24-
export const redisSubscriber = new Redis(redisUrl, redisOptions); // For subscribing
16+
export const redis = createClient();
17+
export const redisPublisher = createClient();
18+
export const redisSubscriber = createClient();
2519

26-
// Log connection events
27-
redis.on('connect', () => console.log('Redis client connected'));
28-
redis.on('error', (err) => console.error('Redis client error:', err));
29-
redis.on('ready', () => console.log('Redis client ready'));
30-
redis.on('reconnecting', () => console.log('Redis client reconnecting...'));
20+
redis.onconnect = () => console.log("Connected to Redis server");
21+
redis.onclose = (err) => {
22+
if (err) console.error("Disconnected from Redis server:", err);
23+
};

0 commit comments

Comments
 (0)