How davronov-alimardon/canva-clone works
Main Components
a. Frontend Client:
• Next.js App – Organized under the “src/app” directory, which includes separate routes for authentication (sign-in, sign-up) and dashboard functionalities.
• Editor – A dedicated section under “src/features/editor” and “src/app/editor/[projectId]” using multiple UI components and hooks for drawing, image handling, and text functionality.
• UI Components – Found in “src/components” and “src/features/*/components”, representing reusable pieces like buttons, avatars, modals, sidebars, etc.
b. Backend API:
• API Routes – Implemented in “src/app/api” that cover multiple endpoints. Specific API endpoints include:
• General application endpoints (under /[[...route]] with endpoints for AI, images, projects, subscriptions, and users).
• Auth endpoints (managed through the NextAuth route in “src/app/api/auth/[...nextauth]”).
• Upload endpoints (using Uploadthing located in “src/app/api/uploadthing”).
c. Database Layer:
• Drizzle ORM & Migrations – Located in “drizzle” (with SQL migration files) and “src/db” (with the Drizzle setup and schema definitions). This is the core for database interactions.
d. Features and Business Logic:
• Authentication-related features – In “src/features/auth” (components, hooks, utilities for sign-in/up flows).
• Projects and Subscriptions – With their own APIs, hooks, and UI components under “src/features/projects” and “src/features/subscriptions”.
• AI and Images – Found in “src/features/ai” and “src/features/images”, adding image generation and manipulation capabilities.
e. External Services/Integrations:
• Payment processing using Stripe (integration code in “src/lib/stripe”).
• Image service integrations (Unsplash, Replicate, Uploadthing, etc. in “src/lib”).
f. Other Configurations and Tools:
• Global CSS and theme configurations (“src/app/globals.css”, tailwind.config.ts).
• Next.js configurations (e.g., “next.config.mjs”, “tsconfig.json”).
• Environment settings (e.g., “.env.example” for env variables).
Relationships and Interactions
• The Frontend renders pages (like the Dashboard and Editor) that call API routes to fetch or update data.
• API endpoints safely orchestrate business logic, handling authentication (via NextAuth), project management, AI image generation, image uploading, and subscriptions.
• The Database layer (managed with Drizzle ORM) underpins persistent storage for user data, projects, templates, and subscription details.
• Integration components (under “src/lib”) wrap third-party services and propagate data to/from API endpoints.
• Components and hooks in “features” interact heavily with the API and database as well as the UX provided by UI components.
• Data flow (e.g., user actions from the Editor, subscriptions, project updates) moves from UI components → custom hooks → API routes → database operations, with results reflected back in the UI.
Architectural Patterns & Principles
• Modular and Feature-Driven Structure: Organizing functionality by features (auth, editor, projects, subscriptions) promotes separation of concerns.
• Client-Server Separation: The Next.js app uses both server-rendered pages and API routes, separating frontend view logic from backend business logic.
• Reusable UI Components: The UI is built using a set of atomic components for consistency and reusability.
• Integration with External Services: Encapsulation of third-party integrations in dedicated “src/lib” modules.