How abhisheknavgan95/thumbcraft works
Purpose and Architecture Split
This repository builds an AI thumbnail-generation product: prompt/image-driven thumbnail creation, enhancement, storage, history, auth, and credit-based billing. It contains:
• A newer TypeScript microservice workspace under apps/ and shared packages/.
• A legacy standalone Express/MongoDB implementation under backend/, which is the architecture described by the root README.
Primary modern entry points: apps/web/src/main.jsx, apps/api-gateway/src/index.ts, apps/auth-service/src/index.ts, apps/generation-worker/src/index.ts, apps/wallet-service/src/index.ts, and apps/notification-service/src/index.ts.
Web Client and User Flow
The React/Vite frontend implements the multi-step thumbnail workflow: select mode, provide prompt or source image, select options/templates, submit, then view/download results and history. Zustand stores separate auth, image/generation, and UI state.
• apps/web/src/App.jsx
• apps/web/src/components/QuestionFlow.jsx
• apps/web/src/stores/imageStore.js
• apps/web/src/api/client.js
The browser should communicate through the API gateway rather than directly with internal services.
API Gateway: External HTTP Boundary
The gateway is the public-facing HTTP composition layer. It exposes auth, enhancement, gallery, generation, model, session/history, and wallet routes; applies auth and centralized error handling; and proxies/coordinates service calls through its HTTP client and multipart support.
• apps/api-gateway/src/app.ts
• apps/api-gateway/src/routes/generations.ts
• apps/api-gateway/src/routes/enhance.ts
• apps/api-gateway/src/plugins/auth.ts
This boundary protects internal services from browser-facing request shape, authorization propagation, and file-upload concerns.
Identity and User Lifecycle
auth-service owns user identity in its Prisma database. It supports signup, OTP verification, login, profile access, and an admin-registration path. Password hashing, token issuance, and OTP behavior are service-level concerns. User-registration events likely initiate downstream wallet setup and welcome notifications.
• apps/auth-service/src/routes/auth.ts
• apps/auth-service/src/controllers/signup.controller.ts
• apps/auth-service/src/services/token.service.ts
• apps/auth-service/prisma/schema.prisma
Generation Domain and AI/Storage Pipeline
generation-worker is the core generation-domain service, despite its name also exposing an application/router. It owns models, generation sessions/jobs, gallery templates/categories, uploads, and prompt enhancement. The expected flow is: authenticated request → session/job creation → optional OpenAI prompt enhancement → model/provider generation → object storage output → generation events and wallet billing integration.
• apps/generation-worker/src/modules/jobs/job.service.ts
• apps/generation-worker/src/providers/openai/prompt-enhancer.ts
• apps/generation-worker/src/modules/sessions/session.service.ts
• apps/generation-worker/src/storage/s3.service.ts
Its Prisma schema defines the durable generation-domain data; S3-compatible object storage replaces the Cloudinary-oriented legacy implementation.
Wallet, Checkout, and Asynchronous Events
wallet-service owns credits, packages, checkout sessions, Stripe integration, and payment webhooks. It consumes domain events for user registration and generation billing, making credit charging decoupled from generation request handling. It also publishes/participates in event-driven purchase outcomes.
• apps/wallet-service/src/services/wallet.service.ts
• apps/wallet-service/src/services/stripe.service.ts
• apps/wallet-service/src/handlers/generation-billing.handler.ts
• apps/wallet-service/src/routes/webhook.ts
RabbitMQ is the intended cross-service event transport, with contracts and client abstractions shared from:
• packages/messaging-contract/src/index.ts
• packages/rabbitmq-client/src/index.ts
Notifications, Infrastructure, and Legacy Boundary
notification-service consumes notification events and sends transactional email for OTP, registration, and purchase outcomes; it also contains generation result templates, implying generation-completed/failed event handling.
• apps/notification-service/src/consumers/notification-events.consumer.ts
• apps/notification-service/src/services/mail.service.ts
• apps/notification-service/src/templates/generation-completed.ts
Infrastructure includes Docker Compose, RabbitMQ bootstrap, and database initialization:
• docker-compose.yml
• infra/scripts/bootstrap-rabbitmq.mjs
• infra/scripts/init-databases.sql
The legacy stack remains independently runnable: Express routes/controllers orchestrate Gemini, OpenAI, Cloudinary, and MongoDB.
• backend/server.js
• backend/controllers/imageController.js
• backend/utils/imageGenerator.js
• backend/utils/cloudinaryUpload.js
Do not conflate legacy MongoDB/Cloudinary endpoints with the newer Prisma/S3/RabbitMQ service architecture without verifying deployment routing.
Main entry points: index.ts RabbitMQ · app.ts API gateway · job.service.ts Generation jobs · wallet.service.ts Wallet service
Components 19
Modern workspace
TypeScript microservices and React client.
- React thumbnail client · Multi-step creation, results, and history UI.
apps/web/src/App.jsx - Client generation state · Tracks image and generation workflow state.
apps/web/src/stores/imageStore.js - API gateway · Applies auth, error handling, request composition, and multipart support.
apps/api-gateway/src/app.ts - Auth service · Owns signup, OTP, login, profiles, and tokens.
apps/auth-service/src/routes/auth.ts - Identity database · Durable user identity data.
apps/auth-service/prisma/schema.prisma - Generation service · Owns models, gallery, uploads, enhancement, sessions, and jobs.
apps/generation-worker/src/index.ts - Generation jobs · Creates and runs generation jobs.
apps/generation-worker/src/modules/jobs/job.service.ts - Generation sessions · Persists user generation history and sessions.
apps/generation-worker/src/modules/sessions/session.service.ts - Wallet service · Owns credit balances, packages, checkout, and billing.
apps/wallet-service/src/services/wallet.service.ts - Notification service · Handles OTP, registration, purchase, and generation-result notifications.
apps/notification-service/src/consumers/notification-events.consumer.ts
Async messaging
Shared RabbitMQ event transport.
- RabbitMQ · Cross-service domain event transport.
packages/rabbitmq-client/src/index.ts - Messaging contracts · Defines cross-service event payloads.
packages/messaging-contract/src/index.ts
Legacy stack
Independently runnable Express implementation.
- Legacy Express backend · Separate MongoDB/Cloudinary-oriented implementation.
backend/server.js - Legacy image pipeline · Orchestrates Gemini/OpenAI generation and Cloudinary uploads.
backend/controllers/imageController.js
Other components
- AI providers · Enhances prompts and generates images.
apps/generation-worker/src/providers/openai/prompt-enhancer.ts - Object storage · Stores generated and uploaded image assets.
apps/generation-worker/src/storage/s3.service.ts - Stripe · Processes checkout and payment webhooks.
apps/wallet-service/src/services/stripe.service.ts - Transactional email · Sends notification emails.
apps/notification-service/src/services/mail.service.ts - Compose infrastructure · Bootstraps services, RabbitMQ, and databases.
docker-compose.yml
Connections 20
- React thumbnail client → Client generation state: updates workflow state
- React thumbnail client → API gateway: public HTTP API
- API gateway → Auth service: auth requests
- API gateway → Generation service: generation, gallery, enhancement
- API gateway → Wallet service: wallet and checkout
- Auth service → Identity database: identity persistence
- Generation service → Generation jobs: creates jobs
- Generation service → Generation sessions: records sessions
- Generation jobs → AI providers: enhance and generate
- Generation jobs → Object storage: stores outputs
- Auth service → RabbitMQ: user registered
- Generation jobs → RabbitMQ: generation events
- Messaging contracts → RabbitMQ: event schemas
- RabbitMQ → Wallet service: registration and billing events
- Wallet service → Stripe: checkout and payments
- Stripe → Wallet service: payment webhook
- RabbitMQ → Notification service: notification events
- Notification service → Transactional email: sends email
- Compose infrastructure → RabbitMQ: provisions
- Legacy Express backend → Legacy image pipeline: routes image requests