A secure, end-to-end encrypted cloud storage API built with Go, featuring advanced authentication, file sharing, and multi-tenant storage management.
- Secure File Storage: End-to-end encrypted file storage with AWS S3 backend
- Drive Volumes: Multi-tenant storage volumes with configurable size limits
- File Sharing: Advanced sharing capabilities with permission management
- File Versioning: Complete revision history and rollback capabilities
- Thumbnail Generation: Automatic thumbnail generation for media files
- SRP Authentication: Secure Remote Password protocol implementation
- Multi-Factor Authentication: TOTP, Email, and SMS-based 2FA
- JWT Tokens: RSA-signed access and refresh tokens
- CSRF Protection: Built-in Cross-Site Request Forgery protection
- Security Events: Comprehensive audit logging and monitoring
- Device Management: Track and manage user devices
- User Profiles: Complete user account management
- Session Management: Secure session handling with Redis
- Recovery Kits: Account recovery mechanisms
- Billing Integration: Stripe integration for subscriptions
- Notification System: Email and SMS notifications
- Graceful Shutdown: Proper cleanup and shutdown procedures
- Health Monitoring: Sentry integration for error tracking
- Redis Caching: High-performance caching layer
- Database Migrations: Automated schema management
- CORS Support: Cross-origin resource sharing configuration
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend ββββββ CirrusSync ββββββ PostgreSQL β
β Applications β β API Server β β Database β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ
β β
βββββββββββββββββββ βββββββββββββββββββ
β Redis Cache β β AWS S3 β
β & Sessions β β File Storage β
βββββββββββββββββββ βββββββββββββββββββ
- Language: Go 1.24.2
- Web Framework: Gin
- Database: PostgreSQL with GORM ORM
- Cache: Redis
- File Storage: AWS S3
- Authentication: JWT + SRP
- Monitoring: Sentry
- Development: Air (hot reload)
- Go 1.24.2 or higher
- PostgreSQL 12+
- Redis 6+
- AWS S3 bucket (or S3-compatible storage)
git clone https://github.com/anans9/cirrussync-api.git
cd cirrussync-apigo mod downloadmkdir -p keys
# Generate private key
openssl genrsa -out keys/private.pem 2048
# Generate public key
openssl rsa -in keys/private.pem -pubout -out keys/public.pemCreate environment configuration files:
# Server Configuration
PORT=8000
HOST=localhost
ENVIRONMENT=development
REQUEST_TIMEOUT=30
SHUTDOWN_TIMEOUT=10
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=cirrussync
DB_USER=postgres
DB_PASSWORD=your_password
DB_SSL_MODE=disable
DB_TIMEZONE=UTC
DB_MAX_OPEN_CONNS=25
DB_MAX_IDLE_CONNS=10
DB_CONN_MAX_LIFETIME=300
MIGRATE_ON_BOOT=true
# Redis Configuration
REDIS_ADDR=localhost:6379
REDIS_PASSWORD=
REDIS_DB=0
REDIS_MAX_RETRIES=3
REDIS_POOL_SIZE=10
# AWS S3 Configuration
S3_REGION=us-east-1
S3_BUCKET_NAME=your-bucket-name
S3_ACCESS_KEY_ID=your-access-key
S3_SECRET_ACCESS_KEY=your-secret-key
S3_ENDPOINT= # Optional: for S3-compatible services
# CSRF Protection
CSRF_SECRET=your-32-char-secret-key-here
CSRF_SECURE=false
# Mail Configuration (SMTP)
MAIL_SMTP_HOST=smtp.gmail.com
MAIL_SMTP_PORT=587
MAIL_SMTP_USERNAME=your-email@gmail.com
MAIL_SMTP_PASSWORD=your-app-password
MAIL_FROM_ADDRESS=noreply@cirrussync.com
MAIL_FROM_NAME=CirrusSync
# TOTP Configuration
TOTP_ISSUER=CirrusSync
TOTP_ACCOUNT_NAME=CirrusSync Account
# Monitoring (Optional)
SENTRY_DSN=your-sentry-dsn
APP_VERSION=1.0.0# Create database
createdb cirrussync
# The application will automatically run migrations on startup
# when MIGRATE_ON_BOOT=true# Install Air for hot reloading
go install github.com/cosmtrek/air@latest
# Run with hot reload
air# Build the application
go build -o cirrussync-api cmd/main.go
# Run the application
./cirrussync-api# Dockerfile example
FROM golang:1.24.2-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o cirrussync-api cmd/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/cirrussync-api .
COPY --from=builder /app/keys ./keys
CMD ["./cirrussync-api"]http://localhost:8000/api/v1
The API uses JWT tokens for authentication. Most endpoints require a valid JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
POST /auth/register- User registrationPOST /auth/login/challenge- SRP login challengePOST /auth/login/verify- SRP login verificationPOST /auth/refresh- Refresh JWT tokenPOST /auth/logout- User logoutGET /auth/me- Get current user info
GET /users/profile- Get user profilePUT /users/profile- Update user profileDELETE /users/account- Delete user account
GET /sessions- List user sessionsDELETE /sessions/:id- Revoke specific sessionDELETE /sessions/all- Revoke all sessions
GET /mfa/methods- List MFA methodsPOST /mfa/totp/setup- Setup TOTPPOST /mfa/totp/verify- Verify TOTPPOST /mfa/email/send- Send email codePOST /mfa/sms/send- Send SMS code
GET /drive/volumes- List drive volumesPOST /drive/volumes- Create new volumeGET /drive/volumes/:id/items- List items in volumePOST /drive/upload- Upload fileGET /drive/download/:id- Download filePOST /drive/share- Share file/folderGET /drive/shared- List shared items
GET /csrf/token- Get CSRF token
The API implements the Secure Remote Password (SRP) protocol for zero-knowledge password authentication:
- Client requests login challenge
- Server responds with salt and challenge
- Client computes proof using password
- Server verifies proof without knowing password
- All file data is encrypted at rest
- Transport layer security with HTTPS
- JWT tokens signed with RSA keys
- Password hashing with bcrypt
- CSRF protection enabled
- CORS properly configured
- Security headers set automatically
βββ api/v1/ # API handlers
β βββ auth/ # Authentication endpoints
β βββ drive/ # File storage endpoints
β βββ mfa/ # Multi-factor auth endpoints
β βββ sessions/ # Session management
β βββ users/ # User management
βββ cmd/ # Application entry point
βββ internal/ # Private application code
β βββ auth/ # Authentication service
β βββ drive/ # Drive service
β βββ jwt/ # JWT service
β βββ middleware/ # HTTP middleware
β βββ models/ # Database models
β βββ user/ # User service
βββ pkg/ # Public packages
β βββ config/ # Configuration
β βββ db/ # Database connection
β βββ redis/ # Redis connection
β βββ s3/ # S3 client
βββ router/ # HTTP router setup
Set environment variable:
export GIN_MODE=debugThe application provides several health check endpoints:
- Database connectivity
- Redis connectivity
- S3 connectivity
Integration with Sentry for error monitoring:
- Automatic error collection
- Performance monitoring
- Custom event tracking
Ensure all required environment variables are set in production:
# Security
CSRF_SECURE=true
ENVIRONMENT=production
# SSL/TLS
DB_SSL_MODE=require
# Monitoring
SENTRY_DSN=your-production-sentry-dsn[Unit]
Description=CirrusSync API Server
After=network.target
[Service]
Type=simple
User=cirrussync
WorkingDirectory=/opt/cirrussync
ExecStart=/opt/cirrussync/cirrussync-api
Restart=always
RestartSec=5
Environment=ENVIRONMENT=production
[Install]
WantedBy=multi-user.targetserver {
listen 80;
server_name api.cirrussync.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Go conventions and best practices
- Write tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
- Use conventional commit messages
- Billing support
- GraphQL API support
- API rate limiting
CirrusSync API - Secure, scalable cloud storage for the modern web.