A complete fullstack application for managing a shoe collection with authentication, built with Node.js, Express, Prisma, and React.
- User Authentication: JWT-based authentication with registration and login
- Shoe Management: CRUD operations for shoes (Create, Read, Delete)
- Modern UI: Clean and professional interface with responsive design
- Secure API: Protected endpoints with JWT middleware
- Database: SQLite database with Prisma ORM
- Node.js + Express with TypeScript
- Prisma ORM with SQLite
- JWT for authentication
- bcryptjs for password hashing
- TypeScript for type safety
- React.js with TypeScript
- Axios for API calls
- Modern CSS with gradients and responsive design
- TypeScript for type safety
livecoding/
βββ server/
β βββ src/
β β βββ controllers/ # TypeScript request handlers
β β βββ routes/ # TypeScript Express routes
β β βββ services/ # TypeScript business logic
β β βββ middleware/ # TypeScript auth middleware
β β βββ index.ts # Main server file
β βββ prisma/ # Database schema & migrations
β βββ tsconfig.json # TypeScript configuration
β βββ package.json
βββ client/ # React TypeScript frontend
β βββ src/
β β βββ components/ # TypeScript React components
β β βββ services/ # TypeScript API service
β β βββ App.tsx # Main app
β βββ tsconfig.json # TypeScript configuration
β βββ package.json
βββ package.json # Root scripts
- Node.js (v14 or higher)
- npm or yarn
- Install backend dependencies:
cd server
npm install- Set up the database:
cd server
npx prisma generate
npx prisma migrate deploy- Create .env file in the server directory:
cd serverCreate a .env file with:
PORT=3000
JWT_SECRET=your-secret-key-change-this-in-production
- Install frontend dependencies:
cd ../client
npm installcd server
npm start
# or use the root script: npm run start:serverThe server will run on http://localhost:3000
cd client
npm start
# or use the root script: npm run start:clientThe React app will run on http://localhost:3001
# Install all dependencies
npm run install:all
# Setup database
npm run setup:db
# Start backend (in one terminal)
npm run start:server
# Start frontend (in another terminal)
npm run start:clientPOST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT token
GET /api/shoes- Get all shoesPOST /api/shoes- Add a new shoeDELETE /api/shoes/:id- Delete a shoe by ID
All shoe endpoints require a Bearer token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Open http://localhost:3001 in your browser
- Register a new account or login
- Add shoes using the form
- Delete shoes by clicking the delete button
- Your data persists across page refreshes (database storage)
- id (Int, auto-increment)
- username (String, unique)
- password (String, hashed)
- createdAt (DateTime)
- id (Int, auto-increment)
- name (String)
- brand (String)
- createdAt (DateTime)
- Passwords are hashed using bcryptjs
- JWT tokens for stateless authentication
- CORS enabled for cross-origin requests
- Protected routes with middleware
- Token expiration (1 hour)
-
Authentication Flow:
- User registers/login with username and password
- Password is hashed and stored in database
- JWT token is generated and sent to client
- Token is stored in localStorage
-
Protected API Calls:
- Frontend includes JWT token in Authorization header
- Backend middleware validates token
- Invalid/expired tokens return 401 Unauthorized
-
Data Flow:
- React components call API service
- Service makes HTTP requests to Express backend
- Backend queries Prisma database
- Data flows back through the stack
- Clean gradient background
- Card-based layout for shoes
- Form validation
- Error handling with user-friendly messages
- Loading states
- Responsive design
Database issues:
- Run
npx prisma generateto regenerate Prisma client - Run
npx prisma migrate devto reset database
Port already in use:
- Change PORT in .env file
- Update REACT_APP_API_URL in client/.env
CORS errors:
- Ensure backend CORS is enabled (already configured)
- Check API URL in client environment variables
For production:
- Change JWT_SECRET to a secure random string
- Update CORS origin to your frontend URL
- Use a production-grade database (PostgreSQL)
- Build React app:
cd client && npm run build - Serve static files from Express or a CDN
- All code is modularized for maintainability
- Separation of concerns: controllers, services, routes
- Error handling throughout the stack
- Clean React component architecture
- Type-safe database operations with Prisma
ISC
Built for live coding assessment π