Overview
The Vaniyk Empire API is built on a modern Node.js architecture that combines multiple cloud services to deliver a robust content management and payment platform. The system uses Express.js for the web framework, MongoDB for data persistence, Supabase for authentication, Cloudinary for media storage, and Stripe for payment processing.Architecture Diagram
Core Components
Express.js Server
The application uses Express.js as the web framework, configured in/workspace/source/src/server.js:1.
MongoDB with Mongoose
MongoDB serves as the primary database, handling all persistent data including users, content, purchases, and categories. Connection is managed through Mongoose ODM.Data Models
The system uses four primary Mongoose models:User Model
User Model
Stores user profiles linked to Supabase authentication.Location:
/workspace/source/src/models/User.js:1Content Model
Content Model
Manages all content items (PDFs, videos, audio).Includes text search index on
title, description, and tags fields.Location: /workspace/source/src/models/Content.js:1Purchase Model
Purchase Model
Tracks all content purchases and payment status.Compound index on
(user, content) prevents duplicate purchases and enables fast lookups.Location: /workspace/source/src/models/Purchase.js:1Supabase Authentication
Supabase handles all authentication and user identity management. The API validates JWT tokens on protected routes.The authentication middleware attaches both
req.user (Supabase) and req.mongoUser (MongoDB) to the request object, allowing access to both authentication data and application-specific user properties like roles.Admin Authorization
Admin-only routes use an additional middleware layer:Cloudinary Storage
Cloudinary manages all file storage for content files and thumbnails. The system usesmulter-storage-cloudinary to handle uploads directly to Cloudinary.
Cloudinary categorizes files into different resource types:
image (for PDFs and thumbnails), video (for videos and audio), and auto for automatic detection. Each content type is organized into separate folders.Stripe Payments
Stripe handles all payment processing through Payment Intents and webhooks for asynchronous payment confirmation.- Payment Intents for secure client-side payment collection
- Webhooks for server-side payment confirmation
- Metadata to link payments to content and users
Request Flow
Authenticated Request Flow
Admin Request Flow
Environment Configuration
The system requires the following environment variables:Error Handling
The application implements centralized error handling:400- Bad Request (validation errors)401- Unauthorized (missing/invalid token)403- Forbidden (insufficient permissions)404- Not Found (resource doesn’t exist)500- Internal Server Error
Security Features
JWT Authentication
All protected routes require valid Supabase JWT tokens
Role-Based Access
Admin routes protected with role verification
Webhook Verification
Stripe webhooks verified using signing secrets
File Size Limits
Upload size limited to 500MB to prevent abuse
Performance Optimizations
- Database Indexing: Text search index on content fields, compound index on purchases
- Field Selection: Public endpoints exclude sensitive fields like
fileUrl - Pagination: All list endpoints support pagination with configurable limits
- Direct Upload: Files upload directly to Cloudinary, reducing server load
Next Steps
Content Management
Learn how content is created, stored, and accessed
Payment Flow
Understand the complete payment lifecycle