Conversation
…ttachment handling Co-authored-by: markmnl <2630321+markmnl@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Create production-quality HTTP API for messaging datastore
Implement fmsg-webapi: production HTTP API for messaging with JWT auth
Mar 8, 2026
markmnl
approved these changes
Mar 8, 2026
Copilot stopped work on behalf of
markmnl due to an error
March 8, 2026 06:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Greenfield implementation of a Go HTTP API exposing CRUD operations for a PostgreSQL-backed messaging datastore. JWT tokens issued externally are validated and user identity is enforced for all authorization decisions.
Structure
All code lives under
/srcas a standard Go module (github.com/markmnl/fmsg-webapi).Authorization
/api/v1routes requireAuthorization: ******; identity (@user@domain`) extracted from JWT claimsmsg.from_addr == identity) required for all write operationsmsg_to.addr) may only read messages and download attachmentstime_sent IS NOT NULL) are immutable — updates, deletes, and attachment mutations rejected with 403fmsgid Integration
After JWT validation, every request checks the user against the fmsgid service:
404→400 "User <addr> not found"200+acceptingNew: false→403 "User <addr> not authorised to send new messages"File Storage
Message data:
<FMSG_DATA_DIR>/<domain>/<user>/out/<msg_id>/data.<ext>Attachments: same directory, collision-resolved via numeric suffix (
file_1.pdf,file_2.pdf, …).msg_attachment.filenamealways stores the original intended name;filepathstores the resolved path on disk.Path traversal protection validates all resolved paths are prefixed by
FMSG_DATA_DIRbefore serving downloads.Dependencies
github.com/gin-gonic/gingithub.com/appleboy/gin-jwt/v2github.com/jackc/pgx/v5github.com/joho/godotenv.envfile loadingOriginal prompt
You are building a production-quality HTTP API from scratch.
The API exposes CRUD operations for a messaging datastore implemented in PostgreSQL.
Authentication is not implemented by this service — it trusts JWT tokens issued by another system.
The service must strictly enforce authorization rules based on the user identity contained in the JWT.
Technology Stack
Implement the system using:
github.com/appleboy/gin-jwtNo user registration, authentication, or identity management should be implemented.
The API must simply validate JWT tokens and extract the user identity.
Repository Layout
Create the repository with the following the Gin Web Framework best practices. All code should live under /src directory.
The project must compile with:
JWT Authorization
The API must use
github.com/appleboy/gin-jwtmiddleware.JWT tokens contain a string identity representing the user address.
Example identity:
This identity must be extracted from the JWT and used for authorization checks.
Handlers must obtain the user identity from the Gin request context.
Authorization Rules
All access control must follow these rules.
Message Ownership
A message is owned by the user where:
Only the owner may:
Draft vs Sent Messages
A message is considered sent when:
Rules:
Once a message has been sent it becomes immutable.
Recipient Access
Users whose address appears in:
may only perform read operations.
Allowed:
GET /messages/{id}GET /messages/{id}/attachments/{filename}Recipients must never modify messages or attachments.
JSON Message Format
The HTTP API must send and receive messages using the following JSON structure:
Notes:
timecorresponds tomsg.time_senttocorresponds to entries inmsg_toattachmentscorrespond to rows inmsg_attachmentAttachment Handling
Attachments must be handled independently of message JSON.
Uploads and downloads must occur one attachment at a time.
Endpoints must operate using:
Authorization rules are identical to message rules:
Attachments cannot be modified or deleted once the message has been sent.
API Routes
Base prefix:
Message Routes
Create message (draft):
Retrieve message:
Update message (draft only):
Delete message (draft only):
Send message:
Sending a message sets
time_sent.Attachment Routes
Upload attachment:
Download attachment:
Delete attachment:
Uploads must store files on disk using the
filepathcolumn.PostgreSQL Schema
ASSUME database schema already created