# abhisheknavgan95/thumbcraft architecture

> Architecture diagram of the GitHub repository abhisheknavgan95/thumbcraft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhisheknavgan95/thumbcraft
- Repository: https://github.com/abhisheknavgan95/thumbcraft

## Overview

#### 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: [`packages/rabbitmq-client/src/index.ts`](https://github.com/abhisheknavgan95/thumbcraft/blob/main/packages/rabbitmq-client/src/index.ts) (RabbitMQ), [`apps/api-gateway/src/app.ts`](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/api-gateway/src/app.ts) (API gateway), [`apps/generation-worker/src/modules/jobs/job.service.ts`](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/modules/jobs/job.service.ts) (Generation jobs), [`apps/wallet-service/src/services/wallet.service.ts`](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/wallet-service/src/services/wallet.service.ts) (Wallet service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_modern["Modern workspace"]
  node_web["React thumbnail client<br/>Vite + React<br/>[App.jsx]"]
  node_web_state["Client generation state<br/>Zustand store<br/>[imageStore.js]"]
  node_gateway{{"API gateway<br/>HTTP boundary<br/>[app.ts]"}}
  node_auth["Auth service<br/>identity service<br/>[auth.ts]"]
  node_auth_db[("Identity database<br/>Prisma database<br/>[schema.prisma]")]
  node_generation["Generation service<br/>generation domain<br/>[index.ts]"]
  node_jobs["Generation jobs<br/>job service<br/>[job.service.ts]"]
  node_sessions["Generation sessions<br/>session service<br/>[session.service.ts]"]
  node_wallet["Wallet service<br/>credits and checkout<br/>[wallet.service.ts]"]
  node_notifications["Notification service<br/>event consumer"]
end

subgraph group_events["Async messaging"]
  node_rabbit["RabbitMQ<br/>event broker<br/>[index.ts]"]
  node_event_contracts["Messaging contracts<br/>shared contracts<br/>[index.ts]"]
end

subgraph group_legacy["Legacy stack"]
  node_legacy_api["Legacy Express backend<br/>standalone API<br/>[server.js]"]
  node_legacy_generation["Legacy image pipeline<br/>controller pipeline<br/>[imageController.js]"]
end

node_ai_provider{{"AI providers<br/>OpenAI / model providers<br/>[prompt-enhancer.ts]"}}
node_object_storage[("Object storage<br/>S3-compatible storage<br/>[s3.service.ts]")]
node_stripe{{"Stripe<br/>payment provider<br/>[stripe.service.ts]"}}
node_mail{{"Transactional email<br/>mail delivery<br/>[mail.service.ts]"}}
node_infra["Compose infrastructure<br/>local deployment<br/>[docker-compose.yml]"]

node_web -->|"updates workflow state"| node_web_state
node_web -->|"public HTTP API"| node_gateway
node_gateway -->|"auth requests"| node_auth
node_gateway -->|"generation, gallery, enhancement"| node_generation
node_gateway -->|"wallet and checkout"| node_wallet
node_auth -->|"identity persistence"| node_auth_db
node_generation -->|"creates jobs"| node_jobs
node_generation -->|"records sessions"| node_sessions
node_jobs -->|"enhance and generate"| node_ai_provider
node_jobs -->|"stores outputs"| node_object_storage
node_auth -.->|"user registered"| node_rabbit
node_jobs -.->|"generation events"| node_rabbit
node_event_contracts -.->|"event schemas"| node_rabbit
node_rabbit -.->|"registration and billing events"| node_wallet
node_wallet -->|"checkout and payments"| node_stripe
node_stripe -->|"payment webhook"| node_wallet
node_rabbit -.->|"notification events"| node_notifications
node_notifications -->|"sends email"| node_mail
node_infra -.->|"provisions"| node_rabbit
node_legacy_api -->|"routes image requests"| node_legacy_generation

