How saadtw/craftit works
CraftIt is a single Next.js App Router monolith that combines the UI, API, domain logic, and database access in one repository. The architecture is centered around role-based experiences for customers, manufacturers, and admins, with shared backend models and route handlers underneath.
The top-level UI is organized by persona:
• app/customer, app/manufacturer, and app/admin contain the main dashboard shells and feature pages.
• app/auth contains signup/login/password recovery/verification flows.
• app/manufacturers, app/bids, and app/custom-orders expose shared public or cross-role pages.
This separation is important for diagramming because the same backend services and models support multiple frontend surfaces.
All server-side HTTP endpoints live under app/api and are grouped by domain rather than by role. The main business domains are orders, products, RFQs, bids, group buys, disputes, support tickets, notifications, chat, payments, users, uploads, and verification documents. These route handlers are the main boundary between the browser and the backend domain logic.
MongoDB with Mongoose is the system of record. The models/ directory defines the persistent entities that drive the marketplace: User, Product, Order, RFQ, Bid, GroupBuy, Chat, ChatMessage, Dispute, SupportTicket, Notification, Review, AdminLog, VerificationDocument, and related sub-entities like product questions and support messages. Most workflows are multi-entity: for example, an RFQ can spawn bids, an accepted bid becomes an order, and the order can later generate milestones, reviews, disputes, and notifications.
Authentication is built around NextAuth.js with JWT credentials sessions, plus separate auth utilities in lib/auth.js, lib/requestAuth.js, lib/token.js, and lib/mobileAuth.js. The app supports browser sessions and a distinct mobile auth surface under app/api/mobile/auth/*. Session state is shared into the client through app/SessionProvider.js.
The marketplace’s core transaction flow runs through RFQs, bids, and orders. Customers create RFQs or direct custom orders, manufacturers respond with bids, and a selected bid can be accepted into an order. Orders then progress through status updates, milestones, shipping, cancellation, and review endpoints. This is the central commercial workflow the architecture should emphasize.
Chat is its own subsystem and is tied to orders and bids. The API includes inbox, per-order chat, read tracking, and a stream endpoint, while lib/chatEmitter.js and lib/sessionEmitter.js indicate real-time event propagation. In the diagram, treat chat as an asynchronous collaboration layer attached to commercial transactions rather than a standalone feature.
Payments are handled as a Stripe-backed escrow-like flow. The API exposes create-intent, capture, refund, and webhook handlers, and the README describes an authorize-then-capture lifecycle. Stripe is an external dependency that affects order state transitions, especially when an order is accepted, cancelled, or disputed.
File and document handling is another distinct subsystem. app/api/upload/* manages uploads, and the README specifies AWS S3 for images, 3D models, and verification documents. This supports product listings, customer order attachments, and manufacturer verification files. In the architecture diagram, S3 should sit outside the app as object storage, with uploads initiated through API routes.
Admin operations are isolated both in UI and in API routes under app/api/admin/*. The admin backend covers manufacturer verification, user suspension, platform stats, activity logs, disputes, and order oversight. models/AdminLog.js plus the admin activity-log API indicate a strong audit trail boundary for sensitive moderation actions.
Manufacturer verification is a dedicated workflow with its own document model and approval endpoints. Manufacturers start unverified, upload business documents, and admins review or verify them. This is a distinct compliance path that gates access to manufacturer capabilities like bidding, publishing products, and participating in platform commerce.
Notifications, support, and reviews form the post-transaction and operational support layer. Notifications are system-generated events, support tickets allow issue escalation with threaded messages, and reviews are linked to completed orders. These features depend on the core order and user domains but have their own routes and models.
The codebase also includes service modules in services/ for non-trivial business logic such as bid comparison, bid handling, matching, and notification generation. These services sit between API routes and Mongoose models, acting as the domain logic layer that keeps route handlers thin.
From an infrastructure perspective, the important external dependencies are MongoDB, AWS S3, Stripe, and NextAuth. The runtime is a Next.js server/client hybrid using React and Tailwind CSS v4 on the frontend, but the diagram should focus less on styling and more on the boundaries between role-based pages, domain APIs, service logic, persistence, and external integrations.
Main entry points: models Mongoose models · api Marketplace API · auth Auth API · admin Admin API
Components 22
UI surfaces
Role-based App Router pages and shared public screens.
- Customer UI · Customer dashboard, marketplace, orders, RFQs, support, and payments.
app/customer - Manufacturer UI · Manufacturer dashboard, bids, products, orders, group buys, and support.
app/manufacturer - Admin UI · Admin dashboards for users, manufacturers, disputes, orders, support, and logs.
app/admin - Auth UI · Login, signup, password recovery, and email verification flows.
app/auth - Public pages · Shared marketplace pages for manufacturers, bids, custom orders, and home.
app
API routes
HTTP boundaries grouped by domain and role.
- Auth API · NextAuth, registration, password reset, verification, and session endpoints.
app/api/auth - Marketplace API · Products, RFQs, bids, custom orders, group buys, and manufacturer discovery endpoints.
app/api - Orders API · Order lifecycle endpoints for creation, status, milestones, shipping, cancellation, and reviews.
app/api/orders - Chat API · Order chat, inbox, read tracking, and streaming endpoints.
app/api/chat - Payments API · Stripe payment intent, capture, refund, and webhook endpoints.
app/api/payments - Admin API · Moderation, verification, stats, user management, disputes, and order oversight endpoints.
app/api/admin - Support API · Support ticket and threaded message endpoints.
app/api/support-tickets - Upload API · Single and batch upload endpoints for media and verification files.
app/api/upload - Mobile Auth API · Mobile login, logout, session lookup, and refresh endpoints.
app/api/mobile/auth
Core domain
Shared models and business logic used across roles and workflows.
- Domain services · Bid comparison, bid handling, matching, and notification orchestration.
services - Mongoose models · Marketplace entities such as users, products, RFQs, bids, orders, chats, disputes, tickets, reviews, and logs.
models
Infrastructure
Authentication, persistence, messaging, payments, and storage integrations.
- Auth helpers · Shared browser/session auth utilities, token handling, and request authorization.
lib/auth.js - MongoDB · System of record accessed through Mongoose.
- Stripe · External escrow-like payment provider for authorize, capture, refund, and webhook flows.
- S3 storage · External storage for product images, 3D models, and verification documents.
- NextAuth · Session and credential authentication layer for browser and API access.
- Event emitters · Chat and session event propagation for asynchronous updates.
lib/chatEmitter.js
Connections 28
- Customer UI → Marketplace API: uses · Customer screens load and mutate marketplace data through domain APIs.
- Customer UI → Orders API: uses · Customer order, dispute, payment, and review actions.
- Customer UI → Chat API: uses · Customer inbox and order chat interactions.
- Manufacturer UI → Marketplace API: uses · Manufacturer product, RFQ, bid, and group-buy actions.
- Manufacturer UI → Orders API: uses · Manufacturer order progress and milestone updates.
- Manufacturer UI → Chat API: uses · Manufacturer messaging around bids and orders.
- Admin UI → Admin API: uses · Admin moderation and oversight screens.
- Auth UI → Auth API: uses · Signup, login, recovery, and verification flows.
- Public pages → Marketplace API: uses · Public manufacturer, bid, custom order, and product pages.
- Auth API → Auth helpers: auth logic · Shared auth helpers and token/session utilities.
- Auth API → NextAuth: session · NextAuth credential session handling.
- Mobile Auth API → Auth helpers: auth logic · Mobile auth shares request and token utilities.
- Marketplace API → Domain services: domain logic · Route handlers delegate matching, bid comparison, and notifications.
- Orders API → Domain services: domain logic · Order lifecycle endpoints use shared business rules.
- Chat API → Event emitters: events · Chat routes publish realtime updates.
- Admin API → Mongoose models: admin data · Moderation and audit routes persist admin actions and reviews.
- Support API → Mongoose models: support data · Support tickets and threaded messages are stored in MongoDB.
- Upload API → S3 storage: stores · Uploads are written to external object storage.
- Payments API → Stripe: payments · Payment lifecycle and webhook processing.
- Payments API → Domain services: domain logic · Payment handlers coordinate state transitions and notifications.
- Domain services → Mongoose models: persists · Business logic reads and updates marketplace entities.
- Mongoose models → MongoDB: backed by · Mongoose models map to MongoDB collections.
- Auth API → Mongoose models: users · Registration, verification, and session flows use user records.
- Marketplace API → Mongoose models: market data · Products, RFQs, bids, group buys, and custom orders.
- Orders API → Mongoose models: orders · Orders, milestones, disputes, reviews, and notifications.
- Chat API → Mongoose models: chat data · Chats and chat messages are persisted through models.
- Admin API → Stripe: oversight · Admin order and dispute actions can affect payment state.
- Admin API → S3 storage: verification files · Manufacturer verification depends on uploaded documents.