How pixelhamza/image-processing-service works
Purpose and entry point
This is a Node.js backend for authenticated image upload, immutable transformations, and secure retrieval. The application starts at server.js, which mounts authentication and image HTTP routes from routes/authRoutes.js and routes/imageRoutes.js.
HTTP and access boundary
Authentication is handled by controllers/auth-controller.js and enforced on protected image operations by middleware/authMiddleware.js. The service boundary is the API: clients request uploads, transformations, or retrieval; private image objects are not directly exposed by the application.
Image workflow
controllers/image-controller.js coordinates image-facing requests and delegates processing/storage work to services/imageService.js. The intended flow is:
1. Authenticate the caller.
2. Upload or locate an image.
3. Apply requested resize, crop, rotate, or filter transformations.
4. Persist each transformed result as a new immutable image.
5. Return backend-controlled access information, including short-lived S3 presigned URLs.
Processing and storage
services/imageService.js is the core image-processing boundary, intended to use Sharp for transformations and AWS S3 for image persistence. utils/connectToS3.js encapsulates S3 connectivity. S3 is a private external storage service; clients retrieve authorized objects directly through expiring presigned URLs rather than public bucket access.
Persistent metadata
models/Image.js represents image records and their associated metadata, while models/User.js represents authenticated users. Database setup is centralized in database/database.js. This separates durable application metadata from binary image storage: metadata belongs in the database, image bytes belong in S3.
Caching and request control
utils/redisClient.js provides Redis connectivity for caching recently transformed images, reducing repeated database lookup or processing work. middleware/ratelimiter.js is the request-control boundary for per-user transformation limits and is expected to rely on Redis-backed counters/state.
Scalability direction
The current request path is controller → image service → storage/cache/database. The design anticipates moving expensive transformations out of the synchronous API path into background workers and a message queue, allowing transformation endpoints to return job-oriented 202 Accepted responses without changing the storage, metadata, or presigned-access model.
Main entry points: imageService.js Image service · server.js Server entry · ratelimiter.js Transformation limits · authRoutes.js Auth routes
Components 16
HTTP API
- Server entry · Mounts authentication and image routes.
server.js - Auth routes
routes/authRoutes.js - Image routes
routes/imageRoutes.js - Auth controller
controllers/auth-controller.js - Image controller · Coordinates upload, transformation, and retrieval requests.
controllers/image-controller.js - Authentication · Protects image operations.
middleware/authMiddleware.js - Transformation limits · Applies per-user transformation limits.
middleware/ratelimiter.js
Image Core
- Image service · Transforms images, persists immutable results, and issues access URLs.
services/imageService.js - Future queue workers · Can move expensive transformations to asynchronous jobs.
Data Services
- Image metadata · Durable image records and metadata.
models/Image.js - Users · Authenticated user records.
models/User.js - Database connection
database/database.js - Redis client · Caches recent transformations and supports request counters.
utils/redisClient.js
External Storage
- S3 connector · Encapsulates S3 connectivity.
utils/connectToS3.js - Private S3 storage · Stores image bytes; access uses expiring presigned URLs.
Other components
- API client · Uploads, transforms, and retrieves authorized images.
Connections 18
- API client → Server entry: API requests
- Server entry → Auth routes: mounts
- Server entry → Image routes: mounts
- Auth routes → Auth controller: dispatches
- Auth controller → Users: authenticates users
- Image routes → Authentication: protects requests
- Authentication → Transformation limits: authorized transforms
- Transformation limits → Redis client: uses counters
- Transformation limits → Image controller: permits
- Image controller → Image service: delegates workflow
- Image service → Redis client: checks/cache results
- Image service → Image metadata: stores metadata
- Image metadata → Database connection: persists via
- Users → Database connection: persists via
- Image service → S3 connector: stores and signs objects
- S3 connector → Private S3 storage: S3 operations
- Image service → Future queue workers: future async handoff
- Private S3 storage → API client: presigned retrieval · Client accesses private objects through short-lived URLs.