How itusiai/open-voicecanvas works
Main Components
• Frontend Interface:
• Built with Next.js 14 and styled using Tailwind CSS and shadcn/ui.
• Contains multiple UI pages/components (e.g., home, auth pages, profile, pricing, cloning) organized in the “app” directory.
• Navigation, theme, and analytics provided by components (e.g., nav-bar, theme-provider, google-analytics).
• Backend/API Endpoints:
• Structured under the “app/api” directory using Next.js routing conventions.
• Contains endpoints for authentication (login, register, NextAuth), checkout sessions (Stripe integration), speech processing, voice cloning, user management (plan updates, quota updates), and webhook handling (Stripe).
• Business Logic & Utility Libraries:
• Located in the “lib” directory which encapsulates core functionalities such as authentication, rate limiting, voice configurations, and third-party API integrations.
• Also includes a robust i18n system in “lib/i18n” for multi-language support.
• Database Layer:
• Managed with Prisma (files in the “prisma” directory) connecting to a Neon PostgreSQL database.
• Contains models for Users, Subscriptions, Character Quotas, and Cloned Voices as described in the README.
• External Services Integration:
• Voice Services: OpenAI TTS, AWS Polly, MiniMax.
• Authentication: NextAuth configured to support OAuth providers like Google and GitHub.
• Payment & Subscription: Stripe payment (checkout sessions and webhooks).
• Environment configurations for API keys and credentials (defined by environment variables).
Relationships and Data Flows
• The Frontend communicates with the Backend APIs through HTTP requests, initiating actions such as user login, registration, file uploads, and voice service requests.
• API endpoints delegate tasks to business logic in the “lib” folder to handle core actions (voice processing, persistence with Prisma, rate limiting, etc.).
• The database (PostgreSQL via Prisma) stores user data, subscription details, usage quotas, and voice clone records.
• External integrations are triggered as needed:
• For TTS/voice cloning, the API endpoints call external services (OpenAI, AWS, MiniMax) through the corresponding modules in “lib”.
• Payment processing involves sending requests to Stripe and receiving webhook events that update the subscription and quota state in the database.
Architectural Patterns and Design Principles
• Separation of Concerns:
• Clearly separate the UI layer (pages/components) from the API/business logic and further separate core integrations (external services) in the “lib” folder.
• Use Next.js API routes to encapsulate backend functionality making the project modular.
• Modular Design:
• Reusable UI components stored in the “components” directory along with dedicated hooks (e.g., use-analytics, use-speech) ensure reusability and ease testing.
• The “lib” directory centralizes third-party integrations and utility functions.
• Extensibility and Scalability:
• The file and folder structure allows you to add new services or modify existing ones without disturbing the overall architecture.
• The i18n structure and modular API routes support expanding language support or additional functionalities.