This document explains what happens internally when a user performs actions in the system.
- File:
frontend/src/pages/Login.jsx - Function:
handleDemoUser(username)or form submit - Action: Calls
api.login(username)fromfrontend/src/api.js
- Endpoint:
POST /users/login - File:
frontend/src/api.js
- File:
backend/api/server.py - Function:
login(request: LoginRequest) - Line: Around line 140
- File:
backend/security/user.py - Function:
UserManager.get_user_by_username()andUserManager.create_user()
1. User enters username (or clicks demo button)
2. API sends POST to /users/login with username
3. Server checks if user exists in UserManager
4. If new user: generates new User with:
- username
- user_id (random 16 hex chars)
- keypair (public/private keys)
5. User is logged in (stored in session)
6. Returns user object with user_id and public_key
- User session created
- Frontend stores user in localStorage
- File:
frontend/src/pages/Repository.jsx - Function:
handleCommit(e) - Action: Collects file content, message, calls
api.createCommit()
- Endpoint:
POST /repos/{repo_id}/commits - File:
frontend/src/api.js
- File:
backend/api/server.py - Function:
create_commit(repo_id, request: CommitRequest)
Input: { repo_id, user_id, message, files: {filename: content} }
- File:
backend/api/server.py-create_commit()function - Log:
"[CRDT] Checking authorization for {username}" - Logic: Calls
repo.is_authorized(user_id, public_key) - File:
backend/crdt/lww_set.py - Function:
CRDTState.is_authorized() - Logic: Checks if public_key exists in LWWSet
If NOT authorized:
- Returns rejection immediately with
"validation_step": "authorization"
-
File:
backend/api/server.py-create_commit()function -
Log:
"[MERKLE] Creating commit hash" -
Logic:
- For each file: create Blob → compute CID (SHA-256)
- Create Tree with TreeEntry for each file
- Create Commit with:
- tree_cid (from Tree)
- parent_cids (previous commit)
- author (username)
- message
- timestamp
-
Files used:
backend/storage/merkle.py- CID, Blob, Tree, Commit classes
Log: "[MERKLE] Linking to previous commit: {parent_cid}"
-
File:
backend/api/server.py-create_commit()function -
Log:
"[SMPP] Signing commit" -
Logic:
- Create SMPPRecord with:
- repo_id
- commit_cid
- crdt_state_cid
- timestamp
- Sign using user's keypair:
user.keypair.sign(record_bytes)
- Create SMPPRecord with:
-
Files used:
backend/security/smpp.py- SMPPRecord classbackend/security/crypto.py- KeyPair.sign()
- File:
backend/api/server.py-create_commit()function - Log:
"[SMPP] Verifying signature" - Logic: Call
user.keypair.verify(record_bytes, signature)
Log: "[SMPP] Validation: VALID" or "[SMPP] Validation: REJECTED"
- File:
backend/api/server.py-create_commit()function - Logic: Save commit to
repo.commitsdict with:- cid, author, author_id, message, timestamp, parent_cids, signature
{
"status": "accepted",
"cid": "...",
"smpp_valid": true,
"logs": ["[USER]", "[CRDT]", "[MERKLE]", "[SMPP]"]
}- File:
frontend/src/pages/Dashboard.jsx - Function:
handleSync() - Action: Calls
api.sync(repoId, userId)
- Endpoint:
POST /repos/{repo_id}/sync
- File:
backend/api/server.py - Function:
sync_with_peers(repo_id, request)
- File:
backend/api/server.py - Logic: Access
state.peers(simulated peers list) - Peers defined in:
ServerState._create_simulated_peers() - File:
backend/api/server.py(ServerState class)
For each online peer (Peer A, Peer B):
- Log:
"[SYNC] Fetching from {peer_name}" - Log:
"[SYNC] Validating via SMPP..." - Log:
"[SYNC] CRDT merge complete"
These are simulated activities - no actual network calls.
- File:
backend/api/server.py - Returns list of peer activities with timestamps
{
"status": "synced",
"logs": [
{"peer": "Peer A", "action": "[SYNC] Fetching from Peer A", "timestamp": ...},
{"peer": "Peer A", "action": "[SYNC] Validating via SMPP...", "timestamp": ...},
{"peer": "Peer A", "action": "[SYNC] CRDT merge complete", "timestamp": ...},
{"peer": "Peer B", "action": "..."}
]
}- File:
frontend/src/pages/Repository.jsx - Function:
handleAddCollaborator(targetUserId)
- Endpoint:
POST /repos/{repo_id}/collaborators
- File:
backend/api/server.py - Function:
add_collaborator(repo_id, request)
- Check if requester is authorized (via CRDT)
- Get target user from UserManager
- Call
repo.add_collaborator(user_id, public_key) - CRDT: Adds public_key to LWWSet with timestamp
- File:
backend/crdt/lww_set.py - Function:
CRDTState.authorize(public_key)
Where used:
- Authorization checking in commit flow
- Adding collaborators
- File:
backend/crdt/lww_set.py
Purpose: Manage authorized users per repository
Where used:
- Creating SMPP record before commit
- Signing record with user's keypair
- Verifying signature
- Files:
backend/security/smpp.py,backend/api/server.py
Purpose: Ensure commit authenticity and prevent tampering
Where used:
- Creating Blob from file content
- Creating Tree from entries
- Creating Commit with parent references
- Computing CIDs (content hashes)
- File:
backend/storage/merkle.py
Purpose: Content-addressable version storage
Where used:
- Sync with peers endpoint
- Display in Dashboard
- File:
backend/api/server.py(ServerState class)
Purpose: Demonstrate P2P sync concept (not real networking)
| Component | File | Key Functions |
|---|---|---|
| Login | backend/security/user.py |
create_user(), login() |
| Authorization | backend/crdt/lww_set.py |
is_authorized(), authorize() |
| Commit Storage | backend/storage/merkle.py |
Commit(), CID.from_data() |
| Signing | backend/security/crypto.py |
KeyPair.sign(), verify() |
| SMPP | backend/security/smpp.py |
SMPPRecord.to_bytes() |
| API | backend/api/server.py |
create_commit(), sync_with_peers() |
| Frontend | frontend/src/pages/Repository.jsx |
handleCommit(), handleSync() |