This document explains how Diora works internally - how data moves through the system, how different components communicate, and the technical decisions behind the platform's architecture.
Diora follows a modern client-server architecture with specialized external services:
| Component | Technology | Purpose |
|---|---|---|
| Mobile App | React Native 0.79.4 + Expo SDK 53 | User interface and interaction |
| API Server | Node.js + Express.js 5.1.0 | Business logic and data processing |
| Database | MongoDB 6.17.0 + Mongoose 8.16.2 | Data persistence and relationships |
| Real-time | Socket.io 4.8.1 | Live messaging and notifications |
| Images | Cloudinary | Image storage and optimization |
| Payments | Stripe | Secure payment processing |
| Notifications | Firebase | Push notifications |
graph TD
%% Component Definitions
subgraph Frontend [Mobile Client]
RNApp[React Native App]
end
subgraph BackendServices [Backend Services]
Express[Node.js/Express API]
SocketIO[Socket.io Server]
end
subgraph Persistence [Data Tier]
DB[(MongoDB)]
end
subgraph External [External Services]
Cloudinary[Cloudinary - Media]
Stripe[Stripe - Payments]
Firebase[Firebase - Push Notifications]
end
%% Data Flows
RNApp <-->|REST API / JSON| Express
RNApp <-->|WebSockets| SocketIO
Express <-->|Mongoose ODM| DB
Express -->|Upload/CDN| Cloudinary
Express -->|Transaction API| Stripe
Express -->|FCM Tokens| Firebase
SocketIO -.->|Event Trigger| Express
%% Styling
style RNApp fill:#3498db,stroke:#2980b9,color:#fff
style Express fill:#2ecc71,stroke:#27ae60,color:#fff
style SocketIO fill:#2ecc71,stroke:#27ae60,color:#fff
style DB fill:#f1c40f,stroke:#f39c12,color:#000
style Cloudinary fill:#e67e22,stroke:#d35400,color:#fff
style Stripe fill:#e67e22,stroke:#d35400,color:#fff
style Firebase fill:#e67e22,stroke:#d35400,color:#fff
%% Legend
subgraph Legend
L1[Frontend]:::frontendStyle
L2[Backend/Logic]:::backendStyle
L3[Database]:::dbStyle
L4[External/Third Party]:::extStyle
end
classDef frontendStyle fill:#3498db,stroke:#2980b9,color:#fff
classDef backendStyle fill:#2ecc71,stroke:#27ae60,color:#fff
classDef dbStyle fill:#f1c40f,stroke:#f39c12,color:#000
classDef extStyle fill:#e67e22,stroke:#d35400,color:#fff
The MongoDB database is organized into collections that reflect the app's core functionality:
- Users Collection: User profiles, authentication data, preferences, and shop information
- Posts Collection: Outfit posts with images, captions, and engagement metrics
- Products Collection: Shop inventory with pricing, descriptions, and category information
- Orders Collection: Purchase records with customer, product, and payment details
- Messages Collection: Chat history with timestamps, reactions, and delivery status
- Conversations Collection: Group and direct message metadata with participant management
- Notifications Collection: User notifications with read status and auto-cleanup (30+ days)
- Reviews Collection: Product and shop reviews with ratings and user feedback
- Reports Collection: Content moderation reports and administrative actions
- Carts Collection: Shopping cart items with quantity and variant information
- Wishlists Collection: Saved products for future purchase consideration
- Promotion Requests Collection: Shop promotion applications with document verification
- User enters credentials in the mobile app
- App calls
authService.login()with email/password - Backend validates credentials against Users collection
- If valid, backend generates JWT token with user information
- App stores token securely and uses for subsequent requests
- User is navigated to main application interface
- User selects photo and writes caption in post creation screen
- App uploads image to Cloudinary and receives optimized URL
- App calls
postService.createPost()with caption and image URL - Backend creates post record in Posts collection
- Backend notifies followers through Socket.io real-time connections
- New post appears in followers' feeds immediately
- User browses products through
productService.getProducts() - Backend queries Products collection with filters and pagination
- User adds items to cart via
cartService.addToCart() - Backend updates user's cart in Carts collection
- During checkout, backend creates Stripe payment session
- Upon successful payment, order is created in Orders collection
- Shop owner and customer receive notifications
- Order status can be tracked and updated through order management
- User types message and submits through message interface
- App sends message via Socket.io connection to backend
- Backend saves message to Messages collection
- If recipient is online, message delivered instantly via Socket.io
- If recipient is offline, message queued for delivery when they reconnect
- Message history synchronized across all user devices
- User reports inappropriate content through report interface
- Frontend calls
reportService.submitReport()with details - Backend creates report record in Reports collection
- Admin receives notification about new report
- Admin reviews content and takes appropriate action
- System can hide content, warn users, or escalate based on severity
UI components focus solely on presentation and user interaction. All data fetching and API communication is handled by dedicated service modules, creating clean separation between UI and business logic.
Custom React hooks encapsulate complex state logic and side effects. This pattern makes components simpler while providing reusable state management across the application.
TypeScript ensures data consistency between frontend and backend. Interface definitions catch errors during development and provide better developer experience with autocomplete and validation.
- Models: MongoDB schemas with Mongoose define data structure and validation
- Views: JSON API responses formatted for frontend consumption
- Controllers: Business logic that processes requests and coordinates responses
Each API request flows through a series of middleware functions:
- Rate Limiting: Prevents abuse with configurable request limits
- Authentication: JWT token validation and user identification
- Authorization: Role-based access control (user/shop/admin)
- Validation: Request data sanitization and validation
- Business Logic: Core functionality in controller methods
- Response: Standardized JSON response formatting
- Indexing: Strategic indexes on frequently queried fields
- Relationships: Balanced use of references vs embedded documents
- Performance: Optimized queries using MongoDB aggregation pipelines
Socket.io maintains persistent connections between user devices and the server, enabling instant bidirectional communication without the overhead of repeated HTTP requests.
- User Registration: Clients register with user ID for targeted messaging
- Room Management: Users join conversation rooms for group messaging
- Presence Tracking: Online/offline status automatically managed
- Reconnection: Automatic reconnection handling for network interruptions
Client to Server Events:
register: Associate connection with user accountjoin_conversation: Subscribe to conversation updatestyping_start/typing_stop: Typing indicator management
Server to Client Events:
message: New message deliverynotification: Real-time notificationsuser_online/user_offline: Presence updatestyping: Typing indicators from other users
- Security: Stripe handles all payment data and PCI compliance
- Flow: Order → Stripe session → Payment → Webhook confirmation → Order update
- Features: Support for multiple payment methods, subscription billing, refunds
- Processing: Automatic image optimization, resizing, and format conversion
- Delivery: Global CDN ensures fast image loading worldwide
- Storage: Unlimited scalable storage with automatic backup
- Delivery: Notifications sent to user devices even when app is closed
- Targeting: User-specific notification preferences and device management
- Types: New messages, order updates, social interactions, promotions
- JWT Tokens: Stateless authentication with user role information
- Password Security: bcrypt hashing with salt for password storage
- Session Management: Token expiration and refresh token handling
- Role-Based Access: Different permission levels for users, shops, and admins
- Input Validation: All user input sanitized to prevent injection attacks
- Rate Limiting: API endpoints protected against abuse and DDoS
- CORS Protection: Cross-origin requests properly controlled
- HTTPS Encryption: All data transmission encrypted in transit
- Automated Detection: Basic content filtering for obvious violations
- Manual Review: Admin tools for investigating reported content
- Action Tracking: Complete audit trail of moderation decisions
- Appeal Process: Users can contest moderation actions
- Indexing Strategy: Compound indexes for complex queries
- Query Optimization: Aggregation pipelines for efficient data processing
- Connection Pooling: Optimized database connection management
- Data Archiving: Automatic cleanup of old notifications and resolved reports
- Image Caching: Cloudinary CDN provides global image distribution
- API Caching: Frequently accessed data cached to reduce database load
- Real-time Optimization: Socket.io rooms minimize unnecessary message broadcasting
- Graceful Degradation: App functionality maintained during service outages
- Circuit Breakers: Automatic failure detection and recovery for external services
- Comprehensive Logging: Detailed error tracking and performance monitoring
- Health Checks: Automated system health monitoring and alerting
- Real-time Analytics: User engagement, order metrics, and growth tracking
- User Management: Search, suspend, ban, and communication tools
- Content Oversight: Post and product visibility controls
- Shop Promotion: Document verification and business validation process
- Data Cleanup: Automatic removal of old notifications and temporary data
- Performance Monitoring: Continuous tracking of system performance metrics
- Security Scanning: Regular checks for potential security vulnerabilities
- Backup Management: Automated database backups with point-in-time recovery
Related Documentation:
- Project Structure - Detailed codebase organization and file locations
- API Documentation - Complete endpoint specifications and examples
- Setup Guide - Development environment configuration