This project is a secure file sharing system built with a Golang backend and a modern React frontend. It allows users to:
- Upload files (currently
.txtonly). - Store and list their uploaded files.
- Generate public shareable links.
- Download files securely.
The system features JWT-based authentication, protected routes, and a modern, responsive UI using Tailwind CSS.
- JWT-based Authentication
- File Upload (Only
.txt) - File Listing
- Public File Sharing via Tokenized URLs
- Secure File Download
- Auth-Protected Routes
- GitHub Actions CI/CD
- Prometheus Exporter
- Grafana Dashboard
- Users register/login using
/registerand/login. - JWT tokens are returned and stored in
localStorage. - Protected endpoints check for valid tokens using middleware.
- Authenticated users upload
.txtfiles viamultipart/form-data. - Files are stored on disk or cloud (configurable).
- Authenticated users can view their uploaded files.
- Each file entry includes a share button and download option.
- Clicking "Share" generates a public URL like
/share/<token>. - Anyone with this link can download the file.
- Prometheus endpoint
/metrics - Grafana dashboard shows:
- Requests/sec
- Response status codes
- File upload/download count
- React + TypeScript
- Tailwind CSS
- React Router DOM
- Axios for HTTP requests
- Golang
- PostgreSQL (with GORM ORM)
- JWT for Authentication
- Prometheus
- Grafana
- GitHub Actions (CI/CD)
- Docker + Docker Compose
- Go 1.18+
- Node.js 18+
- PostgreSQL
- Docker & Docker Compose
- Prometheus + Grafana
git clone https://github.com/shantanugupta2004/HTTP-Server-Go.git
cd backend
go mod tidy
go run main.goExample .env:
PORT=5000
DATABASE_URL=postgres://user:pass@localhost:5432/files_db
JWT_SECRET=your-secret
cd frontend
pnpm install # or npm install / yarn install
pnpm run dev # or npm run dev / yarn devEnsure the API base URL in utils/api.ts points to your backend (e.g., http://localhost:5000).
Add a docker-compose.yml to run:
- Backend
- PostgreSQL
- Prometheus
- Grafana
docker-compose up --buildExample services in
docker-compose.yml:
api,db,prometheus,grafana
- Description: Register a new user.
- Body:
{ "email": "user@example.com", "password": "password123" } - Response:
{ "token": "JWT_TOKEN" }
- Description: Log in and receive a JWT.
- Body:
{ "email": "user@example.com", "password": "password123" } - Response:
{ "token": "JWT_TOKEN" }
- Description: Upload a
.txtfile (authenticated). - Headers:
Authorization: Bearer <JWT> - Body:
multipart/form-datawithfile=<File> - Response:
{ "message": "File uploaded successfully", "fileId": "uuid" }
- Description: Get list of user's uploaded files.
- Headers:
Authorization: Bearer <JWT> - Response:
[ { "id": "uuid", "filename": "example.txt", "uploadedAt": "2025-07-10T12:00:00Z" } ]
- Description: Public download route.
- Access: No auth required.
- Response: Returns the file directly for download.
- Description: Download your own file.
- Headers:
Authorization: Bearer <JWT> - Response: File stream (download)
GET /metrics— Prometheus-compatible metrics
- Register or Login to get a JWT token.
- Upload a
.txtfile. - View the list of uploaded files.
- Click "Share" to get a public download link.
- Others can use the share link to download the file without login.
This project uses GitHub Actions for:
- Linting and formatting
- Running unit tests
- Building backend Docker image
- Pushing to Docker Hub or any registry
name: CI Pipeline
on:
push:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install Dependencies
run: go mod tidy
- name: Run Tests
run: go test ./...
- name: Docker Build
run: docker build -t your-dockerhub/file-sharing-backend .
- name: Docker Push
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker push your-dockerhub/file-sharing-backendAdd in your backend:
import "github.com/prometheus/client_golang/prometheus/promhttp"
r.GET("/metrics", gin.WrapH(promhttp.Handler()))scrape_configs:
- job_name: 'file-sharing-app'
static_configs:
- targets: ['api:5000']- Connect Grafana to Prometheus (
http://prometheus:9090) - Import dashboard or create:
- Upload count over time
- Request duration
- Status codes
- Auth success/failures
- Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000(default creds:admin/admin)