Skip to content

Commit 3ab5871

Browse files
authored
Merge pull request #7 from ManOfTheMask/ManOfTheMask/Add-Database-Basics
ManOfTheMask/Add-Database-Basics
2 parents a3758cb + ab152cb commit 3ab5871

21 files changed

+2159
-354
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pocketbase
77
tsconfig.client.tsbuildinfo
88
tsconfig.server.tsbuildinfo
99
tsconfig.tsbuildinfo
10+
.env

README.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,49 @@ THIS PROJECT IS A WIP UNTIL v1.0 GETS RELEASED
88
### The Plan
99
This is a selfhostable chat app meant for small to medium size groups who want to talk to each other with pgp with the convenience of the encryption being integrated into the chat.
1010

11-
It will use pocketbase to have a portable small db to hold encrypted messages, public keys/users, and chatroom/dm data such as title of chat etc.
11+
It will use mongodb to have a database to hold encrypted messages, public keys/users, and chatroom/dm data such as title of chat etc.
1212
It will use openpgp.js mainly on the client side to handle encryption/decryption, private keys, and other sensitive stuff while the server side will only have functions need for connecting people through websockets, db handling, security challenges with public key etc.
1313
It will also have tailwindcss for styling and expressjs for a minimal webserver with express handlebars for html templating and all while using typescript
1414

15-
Planned db schema:
16-
Chatroom:
17-
chatroom_name: string (unique)
18-
creator: string
19-
messages: list of dicts (each dict contains content, username, date)
20-
list of members: list of public keys
21-
dm: boolean (true if direct message, false if group chat)
22-
23-
User:
24-
public_key: string
25-
dms: list of chatroom names (for direct messages)
26-
groups: list of group names (for group chats)
27-
friends: list of usernames
28-
created_at: datetime
29-
updated_at: datetime
30-
15+
### Planned Database Schema
16+
17+
#### User
18+
- `username`: string (unique)
19+
- `public_key`: string (unique, stored server-side, served to clients for encryption)
20+
- `created_at`: datetime
21+
- `updated_at`: datetime
22+
23+
#### Chatroom
24+
- `name`: string (unique)
25+
- `creator_id`: int (foreign key to User)
26+
- `type`: enum (`dm`, `group`)
27+
- `created_at`: datetime
28+
- `updated_at`: datetime
29+
30+
#### Membership
31+
- `user_id`: int (foreign key to User)
32+
- `chatroom_id`: int (foreign key to Chatroom)
33+
- `joined_at`: datetime
34+
35+
#### Message
36+
- `chatroom_id`: int (foreign key to Chatroom)
37+
- `sender_id`: int (foreign key to User)
38+
- `content`: string (encrypted)
39+
- `created_at`: datetime
40+
41+
#### Friendship
42+
- `user_id`: int (foreign key to User)
43+
- `friend_id`: int (foreign key to Other User)
44+
- `created_at`: datetime
45+
46+
**Notes:**
47+
- The `public_key` field in the User table is stored server-side and served to clients, allowing users to encrypt messages for others and decrypt messages client-side.
48+
- Membership table efficiently manages users in chatrooms (many-to-many).
49+
- Friendship table manages user connections.
50+
- All sensitive data (messages, public keys) remain encrypted or are only public keys.
51+
- Chatroom type uses an enum for clarity (`dm` for direct message, `group` for group chat).
52+
- Timestamps help with auditing and ordering.
53+
- We are using mongodb now because pocketbase has unclear documentation and I am not spending a century learning that
3154

3255
### How To Run
3356
Run "npm install"

0 commit comments

Comments
 (0)