Skip to content

Project Architecture Documentation

Overview

This project is a backend application built with TypeScript, using GraphQL as the API interface and MongoDB as the database. The architecture is modular and follows development best practices.

Folder Structure

📁 Main Directories

  • app/ - Core application
  • bullMQ/ - Asynchronous task management
  • config/ - Configuration and constants
  • datasources/ - Data sources
  • events/ - Event management
  • graphql/ - GraphQL API
  • middleware/ - Middlewares
  • routes/ - HTTP routes
  • security/ - Security
  • services/ - Business services
  • zodSchema/ - Validation schemas

📁 Key Components

1. Schemas (app/schemas/)

Contains all MongoDB data models, organized by domain:

  • Users (UserSchema.ts, UserInventorySchema.ts, etc.)
  • Content (VideoSchema.ts, SerieSchema.ts, NewsSchema.ts)
  • Commerce (ShopItemSchema.ts, StripeItemSchema.ts)
  • Social (CommentSchema.ts, ShareSchema.ts)

2. Utilities (app/utils/)

Technical tools and services:

  • Cache management (CacheManager.ts)
  • Image processing (ImageProcessor.ts)
  • S3 upload (S3Uploader.ts)
  • File management (FileUtils.ts)

3. GraphQL (graphql/)

Complete GraphQL structure:

  • Schemas (graphQL/*.graphql)
  • Resolvers (resolvers/)
  • Directives (directives/)

4. Services (services/)

Main business services:

  • Authentication (AuthService.ts)
  • Payments (StripeService.ts)
  • User management (UserService.ts)
  • Rewards (RewardService.ts)
  • Brevo (BrevoService.ts) (email service)

Technical Highlights

🔐 Authentication

  • Token management (services/Auth/TokenService.ts)
  • Social authentication (services/Auth/SocialAuthService.ts)
  • Password management (services/Auth/PasswordService.ts)

💾 Data Management

  • Modular data sources in datasources/
  • Validation with Zod in zodSchema/
  • Redis cache (app/utils/redisClient.ts)

🔄 Events

Comprehensive event system:

  • Main manager (events/eventManager.ts)
  • Specific listeners for:
    • Quests
    • Logs
    • Achievements
    • Series activities

🛍️ Stripe

  • Stripe integration (services/StripeService.ts)
  • Item management (DS_Shop.ts)
  • Purchase history

📊 Monitoring and Logs

Database logging for key operations:

  • Event logging system (Logs/EventLogSchema.ts)
  • Experience logs (Logs/ExperienceLogSchema.ts)
  • Wallet logs (Logs/WalletLogSchema.ts)

Winston logger (app/utils/Logger.ts) for general logging

Best Practices

  1. Modularity: Each feature is isolated in its own module
  2. Validation: Use Zod schemas for data validation
  3. Events: Use the event system to decouple features
  4. Caching: Use CacheManager for frequently accessed data
  5. Logging: Always use Logger for tracking important operations

Core Tools and Dependencies

  • MongoDB (database)
  • Redis (cache and pub/sub)
  • GraphQL (API)
  • BullMQ (queues)
  • Zod (validation)
  • S3 (file storage)

Development Guidelines

Code Organization

  • Keep related functionality together
  • Use clear, descriptive file names
  • Follow the established folder structure

Error Handling

  • Use proper error types
  • Implement error logging
  • Return meaningful error messages

Security

  • Implement proper authentication checks
  • Validate user permissions
  • Sanitize user inputs

Performance

  • Use caching where appropriate
  • Implement database indexes
  • Monitor query performance