Skip to content

Nwokike/kiri-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kiri.ng - Complete Database Management System

Assignment Overview

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.

Question 1: Database Design

Use Case: Service Marketplace Platform

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

Database Schema Features

The database includes the following well-structured components:

Core Tables:

  • 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)

Additional Features:

  • 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

Relationships Implemented:

  • One-to-One: Users ↔ Profiles
  • One-to-Many: Users → Services, Services → Bookings, Pathways → Modules
  • Many-to-Many: Users ↔ Badges (through user_badges)

Constraints Used:

  • 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

Question 2: CRUD Application

Technology Stack

  • Backend: FastAPI (Python)
  • Database: MySQL with SQLAlchemy ORM
  • Features: Auto-reflection, robust error handling, comprehensive API

Key Features

Implemented CRUD Operations for:

  1. Services - Core marketplace functionality
  2. Bookings - Service reservation system
  3. Users & Profiles - User management
  4. Categories - Service categorization
  5. Blog Posts & Comments - Community features
  6. Learning Pathways & Steps - Educational content

Advanced Features:

  • 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

Installation & Setup

Prerequisites

  • Python 3.8+
  • MySQL Server
  • pip (Python package manager)

Database Setup

  1. Create the database:

    mysql -u root -p < kiri_ng.sql
  2. Configure environment variables: Create a .env file:

    DATABASE_URL=mysql+pymysql://root:your_password@localhost:3306/kiri_ng
    

Application Setup

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the application:

    uvicorn app.main:app --reload
  3. Access the API:

API Endpoints

Core Entities

Services

  • GET /services - List all services
  • GET /services/{id} - Get specific service
  • POST /services - Create new service
  • PUT /services/{id} - Update service
  • DELETE /services/{id} - Delete service

Bookings

  • GET /bookings - List all bookings
  • GET /bookings/{id} - Get specific booking
  • POST /services/{service_id}/bookings - Create booking for service
  • PUT /bookings/{id} - Update booking
  • DELETE /bookings/{id} - Delete booking

Users & Profiles

  • GET /users - List users
  • POST /users - Create user
  • GET /profiles - List profiles
  • POST /profiles - Create profile

Blog System

  • GET /posts - List blog posts
  • POST /posts - Create blog post
  • GET /comments - List comments
  • POST /comments - Create comment

Learning System

  • GET /pathways - List learning pathways
  • POST /pathways - Create pathway
  • GET /steps - List module steps
  • POST /steps - Create step

Utility Endpoints

  • GET / - Welcome message
  • GET /tables - List all database tables (debug)

Example API Usage

Create a Service

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
  }'

Create a Booking

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"
  }'

Create a Blog Post

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
  }'

Project Structure

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

Technical Highlights

Database Design Excellence

  • Normalized structure preventing data redundancy
  • Referential integrity through foreign key constraints
  • Flexible schema supporting multiple business models
  • Scalable design with proper indexing considerations

Application Architecture

  • 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

Advanced Features

  • Field mapping system for database compatibility
  • Comprehensive validation with custom error messages
  • Automatic documentation via FastAPI/OpenAPI
  • Environment-based configuration for different deployments

Future Enhancements

  • 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

Assignment Completion

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages