How amuthavanmoorthi/taiwan-mobile-server works
Purpose and Runtime
This is an Express + Prisma backend API for a marketplace/administrative workflow involving accounts, products, inventory, orders, FAQs, staff, and teams. It runs on port 4000 and exposes a health endpoint at /api/health. Main server bootstrap is in src/server.ts, with Express application composition in src/app.ts.
HTTP API Boundary
Routing is centralized under src/routes/index.ts, which connects domain controllers to HTTP endpoints. Controllers form the request-facing boundary for authentication, product/catalog operations, inventory, orders, accounts, staff/team administration, and FAQs:
• src/controllers/AuthController.ts
• src/controllers/ProductController.ts
• src/controllers/OrderController.ts
Errors and authenticated-request handling are cross-cutting middleware concerns, implemented in src/middleware/errorHandler.ts and src/middleware/auth.ts.
Identity and Authorization
Authentication logic is separated from route/controller code in src/lib/auth.ts, while authorization enforcement occurs in middleware. Seeded roles indicate buyer, staff, and admin access tiers; controllers such as src/controllers/AccountController.ts, src/controllers/StaffController.ts, and src/controllers/TeamController.ts likely expose role-sensitive operations. Authentication failures and domain errors are normalized through src/lib/errors.ts.
Persistence and Domain Models
Prisma defines the authoritative relational schema and accesses a local SQLite database in development. Database initialization/access is isolated in src/lib/db.ts, while schema and seed lifecycle are under:
• prisma/schema.prisma
• prisma/seed.ts
• prisma/seed-sites.ts
Application-facing models separate domain/query shaping from controllers, including customer/admin product and order representations:
• src/models/ProductModel.ts
• src/models/ProductAdminModel.ts
• src/models/OrderAdminModel.ts
This separation allows controllers to remain HTTP-oriented while model modules own database-backed domain operations and response views.
Commerce and Catalog Flow
A typical commerce flow enters via product and inventory endpoints, retrieves or mutates catalog state through product/inventory models, then creates and administers orders through order models and payment services. Key boundaries are:
• Product/catalog: src/controllers/ProductController.ts, src/models/ProductViewModel.ts
• Inventory: src/controllers/InventoryController.ts
• Order/payment: src/controllers/OrderController.ts, src/services/PaymentService.ts
BidModel.ts suggests bidding is a related transaction mechanism within the product/order domain.
Upload and 3D Modeling Pipeline
The repository includes a media-to-3D processing subsystem distinct from the core HTTP/database path. src/services/UploadService.ts handles upload-facing integration; src/services/ModelingService.ts selects or coordinates processing providers. Provider implementations isolate pipeline variants:
• src/services/providers/localPipeline.ts
• src/services/providers/splatPipeline.ts
The external processing boundary is implemented by Node and Python scripts, including scripts/photo-to-3d.mjs, scripts/splat-to-3d.mjs, and scripts/splat_reconstruct.py. Supporting geometry/segmentation modules in scripts/lib/ indicate the pipeline can transform photos or splat data into 3D assets.
Infrastructure and Operations
Development persistence is SQLite managed through Prisma; reset and seed operations rebuild the local database and load demo data. The service can also be containerized through Dockerfile.splat, likely for the splat/3D runtime with its additional dependencies. Core startup and operational dependencies are defined by package.json, while Prisma schema evolution is managed from prisma/schema.prisma.
Main entry points: ProductController.ts Domain controllers · app.ts App composition · ModelingService.ts Modeling service · db.ts Database access
Components 19
HTTP API
- Server bootstrap · Runs the API on port 4000.
src/server.ts - App composition
src/app.ts - Route registry · Owns the API route boundary, including health.
src/routes/index.ts - Auth middleware
src/middleware/auth.ts - Error handler
src/middleware/errorHandler.ts - Domain controllers · Authentication, catalog, orders, accounts, staff, teams, and FAQs.
src/controllers/ProductController.ts
Commerce domain
- Authentication
src/lib/auth.ts - Commerce models · Product, order, inventory, bid, and response-view operations.
src/models/ProductModel.ts - Payment service
src/services/PaymentService.ts
Persistence
- Database access
src/lib/db.ts - Relational schema · Authoritative marketplace data model.
prisma/schema.prisma - Local SQLite
- Seed lifecycle · Loads demo roles and site data.
prisma/seed.ts
3D pipeline
- Upload service
src/services/UploadService.ts - Modeling service · Selects the 3D processing provider.
src/services/ModelingService.ts - Photo pipeline
src/services/providers/localPipeline.ts - Splat pipeline
src/services/providers/splatPipeline.ts - 3D processing scripts · Transforms photos or splat data into 3D assets.
scripts/photo-to-3d.mjs - Splat container · Provides dependencies for the splat/3D runtime.
Dockerfile.splat
Connections 21
- Server bootstrap → App composition: starts
- App composition → Route registry: mounts
- App composition → Auth middleware: uses
- App composition → Error handler: uses
- Route registry → Domain controllers: dispatches to
- Auth middleware → Authentication: verifies identity with
- Domain controllers → Authentication: authenticates
- Domain controllers → Commerce models: uses
- Domain controllers → Payment service: processes payments through
- Domain controllers → Upload service: accepts media through
- Commerce models → Database access: queries
- Database access → Local SQLite: connects to
- Relational schema → Database access: defines client data model
- Seed lifecycle → Relational schema: loads schema data for
- Seed lifecycle → Local SQLite: populates
- Upload service → Modeling service: submits media to
- Modeling service → Photo pipeline: selects
- Modeling service → Splat pipeline: selects
- Photo pipeline → 3D processing scripts: runs
- Splat pipeline → 3D processing scripts: runs
- Splat container → Splat pipeline: hosts runtime for