A full-stack RESTful API for managing phone inventory with complete CRUD operations
Features β’ Installation β’ Usage β’ API Docs β’ Testing
- Overview
- Features
- Tech Stack
- Installation
- Database Setup
- Usage
- API Documentation
- Testing
- Project Structure
- Contributing
- License
CellSync is a modern, full-featured phone inventory management system built with Node.js, Express, and PostgreSQL. It provides a complete RESTful API with all CRUD operations (Create, Read, Update, Delete) and includes a beautiful web interface for easy testing and management.
Perfect for:
- π± Mobile phone retailers
- πͺ E-commerce platforms
- π Inventory management systems
- π Learning REST API development
- π Prototyping and MVP development
- β Create - Add new phones to inventory
- β Read - View all phones, get specific phone, or search with filters
- β Update - Modify existing phone records
- β Delete - Remove phones from inventory
- Filter by brand (Apple, Samsung, Google, etc.)
- Filter by price range (min/max)
- Filter by storage capacity
- Combine multiple filters
- RESTful API design
- SQL injection prevention (parameterized queries)
- Error handling
- ES6 modules
- Environment variables
- Clean code architecture
Backend:
- Node.js - JavaScript runtime
- Express.js - Web framework
- PostgreSQL - Relational database
- pg - PostgreSQL client
- dotenv - Environment variable management
Frontend:
- HTML5 - Markup
- CSS3 - Styling (gradients, animations)
- JavaScript (ES6+) - Fetch API, async/await
Development:
- Nodemon - Auto-restart on file changes
- Clone the repository
git clone https://github.com/0xYurii/cellsync.git
cd cellsync- Install dependencies
npm install- Create environment file
cp .env.example .env- Configure your
.envfile
DB_HOST=localhost
DB_USER=postgres
DB_DATABASE=cellsync
DB_PASSWORD=your_password
DB_PORT=5432# Using psql
psql -U postgresCREATE DATABASE cellsync;
\qOr use the command directly:
createdb cellsync -U postgresCREATE TABLE phones (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
brand VARCHAR(100) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
stock_quantity INTEGER NOT NULL,
color VARCHAR(50) NOT NULL,
storage VARCHAR(50) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);INSERT INTO phones (name, brand, price, stock_quantity, color, storage) VALUES
('iPhone 15 Pro', 'Apple', 999.99, 12, 'Titanium Blue', '256GB'),
('Galaxy S24 Ultra', 'Samsung', 1199.99, 8, 'Phantom Black', '512GB'),
('Pixel 8 Pro', 'Google', 899.99, 15, 'Obsidian', '128GB'),
('iPhone 14', 'Apple', 799.99, 20, 'Purple', '128GB'),
('Galaxy A54', 'Samsung', 449.99, 25, 'Awesome Violet', '128GB'),
('OnePlus 12', 'OnePlus', 799.99, 10, 'Flowy Emerald', '256GB'),
('Xiaomi 13 Pro', 'Xiaomi', 699.99, 7, 'Ceramic White', '256GB');Or use the provided setup file:
psql -U postgres -d cellsync -f db/setup.sqlnpm run devThe server will start on http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| POST | /phones/insert |
Create a new phone |
| GET | /phones |
Get all phones |
| GET | /phones/:id |
Get a specific phone by ID |
| GET | /phones/search |
Search phones with filters |
| PUT | /phones/:id |
Update a phone |
| DELETE | /phones/:id |
Delete a phone |
POST /phones/insert
Content-Type: application/json
{
"name": "iPhone 15 Pro",
"brand": "Apple",
"price": 999.99,
"stock_quantity": 15,
"color": "Titanium Blue",
"storage": "256GB"
}Response: 201 Created
Phone inserted successfully
GET /phonesResponse: 200 OK - HTML list of all phones
GET /phones/1Response: 200 OK
{
"id": 1,
"name": "iPhone 15 Pro",
"brand": "Apple",
"price": "999.99",
"stock_quantity": 12,
"color": "Titanium Blue",
"storage": "256GB"
}GET /phones/search?brand=Apple
GET /phones/search?minPrice=500&maxPrice=800
GET /phones/search?storage=256GB
GET /phones/search?brand=Apple&minPrice=700&maxPrice=1000Response: 200 OK - HTML list of matching phones
PUT /phones/1
Content-Type: application/json
{
"name": "iPhone 15 Pro Max",
"brand": "Apple",
"price": 1199.99,
"stock_quantity": 20,
"color": "Natural Titanium",
"storage": "512GB"
}Response: 200 OK
{
"message": "Phone updated successfully",
"phone": { ... }
}DELETE /phones/1Response: 200 OK
{
"message": "Phone deleted successfully",
"phone": { ... }
}For complete API documentation, see API_DOCUMENTATION.md
- Start the server:
npm run dev - Open browser:
http://localhost:3000/ - Use the tabs to test each operation:
- β Create
- π Read All
- π Search
- βοΈ Update
- ποΈ Delete
- All phones: http://localhost:3000/phones
- Specific phone: http://localhost:3000/phones/1
- Search: http://localhost:3000/phones/search?brand=Apple
Create:
curl -X POST http://localhost:3000/phones/insert \
-H "Content-Type: application/json" \
-d '{"name":"Test Phone","brand":"TestBrand","price":599.99,"stock_quantity":10,"color":"Black","storage":"128GB"}'Read:
curl http://localhost:3000/phones
curl http://localhost:3000/phones/1
curl "http://localhost:3000/phones/search?brand=Apple"Update:
curl -X PUT http://localhost:3000/phones/1 \
-H "Content-Type: application/json" \
-d '{"name":"Updated Phone","brand":"Apple","price":899.99,"stock_quantity":15,"color":"Blue","storage":"256GB"}'Delete:
curl -X DELETE http://localhost:3000/phones/1CellSync/
βββ controllers/ # Business logic layer
β βββ getPhones.js # READ operations (all, search)
β βββ insertPhone.js # CREATE operation
β βββ updatePhone.js # UPDATE & get by ID
β βββ deletePhone.js # DELETE operation
βββ db/ # Database layer
β βββ pool.js # PostgreSQL connection pool
β βββ queries.js # All database queries
β βββ setup.sql # Database schema
βββ routes/ # API routes
β βββ getphones.js # All CRUD endpoints
βββ public/ # Static files
β βββ test.html # Interactive test interface
βββ node_modules/ # Dependencies
βββ .env # Environment variables (create this)
βββ .gitignore # Git ignore file
βββ index.js # Server entry point
βββ package.json # Project metadata
βββ API_DOCUMENTATION.md # Complete API reference
βββ CRUD_SUMMARY.md # Quick reference guide
βββ README.md # This file
Models (db/queries.js)
- Database query functions
- Data validation
- SQL operations
Controllers (controllers/*)
- Business logic
- Request/response handling
- Error handling
Routes (routes/*)
- Endpoint definitions
- HTTP method mapping
- Route organization
Views (public/*)
- User interface
- Interactive testing
- β Parameterized queries - Prevents SQL injection
- β Environment variables - Sensitive data protection
- β Input validation - Data integrity
- β Error handling - Secure error messages
- β CORS ready - Cross-origin support (if needed)
β Star this repo if you find it helpful! β
Made with β€οΈ by developers, for developers