Skip to content

Commit b97aef7

Browse files
committed
refactor: migrate from sql.js to Redis for data storage
- Removed sql.js dependency and related SQLite database logic. - Integrated Redis for storing statistics and ratings, updating relevant functions in db.ts. - Updated architecture documentation and README to reflect the new storage solution. - Adjusted .gitignore to remove SQLite data references.
1 parent 421fabc commit b97aef7

File tree

7 files changed

+139
-141
lines changed

7 files changed

+139
-141
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
# production
2121
/build
2222

23-
# sqlite data
24-
/data
25-
2623
# misc
2724
.DS_Store
2825
*.pem

ARCHITECTURE.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LexPlain is a Next.js 16 application with App Router, supporting English and Sim
1414
| UI | React 19, Tailwind CSS 4, lucide-react |
1515
| i18n | next-intl |
1616
| AI | JoyAI (OpenAI-compatible API via `openai` SDK) |
17-
| Storage | sql.js (SQLite in-memory/file for stats) |
17+
| Storage | Redis (stats: analyses count, ratings count/sum/positive) |
1818

1919
## Directory Structure
2020

@@ -48,16 +48,14 @@ LexPlain/
4848
│ │ ├── request.ts # getRequestConfig (messages, locale)
4949
│ │ └── routing.ts # locales, defaultLocale, prefix
5050
│ ├── lib/
51-
│ │ ├── db.ts # sql.js: stats, recordAnalysis, recordRating
51+
│ │ ├── db.ts # Redis: stats, recordAnalysis, recordRating
5252
│ │ └── utils.ts # cn, prompts, JoyAIFetch, parseJoyAIJson
5353
│ ├── types/
5454
│ │ ├── index.ts # Risk, Clause, AnalysisResult
55-
│ │ └── sql.js.d.ts
5655
│ └── proxy.ts # next-intl middleware (locale routing)
5756
├── messages/
5857
│ ├── en.json
5958
│ └── zh-CN.json
60-
├── data/ # sql.js DB file (lexplain.db)
6159
├── next.config.ts
6260
├── package.json
6361
└── tsconfig.json
@@ -118,7 +116,7 @@ User question → Results page → POST /api/ask
118116
## Storage & Privacy
119117

120118
- **Documents**: Not stored. User input and AI output stay in browser `sessionStorage` for the results page.
121-
- **Stats DB**: sql.js SQLite at `data/lexplain.db`
119+
- **Stats**: Redis (env `REDIS_URL`); keys `stats:analyses`, `stats:ratings:*`
122120
- `analyses`: `id`, `created_at`
123121
- `ratings`: `id`, `score`, `created_at`
124122

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LexPlain is a web app that helps you understand legal documents in plain languag
1616
- **UI:** React 19, [Tailwind CSS](https://tailwindcss.com) 4, [lucide-react](https://lucide.dev)
1717
- **i18n:** [next-intl](https://next-intl-docs.vercel.app)
1818
- **AI:** JoyAI (OpenAI-compatible API) for analysis and Q&A
19-
- **Storage:** sql.js (SQLite) for stats and ratings
19+
- **Storage:** Redis for stats and ratings (set `REDIS_URL`)
2020

2121
## Getting Started
2222

@@ -56,7 +56,7 @@ Open [http://localhost:3000](http://localhost:3000) in your browser.
5656

5757
- `src/app/` — App Router: `[locale]/` (home, results), `api/` (analyze, ask, rate, stats)
5858
- `src/components/` — Reusable UI (ClauseCard, RiskIndicators, RatingWidget, LocaleSwitcher, HeroTypewriter)
59-
- `src/lib/` — Utilities, AI helpers, DB (sql.js for stats)
59+
- `src/lib/` — Utilities, AI helpers, DB (Redis for stats)
6060
- `src/i18n/` — next-intl config and messages
6161
- `messages/` — Locale JSON files (en, zh-CN)
6262

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"openai": "6.25.0",
2222
"react": "19.2.3",
2323
"react-dom": "19.2.3",
24-
"sql.js": "1.14.0",
24+
"redis": "5.11.0",
2525
"tailwind-merge": "3.5.0",
2626
"typed.js": "3.0.0"
2727
},
@@ -38,7 +38,6 @@
3838
"eslint": "9.39.3",
3939
"eslint-config-next": "16.1.6",
4040
"postcss": "8.5.6",
41-
"radis": "2.0.0",
4241
"tailwindcss": "4.2.1",
4342
"typescript": "5.9.3"
4443
}

pnpm-lock.yaml

Lines changed: 76 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)