Skip to content

Chore: Restructure Contract Architecture for Scalable Privacy-First DevelopmentΒ #136

@emarc99

Description

@emarc99

πŸ—’οΈ Description:

The current contract codebase has significant architectural issues that prevent proper development and deployment. We need a complete restructuring to support ShadowChat's privacy-first, decentralized social network vision with proper separation of concerns, consistent patterns, and scalable design.


⚠️ Current Problems:

  1. Mixed Cairo versions - Cairo 0 and Cairo 2 contracts coexist
  2. Inconsistent storage patterns - Vec vs Map+Counter mismatches
  3. Duplicate contract definitions - Multiple ProfileSystem implementations
  4. Poor separation of concerns - All contracts mixed in single files
  5. Missing core infrastructure - No encryption, governance, or identity layers
  6. Inconsistent naming conventions - Mixed patterns across contracts
  7. No clear module boundaries - Hard to maintain and extend

πŸ—οΈ Proposed Architecture:

contract/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.cairo                 # Main entry point, exports all modules
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ mod.cairo            # Core module exports
β”‚   β”‚   β”œβ”€β”€ storage.cairo        # Shared storage patterns and utilities
β”‚   β”‚   β”œβ”€β”€ events.cairo         # Common event definitions
β”‚   β”‚   └── errors.cairo         # Custom error types
β”‚   β”œβ”€β”€ messaging/
β”‚   β”‚   β”œβ”€β”€ mod.cairo           # Messaging module exports
β”‚   β”‚   β”œβ”€β”€ message_storage.cairo # Message storage contract
β”‚   β”‚   β”œβ”€β”€ media_sharing.cairo  # Media sharing contract
β”‚   β”‚   └── encryption.cairo     # E2E encryption layer
β”‚   β”œβ”€β”€ identity/
β”‚   β”‚   β”œβ”€β”€ mod.cairo           # Identity module exports
β”‚   β”‚   β”œβ”€β”€ profile_nft.cairo   # User profile NFT contract
β”‚   β”‚   β”œβ”€β”€ anonymous_identity.cairo # ZK-based anonymous identity
β”‚   β”‚   └── reputation.cairo    # Reputation system
β”‚   β”œβ”€β”€ governance/
β”‚   β”‚   β”œβ”€β”€ mod.cairo           # Governance module exports
β”‚   β”‚   β”œβ”€β”€ community.cairo     # Community/group management
β”‚   β”‚   β”œβ”€β”€ voting.cairo        # Voting and proposal system
β”‚   β”‚   └── moderation.cairo    # Content moderation
β”‚   └── storage/
β”‚       β”œβ”€β”€ mod.cairo           # Storage module exports
β”‚       β”œβ”€β”€ ipfs_manager.cairo  # IPFS integration
β”‚       └── arweave_manager.cairo # Arweave integration
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ integration/            # Integration tests
β”‚   β”œβ”€β”€ unit/                  # Unit tests by module
β”‚   └── fixtures/              # Test data and utilities
└── migrations/                # Contract upgrade scripts

Acceptance Criteria:

πŸ€– Build & Compilation:

  • scarb build succeeds without warnings
  • All contracts compile with Cairo 2.11.4
  • No duplicate contract definitions
  • Consistent storage patterns across all contracts
  • Proper module exports and imports

βš’οΈ Functionality:

  • All existing functionality preserved
  • Storage operations work consistently
  • Events emit correctly for all state changes
  • Error handling prevents invalid operations
  • Cross-contract calls work properly

πŸ§ͺ Testing:

  • All existing tests pass

πŸ“ Documentation:

  • Architecture documentation complete
  • Deployment guides for each module
  • Integration examples provided

Uniti sumus.

Metadata

Metadata

Assignees

Labels

ASAPPriority:highhelp wantedExtra attention is neededonlydust-waveContribute to awesome OSS repos during OnlyDust's open source week

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions