Backend
Application Entry Point#
Location: apps/server/src/main.ts
Startup Sequence:
- Load configuration
- Initialize database
- Run migrations
- Load Becca cache
- Start Express server
- Initialize WebSocket
- Start scheduled tasks
Service Layer#
Located at: apps/server/src/services/
Core Services:
- Notes Management
notes.ts- CRUD operationsnote_contents.ts- Content handlingnote_types.ts- Type-specific logiccloning.ts- Note cloning/multi-parent
- Tree Operations
tree.ts- Tree structure managementbranches.ts- Branch operationsconsistency_checks.ts- Tree integrity
- Search
search/search.ts- Main search enginesearch/expressions/- Search expression parsingsearch/services/- Search utilities
- Sync
sync.ts- Synchronization protocolsync_update.ts- Update handlingsync_mutex.ts- Concurrency control
- Scripting
backend_script_api.ts- Backend script APIscript_context.ts- Script execution context
- Import/Export
import/- Various import formatsexport/- Export to different formatszip.ts- Archive handling
- Security
encryption.ts- Note encryptionprotected_session.ts- Session managementpassword.ts- Password handling
Route Structure#
Located at: apps/server/src/routes/
routes/
├── index.ts # Route registration
├── api/ # REST API endpoints
│ ├── notes.ts
│ ├── branches.ts
│ ├── attributes.ts
│ ├── search.ts
│ ├── login.ts
│ └── ...
└── custom/ # Special endpoints
├── setup.ts
├── share.ts
└── ...API Endpoint Pattern:
router.get('/api/notes/:noteId', (req, res) => {
const noteId = req.params.noteId
const note = becca.getNote(noteId)
res.json(note.getPojoWithContent())
})Middleware#
Key middleware components:
auth.ts- Authenticationcsrf.ts- CSRF protectionrequest_context.ts- Request-scoped dataerror_handling.ts- Error responses