This project implements a complete database management system for Kiri.ng, a service marketplace platform that connects artisans with customers. The system includes both a well-structured MySQL database and a FastAPI-based CRUD application.
Kiri.ng is a platform where:
- Artisans can register and offer their services
- Customers can browse and book services
- Users can engage through blog posts and comments
- Learning pathways help artisans improve their skills
- A badge system recognizes achievements
The database includes the following well-structured components:
- users: User authentication and role management
- profiles: Extended user information (1-to-1 with users)
- services: Services offered by artisans (1-to-many with users)
- bookings: Service bookings (many-to-many between users and services)
- badges & user_badges: Achievement system (many-to-many)
- learning_pathways & modules: Educational content (1-to-many)
- blog_posts & blog_comments: Community engagement
- notifications: User notifications
- One-to-One: Users ↔ Profiles
- One-to-Many: Users → Services, Services → Bookings, Pathways → Modules
- Many-to-Many: Users ↔ Badges (through user_badges)
- PRIMARY KEY on all tables
- FOREIGN KEY relationships with CASCADE deletes
- UNIQUE constraints (email, user-profile relationship)
- NOT NULL constraints on essential fields
- ENUM constraints for status fields
- DEFAULT values and timestamps
- Backend: FastAPI (Python)
- Database: MySQL with SQLAlchemy ORM
- Features: Auto-reflection, robust error handling, comprehensive API
- Services - Core marketplace functionality
- Bookings - Service reservation system
- Users & Profiles - User management
- Categories - Service categorization
- Blog Posts & Comments - Community features
- Learning Pathways & Steps - Educational content
- Auto-reflection: Automatically adapts to database schema changes
- Robust error handling: Graceful handling of missing fields and validation
- Field mapping: Intelligent mapping between API and database field names
- Comprehensive validation: Using Pydantic schemas
- RESTful design: Standard HTTP methods and status codes
- Python 3.8+
- MySQL Server
- pip (Python package manager)
-
Create the database:
mysql -u root -p < kiri_ng.sql
-
Configure environment variables: Create a
.envfile:DATABASE_URL=mysql+pymysql://root:your_password@localhost:3306/kiri_ng
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn app.main:app --reload
-
Access the API:
- API: http://localhost:8000
- Documentation: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
GET /services- List all servicesGET /services/{id}- Get specific servicePOST /services- Create new servicePUT /services/{id}- Update serviceDELETE /services/{id}- Delete service
GET /bookings- List all bookingsGET /bookings/{id}- Get specific bookingPOST /services/{service_id}/bookings- Create booking for servicePUT /bookings/{id}- Update bookingDELETE /bookings/{id}- Delete booking
GET /users- List usersPOST /users- Create userGET /profiles- List profilesPOST /profiles- Create profile
GET /posts- List blog postsPOST /posts- Create blog postGET /comments- List commentsPOST /comments- Create comment
GET /pathways- List learning pathwaysPOST /pathways- Create pathwayGET /steps- List module stepsPOST /steps- Create step
GET /- Welcome messageGET /tables- List all database tables (debug)
curl -X POST "http://localhost:8000/services" \
-H "Content-Type: application/json" \
-d '{
"title": "Web Development",
"description": "Professional website development services",
"price": 500.00,
"artisan_id": 1,
"category_id": 1
}'curl -X POST "http://localhost:8000/services/1/bookings" \
-H "Content-Type: application/json" \
-d '{
"customer_name": "John Doe",
"customer_email": "john@example.com",
"customer_phone": "+1234567890",
"notes": "Need a business website",
"status": "pending"
}'curl -X POST "http://localhost:8000/posts" \
-H "Content-Type: application/json" \
-d '{
"title": "Getting Started with Web Development",
"content": "Here are some tips for beginners...",
"author_id": 1
}'kiri_ng/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application and routes
│ ├── database.py # Database connection and setup
│ ├── deps.py # Dependency injection
│ └── schemas.py # Pydantic models for validation
├── kiri_ng.sql # Database schema
├── requirements.txt # Python dependencies
├── .env # Environment variables
└── README.md # This file
- Normalized structure preventing data redundancy
- Referential integrity through foreign key constraints
- Flexible schema supporting multiple business models
- Scalable design with proper indexing considerations
- Clean separation of concerns (database, schemas, routes)
- Auto-reflection for database schema flexibility
- Robust error handling with meaningful HTTP responses
- Type safety with Pydantic validation
- RESTful API design following best practices
- Field mapping system for database compatibility
- Comprehensive validation with custom error messages
- Automatic documentation via FastAPI/OpenAPI
- Environment-based configuration for different deployments
- Authentication and authorization system
- File upload capabilities for service images
- Real-time notifications
- Payment integration
- Advanced search and filtering
- Rate limiting and caching
- Unit and integration tests
✅ Question 1 Complete: Comprehensive MySQL database with proper relationships and constraints
✅ Question 2 Complete: Full-featured FastAPI CRUD application with extensive functionality
✅ Bonus Features: Auto-reflection, robust error handling, comprehensive API documentation
This project demonstrates mastery of database design principles, modern web API development, and software engineering best practices.