Backend API for a note-taking application with workspaces, notes, charts, and activities.
- Create a
.envfile in the project root:
POSTGRES_USER=focuz_user
POSTGRES_PASSWORD=focuz_password
POSTGRES_DB=focuz_db
JWT_SECRET=your_secret_key_here
MINIO_EXTERNAL_ENDPOINT=http://localhost:9000- Start the project:
docker-compose up -d- The API will be available at: http://localhost:8080
- API documentation (Swagger UI): http://localhost:8081
main.go- application entry pointhandlers/- HTTP handlersmodels/- data modelsrepository/- data access layermigrations/- database migrationsmiddleware/- middleware (CORS, authentication)initializers/- service initializerstypes/- data typestests/- tests
POST /register- user registrationPOST /login- user login
GET /spaces- get available workspacesPOST /spaces- create a workspacePATCH /spaces/{id}- update a workspacePATCH /spaces/{id}/delete- soft delete a workspacePATCH /spaces/{id}/restore- restore a workspaceGET /spaces/{id}/users- get users in a workspacePOST /spaces/{id}/invite- invite a userDELETE /spaces/{id}/users/{userId}- remove a user from a workspace
GET /notes- get notesPOST /notes- create a noteGET /notes/{id}- get a note by IDPATCH /notes/{id}/delete- soft delete a notePATCH /notes/{id}/restore- restore a noteGET /tags/autocomplete- tag autocomplete
GET /activities- get activity analysisPOST /activities- create an activityPATCH /activities/{id}- update an activityPATCH /activities/{id}/delete- soft delete an activityPATCH /activities/{id}/restore- restore an activity
GET /spaces/{spaceId}/activity-types- get activity typesPOST /spaces/{spaceId}/activity-types- create an activity typePATCH /spaces/{spaceId}/activity-types/{typeId}/delete- soft delete an activity typePATCH /spaces/{spaceId}/activity-types/{typeId}/restore- restore an activity type
GET /charts- get chartsPOST /charts- create a chartPATCH /charts/{id}- update a chartPATCH /charts/{id}/delete- soft delete a chartPATCH /charts/{id}/restore- restore a chartGET /chart-types- get chart typesGET /period-types- get period types
POST /upload- upload a fileGET /files/{id}- get a file
GET /sync?since=<RFC3339>&spaceId?=<id>— pull changes since timestamp. Returns notes, tags, filters, charts, activities, spaces changed aftersince. Use for polling or after WS/SSE events.POST /sync— push local changes. Body contains arrays:notes,tags,filters,charts,activities. Server applies with last-write-wins bymodified_atand returnsmappings(clientId -> serverId) andconflicts.
Example pull:
curl -H "Authorization: Bearer <TOKEN>" \
"http://localhost:8080/sync?since=2024-01-01T00:00:00Z"Example push:
curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" \
-d '{
"notes": [
{
"clientId": "tmp-123",
"space_id": 1,
"user_id": 1,
"text": "Hello",
"tags": ["important"],
"created_at": "2025-01-01T10:00:00Z",
"modified_at": "2025-01-01T10:00:00Z"
}
],
"tags": [], "filters": [], "charts": [], "activities": []
}' \
http://localhost:8080/syncGET /spaces/{spaceId}/tags— list tags in space.GET /spaces/{spaceId}/filters— list filters in space (alias ofGET /filters?spaceId=...).
Saved note filters with nested grouping and JSON parameters.
- Create: POST
/filters{ spaceId, parentId?, name, params<object/json> } - List: GET
/filters?spaceId=...&page=1&pageSize=20 - Update: PATCH
/filters/{id}{ name?, parentId?, params? } - Delete: PATCH
/filters/{id}/delete - Restore: PATCH
/filters/{id}/restore
- Go 1.24 - main language
- Gin - web framework
- PostgreSQL - database
- pgroonga - full-text search
- MinIO - object storage
- JWT - authentication
- Docker - containerization
# Quick test run (PowerShell)
.\run-tests.ps1# Start only the database and MinIO
# IMPORTANT: the DB image includes PGroonga extension required by migrations
# If you run Postgres yourself, ensure PGroonga is installed, or migrations will fail
# Recommended:
docker-compose up db minio -d
# Run the API locally
go run main.goALLOWED_ORIGINS: comma-separated origins allowed in production for CORS and WebSocket (e.g.https://app.example.com,https://staging.example.com).TRUSTED_PROXIES: comma-separated proxy CIDRs or IPs for correct client IP; defaults to127.0.0.1, ::1when unset.RATE_LIMIT_RPS,RATE_LIMIT_BURST,RATE_LIMIT_WHITELIST,RATE_LIMIT_ENABLED: tune/disable rate limiting.MINIO_EXTERNAL_ENDPOINT: external hostname:port for presigned URLs; if empty, internal endpoint is used.
Swagger UI is available at: http://localhost:8081
The documentation is automatically updated when the openapi.yaml file changes.