Skip to content

Conversation

@MathisVerstrepen
Copy link
Owner

@MathisVerstrepen MathisVerstrepen commented Dec 31, 2025

Short Summary

This PR introduces a comprehensive usage limitation system for the Free tier to ensure sustainable resource allocation and incentivize Premium upgrades. It implements limits on file storage (50MB), the number of active canvases (max 5), and restricts access to specific premium nodes (GitHub). This includes full-stack implementation from database schema changes and atomic storage reservation logic to frontend state management and UI enforcement.

Technical Changes

Backend (API & Database)

  • Database Schema (api/app/database/pg/models.py, api/migrations):
    • Added UserStorageUsage table to track total bytes used per user.
    • Created Alembic migration c8c2d84a3b86 for the new table.
  • Storage Logic (api/app/database/pg/user_ops/storage_crud.py):
    • Implemented check_and_reserve_storage: Atomically checks limits and updates usage with row locking to prevent race conditions during concurrent uploads.
    • Implemented release_storage: Decrements usage upon file deletion.
    • Implemented get_recursive_item_size: Calculates the size of folders/files for accurate quota management.
    • Added logic to sync actual Files table size with UserStorageUsage if records drift or are missing.
  • Usage Enforcement (api/app/database/pg/user_ops/usage_limits.py):
    • check_free_tier_canvas_limit: Enforces a hard limit of 5 non-temporary graphs for free users.
    • validate_premium_nodes: Blocks creation/update of graphs containing premium-only nodes (e.g., GitHub nodes) for free users.
  • Routers:
    • Files: Integrated storage reservation into upload flow and release logic into deletion flow. Added rollback logic to release reserved storage if disk write fails.
    • Graph: Added middleware-style checks for canvas limits on creation and premium node validation on updates.
    • Users: Updated get_user_query_usage to return storage metrics (used vs limited bytes).

Frontend (Nuxt/Vue)

  • State Management (ui/app/stores/usageStore.ts):
    • Extended usageStore to track storageUsage (used bytes, limit, percentage).
  • UI Components:
    • File Manager: Added "Storage Full" indicators. Disables upload buttons and drag-and-drop zones when limits are reached.
    • Sidebar/Blocks: Implemented visual locking (padlock overlay) for Premium nodes (GitHub). Prevents dragging these nodes onto the canvas for free users.
    • Sidebar/History: Added logic to prevent creating new canvases if the 5-canvas limit is reached.
    • Usage Display: Added a new Storage section to the user usage visualization with byte-formatted progress bars.
  • Utils:
    • Updated useFormatters.ts to use binary prefixes (1024) for accurate matching with backend file system logic.
    • Added PLAN_LIMITS constant for centralized limit definitions.

Impact and Scope

  • Functional Impact: Free tier users will now face strict limits on storage and graph creation. They will be visually blocked from using GitHub nodes.
  • System Reach:
    • Database: Schema migration required (user_storage_usage).
    • API: GET /users/usage response signature changed to include storage data.
  • Breaking Changes: None technically, but significantly changes the UX for free users by enforcing previously non-existent limits.
  • Performance/Security:
    • Storage calculations use recursive CTEs for folder sizes but are optimized to run only on deletion; uploads use direct file size.
    • Row locking (with_for_update) is used during file uploads to ensure quota integrity.

@MathisVerstrepen MathisVerstrepen self-assigned this Dec 31, 2025
@MathisVerstrepen MathisVerstrepen added the enhancement Improving existing features or functionality, without adding entirely new capabilities. label Dec 31, 2025
@MathisVerstrepen MathisVerstrepen merged commit 0285092 into nightly Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving existing features or functionality, without adding entirely new capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants