A comprehensive backend API for an online pet shop and pet adoption platform built with ASP.NET Core 9, PostgreSQL, and Docker.
- Product Management: Complete CRUD operations for pet products
- Categories: Support for Cats, Dogs, and Other animals
- Product Filtering: Filter by price range, category (toys, food, litters, medicines), and more
- Shopping Cart: Add, update, remove items from cart
- Order Management: Create orders, track order status
- Inventory Management: Stock tracking with low stock alerts
- Dashboard: Total products, inventory value, low stock alerts, recent products
- Product Management: Add, edit, delete products with image support
- Order Management: View and update order statuses (waiting, processing, completed, withdrawn, rejected)
- Inventory Tracking: Monitor stock levels and get low stock alerts
- JWT Authentication: Secure token-based authentication
- Role-based Authorization: Admin and User roles
- Refresh Tokens: Secure token refresh mechanism
- User Management: Registration, login, logout functionality
- Framework: ASP.NET Core 9 Web API
- Database: PostgreSQL with Entity Framework Core
- Authentication: JWT Bearer tokens
- Documentation: OpenAPI/Swagger with Scalar UI
- Containerization: Docker & Docker Compose
- ORM: Entity Framework Core with Npgsql
- .NET 9 SDK
- Docker and Docker Compose
- Git
git clone https://github.com/yourusername/PetpetAPI.git
cd PetpetAPIThe application uses Docker Compose for easy setup. All necessary configuration is already included.
# Build and start all services
docker-compose up --build
# Or run in detached mode
docker-compose up -d --buildThis will start:
- PostgreSQL database on port 5432
- PetPet API on port 8080
- API Base URL: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger
- Scalar API Documentation: http://localhost:8080/api/reference
- Email: [email protected]
- Password: Admin123!
The API includes comprehensive OpenAPI documentation accessible at:
- Swagger UI: http://localhost:8080/swagger
- Scalar UI: http://localhost:8080/api/reference (Modern API documentation interface)
PetpetAPI/
βββ src/
β βββ PetpetAPI/
β βββ Controllers/ # API Controllers
β βββ Data/ # Database Context
β βββ DTOs/ # Data Transfer Objects
β β βββ Auth/
β β βββ Products/
β β βββ Cart/
β β βββ Orders/
β β βββ Admin/
β β βββ Common/
β βββ Models/ # Entity Models
β βββ Services/ # Business Logic
β βββ Program.cs # Application Entry Point
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose configuration
βββ README.md
POST /api/auth/register
Content-Type: application/json
{
"email": "[email protected]",
"password": "Password123!",
"firstName": "John",
"lastName": "Doe"
}POST /api/auth/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "Password123!"
}Include the JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>GET /api/products- Get products with filteringGET /api/products/{id}- Get specific productPOST /api/products- Create product (Admin)PUT /api/products/{id}- Update product (Admin)DELETE /api/products/{id}- Delete product (Admin)
GET /api/cart- Get user's cartPOST /api/cart/items- Add item to cartPUT /api/cart/items/{id}- Update cart itemDELETE /api/cart/items/{id}- Remove cart item
POST /api/orders- Create order from cartGET /api/orders/my-orders- Get user's ordersGET /api/orders- Get all orders (Admin)PUT /api/orders/{id}/status- Update order status (Admin)
GET /api/admin/dashboard/stats- Dashboard statisticsGET /api/admin/products/low-stock- Low stock products
The connection string is configured in appsettings.Development.json:
{
"ConnectionStrings": {
"DefaultConnection": "Host=db;Database=petpetdb;Username=postgres;Password=postgres"
}
}JWT configuration in appsettings.json:
{
"JwtSettings": {
"SecretKey": "your-secret-key-here-minimum-32-characters-long",
"Issuer": "PetpetAPI",
"Audience": "PetpetAPI-Users",
"ExpirationInMinutes": 60,
"RefreshTokenExpirationInDays": 7
}
}-
Install PostgreSQL locally
-
Update connection string in
appsettings.json -
Run migrations:
cd src/PetpetAPI dotnet ef database update -
Run the application:
dotnet run
# Add new migration
dotnet ef migrations add MigrationName
# Update database
dotnet ef database update
# Remove last migration
dotnet ef migrations removeThe application automatically seeds sample data including:
- Default admin user
- Sample products (cat food, dog toys, cat litter)
- Product images
- User and Admin roles
# Build production image
docker build -t petpetapi:latest .
# Run with external database
docker run -d \
-p 8080:8080 \
-e ConnectionStrings__DefaultConnection="Host=your-db-host;Database=petpetdb;Username=user;Password=pass" \
petpetapi:latest- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.
For support, email [email protected] or create an issue in the repository.
PetPet API - Making pet care accessible and convenient! πΎ