Connect World follows a layered architecture with clear separation between domain logic, application workflows, infrastructure, and presentation.
Root Directory Structure
Source Code Structure
Thesrc/ directory is organized into layers following Domain-Driven Design principles:
Complete Directory Tree
Complete Directory Tree
Layer Breakdown
Domain Layer (src/domain/)
Domain Layer
Pure business logic with zero dependencies on frameworks or infrastructure.
Entities
Entities
Location:
Example:
src/domain/entities/| File | Purpose | Key Features |
|---|---|---|
Customer.ts | Customer entity and factory | Email, phone, name validation |
Order.ts | Order entity and factory | Payment tracking, subscription dates |
Plan.ts | Plan entity and pricing matrix | Dynamic pricing, feature lists |
src/domain/entities/Order.ts:19Value Objects
Value Objects
Location:
Example:
src/domain/value-objects/| File | Purpose | Validation |
|---|---|---|
Email.ts | Email validation | Regex, lowercase, trim |
Phone.ts | Phone validation | Digit extraction, length check |
src/domain/value-objects/Email.ts:4Repository Interfaces
Repository Interfaces
Location:
Purpose: Define data access contracts without implementation details.
src/domain/repositories/| File | Interface | Methods |
|---|---|---|
ICustomerRepository.ts | ICustomerRepository | create, findByEmail, findById |
IOrderRepository.ts | IOrderRepository | create, findByCustomerId, findByReceiptId |
Application Layer (src/application/)
Application Layer
Orchestrates business workflows by coordinating domain entities and repositories.
Use Cases
Use Cases
Location:
Key Code:
src/application/use-cases/| File | Use Case | Workflow |
|---|---|---|
CreateOrderUseCase.ts | Order creation | Validate → Create customer → Create order → Persist → Return DTO |
src/application/use-cases/CreateOrderUseCase.ts:15DTOs
DTOs
Location:
Purpose: Decouple external API from internal domain entities.
src/application/dtos/| File | DTOs | Purpose |
|---|---|---|
OrderDto.ts | CreateOrderDto, OrderResponseDto | API contract, serialization |
Infrastructure Layer (src/infrastructure/)
Infrastructure Layer
Implements technical concerns: database, external APIs, and repository implementations.
Database
Database
Location:
Connection Caching:
src/infrastructure/database/| File | Purpose | Key Features |
|---|---|---|
connection.ts | MongoDB connection | Cached connection for serverless |
models/CustomerModel.ts | Customer Mongoose schema | snake_case fields, timestamps |
models/OrderModel.ts | Order Mongoose schema | Unique payment receipt ID |
src/infrastructure/database/connection.ts:22Repositories
Repositories
Location:
Data Mapping:
src/infrastructure/repositories/| File | Implementation | Maps |
|---|---|---|
MongoCustomerRepository.ts | ICustomerRepository | Customer ↔ CustomerDbDoc |
MongoOrderRepository.ts | IOrderRepository | Order ↔ OrderDbDoc |
src/infrastructure/repositories/MongoOrderRepository.ts:7External Services
External Services
Location:
Example:
src/infrastructure/external/| File | Service | Features |
|---|---|---|
tmdbService.ts | TMDB API | Trending content, now playing, top rated, poster URLs |
src/infrastructure/external/tmdbService.ts:29Presentation Layer (src/presentation/ + src/app/)
Presentation Layer
User interface components and API route handlers.
API Routes
API Routes
Location:
Security: All routes implement rate limiting, sanitization, and validation.
src/app/api/| Endpoint | File | Purpose |
|---|---|---|
POST /api/orders | api/orders/route.ts | Create order (with use case) |
POST /api/stripe | api/stripe/route.ts | Stripe payment intent |
POST /api/paypal/create-order | api/paypal/create-order/route.ts | PayPal order creation |
POST /api/paypal/capture-order | api/paypal/capture-order/route.ts | PayPal payment capture |
GET /api/tmdb | api/tmdb/route.ts | Proxy TMDB requests |
Section Components
Section Components
Location:
src/presentation/components/sections/| Component | Purpose | Key Features |
|---|---|---|
HeroSection.tsx | Landing hero | Spotlight effect, animated text |
PlansSection.tsx | Pricing display | Dynamic pricing, popular badge |
CatalogSection.tsx | Content showcase | TMDB integration, moving cards |
CheckoutModal.tsx | Payment form | Stripe & PayPal, validation |
ContactSection.tsx | Contact info | Social links, support details |
AboutSection.tsx | About section | Company information |
StatsSection.tsx | Statistics | Animated counters |
Navbar.tsx | Navigation | Scroll-triggered transparency |
Footer.tsx | Site footer | Links, copyright |
UI Components
UI Components
Location:
src/presentation/components/ui/| Component | Effect | Usage |
|---|---|---|
BackgroundGradient.tsx | Gradient background | Card highlights |
GlowCard.tsx | Glow effect | Featured items |
MovingCards.tsx | Animated carousel | Content display |
Spotlight.tsx | Spotlight effect | Hero section |
SparklesCore.tsx | Particle effects | Visual polish |
TextReveal.tsx | Text animations | Reveal effects |
NumberCounter.tsx | Animated counters | Statistics |
Root Pages
Root Pages
Location:
src/app/| File | Purpose | Renders |
|---|---|---|
page.tsx | Homepage | LandingClient component |
layout.tsx | Root layout | Metadata, fonts, global styles |
Shared Utilities (src/lib/)
Shared Utilities
Reusable helper functions used across layers.
Example:
| File | Purpose | Key Functions |
|---|---|---|
sanitize.ts | Input sanitization | sanitizeString, sanitizeEmail, sanitizePhone, sanitizeNumber, sanitizeEnum |
rateLimiter.ts | Rate limiting | checkRateLimit, getClientIp |
caseUtils.ts | Case conversion | camelToSnake, snakeToCamel (for DB mapping) |
utils.ts | General utilities | cn (className merger with tailwind-merge) |
src/lib/sanitize.tsConfiguration Files
next.config.ts
Next.js configuration:
- Image domains (TMDB)
- Environment variables
- Build settings
tsconfig.json
TypeScript configuration:
- Path aliases (
@/*) - Strict mode enabled
- JSX support for React
package.json
Dependencies and scripts:
dev: Start dev serverbuild: Production buildstart: Serve productionlint: Run ESLint
eslint.config.mjs
ESLint configuration:
- Next.js rules
- TypeScript rules
- Code quality checks
File Naming Conventions
Connect World follows consistent naming conventions across the codebase.
| Context | Convention | Example |
|---|---|---|
| React Components | PascalCase + .tsx | CheckoutModal.tsx |
| TypeScript Files | PascalCase + .ts | CreateOrderUseCase.ts |
| Utility Files | camelCase + .ts | sanitize.ts, rateLimiter.ts |
| API Routes | lowercase + /route.ts | api/orders/route.ts |
| Domain Entities | PascalCase | Customer.ts, Order.ts |
| Value Objects | PascalCase | Email.ts, Phone.ts |
| Repository Interfaces | I prefix + PascalCase | IOrderRepository.ts |
| Repository Implementations | Mongo prefix + PascalCase | MongoOrderRepository.ts |
| Database Models | PascalCase + Model | OrderModel.ts |
| DTOs | PascalCase + Dto | OrderDto.ts |
Code Conventions
Domain Layer
- Entities: camelCase properties
- Factory functions:
createprefix - No framework imports
Database Layer
- Schema fields: snake_case
- MongoDB collections: lowercase plural
- Mapping functions:
toDb,fromDb
API Routes
- HTTP methods: Uppercase (GET, POST)
- Error handling: Try-catch with status codes
- Response: JSON with NextResponse
Components
- Props: TypeScript interfaces
- Exports: Named or default
- Styling: Tailwind CSS classes
Import Path Aliases
Connect World uses TypeScript path aliases for clean imports:tsconfig.json
Key Files Reference
Critical Business Logic Files
Critical Business Logic Files
| File | Purpose | Lines |
|---|---|---|
src/domain/entities/Order.ts | Order entity and factory | 31 |
src/domain/entities/Plan.ts | Pricing logic | 79 |
src/application/use-cases/CreateOrderUseCase.ts | Order workflow | 55 |
src/app/api/orders/route.ts | Order API endpoint | 98 |
Infrastructure Files
Infrastructure Files
| File | Purpose | Lines |
|---|---|---|
src/infrastructure/repositories/MongoOrderRepository.ts | Order data access | 64 |
src/infrastructure/database/connection.ts | MongoDB connection | 34 |
src/infrastructure/external/tmdbService.ts | TMDB API client | 48 |
Security & Utilities
Security & Utilities
| File | Purpose | Features |
|---|---|---|
src/lib/sanitize.ts | Input sanitization | XSS prevention, validation |
src/lib/rateLimiter.ts | Rate limiting | IP-based, configurable windows |
src/domain/value-objects/Email.ts | Email validation | Regex, normalization |
Directory Purpose Summary
src/domain/
Pure business logicNo dependencies on frameworks, databases, or external services. Contains entities, value objects, and repository interfaces.
src/application/
Workflow orchestrationCoordinates domain entities and repositories to implement business use cases. Defines DTOs for data transfer.
src/infrastructure/
Technical implementationImplements repository interfaces, database models, external API clients, and connection management.
src/presentation/
User interfaceReact components for UI sections and reusable UI elements with animations and effects.
src/app/
Next.js App RouterAPI route handlers and page components following Next.js conventions.
src/lib/
Shared utilitiesReusable helper functions for sanitization, rate limiting, case conversion, and more.
Dependencies Overview
Core Dependencies
Core Dependencies
Payment & External Services
Payment & External Services
UI & Animations
UI & Animations
Development Workflow
Add Feature
- Define entity in
domain/ - Create use case in
application/ - Implement repository in
infrastructure/ - Add API route in
app/api/ - Create UI in
presentation/
Modify Business Logic
- Update entity in
domain/entities/ - Adjust use case in
application/use-cases/ - Update DTOs if needed
- Test changes
Change Database
- Update model in
infrastructure/database/models/ - Adjust repository mapping
- Update interfaces if schema changes
- Migrate data if needed
Testing Strategy
The layered architecture makes testing straightforward - each layer can be tested independently.
Unit Tests
Unit Tests
Domain Layer:
- Test entity factory functions
- Test value object validation
- No mocking needed (pure functions)
- Test use cases with mock repositories
- Verify workflow logic
- Test DTO mappings
Integration Tests
Integration Tests
Infrastructure Layer:
- Test repository implementations with test database
- Test external service clients with mock servers
- Test database connection
- Test API routes with mock use cases
- Test component rendering
- Test user interactions
Next Steps
Architecture Overview
High-level system architecture and design
Domain-Driven Design
Deep dive into DDD layers and patterns
API Reference
Detailed API endpoint documentation
Development Guide
Setup and development workflow
