@@ -170,88 +170,57 @@ If you prefer to install PostgreSQL locally instead of Docker:
170170
171171## API Endpoints
172172
173- 📚 ** Full API documentation with interactive examples available at [ https://api.typelets.com/docs ] ( https://api.typelets.com/docs ) ** (Swagger/OpenAPI)
173+ 📚 ** Complete API documentation with interactive examples: [ https://api.typelets.com/docs ] ( https://api.typelets.com/docs ) ** (Swagger/OpenAPI)
174174
175- ### Public Endpoints
176-
177- - ` GET / ` - API information and health status
178- - ` GET /health ` - Enhanced health check with system status
179- - ` GET /metrics ` - Prometheus metrics endpoint for Grafana (requires Basic Auth)
180- - ` GET /ready ` - Readiness probe for container orchestration
181- - ` GET /live ` - Liveness probe for container orchestration
182- - ` GET /websocket/status ` - WebSocket server status and statistics
183-
184- ### Authentication
175+ The API provides comprehensive REST endpoints for:
185176
186- All ` /api/* ` endpoints require authentication via Bearer token in the Authorization header.
177+ - ** Users** - Profile management and account deletion
178+ - ** Folders** - Hierarchical folder organization with nested support
179+ - ** Notes** - Full CRUD with encryption support, pagination, filtering, and search
180+ - ** File Attachments** - Encrypted file uploads and downloads
181+ - ** Code Execution** - Secure Judge0 API proxy for running code in multiple languages
182+ - ** Health & Metrics** - System health checks and Prometheus metrics
187183
188- ### Users
189-
190- - ` GET /api/users/me ` - Get current user profile
191- - ` DELETE /api/users/me ` - Delete user account
192-
193- ### Folders
184+ ### Public Endpoints
194185
195- - ` GET /api/folders ` - List all folders
196- - ` POST /api/folders ` - Create new folder
197- - ` GET /api/folders/:id ` - Get folder details
198- - ` PUT /api/folders/:id ` - Update folder
199- - ` DELETE /api/folders/:id ` - Delete folder
200- - ` POST /api/folders/:id/reorder ` - Reorder folder position
186+ | Endpoint | Description |
187+ | ----------------------- | ---------------------------------------- |
188+ | ` GET / ` | API information and version |
189+ | ` GET /health ` | Enhanced health check with system status |
190+ | ` GET /metrics ` | Prometheus metrics (requires Basic Auth) |
191+ | ` GET /ready ` | Readiness probe for orchestration |
192+ | ` GET /live ` | Liveness probe for orchestration |
193+ | ` GET /websocket/status ` | WebSocket server statistics |
201194
202- ### Notes
195+ ### Authentication
203196
204- - ` GET /api/notes ` - List notes (with pagination and filtering)
205- - ` POST /api/notes ` - Create new note
206- - ` GET /api/notes/:id ` - Get note details
207- - ` PUT /api/notes/:id ` - Update note
208- - ` DELETE /api/notes/:id ` - Delete note (move to trash)
209- - ` DELETE /api/notes/empty-trash ` - Permanently delete trashed notes
210- - ` POST /api/notes/:id/star ` - Star/unstar a note
211- - ` POST /api/notes/:id/restore ` - Restore note from trash
212- - ` POST /api/notes/:id/hide ` - Hide a note
213- - ` POST /api/notes/:id/unhide ` - Unhide a note
197+ All ` /api/* ` endpoints require authentication via Bearer token:
214198
215- ### File Attachments
199+ ```
200+ Authorization: Bearer <clerk_jwt_token>
201+ ```
216202
217- - ` POST /api/notes/:noteId/files ` - Upload file attachment
218- - ` GET /api/notes/:noteId/files ` - List note attachments
219- - ` GET /api/files/:id ` - Get file details
220- - ` DELETE /api/files/:id ` - Delete file attachment
203+ ### Interactive Documentation
221204
222- ### Code Execution (requires Judge0 API key)
205+ Visit the Swagger UI at [ /docs ] ( https://api.typelets.com/docs ) for:
223206
224- - ` POST /api/code/execute ` - Submit code for execution
225- - ` GET /api/code/status/:token ` - Get execution status and results
226- - ` GET /api/code/languages ` - Get supported programming languages
227- - ` GET /api/code/health ` - Check Judge0 service connectivity
207+ - Complete endpoint reference with request/response schemas
208+ - Interactive "Try it out" functionality
209+ - Example requests and responses
210+ - Schema definitions and validation rules
228211
229212### WebSocket Real-time Sync
230213
231- The API provides real-time synchronization via WebSocket connection at ` ws://localhost:3000 ` (or your configured port).
232-
233- ** Connection Flow:**
214+ Connect to ` ws://localhost:3000 ` (or your deployment URL) for real-time synchronization.
234215
235- 1 . Connect to WebSocket endpoint
236- 2 . Send authentication message with Clerk JWT token
237- 3 . Join/leave specific notes for real-time updates
238- 4 . Receive real-time sync messages for notes and folders
216+ ** Features:**
239217
240- ** Message Types:**
218+ - JWT authentication required
219+ - Real-time note and folder updates
220+ - Rate limiting (300 msg/min per connection)
221+ - Connection limits (20 connections per user)
241222
242- - ` auth ` - Authenticate with JWT token
243- - ` ping ` /` pong ` - Heartbeat messages
244- - ` join_note ` /` leave_note ` - Subscribe/unsubscribe from note updates
245- - ` note_update ` - Real-time note content changes and folder moves
246- - ` note_created ` /` note_deleted ` - Note lifecycle events
247- - ` folder_created ` /` folder_updated ` /` folder_deleted ` - Folder events
248-
249- ** Security Features:**
250-
251- - JWT authentication required for all operations
252- - Authorization checks ensure users only access their own notes/folders
253- - Rate limiting (configurable, default: 300 messages per minute per connection)
254- - Connection limits (configurable, default: 20 connections per user)
223+ ** Message types:** ` auth ` , ` ping ` /` pong ` , ` join_note ` /` leave_note ` , ` note_update ` , ` note_created ` /` note_deleted ` , ` folder_created ` /` folder_updated ` /` folder_deleted `
255224
256225## Database Schema
257226
@@ -311,8 +280,27 @@ The application uses the following main tables:
311280
312281## Monitoring with Prometheus & Grafana
313282
283+ ⚠️ ** Monitoring is completely optional** - The API works perfectly without it.
284+
314285The API exposes Prometheus metrics at the ` /metrics ` endpoint for monitoring with Grafana or other Prometheus-compatible systems.
315286
287+ 📖 ** For complete setup instructions, see [ grafana/PROMETHEUS.md] ( grafana/PROMETHEUS.md ) **
288+ 📁 ** Example configurations available in [ grafana/] ( grafana/ ) folder**
289+
290+ ### Quick Overview
291+
292+ ** What's Built-In (Always Available):**
293+
294+ - ` /metrics ` endpoint with Prometheus format metrics
295+ - Automatic instrumentation for HTTP, WebSocket, Database, and more
296+ - No setup required - just add ` METRICS_API_KEY ` to your ` .env `
297+
298+ ** What's Optional (In grafana/ folder):**
299+
300+ - Prometheus server deployment configs
301+ - Grafana dashboard templates
302+ - AWS ECS task definitions
303+
316304### Available Metrics
317305
318306- ** HTTP Metrics** : Request counts, duration histograms, status codes
@@ -324,33 +312,33 @@ The API exposes Prometheus metrics at the `/metrics` endpoint for monitoring wit
324312- ** Security Events** : Security-related event tracking
325313- ** System Metrics** : Memory, CPU, event loop, and other Node.js metrics
326314
327- ### Grafana Configuration
315+ ### Testing the Metrics Endpoint
328316
329- To connect Grafana to the metrics endpoint:
317+ ``` bash
318+ # 1. Set your API key in .env
319+ METRICS_API_KEY=your-secure-random-key-here
330320
331- 1 . ** Generate a secure API key** : ` openssl rand -hex 32 `
332- 2 . ** Set ` METRICS_API_KEY ` in your environment** (ECS task definition or ` .env ` )
333- 3 . ** Add Prometheus data source in Grafana** :
334- - ** Type** : Prometheus
335- - ** URL** : ` https://api.typelets.com/metrics ` (or your API URL)
336- - ** Auth** : Basic auth
337- - ** User** : ` metrics ` (or any username)
338- - ** Password** : Your ` METRICS_API_KEY ` value
321+ # 2. Start the server
322+ pnpm run dev
339323
340- ### Local Testing
324+ # 3. Test with curl (Basic Auth)
325+ curl -u metrics:your-secure-random-key-here http://localhost:3000/metrics
326+ ```
341327
342- Test the metrics endpoint locally:
328+ ### Setting Up Prometheus & Grafana (Optional)
343329
344- ``` bash
345- # Set your API key in .env
346- METRICS_API_KEY=your-secure-key-here
330+ If you want to visualize metrics in Grafana:
347331
348- # Start the server
349- pnpm run dev
332+ 1 . ** Check the [ grafana/] ( grafana/ ) folder** for example configuration files
333+ 2 . ** Read [ grafana/PROMETHEUS.md] ( grafana/PROMETHEUS.md ) ** for detailed setup instructions
334+ 3 . ** Choose your deployment option** :
335+ - Docker/ECS deployment (see example configs)
336+ - Amazon Managed Service for Prometheus
337+ - Self-hosted Prometheus
350338
351- # Test with curl (Basic Auth)
352- curl -u metrics:your-secure-key-here http://localhost:3000/metrics
353- ```
339+ ** Architecture ** : ` API (/metrics) ` → ` Prometheus Server ` → ` Grafana `
340+
341+ ** Note ** : You cannot connect Grafana directly to the ` /metrics ` endpoint. You need a Prometheus server in between.
354342
355343## Development
356344
0 commit comments