Connect World follows a Domain-Driven Design (DDD) architecture with clear separation of concerns between presentation, application, domain, and infrastructure layers.
System Architecture
Connect World is built as a modern full-stack streaming platform using Next.js 16 with the App Router. The architecture follows clean architecture principles with well-defined boundaries between layers.Frontend Framework
Next.js 16 with App Router for server-side rendering and optimal performance
Backend Architecture
API Routes with DDD pattern, separating business logic from infrastructure
Database
MongoDB with Mongoose ODM for flexible document storage
External Services
TMDB API for content, Stripe & PayPal for payments
Architecture Layers
The application is organized into four distinct layers following DDD principles:Domain Layer
Domain Layer
The core business logic layer containing:
- Entities:
Customer,Order,Plan - Value Objects:
Email,Phone(with validation) - Repository Interfaces:
ICustomerRepository,IOrderRepository
src/domain/Application Layer
Application Layer
Orchestrates business workflows through use cases:
- Use Cases:
CreateOrderUseCase - DTOs:
OrderDtofor data transfer between layers
src/application/Infrastructure Layer
Infrastructure Layer
Implements technical concerns:
- Database Connection: MongoDB connection management
- Repository Implementations:
MongoOrderRepository,MongoCustomerRepository - Database Models: Mongoose schemas with snake_case conventions
- External Services: TMDB API integration
src/infrastructure/Presentation Layer
Presentation Layer
User interface and API endpoints:
- React Components: Landing page sections, UI components
- API Routes: RESTful endpoints for orders, payments, content
- Client Components: Interactive elements with Framer Motion
src/presentation/ and src/app/Next.js App Router Structure
Connect World leverages Next.js 16’s App Router for optimal performance and developer experience:API Routes Organization
All API routes follow Next.js conventions and implement:- Rate limiting to prevent abuse
- Input sanitization for security
- Honeypot fields for bot detection
- Validation against business rules
Database Layer
Connect World uses MongoDB with Mongoose ODM for data persistence:Database Design
- Collections:
customers,orders - Schema Validation: Mongoose schemas with TypeScript types
- Naming Convention: snake_case in database, camelCase in domain
- Connection Management: Cached connection for serverless environments
Data Mapping Strategy
The infrastructure layer handles conversion between domain entities (camelCase) and database documents (snake_case):src/infrastructure/repositories/MongoOrderRepository.ts:6
External Integrations
TMDB API
Purpose: Content catalog (movies, TV shows)Endpoints:
- Trending content
- Now playing movies
- Top-rated series
src/infrastructure/external/tmdbService.tsStripe
Purpose: Primary payment processorFeatures:
- One-time payments
- Subscription handling
- Webhook integration
src/app/api/stripe/route.tsPayPal
Purpose: Alternative payment methodFlow:
- Create order
- Customer approval
- Capture payment
src/app/api/paypal/Mongoose
Purpose: MongoDB ODMFeatures:
- Schema validation
- Type safety
- Query building
src/infrastructure/database/Security & Validation
Connect World implements multiple security layers:Input Sanitization
Input Sanitization
All user inputs are sanitized using dedicated utility functions:
sanitizeString: Prevents XSS attackssanitizeEmail: Validates and normalizes email addressessanitizePhone: Formats and validates phone numberssanitizeNumber: Enforces numeric rangessanitizeEnum: Validates against allowed values
src/lib/sanitize.tsRate Limiting
Rate Limiting
IP-based rate limiting prevents abuse:
- 5 orders per IP per 10 minutes
- Configurable time windows and limits
- In-memory cache for serverless compatibility
src/lib/rateLimiter.tsHoneypot Fields
Honeypot Fields
Hidden form fields catch automated bots:
- Field
_hpinvisible to human users - Bots fill all fields and get silently rejected
- Returns fake success to avoid aggressive retries
src/app/api/orders/route.ts:33Business Rule Validation
Business Rule Validation
Server-side validation ensures data integrity:
- Plan existence verification
- Price manipulation prevention
- Device count validation
- Subscription duration limits
src/app/api/orders/route.ts:53Technology Stack
Frontend
- React 19
- Next.js 16
- Tailwind CSS v4
- Framer Motion
Backend
- Next.js API Routes
- TypeScript 5
- Mongoose ODM
- Axios HTTP client
Infrastructure
- MongoDB database
- Vercel hosting
- TMDB API
- Stripe & PayPal
Development Principles
The architecture prioritizes maintainability, testability, and scalability through clear separation of concerns and dependency inversion.
Key Principles
- Domain-Driven Design: Business logic isolated in domain layer
- Dependency Injection: Components receive dependencies, don’t create them
- Interface Segregation: Small, focused interfaces (repositories)
- Single Responsibility: Each module has one reason to change
- Type Safety: Full TypeScript coverage with strict mode
Code Organization Benefits
- Testability: Domain logic can be tested without database or HTTP
- Flexibility: Easy to swap MongoDB for another database
- Clarity: Each layer has a clear purpose and boundaries
- Scalability: New features follow established patterns
- Maintainability: Changes are localized to specific layers
Next Steps
Domain-Driven Design
Deep dive into DDD layers and patterns
Project Structure
Complete directory tree and file organization
API Reference
Detailed API endpoint documentation
Development Guide
Setup and development workflow
