# pixelhamza/image-processing-service architecture

> Architecture diagram of the GitHub repository pixelhamza/image-processing-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pixelhamza/image-processing-service
- Repository: https://github.com/pixelhamza/image-processing-service

## Overview

#### 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: [`services/imageService.js`](https://github.com/pixelhamza/image-processing-service/blob/main/services/imageService.js) (Image service), [`server.js`](https://github.com/pixelhamza/image-processing-service/blob/main/server.js) (Server entry), [`middleware/ratelimiter.js`](https://github.com/pixelhamza/image-processing-service/blob/main/middleware/ratelimiter.js) (Transformation limits), [`routes/authRoutes.js`](https://github.com/pixelhamza/image-processing-service/blob/main/routes/authRoutes.js) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["Server entry<br/>Node.js app<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>HTTP routes<br/>[authRoutes.js]"]
  node_image_routes["Image routes<br/>HTTP routes<br/>[imageRoutes.js]"]
  node_auth_controller["Auth controller<br/>[auth-controller.js]"]
  node_image_controller["Image controller"]
  node_auth_middleware["Authentication<br/>middleware<br/>[authMiddleware.js]"]
  node_rate_limiter["Transformation limits<br/>middleware<br/>[ratelimiter.js]"]
end

subgraph group_core["Image Core"]
  node_image_service{{"Image service<br/>processing service<br/>[imageService.js]"}}
  node_queue_workers["Future queue workers<br/>scalability direction"]
end

subgraph group_data["Data Services"]
  node_image_model["Image metadata<br/>model<br/>[Image.js]"]
  node_user_model["Users<br/>model<br/>[User.js]"]
  node_database[("Database connection<br/>database setup<br/>[database.js]")]
  node_redis_client["Redis client<br/>cache client<br/>[redisClient.js]"]
end

subgraph group_external["External Storage"]
  node_s3_connector["S3 connector<br/>storage client<br/>[connectToS3.js]"]
  node_s3[("Private S3 storage<br/>object storage")]
end

node_client(("API client<br/>consumer"))

node_client -->|"API requests"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_image_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_controller -->|"authenticates users"| node_user_model
node_image_routes -->|"protects requests"| node_auth_middleware
node_auth_middleware -->|"authorized transforms"| node_rate_limiter
node_rate_limiter -->|"uses counters"| node_redis_client
node_rate_limiter -->|"permits"| node_image_controller
node_image_controller -->|"delegates workflow"| node_image_service
node_image_service -->|"checks/cache results"| node_redis_client
node_image_service -->|"stores metadata"| node_image_model
node_image_model -->|"persists via"| node_database
node_user_model -->|"persists via"| node_database
node_image_service -->|"stores and signs objects"| node_s3_connector
node_s3_connector -->|"S3 operations"| node_s3
node_image_service -.->|"future async handoff"| node_queue_workers
node_s3 -->|"presigned retrieval"| node_client

click node_server "https://github.com/pixelhamza/image-processing-service/blob/main/server.js"
click node_auth_routes "https://github.com/pixelhamza/image-processing-service/blob/main/routes/authRoutes.js"
click node_image_routes "https://github.com/pixelhamza/image-processing-service/blob/main/routes/imageRoutes.js"
click node_auth_controller "https://github.com/pixelhamza/image-processing-service/blob/main/controllers/auth-controller.js"
click node_image_controller "https://github.com/pixelhamza/image-processing-service/blob/main/controllers/image-controller.js"
click node_auth_middleware "https://github.com/pixelhamza/image-processing-service/blob/main/middleware/authMiddleware.js"
click node_rate_limiter "https://github.com/pixelhamza/image-processing-service/blob/main/middleware/ratelimiter.js"
click node_image_service "https://github.com/pixelhamza/image-processing-service/blob/main/services/imageService.js"
click node_image_model "https://github.com/pixelhamza/image-processing-service/blob/main/models/Image.js"
click node_user_model "https://github.com/pixelhamza/image-processing-service/blob/main/models/User.js"
click node_database "https://github.com/pixelhamza/image-processing-service/blob/main/database/database.js"
click node_redis_client "https://github.com/pixelhamza/image-processing-service/blob/main/utils/redisClient.js"
click node_s3_connector "https://github.com/pixelhamza/image-processing-service/blob/main/utils/connectToS3.js"

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_auth_routes,node_image_routes,node_auth_controller,node_image_controller,node_auth_middleware,node_rate_limiter toneBlue
class node_image_service,node_queue_workers toneAmber
class node_image_model,node_user_model,node_database,node_redis_client toneMint
class node_s3_connector,node_s3 toneRose
class node_client toneNeutral
```

## Components

### HTTP API

- [Server entry](https://github.com/pixelhamza/image-processing-service/blob/main/server.js): Node.js app · Mounts authentication and image routes. · `server.js`
- [Auth routes](https://github.com/pixelhamza/image-processing-service/blob/main/routes/authRoutes.js): HTTP routes · `routes/authRoutes.js`
- [Image routes](https://github.com/pixelhamza/image-processing-service/blob/main/routes/imageRoutes.js): HTTP routes · `routes/imageRoutes.js`
- [Auth controller](https://github.com/pixelhamza/image-processing-service/blob/main/controllers/auth-controller.js): controller · `controllers/auth-controller.js`
- [Image controller](https://github.com/pixelhamza/image-processing-service/blob/main/controllers/image-controller.js): controller · Coordinates upload, transformation, and retrieval requests. · `controllers/image-controller.js`
- [Authentication](https://github.com/pixelhamza/image-processing-service/blob/main/middleware/authMiddleware.js): middleware · Protects image operations. · `middleware/authMiddleware.js`
- [Transformation limits](https://github.com/pixelhamza/image-processing-service/blob/main/middleware/ratelimiter.js): middleware · Applies per-user transformation limits. · `middleware/ratelimiter.js`

### Image Core

- [Image service](https://github.com/pixelhamza/image-processing-service/blob/main/services/imageService.js): processing service · Transforms images, persists immutable results, and issues access URLs. · `services/imageService.js`
- **Future queue workers**: scalability direction · Can move expensive transformations to asynchronous jobs.

### Data Services

- [Image metadata](https://github.com/pixelhamza/image-processing-service/blob/main/models/Image.js): model · Durable image records and metadata. · `models/Image.js`
- [Users](https://github.com/pixelhamza/image-processing-service/blob/main/models/User.js): model · Authenticated user records. · `models/User.js`
- [Database connection](https://github.com/pixelhamza/image-processing-service/blob/main/database/database.js): database setup · `database/database.js`
- [Redis client](https://github.com/pixelhamza/image-processing-service/blob/main/utils/redisClient.js): cache client · Caches recent transformations and supports request counters. · `utils/redisClient.js`

### External Storage

- [S3 connector](https://github.com/pixelhamza/image-processing-service/blob/main/utils/connectToS3.js): storage client · Encapsulates S3 connectivity. · `utils/connectToS3.js`
- **Private S3 storage**: object storage · Stores image bytes; access uses expiring presigned URLs.

### Other components

- **API client**: consumer · Uploads, transforms, and retrieves authorized images.

## Connections

- 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.
