# amuthavanmoorthi/taiwan-mobile-server architecture

> Architecture diagram of the GitHub repository amuthavanmoorthi/taiwan-mobile-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amuthavanmoorthi/taiwan-mobile-server
- Repository: https://github.com/amuthavanmoorthi/taiwan-mobile-server

## Overview

#### 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: [`src/controllers/ProductController.ts`](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/controllers/ProductController.ts) (Domain controllers), [`src/app.ts`](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/app.ts) (App composition), [`src/services/ModelingService.ts`](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/ModelingService.ts) (Modeling service), [`src/lib/db.ts`](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/lib/db.ts) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["Server bootstrap<br/>Express runtime<br/>[server.ts]"]
  node_app["App composition<br/>Express app<br/>[app.ts]"]
  node_routes["Route registry<br/>HTTP routing<br/>[index.ts]"]
  node_auth_middleware["Auth middleware<br/>authorization<br/>[auth.ts]"]
  node_error_handler["Error handler<br/>middleware<br/>[errorHandler.ts]"]
  node_controllers["Domain controllers<br/>HTTP controllers"]
end

subgraph group_commerce["Commerce domain"]
  node_auth_logic["Authentication<br/>identity logic<br/>[auth.ts]"]
  node_commerce_models["Commerce models<br/>domain/query models<br/>[ProductModel.ts]"]
  node_payment["Payment service<br/>commerce service<br/>[PaymentService.ts]"]
end

subgraph group_data["Persistence"]
  node_prisma_client["Database access<br/>Prisma client<br/>[db.ts]"]
  node_prisma_schema["Relational schema<br/>Prisma schema<br/>[schema.prisma]"]
  node_sqlite[("Local SQLite<br/>development database")]
  node_seed_data["Seed lifecycle<br/>database seeding<br/>[seed.ts]"]
end

subgraph group_pipeline["3D pipeline"]
  node_upload_service["Upload service<br/>media integration<br/>[UploadService.ts]"]
  node_modeling_service["Modeling service<br/>pipeline coordinator<br/>[ModelingService.ts]"]
  node_local_pipeline["Photo pipeline<br/>local provider<br/>[localPipeline.ts]"]
  node_splat_pipeline["Splat pipeline<br/>splat provider<br/>[splatPipeline.ts]"]
  node_processing_scripts{{"3D processing scripts<br/>Node and Python workers<br/>[photo-to-3d.mjs]"}}
  node_splat_container["Splat container<br/>container runtime<br/>[Dockerfile.splat]"]
end

node_server -->|"starts"| node_app
node_app -->|"mounts"| node_routes
node_app -->|"uses"| node_auth_middleware
node_app -->|"uses"| node_error_handler
node_routes -->|"dispatches to"| node_controllers
node_auth_middleware -->|"verifies identity with"| node_auth_logic
node_controllers -->|"authenticates"| node_auth_logic
node_controllers -->|"uses"| node_commerce_models
node_controllers -->|"processes payments through"| node_payment
node_controllers -->|"accepts media through"| node_upload_service
node_commerce_models -->|"queries"| node_prisma_client
node_prisma_client -->|"connects to"| node_sqlite
node_prisma_schema -.->|"defines client data model"| node_prisma_client
node_seed_data -->|"loads schema data for"| node_prisma_schema
node_seed_data -->|"populates"| node_sqlite
node_upload_service -->|"submits media to"| node_modeling_service
node_modeling_service -->|"selects"| node_local_pipeline
node_modeling_service -->|"selects"| node_splat_pipeline
node_local_pipeline -->|"runs"| node_processing_scripts
node_splat_pipeline -->|"runs"| node_processing_scripts
node_splat_container -.->|"hosts runtime for"| node_splat_pipeline

click node_server "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/server.ts"
click node_app "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/app.ts"
click node_routes "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/routes/index.ts"
click node_auth_middleware "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/middleware/auth.ts"
click node_error_handler "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/middleware/errorHandler.ts"
click node_controllers "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/controllers/ProductController.ts"
click node_auth_logic "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/lib/auth.ts"
click node_commerce_models "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/models/ProductModel.ts"
click node_payment "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/PaymentService.ts"
click node_prisma_client "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/lib/db.ts"
click node_prisma_schema "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/prisma/schema.prisma"
click node_seed_data "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/prisma/seed.ts"
click node_upload_service "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/UploadService.ts"
click node_modeling_service "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/ModelingService.ts"
click node_local_pipeline "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/providers/localPipeline.ts"
click node_splat_pipeline "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/providers/splatPipeline.ts"
click node_processing_scripts "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/scripts/photo-to-3d.mjs"
click node_splat_container "https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/Dockerfile.splat"

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_server,node_app,node_routes,node_auth_middleware,node_error_handler,node_controllers toneBlue
class node_auth_logic,node_commerce_models,node_payment toneAmber
class node_prisma_client,node_prisma_schema,node_sqlite,node_seed_data toneMint
class node_upload_service,node_modeling_service,node_local_pipeline,node_splat_pipeline,node_processing_scripts,node_splat_container toneRose
```

## Components

### HTTP API

- [Server bootstrap](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/server.ts): Express runtime · Runs the API on port 4000. · `src/server.ts`
- [App composition](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/app.ts): Express app · `src/app.ts`
- [Route registry](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/routes/index.ts): HTTP routing · Owns the API route boundary, including health. · `src/routes/index.ts`
- [Auth middleware](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/middleware/auth.ts): authorization · `src/middleware/auth.ts`
- [Error handler](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/middleware/errorHandler.ts): middleware · `src/middleware/errorHandler.ts`
- [Domain controllers](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/controllers/ProductController.ts): HTTP controllers · Authentication, catalog, orders, accounts, staff, teams, and FAQs. · `src/controllers/ProductController.ts`

### Commerce domain

- [Authentication](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/lib/auth.ts): identity logic · `src/lib/auth.ts`
- [Commerce models](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/models/ProductModel.ts): domain/query models · Product, order, inventory, bid, and response-view operations. · `src/models/ProductModel.ts`
- [Payment service](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/PaymentService.ts): commerce service · `src/services/PaymentService.ts`

### Persistence

- [Database access](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/lib/db.ts): Prisma client · `src/lib/db.ts`
- [Relational schema](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/prisma/schema.prisma): Prisma schema · Authoritative marketplace data model. · `prisma/schema.prisma`
- **Local SQLite**: development database
- [Seed lifecycle](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/prisma/seed.ts): database seeding · Loads demo roles and site data. · `prisma/seed.ts`

### 3D pipeline

- [Upload service](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/UploadService.ts): media integration · `src/services/UploadService.ts`
- [Modeling service](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/ModelingService.ts): pipeline coordinator · Selects the 3D processing provider. · `src/services/ModelingService.ts`
- [Photo pipeline](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/providers/localPipeline.ts): local provider · `src/services/providers/localPipeline.ts`
- [Splat pipeline](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/src/services/providers/splatPipeline.ts): splat provider · `src/services/providers/splatPipeline.ts`
- [3D processing scripts](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/scripts/photo-to-3d.mjs): Node and Python workers · Transforms photos or splat data into 3D assets. · `scripts/photo-to-3d.mjs`
- [Splat container](https://github.com/amuthavanmoorthi/taiwan-mobile-server/blob/master/Dockerfile.splat): container runtime · Provides dependencies for the splat/3D runtime. · `Dockerfile.splat`

## Connections

- 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
