Appearance
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 applicationbullMQ/- Asynchronous task managementconfig/- Configuration and constantsdatasources/- Data sourcesevents/- Event managementgraphql/- GraphQL APImiddleware/- Middlewaresroutes/- HTTP routessecurity/- Securityservices/- Business serviceszodSchema/- 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
- Modularity: Each feature is isolated in its own module
- Validation: Use Zod schemas for data validation
- Events: Use the event system to decouple features
- Caching: Use CacheManager for frequently accessed data
- 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