Skip to content

Quota management and Docker build workflow - #4

Merged
figassis merged 1 commit into
masterfrom
agent/quota-management
Jan 11, 2026
Merged

Quota management and Docker build workflow#4
figassis merged 1 commit into
masterfrom
agent/quota-management

Conversation

@figassis

@figassis figassis commented Jan 11, 2026

Copy link
Copy Markdown

Summary

  • Implement comprehensive quota management with per-user and per-domain quotas
  • Add REST API endpoints for quota reporting and configuration (GET/PUT)
  • Enforce quotas on SMTP delivery with 552 rejection when over limit
  • Create separate GitHub Actions workflow for timestamped Docker image builds supporting amd64 and arm64

Files Changed

New files: quota.go, internal/rest/model/quota.go, internal/storage/imapsql/quota.go, .github/workflows/docker-build.yml
Modified: api.go, delivery.go, CLAUDE.md, architecture.md

Implementation Details

Quota hierarchy: user_quotas > domain_quotas > unlimited (0). Quotas calculated using msgs.bodylen for storage usage. New tables created automatically on startup.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Quota management system with REST API endpoints for per-user and per-domain quotas
    • Quota enforcement during email delivery to prevent exceeding limits
    • Docker image build automation for multi-architecture deployments
  • Documentation

    • Updated documentation reflecting quota management capabilities and API endpoints

✏️ Tip: You can customize this high-level summary in your review settings.

Add comprehensive quota management system with per-user and per-domain quotas,
SMTP delivery enforcement, and REST API endpoints for quota reporting and
configuration. Create separate GitHub Actions workflow for building and pushing
timestamped Docker images to Docker Hub supporting both amd64 and arm64.

Changes:
- New quota.go: GET/PUT endpoints for user and domain quotas
- New internal/storage/imapsql/quota.go: CheckQuota enforcement logic
- New internal/rest/model/quota.go: Quota response DTOs
- New .github/workflows/docker-build.yml: Multi-platform Docker build workflow
- Modified api.go: Added quota table initialization and routes
- Modified delivery.go: Added quota checks in AddRcpt and Body methods
- Updated CLAUDE.md and architecture.md: Documented quota tables and API

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jan 11, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces a quota management system with REST API endpoints, database schema extensions, quota enforcement logic during SMTP delivery, HTTP handlers for get/set operations, and related data models. Also adds a Docker CI/CD workflow and documentation updates.

Changes

Cohort / File(s) Summary
CI/CD Automation
.github/workflows/docker-build.yml
New GitHub Actions workflow that builds and pushes multi-architecture Docker images to Docker Hub on pushes to master, using QEMU for arm64 support and OCI labels.
Documentation
CLAUDE.md, architecture.md
Updated to document the new quota management feature, including API endpoints, database schema (domain_quotas, user_quotas tables), quota hierarchy semantics, and usage examples.
API Integration
api.go
Adds runtime initialization of quota tables via initDomainQuotasTable(), exposes four new quota REST endpoints (GET/PUT for users and domains), and depends on imapsql storage backend.
Quota Data Models
internal/rest/model/quota.go
New file defining exported types: UserQuotaResponse, DomainQuotaResponse, MailboxUsage, UserUsage, and SetQuotaRequest for API request/response serialization.
Quota Enforcement Logic
internal/storage/imapsql/quota.go
New file implementing Storage.CheckQuota() method that retrieves effective quota (user override → domain → unlimited), sums current mailbox usage, and returns SMTP 552 error if exceeded.
SMTP Delivery Integration
internal/storage/imapsql/delivery.go
Adds pre-flight quota checks in AddRcpt (size 0) and Body (actual message size) before IMAP filtering and storage, with early fail-fast return on quota breach.
Quota Management Handlers
quota.go
New root-level file with HTTP handlers for get/set user and domain quotas, including per-mailbox usage aggregation, quota source determination (user/domain/none precedence), and structured JSON responses with user/mailbox breakdowns.

Sequence Diagrams

sequenceDiagram
    participant Client
    participant API as API Handler
    participant ImapSQL as imapsql.Storage
    participant DB as Database
    
    Client->>API: GET /v1/users/:id/quota
    API->>ImapSQL: Query mailbox usage for user
    ImapSQL->>DB: SELECT SUM(bodylen) FROM msgs GROUP BY mailbox
    DB-->>ImapSQL: Usage per mailbox
    ImapSQL-->>API: Usage data
    API->>ImapSQL: Get user quota override
    ImapSQL->>DB: SELECT quota_bytes FROM user_quotas WHERE username=:id
    DB-->>ImapSQL: User quota (if exists)
    ImapSQL-->>API: User quota
    API->>ImapSQL: Get domain quota
    ImapSQL->>DB: SELECT quota_bytes FROM domain_quotas WHERE domain=:domain
    DB-->>ImapSQL: Domain quota (if exists)
    ImapSQL-->>API: Domain quota
    API->>API: Determine quota source & build response
    API-->>Client: UserQuotaResponse (with mailbox breakdown)
Loading
sequenceDiagram
    participant SMTP as SMTP Delivery
    participant Storage as imapsql.Storage
    participant Quota as CheckQuota
    participant DB as Database
    
    SMTP->>Storage: AddRcpt(recipient)
    Storage->>Quota: CheckQuota(username, 0)
    Quota->>DB: Get mailbox usage & quotas
    DB-->>Quota: Usage + effective quota
    alt Quota Exceeded
        Quota-->>Storage: SMTPError 552
        Storage-->>SMTP: Reject recipient
    else Quota OK
        Quota-->>Storage: nil
        Storage-->>SMTP: Accept recipient
    end
    
    SMTP->>Storage: Body(message data)
    Storage->>Quota: CheckQuota(username, message_size)
    Quota->>DB: Get updated usage & quotas
    DB-->>Quota: Usage + effective quota
    alt Quota Would Exceed
        Quota-->>Storage: SMTPError 552
        Storage-->>SMTP: Fail delivery
    else Within Quota
        Quota-->>Storage: nil
        Storage->>Storage: IMAP filter & store message
        Storage-->>SMTP: Success
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 1e4ea31 and 214d0d1.

📒 Files selected for processing (8)
  • .github/workflows/docker-build.yml
  • CLAUDE.md
  • api.go
  • architecture.md
  • internal/rest/model/quota.go
  • internal/storage/imapsql/delivery.go
  • internal/storage/imapsql/quota.go
  • quota.go

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@figassis
figassis merged commit d35685f into master Jan 11, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant