Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
aa7b893
Add Redis service configuration to docker-compose.yml
jchen1124 Jul 25, 2026
b2c34df
edited redis password and saved it privately
jchen1124 Jul 25, 2026
7218be1
Add Redis dependency to package.json and package-lock.json
jchen1124 Jul 26, 2026
86a54c2
Add Redis client implementation and connection logic
jchen1124 Jul 31, 2026
ee41561
Refactor server startup to include Redis connection and update docker…
jchen1124 Aug 1, 2026
e972d30
Add comment to clarify Redis connection in server startup
jchen1124 Aug 1, 2026
ac7e2c1
Fixed backend connection to redis container issue
jchen1124 Aug 4, 2026
48d07b2
initial full redis cache implementation for reverse geocode results
jchen1124 Aug 4, 2026
fed8793
Add timing logs for cache hits and misses in geocode route
jchen1124 Aug 4, 2026
1e28f72
chore: update dependencies in package.json
jchen1124 Aug 4, 2026
f2462f6
Add tests for geocode route with caching logic
jchen1124 Aug 6, 2026
51fc7bb
Update README to include Redis caching details for reverse geocoding
jchen1124 Aug 6, 2026
f383cfe
Implement Redis caching for S3 signed URLs in image retrieval
jchen1124 Aug 11, 2026
5d679e4
Remove signed URL from Redis cache upon image deletion
jchen1124 Aug 12, 2026
b9b3b6f
Refactor comments for clarity and consistency in posts route
jchen1124 Aug 12, 2026
eda0353
Update README to enhance Redis caching documentation for S3 signed UR…
jchen1124 Aug 13, 2026
e4085b3
initial commit for rate limiting middleware implementation
jchen1124 Aug 13, 2026
11ab1db
Add express-rate-limit and rate-limit-redis dependencies for rate lim…
jchen1124 Aug 13, 2026
fed57f1
Implement geocode rate limiting middleware using express-rate-limit a…
jchen1124 Aug 14, 2026
1a3c4e4
Refactor upload rate limiter to correct error message and ensure prop…
jchen1124 Aug 14, 2026
e6a9553
Add comments to clarify rate limiting configurations for geocoding an…
jchen1124 Aug 14, 2026
b45719b
Update geocode rate limiter to 50 requests per minute and apply middl…
jchen1124 Aug 14, 2026
8175c46
Add upload rate limiter middleware to post route
jchen1124 Aug 14, 2026
8a80cf5
Set trust proxy for rate limiting in Express app configuration
jchen1124 Aug 14, 2026
47c84e2
Import app dynamically in server startup to improve module loading
jchen1124 Aug 15, 2026
68361d0
Add handling for 429 status in geocoding function to improve user fee…
jchen1124 Aug 15, 2026
1b88c47
Remove commented console log from geocoding function for cleaner code
jchen1124 Aug 15, 2026
406ae10
Refactor MapView component for improved readability and add 429 statu…
jchen1124 Aug 16, 2026
12a6d17
Add Vitest configuration files and update geocode test setup
jchen1124 Aug 17, 2026
07e9530
Add tests for signed S3 URL caching in posts API
jchen1124 Aug 18, 2026
92a6b03
Fix mock response for S3 send in posts test to return undefined
jchen1124 Aug 18, 2026
e8c3fa3
Update README to clarify Redis usage for caching and rate limiting
jchen1124 Aug 18, 2026
8d98f3f
Add GeoGallery image to README and update layout
jchen1124 Aug 18, 2026
d5ac11e
Update README to center align the title
jchen1124 Aug 18, 2026
66a4891
Increase geocode rate limit to 60 requests per minute and log rate li…
jchen1124 Aug 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 130 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# GeoGallery v2.0
<h1 align="center">
GeoGallery v2.0
</h1>

GeoGallery is a full-stack photo mapping application where users can upload
photos, pin them to real-world locations, and revisit their memories through an
interactive global map.

The project was originally developed as Globe Pin and combines a React
frontend with an Express API, Supabase authentication and data storage, Amazon
S3 image storage, and Mapbox mapping services.
S3 image storage, Redis caching and rate limiting, and Mapbox mapping services.

<p align="center">
<img src="./src/assets/geogallery.png" width="100%"/>

</p>

## Features

Expand All @@ -16,6 +23,8 @@ S3 image storage, and Mapbox mapping services.
- Sign in with Google through Supabase Auth
- Filter the map to show only your posts
- Bookmark posts and browse saved places
- Cache reverse geocoding and signed image URLs with Redis
- Rate limit expensive geocoding and upload routes
- View and delete your own posts
- Switch between colorful light and satellite dark map themes
- Use your current location when creating a post
Expand All @@ -39,11 +48,15 @@ S3 image storage, and Mapbox mapping services.
- TypeScript
- Multer for image uploads
- AWS SDK for S3
- Redis for backend caching
- `express-rate-limit` and Redis-backed request limits
- Vitest and Supertest for backend route tests

### Services

