Skip to content

Commit 472acb4

Browse files
committed
adds missing doc files and updates database schema
1 parent 32c28e6 commit 472acb4

File tree

2 files changed

+81
-29
lines changed

2 files changed

+81
-29
lines changed

api/README.md

+81-29
Original file line numberDiff line numberDiff line change
@@ -246,51 +246,103 @@ The system also provides a browser-friendly search interface at /directory/searc
246246
![Micro Plugin Publisher Search](../docs/assets/micro-plugin-publisher-search-page.jpg)
247247

248248

249-
### Database Schema
249+
# Database Schema and Storage
250250

251-
The SQLite database contains three main tables:
251+
The system uses a combination of SQLite databases (via Durable Objects) and Cloudflare KV for data management. Here's the current structure:
252+
253+
## Database Schema
254+
255+
### Plugin Registry (PluginRegistryDO)
252256

253257
```sql
254258
-- Plugin metadata table
255259
CREATE TABLE plugins (
256-
id INTEGER PRIMARY KEY AUTOINCREMENT,
257-
author TEXT NOT NULL,
258-
slug TEXT NOT NULL,
259-
name TEXT NOT NULL,
260-
short_description TEXT,
261-
version TEXT NOT NULL,
262-
download_count INTEGER DEFAULT 0,
263-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
264-
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
265-
UNIQUE(author, slug)
260+
id INTEGER PRIMARY KEY AUTOINCREMENT,
261+
author TEXT NOT NULL,
262+
slug TEXT NOT NULL,
263+
name TEXT NOT NULL,
264+
short_description TEXT,
265+
version TEXT NOT NULL,
266+
download_count INTEGER DEFAULT 0,
267+
activation_count INTEGER DEFAULT 0,
268+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
269+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
270+
icons_1x TEXT,
271+
icons_2x TEXT,
272+
banners_high TEXT,
273+
banners_low TEXT,
274+
UNIQUE(author, slug)
266275
);
267276

268277
-- Plugin tags for search
269278
CREATE TABLE plugin_tags (
270-
plugin_id INTEGER,
271-
tag TEXT NOT NULL,
272-
FOREIGN KEY(plugin_id) REFERENCES plugins(id),
273-
PRIMARY KEY(plugin_id, tag)
279+
plugin_id INTEGER,
280+
tag TEXT NOT NULL,
281+
FOREIGN KEY(plugin_id) REFERENCES plugins(id),
282+
PRIMARY KEY(plugin_id, tag)
274283
);
275284

276-
-- Download tracking queue
277-
CREATE TABLE download_queue (
278-
id INTEGER PRIMARY KEY AUTOINCREMENT,
279-
plugin_id INTEGER,
280-
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
281-
processed BOOLEAN DEFAULT FALSE,
282-
FOREIGN KEY(plugin_id) REFERENCES plugins(id)
285+
-- Authors table
286+
CREATE TABLE authors (
287+
id INTEGER PRIMARY KEY AUTOINCREMENT,
288+
username TEXT NOT NULL UNIQUE,
289+
email TEXT,
290+
avatar_url TEXT,
291+
bio TEXT,
292+
member_since TIMESTAMP,
293+
website TEXT,
294+
twitter TEXT,
295+
github TEXT,
296+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
297+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
283298
);
284299
```
285300

286-
### Initial Database Setup
301+
### User Authentication (UserAuthDO)
287302

288-
After deploying, you'll need to migrate your existing plugins to the SQLite database:
303+
```sql
304+
-- Users table
305+
CREATE TABLE users (
306+
id INTEGER PRIMARY KEY AUTOINCREMENT,
307+
username TEXT NOT NULL UNIQUE,
308+
email TEXT NOT NULL,
309+
github_username TEXT,
310+
key_id TEXT NOT NULL UNIQUE,
311+
key_hash TEXT NOT NULL,
312+
invite_code_used TEXT NOT NULL,
313+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
314+
last_key_rotation TIMESTAMP DEFAULT CURRENT_TIMESTAMP
315+
);
289316

290-
```bash
291-
# Migrate existing data from R2 to SQLite
292-
curl -X POST https://your-worker.workers.dev/migrate-data \
293-
-H "Authorization: Bearer YOUR_API_KEY"
317+
-- Key roll verification table
318+
CREATE TABLE key_roll_verifications (
319+
id INTEGER PRIMARY KEY AUTOINCREMENT,
320+
username TEXT NOT NULL,
321+
verification_token TEXT NOT NULL UNIQUE,
322+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
323+
expires_at TIMESTAMP NOT NULL,
324+
used BOOLEAN DEFAULT 0,
325+
FOREIGN KEY(username) REFERENCES users(username)
326+
);
327+
```
328+
329+
## Download Tracking
330+
331+
The system uses Cloudflare KV for download and activation tracking:
332+
- Each download/activation is recorded in KV with a 1-hour expiration
333+
- A scheduled worker processes the queue periodically and updates the database
334+
- Rate limiting is enforced at 5 downloads per hour per IP/plugin combination
335+
- The system maintains consistency through atomic updates via Durable Objects
336+
337+
## Search Performance
338+
339+
The following indexes are maintained for optimal performance:
340+
341+
```sql
342+
CREATE INDEX idx_plugins_search ON plugins(name, short_description);
343+
CREATE INDEX idx_plugins_downloads ON plugins(download_count DESC);
344+
CREATE INDEX idx_authors_username ON authors(username);
345+
CREATE INDEX idx_users_key_id ON users(key_id);
294346
```
295347

296348
### Download Tracking

docs/assets/roll-key-screenshot.jpg

464 KB
Loading

0 commit comments

Comments
 (0)