A RESTful API for managing shopping carts, built with Symfony 7.2 and following Domain-Driven Design (DDD) principles.
- Create and manage shopping carts
- Add/remove products to/from cart
- Update product quantities in cart
- View cart contents and total price
- Product management (CRUD operations)
- Input validation and error handling
- API documentation with Swagger/OpenAPI
- PHP 8.2 or higher
- Composer
- MySQL 5.7+ or compatible database
- Symfony CLI (recommended)
-
Clone the repository:
git clone [repository-url] cd cart-api
-
Install dependencies:
composer install
-
Configure your environment:
cp .env .env.local # Update the DATABASE_URL in .env.local with your database credentials # you could run docker compose up where the database is running
-
Create and populate the database:
php bin/console doctrine:database:create php bin/console doctrine:migrations:migrate php bin/console doctrine:fixtures:load
-
Start the development server:
symfony server:start
POST /api/carts
- Create a new cartGET /api/carts/{cartId}
- Get cart detailsDELETE /api/carts/{cartId}
- Clear cartPOST /api/carts/{cartId}/products
- Add product to cartPUT /api/carts/{cartId}/products/{productId}
- Update product quantity in cartDELETE /api/carts/{cartId}/products/{productId}
- Remove product from cart
GET /api/products
- List all productsGET /api/products/{id}
- Get product detailsPOST /api/products
- Create a new productPUT /api/products/{id}
- Update a productDELETE /api/products/{id}
- Delete a product