- Supabase Auth and Postgres
- Amazon S3
- Redis / Render Key Value
- Mapbox
- Google Maps Platform
- Vercel for the frontend
Expand All @@ -60,13 +73,26 @@ Browser
`-- Express API
|-- Supabase Postgres
|-- Amazon S3
|-- Redis cache / rate limit store
`-- Mapbox Geocoding API
```

When a user creates a post, the frontend sends the photo and post details to
the Express API. The API uploads the image to S3 and stores its object key with
the post data in Supabase. When posts are requested, the API generates signed
S3 URLs and returns them to the frontend.
S3 URLs and returns them to the frontend. Signed S3 URLs are cached in Redis so
repeated post fetches can reuse valid access URLs instead of regenerating them
for every image.

Reverse geocoding requests are cached with Redis. When the frontend asks for a
readable address from latitude and longitude coordinates, the API first checks
Redis using a rounded coordinate cache key. Cache hits return immediately from
Redis, while cache misses call the Mapbox Geocoding API, store the result in
Redis with a TTL, and then return it to the frontend.

Redis is also used as the shared store for API rate limiting. This protects
high-cost routes such as reverse geocoding and image uploads from repeated
bursts of traffic before they reach Mapbox, S3, or the database.

## Project Structure

Expand All @@ -75,10 +101,13 @@ Globe-Pin/
|-- .github/workflows/ci.yml # Frontend and backend CI checks
|-- backend/
| |-- src/
| | |-- __tests__/ # Backend route tests
| | |-- middleware/ # Express middleware such as rate limiting
| | |-- routes/ # Posts, bookmarks, and geocoding routes
| | |-- scripts/ # Data migration utilities
| | |-- app.ts # Express application
| | |-- db.ts # Supabase server client
| | |-- redis.ts # Redis client
| | `-- s3.ts # Amazon S3 client
| |-- Dockerfile
| `-- package.json
Expand Down Expand Up @@ -111,12 +140,22 @@ AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
AWS_REGION=your_aws_region
AWS_S3_BUCKET=your_s3_bucket_name
REDIS_URL=redis://redis:6379
FRONTEND_URL=http://localhost:8080
```

Do not commit either `.env` file. The Supabase service-role key and AWS
credentials must only be used by the backend.

Use `REDIS_URL=redis://redis:6379` when the backend runs inside Docker Compose.
Use `REDIS_URL=redis://localhost:6379` when the backend runs locally with
`npm run dev --prefix backend` and only the Redis container is running in
Docker. In production on Render, use the internal URL from the Render Key Value
instance.

The backend must connect to Redis before the Express app imports routes that
create Redis-backed rate limiters.

## Run With Docker

Docker is the recommended way to run the complete application.
Expand All @@ -127,7 +166,7 @@ Docker is the recommended way to run the complete application.
- Supabase, AWS, Mapbox, and Google Maps credentials
- The two environment files described above

From the project root, build and start both services:
From the project root, build and start all services:

```bash
docker compose up --build
Expand All @@ -138,6 +177,7 @@ Open:
```text
Frontend: http://localhost:8080
Backend: http://localhost:3001
Redis: localhost:6379
```

The Docker images install their own npm dependencies, so a local
Expand Down Expand Up @@ -181,6 +221,14 @@ npm run dev

The frontend development server is available at `http://localhost:5173`. When
using this mode, set `FRONTEND_URL=http://localhost:5173` in `backend/.env`.
If Redis is running through Docker while the backend runs locally, set
`REDIS_URL=redis://localhost:6379`.

To run only Redis through Docker for local backend development:

```bash
docker compose up redis
```

## Available Commands

Expand All @@ -198,6 +246,8 @@ npm run preview # Preview the production build
```bash
npm run dev --prefix backend # Start with automatic reload
npm run build --prefix backend # Compile TypeScript
npm test --prefix backend # Run backend route tests
npm run test:watch --prefix backend
npm start --prefix backend # Run the compiled server
npm run migrate:s3 --prefix backend
```
Expand All @@ -218,5 +268,79 @@ The script:
- Downloads missing images from Supabase Storage
- Uploads them to the configured S3 bucket

n Vercel and
Render. Local `.env` files are not uploaded to either platform.
## Redis Caching

Redis is used for backend caches that avoid repeated external service work.

### Reverse Geocoding

The `/geocode` route uses Redis to cache Mapbox reverse-geocoding responses.
The cache key is based on rounded coordinates:

```text
geocode:v1:<latitude>:<longitude>
```

Example:

```text
geocode:v1:40.71280:-74.00600
```

The first request for a coordinate pair is a cache miss, so the API calls
Mapbox and stores the address in Redis. Later requests for the same rounded
coordinates are cache hits, so the API returns the cached address without
calling Mapbox again.

This improves response time for frequently viewed posts, reduces repeated
external API calls, and lowers the chance of hitting Mapbox rate limits.

### S3 Signed URLs

The `/api/posts` route uses Redis to cache signed S3 URLs for post images.
Supabase stores the S3 object key for each post, and the backend turns that key
into a temporary signed URL that the frontend can use in image tags.

The cache key is based on the S3 object key:

```text
s3:signed-url:v1:<image-key>
```

Example:

```text
s3:signed-url:v1:user-id-1720000000000.jpg
```

On a cache miss, the API verifies the object exists in S3, generates a signed
URL, stores it in Redis, and returns it with the post data. On a cache hit, the
API returns the cached signed URL and skips the S3 object check and signing
work.

Signed URLs are generated with a seven-day expiration, while Redis stores them
for six days. The shorter Redis TTL prevents the API from returning a cached URL
after the S3 URL has expired. When a post is deleted, the API also removes that
image's cached signed URL from Redis.

## API Rate Limiting

The backend uses `express-rate-limit` with Redis as the shared store for
request counters. This keeps limits consistent if the backend runs multiple
instances and avoids relying on per-process memory.

Current protected routes:

- `/geocode`: limits repeated reverse-geocoding requests
- `POST /api/posts`: limits image upload attempts before Multer parses files

When a client exceeds a limit, the middleware returns:

```text
429 Too Many Requests
```

Rate limit headers are enabled so clients can inspect remaining quota and reset
timing. In production behind Render's proxy, Express should trust the proxy so
IP-based limiting uses the forwarded client IP instead of the proxy address.

Loading
Loading