How jinjutroy/chieu-studio-be works
Purpose and Runtime
LensFlow is a backend-only studio workflow API for customer, album, package, authentication, and lifecycle management. It is a TypeScript NestJS service with a separate maintenance worker. The HTTP entry point is src/server/main.ts; application composition is src/server/app.module.ts; scheduled/background maintenance begins under src/worker/maintenance/maintenance.module.ts.
API Contract Boundary
HTTP controllers expose the service surface for authentication, customers/packages, albums, sessions, and health. OpenAPI is maintained as a repository contract and generated/exported from the server integration.
• src/server/auth/auth.controller.ts
• src/server/customers/customers.controller.ts
• src/server/albums/albums.controller.ts
• openapi.yaml
• src/server/openapi.ts
Shared Zod schemas, permissions, state-machine definitions, error codes, and notification types form a cross-boundary contract consumed by server code and contract tests.
• src/shared/auth.schemas.ts
• src/shared/state-machine.ts
• src/shared/permissions.ts
Domain Modules and Business Flow
Nest feature modules use controller → service → persistence flow. Customer and package management feed album workflows, including customer-scoped album access. Auth establishes identities and sessions; guards enforce authenticated, live-session, and role-based access before protected domain operations.
• src/server/customers/customers.module.ts
• src/server/customers/packages.service.ts
• src/server/albums/customer-albums.controller.ts
• src/server/auth/guards/auth.guard.ts
• src/server/auth/guards/roles.guard.ts
Persistence and Audit Boundary
Prisma is the database abstraction and migration authority. The schema/migrations define durable entities and roles; services access it through the Prisma module. Audit is isolated as a dedicated module/service, supporting append-only accountability rather than being embedded in each domain controller.
• prisma/schema.prisma
• prisma/migrations/20260705000001_init/migration.sql
• src/server/prisma/prisma.service.ts
• src/server/audit/audit.service.ts
Security and Session Lifecycle
Authentication is a distinct subsystem: token issuance, refresh/session endpoints, cookie handling, lockout behavior, password-reset tokens, and request context. Live-session validation makes session revocation/expiry an explicit authorization boundary, not merely a token-verification concern.
• src/server/auth/auth.service.ts
• src/server/auth/token.service.ts
• src/server/auth/lockout.service.ts
• src/server/auth/sessions.controller.ts
Infrastructure and External Services
PostgreSQL is implied by Prisma migrations; Redis backs the server’s Redis module and queue infrastructure. Storage and mail delivery are adapter-style modules behind services. Docker Compose/Dockerfiles provide containerized operation, while backup scripts implement database backup, restore, health checks, and notifications.
• src/server/redis/redis.module.ts
• src/server/queue/queue.module.ts
• src/server/storage/storage.service.ts
• src/server/mailer/mailer.service.ts
• docker-compose.yml
• scripts/backup/backup.sh
Background Maintenance and Operational Controls
The worker maintenance subsystem schedules and processes purge operations independently of request handling. Health endpoints, centralized configuration validation, structured logging, exception normalization, and Zod request validation establish operational and API-safety boundaries.
• src/worker/maintenance/maintenance.scheduler.ts
• src/worker/maintenance/purge.processor.ts
• src/server/health/health.controller.ts
• src/server/config/env.schema.ts
• src/server/common/all-exceptions.filter.ts
Main entry points: customers.controller.ts HTTP controllers · auth.service.ts Authentication service · prisma.service.ts Prisma service · app.module.ts Application module
Components 21
HTTP Server
NestJS request runtime and API boundary.
- Server entry point
src/server/main.ts - Application module · Composes HTTP feature and infrastructure modules.
src/server/app.module.ts - HTTP controllers · Auth, customer, album, session, and health endpoints.
src/server/customers/customers.controller.ts - OpenAPI contract · Published repository API contract.
openapi.yaml - OpenAPI export
src/server/openapi.ts - Request safety · Zod validation and normalized exception responses.
src/server/common/all-exceptions.filter.ts - Shared contracts · Schemas, permissions, and lifecycle state definitions.
src/shared/auth.schemas.ts
Domain Services
Customer, package, and album workflows.
- Customer & package module · Manages customers and packages used by album workflows.
src/server/customers/customers.module.ts - Package service
src/server/customers/packages.service.ts - Customer album access · Exposes customer-scoped album operations.
src/server/albums/customer-albums.controller.ts
Auth & Access
Identity, live-session, and authorization controls.
- Authentication service · Handles authentication, refresh, reset, cookies, and sessions.
src/server/auth/auth.service.ts - Token service
src/server/auth/token.service.ts - Access guards · Enforces authentication, live sessions, and roles.
src/server/auth/guards/auth.guard.ts
Data & Integrations
Durable storage, audit, and external adapters.
- Prisma service
src/server/prisma/prisma.service.ts - Database schema & migrations · Defines durable entities, roles, and migration history.
prisma/schema.prisma - Audit service · Records accountability separately from controllers.
src/server/audit/audit.service.ts - Redis queue · Redis-backed queue infrastructure.
src/server/queue/queue.module.ts - Storage & mail adapters · Adapter services for file storage and mail delivery.
src/server/storage/storage.service.ts
Operations
Independent maintenance and operational safeguards.
- Maintenance worker · Runs purge maintenance outside the HTTP request path.
src/worker/maintenance/maintenance.module.ts - Purge processor
src/worker/maintenance/purge.processor.ts - Operational controls · Health API, validated environment, logging, and backups.
scripts/backup/backup.sh
Connections 24
- Server entry point → Application module: bootstraps
- Application module → HTTP controllers: mounts
- HTTP controllers → Access guards: protects routes with
- HTTP controllers → Request safety: validated and normalized by
- OpenAPI export → OpenAPI contract: exports
- Application module → OpenAPI export: integrates
- HTTP controllers → Shared contracts: uses
- HTTP controllers → Customer & package module: dispatches customer operations
- HTTP controllers → Customer album access: dispatches album operations
- HTTP controllers → Authentication service: dispatches auth and session operations
- Customer & package module → Package service: contains
- Customer & package module → Prisma service: persists through
- Customer album access → Prisma service: reads and writes through
- Customer & package module → Audit service: records changes
- Authentication service → Token service: issues and refreshes via
- Access guards → Authentication service: checks live session state
- Authentication service → Prisma service: stores identities and sessions
- Prisma service → Database schema & migrations: implements
- Application module → Redis queue: configures
- Authentication service → Storage & mail adapters: sends reset mail through
- Maintenance worker → Purge processor: schedules
- Purge processor → Redis queue: processes queued work
- Purge processor → Prisma service: purges durable records
- Operational controls → Server entry point: monitors and supports