Skip to content

This service provides a production-ready foundation for building RESTful APIs with FastAPI, featuring in-memory data storage and comprehensive testing capabilities. The service supports basic database operations (CRUD) and allows for simple join operations between datasets.

Notifications You must be signed in to change notification settings

maxdata/In-Memory-DB-Service

Repository files navigation

In-Memory Database Service

Table of Contents

1. Overview

This service provides a production-ready foundation for building RESTful APIs with FastAPI, featuring in-memory data storage and comprehensive testing capabilities. The service supports basic database operations (CRUD) and allows for simple join operations between datasets.

2. Project Document Structure

2.1 README.md

./README.md
Primary entry point for the project, containing quick start guide, installation instructions, and overview of all features and components.

2.2 Product Requirements

./1_PRODUCT_REQUIREMENTS.md
Comprehensive documentation of product features, user stories, acceptance criteria, and business requirements.

2.3 Technical Design

./2_TECHNICAL_DESIGN.md
Detailed technical architecture, system design, implementation specifications, and architectural decisions.

2.4 Performance Optimization

./3_PERFORMANCE_OPTIMIZATION.md
Comprehensive performance optimization strategies, test results, and future optimization plans.

2.5 Contributing Guide

./4_CONTRIBUTING.md
Development standards, workflow guidelines, and contribution procedures for developers.

2.6 Test Strategy

./backend/tests/TESTING_STRATEGY.md
Testing methodology, test organization, and execution guidelines.

2.7 Deployment Guide

./deploy/DEPLOYMENT.md
Complete deployment procedures, environment setup, and operational instructions.

3. Quick Start

3.1 Installation & Usage

  1. Clone the repository:
git clone https://github.com/yourusername/in-memory-db-service.git
cd in-memory-db-service
  1. View available commands:
make help
  1. Quick development setup:
make dev  # Installs dependencies, formats code, runs linter and tests, starts the server

3.2 Common Make Commands

Command Description
make install Install dependencies
make run Run the application locally
make test Run all tests
make test-report Generate comprehensive test report
make clean Clean up temporary files

3.3 Code Quality

Command Tool Description
make format Black Automatically format Python code to match PEP 8 style
make lint Flake8 Check code style and quality for potential errors

4. Technical Design

For detailed technical specifications and architecture details, please refer to our comprehensive Technical Design Document. The document covers:

Key technical features include:

  • In-memory data storage with table-level locking
  • Singleton pattern implementation for database consistency
  • Hash-based indexing with proven performance improvements
  • Async/await support for non-blocking operations
  • RESTful API with FastAPI framework
  • Comprehensive error handling and validation
  • Efficient data relationship management

For implementation details and guidelines, see:

5. Performance Optimization

For detailed performance optimization strategies and benchmarks, please refer to our Performance Optimization Document. The document covers:

Key performance improvements include:

  • Hash-based indexing implementation with proven improvements:
    • 59.9% faster worst-case user retrieval operations
    • 43.3% improvement in table dump maximum latency
    • 16.3% better worst-case relationship query performance
    • 7.8% improvement in mean latency for table dumps
    • 10.9% increase in operations per second for relationship endpoints
  • O(1) lookup time for indexed fields with minimal memory overhead

Current focus areas include:

  • Relationship-based query optimization
  • Memory-efficient data structures
  • Table-level operation performance
  • Query response time improvements

Upcoming optimizations:

  • Advanced caching strategies
  • Query result pagination
  • Additional index features
  • Memory optimization techniques

For detailed metrics and implementation details, see:

6. Testing

For comprehensive testing information, including test organization, implementation, execution, and reporting, please refer to our Testing Strategy Document.

The testing documentation covers:

  • Test Directory Structure
  • Test Categories and Organization
  • Test Implementation Details
  • Test Execution and Reporting
  • Coverage Analysis
  • Performance Testing

Quick reference for common test-related commands:

make test           # Run all tests
make test-report    # Generate comprehensive test report

7. Deployment

For detailed deployment instructions, configurations, and commands, please refer to our comprehensive Deployment Guide. The guide covers:

For quick reference to deployment commands, see:

8. API Documentation

8.1 API Reference

Documentation Type URL Description
Swagger UI http://localhost:8000/docs Interactive API documentation with testing capability
ReDoc http://localhost:8000/redoc Alternative API documentation with better readability

Below are examples of how to interact with the API using cURL. All responses are in JSON format.

8.2 User Operations

  1. Create a new user:
curl -X POST http://localhost:8000/api/v1/users \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "full_name": "John Doe",
    "password": "securepass123"
  }'
  1. Get a user by ID:
curl -X GET http://localhost:8000/api/v1/users/550e8400-e29b-41d4-a716-446655440000
  1. List all users:
curl -X GET http://localhost:8000/api/v1/users
  1. Update a user:
curl -X PATCH http://localhost:8000/api/v1/users/550e8400-e29b-41d4-a716-446655440000 \
  -H "Content-Type: application/json" \
  -d '{
    "full_name": "John Smith"
  }'
  1. Delete a user:
curl -X DELETE http://localhost:8000/api/v1/users/550e8400-e29b-41d4-a716-446655440000

8.3 Order Operations

  1. Create a new order:
curl -X POST http://localhost:8000/api/v1/orders \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "amount": 99.99,
    "description": "Premium Package",
    "status": "pending"
  }'
  1. Get an order by ID:
curl -X GET http://localhost:8000/api/v1/orders/550e8400-e29b-41d4-a716-446655441111
  1. List all orders:
curl -X GET http://localhost:8000/api/v1/orders
  1. Update an order:
curl -X PATCH http://localhost:8000/api/v1/orders/550e8400-e29b-41d4-a716-446655441111 \
  -H "Content-Type: application/json" \
  -d '{
    "status": "completed"
  }'
  1. Delete an order:
curl -X DELETE http://localhost:8000/api/v1/orders/550e8400-e29b-41d4-a716-446655441111

8.4 Relationship Operations

  1. Get all orders for a user:
curl -X GET http://localhost:8000/api/v1/users/550e8400-e29b-41d4-a716-446655440000/orders
  1. Get user associated with an order:
curl -X GET http://localhost:8000/api/v1/orders/550e8400-e29b-41d4-a716-446655441111/user

8.5 Table Operations

  1. Dump table contents (formatted):
curl -X GET http://localhost:8000/api/v1/tables/users/dump  # For users table
curl -X GET http://localhost:8000/api/v1/tables/orders/dump # For orders table
  1. Dump table contents (raw):
curl -X GET http://localhost:8000/api/v1/db/dump/users  # For users table
curl -X GET http://localhost:8000/api/v1/db/dump/orders # For orders table
  1. Clear table contents:
curl -X DELETE http://localhost:8000/api/v1/tables/users  # Clear users table
curl -X DELETE http://localhost:8000/api/v1/tables/orders # Clear orders table

8.6 Health Check Operations

  1. Health check:
curl -X GET http://localhost:8000/api/v1/health
  1. Readiness check:
curl -X GET http://localhost:8000/api/v1/ready

Note: Replace the UUIDs in the examples with actual UUIDs from your system. All endpoints return appropriate HTTP status codes:

  • 200: Successful operation
  • 201: Resource created
  • 400: Bad request
  • 404: Resource not found
  • 422: Validation error
  • 500: Internal server error

About

This service provides a production-ready foundation for building RESTful APIs with FastAPI, featuring in-memory data storage and comprehensive testing capabilities. The service supports basic database operations (CRUD) and allows for simple join operations between datasets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages