Skip to content

Commit 9309cc8

Browse files
committed
chore: wip.
1 parent f4ef381 commit 9309cc8

125 files changed

Lines changed: 26888 additions & 356 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
backend-tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v5
17+
with:
18+
enable-cache: true
19+
20+
- name: Set up Python
21+
run: uv python install 3.12
22+
23+
- name: Install dependencies
24+
run: |
25+
cd backend
26+
uv venv
27+
uv pip install -r requirements.txt -r requirements-dev.txt
28+
29+
- name: Run tests
30+
run: |
31+
cd backend
32+
source .venv/bin/activate
33+
pytest
34+
35+
frontend-tests:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 20
44+
cache: 'npm'
45+
cache-dependency-path: frontend/package-lock.json
46+
47+
- name: Install dependencies
48+
run: |
49+
cd frontend
50+
npm ci
51+
npm install -D vitest jsdom @testing-library/react @testing-library/jest-dom @testing-library/dom
52+
53+
- name: Lint
54+
run: |
55+
cd frontend
56+
npm run lint
57+
58+
- name: Run tests
59+
run: |
60+
cd frontend
61+
npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ dist/
88
.env
99
*.egg-info/
1010
.DS_Store
11+
.venv*
12+
*.coverage
13+
.claude

CLAUDE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
JustWiki is a lightweight, self-hosted wiki for small teams. Markdown-first, single SQLite file, no external dependencies. Backend is Python/FastAPI, frontend is React/Vite.
8+
9+
## Development Commands
10+
11+
```bash
12+
make setup # First-time: install deps (uv + npm), create .env from .env.example
13+
make dev # Start backend (port 8000) + frontend (port 5173) concurrently
14+
make dev-backend # Backend only: uvicorn with --reload on port 8000
15+
make dev-frontend # Frontend only: Vite dev server on port 5173
16+
make build # Build frontend for production (vite build)
17+
make test # Run all backend and frontend tests
18+
make test-backend # Run backend tests with pytest
19+
make test-frontend # Run frontend tests with vitest
20+
make lint # Run frontend linting
21+
make backup # Copy SQLite DB to backup/ with timestamp
22+
```
23+
24+
Frontend linting: `cd frontend && npm run lint`
25+
Backend tests location: `backend/tests/`
26+
Frontend tests location: `frontend/src/**/*.test.{js,jsx}`
27+
28+
## Architecture
29+
30+
### Backend (`backend/app/`)
31+
32+
- **Framework**: FastAPI (async), aiosqlite for SQLite access (WAL mode)
33+
- **Entry**: `main.py` — app creation, CORS, lifespan hooks, router mounting
34+
- **Auth**: `auth.py` — JWT tokens in httpOnly cookies, bcrypt passwords, rate-limited login
35+
- **Config**: `config.py` — Pydantic Settings reading from `.env`
36+
- **Database**: `database.py` — schema DDL, migrations, FTS5 search index setup
37+
- **Routers**: One file per domain — `pages.py`, `search.py`, `media.py`, `versions.py`, `tags.py`, `templates.py`, `users.py`, `diagrams.py`, `comments.py`, `bookmarks.py`, `activity.py`, `backup.py`, `export.py`, `auth_router.py`
38+
- **Services**: `search.py` (FTS5 indexing, CJK segmentation), `wikilink.py` (backlink tracking)
39+
- **Deps**: Python 3.11+, managed with `uv`
40+
41+
### Frontend (`frontend/src/`)
42+
43+
- **Framework**: React 19, Vite 8, Tailwind CSS 4
44+
- **State**: Zustand stores in `store/` — one per domain (useAuth, usePages, useTags, useBookmarks, useTheme, useSearch, useActivity)
45+
- **API client**: `api/client.js` — Axios instance with interceptors, 401 redirect to login
46+
- **Routing**: React Router v7 in `App.jsx`, PrivateRoute wrapper for auth
47+
- **Keyboard shortcuts**: `hooks/useKeyboard.jsx` (Ctrl+E edit, Ctrl+K search, etc.)
48+
49+
### Editor and Viewer (dual rendering paths)
50+
51+
These are separate systems with independent rendering logic — changes to one do not affect the other. **Always verify both when modifying markdown-related features.**
52+
53+
- **Editor**: `components/Editor/Editor.jsx` — Milkdown (ProseMirror-based) WYSIWYG editor with slash commands, wikilink autocomplete `[[page]]`, image paste upload, GFM support
54+
- **Viewer**: `components/Viewer/MarkdownViewer.jsx` — Custom markdown-to-HTML parser (not a library). Handles Mermaid diagrams, KaTeX math (`$$...$$`), callout blocks (`:::info`), wikilinks, tables, nested lists. Sanitized with DOMPurify.
55+
56+
### Database (SQLite, single file at `data/just-wiki.db`)
57+
58+
Key tables: `users`, `pages` (with `parent_id` hierarchy and `slug` URL), `page_versions`, `tags`, `page_tags`, `backlinks`, `templates`, `media`, `diagrams`, `comments`, `bookmarks`, `activity_log`. FTS5 virtual table `search_index` for full-text search with CJK support.
59+
60+
Schema auto-migrates on startup in `database.py`.
61+
62+
### Wikilinks
63+
64+
Format: `[[slug]]` or `[[slug|display text]]`. Parsed on both backend (backlink tracking in `backlinks` table via `services/wikilink.py`) and frontend (navigation in viewer). Slug generation uses `pypinyin` for Chinese characters.
65+
66+
## API Structure
67+
68+
All endpoints under `/api/`. Vite dev server proxies `/api` to `localhost:8000`. Key routes:
69+
70+
- Pages CRUD: `/api/pages`, `/api/pages/{slug}`, `/api/pages/tree`, `/api/pages/graph`
71+
- Versions: `/api/pages/{slug}/versions`, `/api/pages/{slug}/diff/{v1}/{v2}`
72+
- Search: `/api/search?q=...`
73+
- Media upload: `POST /api/media/upload` (20MB limit)
74+
- Auth: `/api/auth/login`, `/api/auth/me`
75+
76+
## Themes
77+
78+
Multiple built-in themes (light, dark, lavender, forest, etc.) via CSS variables in `frontend/src/index.css`, persisted with Zustand store `useTheme.js`.
79+
80+
## Deployment
81+
82+
Docker Compose: backend (uvicorn, port 8000) + frontend (nginx, port 3000). Shared `./data` volume. All config in `.env`.

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: dev dev-backend dev-frontend build backup clean
1+
.PHONY: dev dev-backend dev-frontend build backup clean test test-backend test-frontend lint
22

33
dev:
44
@echo "Starting backend and frontend..."
@@ -25,6 +25,17 @@ clean:
2525
rm -rf frontend/dist
2626
@echo "Cleaned"
2727

28+
test: test-backend test-frontend
29+
30+
test-backend:
31+
cd backend && source .venv/bin/activate && python -m pytest
32+
33+
test-frontend:
34+
cd frontend && npm test
35+
36+
lint:
37+
cd frontend && npm run lint
38+
2839
docker-up:
2940
docker-compose up -d
3041

@@ -33,9 +44,9 @@ docker-down:
3344

3445
setup:
3546
@echo "Setting up backend..."
36-
cd backend && uv venv && source .venv/bin/activate && uv pip install -r requirements.txt
47+
cd backend && uv venv && source .venv/bin/activate && uv pip install -r requirements.txt -r requirements-dev.txt
3748
@echo "Setting up frontend..."
38-
cd frontend && npm install
49+
cd frontend && npm install && npm install -D vitest jsdom @testing-library/react @testing-library/jest-dom @testing-library/dom
3950
@echo "Creating .env..."
4051
cp -n .env.example .env || true
4152
@echo "Done! Run 'make dev' to start."

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ A lightweight, self-hosted wiki for small teams. Just clone, run, and write.
1313
- **Full-text search** — FTS5 powered, with optional AI Q&A (Gemini)
1414
- **Version history** — page revisions with diff view
1515
- **Draw.io integration** — embedded diagram editor
16-
- **Themes**multiple built-in themes
16+
- **Themes**9 built-in color palettes ([preview](#themes))
1717
- **PWA ready** — installable on mobile and desktop
1818
- **Docker support**`docker-compose up` and done
1919

20+
## Themes
21+
22+
<p align="center">
23+
<img src="docs/images/themes.png" alt="9 built-in themes: Light, Dark, Lavender, Forest, Rose, Ocean, Sand, Sunset, Nord" width="100%">
24+
</p>
25+
26+
Nine curated palettes ship out of the box — **Light, Dark, Lavender, Forest, Rose, Ocean, Sand, Sunset, Nord**. Switch any time from the top-right theme picker; your choice is remembered per browser.
27+
2028
## Tech Stack
2129

2230
| Layer | Stack |
@@ -77,6 +85,32 @@ make docker-down # docker-compose down
7785
make setup # First-time setup (install deps, create .env)
7886
```
7987

88+
## Slash Commands
89+
90+
<p align="center">
91+
<img src="docs/images/slash-commands.png" alt="Type / in the editor to open the slash command menu" width="80%">
92+
</p>
93+
94+
In the editor, type `/` to open the slash menu. You can filter by typing after the slash.
95+
96+
| Command | Description |
97+
| ------- | ----------- |
98+
| `/h1` | Heading 1 — big section heading |
99+
| `/h2` | Heading 2 — medium section heading |
100+
| `/h3` | Heading 3 — small section heading |
101+
| `/bullet` | Bullet List — unordered list |
102+
| `/ordered` | Ordered List — numbered list |
103+
| `/quote` | Blockquote — quote block |
104+
| `/code` | Code Block — code snippet |
105+
| `/hr` | Divider — horizontal rule |
106+
| `/callout-info` | Info Callout — `:::info` block |
107+
| `/callout-warning` | Warning Callout — `:::warning` block |
108+
| `/callout-tip` | Tip Callout — `:::tip` block |
109+
| `/callout-danger` | Danger Callout — `:::danger` block |
110+
| `/mermaid` | Mermaid Diagram — insert mermaid chart |
111+
| `/math` | Math Formula — KaTeX math block |
112+
| `/drawio` | Draw.io Diagram — insert Draw.io embed |
113+
80114
## Project Structure
81115

82116
```

0 commit comments

Comments
 (0)