Spaces:
Sleeping
Sleeping
File size: 12,386 Bytes
9eafd9f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# Quickstart Guide: Full-Stack Integration & UI Experience
**Feature**: 002-fullstack-ui-integration
**Date**: 2026-01-09
**Purpose**: Testing and validation guide for integration and UI polish
## Overview
This guide helps developers and reviewers quickly set up, test, and validate the Full-Stack Integration & UI Experience feature. Since this feature builds on existing implementations (Specs 1 & 2), most setup is already complete.
## Prerequisites
Before testing this feature, ensure:
1. **Specs 1 & 2 are complete**:
- ✅ Task CRUD endpoints working (Spec 1)
- ✅ Authentication & JWT working (Spec 2)
- ✅ Database migrations applied
- ✅ Environment variables configured
2. **Development environment**:
- Node.js 18+ installed
- Python 3.11+ installed
- PostgreSQL database accessible (Neon or local)
- Git repository cloned
## Quick Setup (5 minutes)
### 1. Backend Setup
```bash
# Navigate to backend directory
cd backend
# Install dependencies (if not already done)
pip install -r requirements.txt
# Verify environment variables
cat .env
# Should contain:
# - DATABASE_URL
# - BETTER_AUTH_SECRET
# - JWT_ALGORITHM=HS256
# - JWT_EXPIRATION_DAYS=7
# Apply migrations (if not already done)
python -m alembic upgrade head
# Start backend server
python -m uvicorn src.main:app --reload
# Server should start at http://localhost:8000
# Verify: Open http://localhost:8000/docs (Swagger UI)
```
### 2. Frontend Setup
```bash
# Navigate to frontend directory (in new terminal)
cd frontend
# Install dependencies (if not already done)
npm install
# Verify environment variables
cat .env.local
# Should contain:
# - NEXT_PUBLIC_API_URL=http://localhost:8000
# - BETTER_AUTH_SECRET (same as backend)
# Start frontend server
npm run dev
# Server should start at http://localhost:3000
# Verify: Open http://localhost:3000
```
### 3. Verify Setup
**Backend Health Check**:
```bash
curl http://localhost:8000/health
# Expected: {"status":"healthy"}
```
**Frontend Access**:
- Open http://localhost:3000
- Should redirect to http://localhost:3000/auth/signin
- Signin page should load without errors
## Testing User Stories
### P1: Complete Authentication Flow (MVP)
**Test Scenario**: New user signup → signin → task management
**Steps**:
1. **Navigate to signup**:
```
Open: http://localhost:3000/auth/signup
```
2. **Test validation errors**:
- Try empty email → Should show "Email is required"
- Try invalid email (e.g., "notanemail") → Should show "Invalid email format"
- Try weak password (e.g., "pass") → Should show password requirements
- Try short name → Should show "Name is required"
3. **Create account**:
- Email: `test@example.com`
- Password: `TestPass123`
- Name: `Test User`
- Click "Sign Up"
- **Expected**: Redirect to signin page with success message
4. **Sign in**:
- Email: `test@example.com`
- Password: `TestPass123`
- Click "Sign In"
- **Expected**: Redirect to home page (http://localhost:3000)
5. **Verify authenticated state**:
- Header should show "Welcome, Test User"
- "Sign Out" button should be visible
- Task form and list should be visible
6. **Sign out**:
- Click "Sign Out" button
- **Expected**: Redirect to signin page
- **Expected**: Cannot access home page without signin
**Pass Criteria**:
- ✅ Validation errors display inline
- ✅ Signup creates account successfully
- ✅ Signin issues JWT token
- ✅ Home page shows user profile
- ✅ Sign out clears session
---
### P2: Responsive UI States
**Test Scenario**: Loading, empty, and error states
**Steps**:
1. **Test loading state**:
- Sign in as test user
- Observe task list loading
- **Expected**: Loading spinner with "Loading tasks..." message
- **Expected**: Spinner disappears when tasks load
2. **Test empty state**:
- If no tasks exist:
- **Expected**: "No tasks yet" message
- **Expected**: Call-to-action to create first task
- **Expected**: Empty state is centered and clear
3. **Test error state**:
- Stop backend server (Ctrl+C in backend terminal)
- Try to create a task
- **Expected**: Error message "Unable to connect to server"
- **Expected**: Retry button appears
- Restart backend server
- Click retry button
- **Expected**: Operation succeeds
4. **Test form loading state**:
- Create a task
- Observe submit button during API call
- **Expected**: Button shows "Creating..." and is disabled
- **Expected**: Button returns to normal after success
5. **Test token expiration** (optional - requires waiting 7 days or manual token manipulation):
- With expired token, try to access home page
- **Expected**: Redirect to signin with "Session expired" message
**Pass Criteria**:
- ✅ Loading states appear within 100ms
- ✅ Empty states provide clear guidance
- ✅ Error messages are actionable
- ✅ Form buttons show loading state
- ✅ Token expiration handled gracefully
---
### P3: Responsive Design
**Test Scenario**: Mobile, tablet, desktop layouts
**Steps**:
1. **Test desktop layout (≥1024px)**:
- Open browser DevTools (F12)
- Set viewport to 1920x1080
- **Expected**: Three-column layout
- **Expected**: Task form (left), filters (middle), task list (right)
2. **Test tablet layout (768px-1023px)**:
- Set viewport to 768x1024
- **Expected**: Two-column layout
- **Expected**: Task form and filters stacked (left), task list (right)
3. **Test mobile layout (<768px)**:
- Set viewport to 375x667 (iPhone SE)
- **Expected**: Single-column layout
- **Expected**: All elements stacked vertically
- **Expected**: No horizontal scrolling
4. **Test touch targets**:
- On mobile viewport, inspect buttons
- **Expected**: All buttons are at least 44x44px
- **Expected**: Adequate spacing between interactive elements
5. **Test signin/signup forms**:
- Navigate to signin page on mobile
- **Expected**: Form is centered and readable
- **Expected**: Input fields use appropriate types (email, password)
- **Expected**: Keyboard doesn't obscure form fields
**Pass Criteria**:
- ✅ Layouts adapt to viewport width
- ✅ No horizontal scrolling on any device
- ✅ Touch targets are 44x44px minimum
- ✅ Forms are usable on mobile
- ✅ Text is readable without zooming
---
### P4: Centralized API Communication
**Test Scenario**: Verify API client consistency
**Steps**:
1. **Verify JWT token inclusion**:
- Sign in as test user
- Open browser DevTools → Network tab
- Create a task
- Inspect POST /api/tasks request
- **Expected**: Authorization header present: `Bearer <token>`
2. **Verify 401 handling**:
- Clear localStorage (DevTools → Application → Local Storage → Clear)
- Try to access home page
- **Expected**: Automatic redirect to signin
- **Expected**: No console errors
3. **Verify error formatting**:
- Sign in
- Stop backend server
- Try to create a task
- Open browser console
- **Expected**: APIError with status, detail, error_code
- **Expected**: Error displayed in UI (not just console)
4. **Verify all endpoints use fetchAPI**:
- Review code: `frontend/src/lib/api.ts`
- **Expected**: All API functions use fetchAPI helper
- **Expected**: No direct fetch() calls in components
**Pass Criteria**:
- ✅ JWT tokens included automatically
- ✅ 401 errors trigger signin redirect
- ✅ Errors formatted consistently
- ✅ All API calls use centralized client
- ✅ No unhandled promise rejections
---
### P5: Environment Coordination
**Test Scenario**: Setup and configuration
**Steps**:
1. **Verify environment variables**:
```bash
# Backend
grep BETTER_AUTH_SECRET backend/.env
# Frontend
grep BETTER_AUTH_SECRET frontend/.env.local
# Expected: Both values match exactly
```
2. **Test with missing environment variable**:
- Temporarily rename `backend/.env` to `backend/.env.backup`
- Try to start backend
- **Expected**: Clear error message about missing variables
- Restore `backend/.env`
3. **Test with mismatched secrets**:
- Change BETTER_AUTH_SECRET in `frontend/.env.local`
- Sign in
- **Expected**: Token verification fails
- **Expected**: Clear error message
- Restore correct secret
4. **Verify README documentation**:
- Read `backend/README.md`
- **Expected**: Authentication setup instructions present
- **Expected**: Environment variable documentation
- Read `frontend/README.md`
- **Expected**: Better Auth configuration notes
- **Expected**: Setup instructions
**Pass Criteria**:
- ✅ Environment variables documented
- ✅ Missing variables show clear errors
- ✅ Mismatched secrets are detected
- ✅ README files are up-to-date
- ✅ Setup takes under 10 minutes
---
## Common Issues & Solutions
### Issue: "404 Not Found" on /api/auth/signup
**Cause**: Auth router not registered in backend/src/main.py
**Solution**:
```python
# In backend/src/main.py, ensure:
from .api.routes import tasks, auth
app.include_router(auth.router) # Must be present
app.include_router(tasks.router)
```
### Issue: "Token signature verification failed"
**Cause**: BETTER_AUTH_SECRET differs between frontend and backend
**Solution**:
```bash
# Verify secrets match:
grep BETTER_AUTH_SECRET backend/.env
grep BETTER_AUTH_SECRET frontend/.env.local
# If different, copy backend secret to frontend
```
### Issue: "Unable to connect to database"
**Cause**: DATABASE_URL is incorrect or database is not running
**Solution**:
```bash
# For Neon PostgreSQL:
# Verify connection string in backend/.env includes ?sslmode=require
# For local PostgreSQL:
# Ensure PostgreSQL is running:
# Windows: Check Services
# Mac/Linux: sudo systemctl status postgresql
```
### Issue: Frontend shows blank page
**Cause**: JavaScript error or build issue
**Solution**:
```bash
# Check browser console for errors
# Clear Next.js cache:
cd frontend
rm -rf .next
npm run dev
```
### Issue: Tasks not loading
**Cause**: JWT token missing or invalid
**Solution**:
```bash
# Check localStorage in browser DevTools:
# Application → Local Storage → http://localhost:3000
# Look for 'auth_session' key
# If missing or invalid, sign out and sign in again
```
## Performance Benchmarks
**Expected Performance**:
- Loading states appear: <100ms
- Page transitions: <500ms
- API responses: <200ms
- Task list load (10 tasks): <300ms
- Signup/signin: <1s
**How to Measure**:
```javascript
// In browser console:
performance.mark('start');
// Perform action (e.g., create task)
performance.mark('end');
performance.measure('action', 'start', 'end');
console.log(performance.getEntriesByType('measure'));
```
## Validation Checklist
Before marking this feature complete, verify:
**Authentication Flow**:
- [ ] Signup form validates inputs
- [ ] Signup creates user in database
- [ ] Signin issues JWT token
- [ ] Home page shows user profile
- [ ] Sign out clears session
**UI States**:
- [ ] Loading spinners appear during async operations
- [ ] Empty states show helpful messages
- [ ] Error messages are clear and actionable
- [ ] Form buttons show loading state
**Responsive Design**:
- [ ] Desktop layout (3 columns) works at 1920px
- [ ] Tablet layout (2 columns) works at 768px
- [ ] Mobile layout (1 column) works at 375px
- [ ] No horizontal scrolling on any device
- [ ] Touch targets are 44x44px minimum
**API Communication**:
- [ ] JWT tokens included in all requests
- [ ] 401 errors trigger signin redirect
- [ ] Errors formatted consistently
- [ ] No unhandled promise rejections
**Environment Setup**:
- [ ] Backend starts without errors
- [ ] Frontend starts without errors
- [ ] Environment variables documented
- [ ] README files are accurate
## Next Steps
After validating all user stories:
1. **Mark tasks complete** in `tasks.md`
2. **Document any issues** found during testing
3. **Create git commit** with implementation
4. **Prepare for demo** (if hackathon submission)
## Support
For issues or questions:
- Review specification: `specs/002-fullstack-ui-integration/spec.md`
- Review implementation plan: `specs/002-fullstack-ui-integration/plan.md`
- Check API reference: `specs/002-fullstack-ui-integration/contracts/existing-api-reference.yaml`
- Review existing specs: `specs/001-auth-security/`
|