click node_web "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/web/src/App.jsx"
click node_web_state "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/web/src/stores/imageStore.js"
click node_gateway "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/api-gateway/src/app.ts"
click node_auth "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/auth-service/src/routes/auth.ts"
click node_auth_db "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/auth-service/prisma/schema.prisma"
click node_generation "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/index.ts"
click node_jobs "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/modules/jobs/job.service.ts"
click node_sessions "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/modules/sessions/session.service.ts"
click node_ai_provider "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/providers/openai/prompt-enhancer.ts"
click node_object_storage "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/storage/s3.service.ts"
click node_wallet "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/wallet-service/src/services/wallet.service.ts"
click node_stripe "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/wallet-service/src/services/stripe.service.ts"
click node_rabbit "https://github.com/abhisheknavgan95/thumbcraft/blob/main/packages/rabbitmq-client/src/index.ts"
click node_event_contracts "https://github.com/abhisheknavgan95/thumbcraft/blob/main/packages/messaging-contract/src/index.ts"
click node_notifications "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/notification-service/src/consumers/notification-events.consumer.ts"
click node_mail "https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/notification-service/src/services/mail.service.ts"
click node_infra "https://github.com/abhisheknavgan95/thumbcraft/blob/main/docker-compose.yml"
click node_legacy_api "https://github.com/abhisheknavgan95/thumbcraft/blob/main/backend/server.js"
click node_legacy_generation "https://github.com/abhisheknavgan95/thumbcraft/blob/main/backend/controllers/imageController.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_web_state,node_gateway,node_auth,node_auth_db,node_generation,node_jobs,node_sessions,node_wallet,node_notifications toneBlue
class node_rabbit,node_event_contracts toneAmber
class node_legacy_api,node_legacy_generation toneMint
class node_ai_provider,node_object_storage,node_stripe,node_mail,node_infra toneNeutral
```

## Components

### Modern workspace

TypeScript microservices and React client.

- [React thumbnail client](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/web/src/App.jsx): Vite + React · Multi-step creation, results, and history UI. · `apps/web/src/App.jsx`
- [Client generation state](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/web/src/stores/imageStore.js): Zustand store · Tracks image and generation workflow state. · `apps/web/src/stores/imageStore.js`
- [API gateway](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/api-gateway/src/app.ts): HTTP boundary · Applies auth, error handling, request composition, and multipart support. · `apps/api-gateway/src/app.ts`
- [Auth service](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/auth-service/src/routes/auth.ts): identity service · Owns signup, OTP, login, profiles, and tokens. · `apps/auth-service/src/routes/auth.ts`
- [Identity database](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/auth-service/prisma/schema.prisma): Prisma database · Durable user identity data. · `apps/auth-service/prisma/schema.prisma`
- [Generation service](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/index.ts): generation domain · Owns models, gallery, uploads, enhancement, sessions, and jobs. · `apps/generation-worker/src/index.ts`
- [Generation jobs](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/modules/jobs/job.service.ts): job service · Creates and runs generation jobs. · `apps/generation-worker/src/modules/jobs/job.service.ts`
- [Generation sessions](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/modules/sessions/session.service.ts): session service · Persists user generation history and sessions. · `apps/generation-worker/src/modules/sessions/session.service.ts`
- [Wallet service](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/wallet-service/src/services/wallet.service.ts): credits and checkout · Owns credit balances, packages, checkout, and billing. · `apps/wallet-service/src/services/wallet.service.ts`
- [Notification service](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/notification-service/src/consumers/notification-events.consumer.ts): event consumer · Handles OTP, registration, purchase, and generation-result notifications. · `apps/notification-service/src/consumers/notification-events.consumer.ts`

### Async messaging

Shared RabbitMQ event transport.

- [RabbitMQ](https://github.com/abhisheknavgan95/thumbcraft/blob/main/packages/rabbitmq-client/src/index.ts): event broker · Cross-service domain event transport. · `packages/rabbitmq-client/src/index.ts`
- [Messaging contracts](https://github.com/abhisheknavgan95/thumbcraft/blob/main/packages/messaging-contract/src/index.ts): shared contracts · Defines cross-service event payloads. · `packages/messaging-contract/src/index.ts`

### Legacy stack

Independently runnable Express implementation.

- [Legacy Express backend](https://github.com/abhisheknavgan95/thumbcraft/blob/main/backend/server.js): standalone API · Separate MongoDB/Cloudinary-oriented implementation. · `backend/server.js`
- [Legacy image pipeline](https://github.com/abhisheknavgan95/thumbcraft/blob/main/backend/controllers/imageController.js): controller pipeline · Orchestrates Gemini/OpenAI generation and Cloudinary uploads. · `backend/controllers/imageController.js`

### Other components

- [AI providers](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/providers/openai/prompt-enhancer.ts): OpenAI / model providers · Enhances prompts and generates images. · `apps/generation-worker/src/providers/openai/prompt-enhancer.ts`
- [Object storage](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/generation-worker/src/storage/s3.service.ts): S3-compatible storage · Stores generated and uploaded image assets. · `apps/generation-worker/src/storage/s3.service.ts`
- [Stripe](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/wallet-service/src/services/stripe.service.ts): payment provider · Processes checkout and payment webhooks. · `apps/wallet-service/src/services/stripe.service.ts`
- [Transactional email](https://github.com/abhisheknavgan95/thumbcraft/blob/main/apps/notification-service/src/services/mail.service.ts): mail delivery · Sends notification emails. · `apps/notification-service/src/services/mail.service.ts`
- [Compose infrastructure](https://github.com/abhisheknavgan95/thumbcraft/blob/main/docker-compose.yml): local deployment · Bootstraps services, RabbitMQ, and databases. · `docker-compose.yml`

## Connections

- 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
