22
33A secure platform where Penn students can buy/sell items and browse/post sublet opportunities. This repo contains the full-stack application (Next.js frontend + Django backend) along with Postgres, Redis, and a fully containerized development environment.
44
5+ ## Architecture
56
6- ## 1. Requirements
7-
8- ** App runtime is Docker-first.**
7+ ** Hybrid approach:** Services (Postgres, Redis, Django, Next.js) run in Docker for consistency, but dependencies are also installed locally for IDE support (autocomplete, type checking, go-to-definition).
98
10- You do not need Python, Node, Postgres, or Redis installed locally to run the app.
9+ ## 1. Requirements
1110
12- ### Required for running the application
11+ ### Required
1312
1413- ** Docker Desktop** – Run the app containers
14+ - macOS: ` brew install --cask docker ` or download from [ docker.com] ( https://www.docker.com/products/docker-desktop )
15+ - Linux: Install via system package manager + docker-compose plugin
16+ - Windows: Download from [ docker.com] ( https://www.docker.com/products/docker-desktop )
1517
16- ### Required for local code quality tooling
18+ ### Required for IDE Support & Pre-commit Hooks
1719
18- The following are required for pre-commit hooks (formatting, linting, type checks) as well as VSCode / IDE support (import resolution, autocomplete, type hints)
20+ - ** [ uv] ( https://docs.astral.sh/uv/getting-started/installation/ ) ** – Python package manager
21+ - ** [ pnpm] ( https://pnpm.io/installation ) ** – Node.js package manager
1922
20- - [ uv] ( https://docs.astral.sh/uv/getting-started/installation/ ) – Python package manager
21- - [ pnpm] ( https://pnpm.io/installation ) – Node.js package manager
23+ These install dependencies ** locally** so your IDE (VSCode/Cursor) can:
24+ - Provide autocomplete and type hints
25+ - Resolve imports (no red squiggles)
26+ - Run linters and formatters
27+ - Enable go-to-definition
2228
29+ ** The app itself runs in Docker** - you don't need Python, Node, Postgres, or Redis installed system-wide.
2330
2431## 2. Clone the Repository
2532
@@ -28,85 +35,111 @@ git clone https://github.com/pennlabs/penn-marketplace.git
2835cd penn-marketplace
2936```
3037
31- ## 3. One-Time Setup (Local Machine)
38+ ## 3. One-Time Setup
3239
3340``` bash
3441make setup
3542```
3643
3744This runs ` scripts/setup.sh ` , which:
3845
39- 1 . Verifies ` uv ` and ` pnpm ` are installed
40- 2 . Installs backend Python dependencies locally → ` backend/.venv/ `
41- 3 . Installs frontend Node dependencies locally → ` frontend/node_modules/ `
42- 4 . Installs pre-commit hooks into ` .git/hooks/ `
46+ 1 . ✅ Verifies ` uv ` and ` pnpm ` are installed
47+ 2 . 📦 Installs backend Python dependencies locally → ` backend/.venv/ `
48+ 3 . 📦 Installs frontend Node dependencies locally → ` frontend/node_modules/ `
49+ 4 . 🪝 Installs pre-commit hooks into ` .git/hooks/ `
4350
44- You only need to do this ** once** .
51+ ** You only need to do this once. **
4552
53+ ### What this enables:
54+ - ** IDE tooling** works (autocomplete, type hints, import resolution)
55+ - ** Pre-commit hooks** run on your machine before commits
56+ - ** The app still runs in Docker** for consistency
4657
4758## 4. Start Development Environment
4859
49- ### 🚀 Standard Start
60+ ### 🚀 Standard Start (with logs)
5061``` bash
5162make up
5263```
64+ or
65+ ``` bash
66+ docker compose up
67+ ```
5368
5469### 🖥 Start in Background
5570``` bash
5671make up-d
5772```
73+ or
74+ ``` bash
75+ docker compose up -d
76+ ```
5877
5978This will:
6079
61- - Build backend & frontend Docker images (if needed)
62- - Start Postgres + Redis
63- - Run Django migrations
64- - Launch:
65- - Frontend → http://localhost:3000
66- - Backend → http://localhost:8000
67-
80+ 1 . Build Docker images (if needed)
81+ 2 . Start Postgres + Redis
82+ 3 . Run Django migrations automatically
83+ 4 . Launch services:
84+ - ** Frontend** → http://localhost:3000
85+ - ** Backend** → http://localhost:8000
86+ - ** Database** → localhost:5432 (accessible with DB tools)
87+ - ** Redis** → localhost:6379
6888
6989## 5. Stopping & Resetting
7090
7191### Stop containers
7292``` bash
7393make down
7494```
95+ or
96+ ``` bash
97+ docker compose down
98+ ```
7599
76- ### Full reset (⚠ deletes DB + local deps)
100+ ### Full reset (⚠ deletes DB data + local deps)
77101``` bash
78102make clean
79103```
80104
81- ` clean ` does:
82- - ` docker compose down -v ` (removes containers + volumes)
83- - Deletes ` backend/.venv `
84- - Deletes ` frontend/node_modules `
105+ ** What ` clean ` does:**
106+ - Stops and removes all containers
107+ - ** Deletes database volumes** (all data lost)
108+ - Removes ` backend/.venv/ `
109+ - Removes ` frontend/node_modules/ `
85110
86- Use this only when things are seriously broken.
111+ ** Use this only when:**
112+ - You need a completely fresh start
113+ - Database migrations are irreversibly broken
114+ - Dependencies are corrupted
87115
88- ## 6. Common Dev Commands
116+ ## 6. Common Development Commands
89117
90118| Task | Command |
91119| ------| ---------|
92- | Start dev env | ` make up-d ` |
120+ | Start dev environment | ` make up-d ` |
93121| Stop containers | ` make down ` |
94- | Rebuild Docker images | ` make build ` |
95122| View logs | ` make logs ` |
96- | Backend shell | ` make shell-backend ` |
123+ | View logs (specific service) | ` make logs-backend ` or ` make logs-frontend ` |
124+ | Rebuild Docker images | ` make build ` |
125+ | Backend Django shell | ` make shell-backend ` |
97126| Frontend shell | ` make shell-frontend ` |
127+ | Database shell | ` make shell-db ` |
98128| Run migrations | ` make migrate ` |
99- | Run backend tests | ` make test ` |
100- | Generate fake listings | ` make generate-data ` |
101-
129+ | Create migrations | ` make makemigrations ` |
130+ | Run backend tests | ` make test-backend ` |
131+ | Run frontend tests | ` make test-frontend ` |
132+ | Generate fake data | ` make generate-data ` |
133+ | Run all quality checks | ` make check ` |
134+ | Auto-fix formatting | ` make format ` |
102135
103- ## 7. Migrations
136+ ## 7. Working with Migrations
104137
105- ### When you ** change models** (` models.py ` ):
138+ ### When you change Django models (` models.py ` ):
106139
107140``` bash
108- make makemigrations
109- make migrate
141+ make makemigrations # Create migration files
142+ make migrate # Apply migrations
110143```
111144
112145### When you pull changes from teammates:
@@ -116,60 +149,114 @@ make down
116149make up
117150```
118151
119- Migrations run automatically on startup.
152+ ** Migrations run automatically on startup** , so you don't need to run them manually when pulling .
120153
154+ ### Reset database (nuclear option):
155+
156+ ``` bash
157+ make down
158+ docker volume rm penn-marketplace_postgres-data
159+ make up
160+ ```
121161
122162## 8. Installing New Packages
123163
124- ### Backend (Python • uv )
164+ ### Backend (Python)
125165
166+ ** 1. Add the package locally (updates ` pyproject.toml ` and ` uv.lock ` ):**
126167``` bash
127- docker compose exec backend uv add < package>
128- make build
129- make up
168+ cd backend
169+ uv add
130170```
131171
132- ### Frontend (Node • pnpm)
172+ ** 2. Sync to container (picks up the updated lock file):**
173+ ``` bash
174+ docker compose exec backend uv sync
175+ ```
176+
177+ ** That's it!** No rebuild needed. The container reads the updated ` uv.lock ` file.
178+
179+ ### Frontend (Node)
133180
181+ ** 1. Add the package locally (updates ` package.json ` and ` pnpm-lock.yaml ` ):**
134182``` bash
135- docker compose exec frontend pnpm add < package>
136- make build
137- make up
183+ cd frontend
184+ pnpm add
185+ ```
186+
187+ ** 2. Sync to container (picks up the updated lock file):**
188+ ``` bash
189+ docker compose exec frontend pnpm install
138190```
139191
140- ⚠ Always rebuild after dependency changes.
192+ ** That's it!** No rebuild needed. The container reads the updated ` pnpm-lock.yaml ` file.
193+
194+ ### Why this order?
141195
196+ - ** Install locally first** → Updates lock files (` uv.lock ` , ` pnpm-lock.yaml ` )
197+ - ** Sync in container** → Container picks up changes from the lock files via volume mount
198+ - Your IDE gets autocomplete immediately
199+ - You don't have to run the install command twice
200+ - ** No rebuild needed** because lock files are mounted into the container
201+
202+ ### When DO you need to rebuild?
203+
204+ Only if you change the ** Dockerfile itself** (like adding system packages or changing base image):
205+ ``` bash
206+ docker compose up --build backend # For backend
207+ docker compose up --build frontend # For frontend
208+ ```
142209
143210## 9. Code Quality
144211
145- Run checks (same as CI):
212+ ### Run all checks (same as CI):
146213
214+ ``` bash
215+ make check
216+ ```
217+ or
147218``` bash
148219./scripts/check.sh
149220```
150221
151- Auto-fix issues :
222+ ### Auto-fix formatting and linting :
152223
224+ ``` bash
225+ make format
226+ ```
227+ or
153228``` bash
154229./scripts/check.sh --fix
155230```
156231
157- ### Pre-Commit Hooks
232+ ### Pre-commit Hooks
233+
234+ Installed automatically via ` make setup ` .
235+
236+ ** What they do:**
237+ - ✨ Format Python code (ruff format)
238+ - 🔍 Lint Python code (ruff check)
239+ - ✨ Format JS/TS/JSON/CSS (Prettier)
240+ - 🔍 Lint JS/TS (ESLint)
241+ - 🔍 Check TypeScript types
242+ - 🧹 Fix trailing whitespace
243+
244+ ** Hooks run automatically before each commit.** If checks fail, the commit is blocked.
158245
159- Installed via ` make setup ` .
160246
161- Hooks automatically:
162- - Format Python (ruff format)
163- - Lint Python (ruff)
164- - Format JS/TS (Prettier)
165- - Lint JS/TS (ESLint)
166- - Check TypeScript types
167- - Fix whitespace issues
247+ ## 10. Accessing Services
168248
249+ ### From your browser:
250+ - ** Frontend:** http://localhost:3000
251+ - ** Backend API:** http://localhost:8000
169252
170- ## 10. Hot Reload
253+ ### From database tools (TablePlus, pgAdmin, DBeaver, etc.):
254+ - ** Host:** ` localhost `
255+ - ** Port:** ` 5432 `
256+ - ** Database:** ` penn_marketplace `
257+ - ** User:** ` postgres `
258+ - ** Password:** ` postgres `
171259
172- | Area | Behavior |
173- | ------| ----------|
174- | Frontend | Edits auto-refresh (Next.js) |
175- | Backend | Django auto-reloads |
260+ ### From Redis tools:
261+ - ** Host:** ` localhost `
262+ - ** Port:** ` 6379 `
0 commit comments