How jashwanth0725/snap-tune works
Project Type and Purpose
• This is a full-stack SaaS application (“AI Caption Generator”) that lets authenticated users upload an image and receive AI-generated captions. It includes a React + TypeScript client, a Node.js + Express backend, MongoDB for persistence, Firebase for authentication, Stripe for payments, Cloudinary for image storage, and an external AI integration (Gemini).
File Structure Analysis
• Top-Level Directories
• /client – Frontend (React, Vite, Tailwind CSS, TypeScript)
• /server – Backend (Express, Mongoose, AI API integrations)
• Backend Patterns
• /server/src/routes → REST endpoints
• /server/src/controllers → Business logic & orchestration
• /server/src/models → Mongoose schemas for users, history, captions, payments
• /server/src/apis → External AI service calls (caption.api.js, summary.api.js)
• /server/src/middlewares → Auth, file‐upload (Multer)
• Layered MVC + service integration pattern
• Frontend Patterns
• /client/src/api → wrappers for backend calls (caption, summary, stripe)
• /client/src/auth → Firebase auth + protected routes
• /client/src/components → UI & AI components
• /client/src/db → client-side caching/state
• /client/src/layout, /client/src/pages → routing & page structure
Key Insights from README
• Workflow: user signs up/logs in → uploads image → backend calls Gemini AI → caption returned → optional save (MongoDB) → payment checks (Stripe)
• Tech stack calls out all external services: Firebase Auth, Stripe, Cloudinary, Gemini AI
• Scalability & history tracking are core non-functional requirements
Main Components
• User Interface Layer
• React Client (Browser)
• Firebase Auth widget
• API Layer
• Express REST API (Routes → Controllers → Services)
• Business Logic Layer
• CaptionController invokes Gemini via CaptionAPI
• HistoryController reads/writes MongoDB
• StripeController handles payment workflows
• Data Layer
• MongoDB (hosted in the cloud)
• Cloudinary for image storage
• External Services
• Gemini AI service
• Firebase Auth service
• Stripe payment gateway
Relationships & Data Flows
• Express → Gemini AI API → response back to Controller → HTTP response back to UI
• Save/retrieve operations: Controller ↔ MongoDB
• Image upload flow: Browser → Cloudinary (via backend or direct signed upload) → stored URL → backend
• Auth flow: React ↔ Firebase Auth → JWT passed in header to Express → auth.middleware
• Payment flow: React ↔ Stripe SDK → backend StripeController → Stripe API
Architectural Patterns & Principles
• Layered MVC on the server (Routes → Controllers → Models)
• Separation of concerns: UI, API gateway, business logic, persistence, external integrations
• Stateless REST endpoints, token-based auth via Firebase
• Single Responsibility in controllers/services
Detail-Level Recommendations
• Zoom into critical flows: Image upload → Caption generation → Save to history
• Rate limits or free-tier checks (20 free uses)
• Call out middleware steps: auth.middleware, multer.middleware