|
| 1 | +# API Access Patterns Analysis |
| 2 | + |
| 3 | +**CRITICAL**: These patterns represent ALL access patterns that must be supported in the DynamoDB design. |
| 4 | + |
| 5 | +## Complete API Endpoints and Data Access Requirements |
| 6 | + |
| 7 | +### 1. Authentication Endpoints (`/api/auth`) |
| 8 | + |
| 9 | +| Method | Endpoint | Auth Required | Data Access Pattern | |
| 10 | +|--------|----------|---------------|-------------------| |
| 11 | +| POST | `/register` | ❌ | Create user record | |
| 12 | +| POST | `/login` | ❌ | Query user by username | |
| 13 | +| GET | `/profile` | ✅ | Query user by ID | |
| 14 | +| PUT | `/profile` | ✅ | Update user by ID | |
| 15 | +| POST | `/upgrade-seller` | ✅ | Update user is_seller flag by ID | |
| 16 | +| POST | `/logout` | ✅ | No database operation | |
| 17 | +| GET | `/verify` | ✅ | Query user by ID | |
| 18 | + |
| 19 | +### 2. Product Endpoints (`/api/products`) |
| 20 | + |
| 21 | +| Method | Endpoint | Auth Required | Data Access Pattern | |
| 22 | +|--------|----------|---------------|-------------------| |
| 23 | +| GET | `/` | ❌ | Query products with filters (category_id, seller_id, search, price range, stock) + pagination | |
| 24 | +| GET | `/search` | ❌ | Query products by name/description text search + pagination | |
| 25 | +| GET | `/category/:categoryId` | ❌ | Query products by category_id + pagination | |
| 26 | +| GET | `/:id` | ❌ | Query single product by ID | |
| 27 | +| POST | `/` | ✅ (Seller) | Create product record | |
| 28 | +| PUT | `/:id` | ✅ (Seller) | Update product by ID (owner validation) | |
| 29 | +| DELETE | `/:id` | ✅ (Seller) | Delete product by ID (owner validation) | |
| 30 | +| GET | `/seller/my-products` | ✅ (Seller) | Query products by seller_id + pagination | |
| 31 | +| PUT | `/:id/inventory` | ✅ (Seller) | Update product inventory by ID (owner validation) | |
| 32 | +| GET | `/seller/stats` | ✅ (Seller) | Aggregate query: count products by seller_id | |
| 33 | +| POST | `/upload-image` | ✅ (Seller) | File upload (no database operation) | |
| 34 | + |
| 35 | +### 3. Category Endpoints (`/api/categories`) |
| 36 | + |
| 37 | +| Method | Endpoint | Auth Required | Data Access Pattern | |
| 38 | +|--------|----------|---------------|-------------------| |
| 39 | +| GET | `/search` | ❌ | Query categories by name text search | |
| 40 | +| GET | `/flat` | ❌ | Query all categories (flat list) | |
| 41 | +| GET | `/roots` | ❌ | Query categories where parent_id is NULL | |
| 42 | +| GET | `/:id/children` | ❌ | Query categories by parent_id | |
| 43 | +| GET | `/:id/path` | ❌ | Recursive query: category path from root to category | |
| 44 | +| GET | `/:id` | ❌ | Query single category by ID | |
| 45 | +| GET | `/` | ❌ | Query all categories in hierarchical tree structure | |
| 46 | +| POST | `/` | ✅ (Seller) | Create category record | |
| 47 | +| PUT | `/:id` | ✅ (Seller) | Update category by ID | |
| 48 | +| DELETE | `/:id` | ✅ (Seller) | Delete category by ID (with child validation) | |
| 49 | + |
| 50 | +### 4. Order Endpoints (`/api/orders`) |
| 51 | + |
| 52 | +| Method | Endpoint | Auth Required | Data Access Pattern | |
| 53 | +|--------|----------|---------------|-------------------| |
| 54 | +| POST | `/checkout` | ✅ | Create order + order_items from cart, update product inventory | |
| 55 | +| GET | `/` | ✅ | Query orders by user_id + pagination | |
| 56 | +| GET | `/:orderId` | ✅ | Query order by ID (owner validation) | |
| 57 | +| PUT | `/:orderId/cancel` | ✅ | Update order status by ID (owner validation) | |
| 58 | +| GET | `/user/summary` | ✅ | Aggregate query: order statistics by user_id | |
| 59 | +| PUT | `/:orderId/status` | ✅ | Update order status by ID (seller validation) | |
| 60 | +| GET | `/user/recent` | ✅ | Query recent orders by user_id (limited) | |
| 61 | +| GET | `/user/search` | ✅ | Query orders by user_id with text search | |
| 62 | +| GET | `/checkout/validate` | ✅ | Validate cart inventory before checkout | |
| 63 | + |
| 64 | +### 5. Shopping Cart Endpoints (`/api/cart`) |
| 65 | + |
| 66 | +| Method | Endpoint | Auth Required | Data Access Pattern | |
| 67 | +|--------|----------|---------------|-------------------| |
| 68 | +| GET | `/` | ✅ | Query cart items by user_id | |
| 69 | +| POST | `/items` | ✅ | Create/update cart item by user_id + product_id | |
| 70 | +| PUT | `/items/:productId` | ✅ | Update cart item quantity by user_id + product_id | |
| 71 | +| DELETE | `/items/:productId` | ✅ | Delete cart item by user_id + product_id | |
| 72 | +| DELETE | `/` | ✅ | Delete all cart items by user_id | |
| 73 | +| GET | `/summary` | ✅ | Aggregate query: cart summary by user_id | |
| 74 | +| GET | `/validate` | ✅ | Validate cart inventory by user_id | |
| 75 | + |
| 76 | +### 6. Seller Endpoints (`/api/seller`) |
| 77 | + |
| 78 | +| Method | Endpoint | Auth Required | Data Access Pattern | |
| 79 | +|--------|----------|---------------|-------------------| |
| 80 | +| POST | `/upgrade` | ✅ | Update user is_seller flag by ID | |
| 81 | +| GET | `/profile` | ✅ (Seller) | Query user by ID | |
| 82 | +| GET | `/dashboard` | ✅ (Seller) | Query user by ID + aggregate seller statistics | |
| 83 | +| PUT | `/profile` | ✅ (Seller) | Update user profile by ID | |
| 84 | + |
| 85 | +## Entity Relationships |
| 86 | + |
| 87 | +### Core Entities and Their Relationships |
| 88 | + |
| 89 | +1. **Users** |
| 90 | + - Primary Key: `id` |
| 91 | + - Unique Keys: `username`, `email` |
| 92 | + - Relationships: |
| 93 | + - One-to-Many with Products (as seller) |
| 94 | + - One-to-Many with Orders (as customer) |
| 95 | + - One-to-Many with Cart Items |
| 96 | + |
| 97 | +2. **Categories** |
| 98 | + - Primary Key: `id` |
| 99 | + - Self-referencing: `parent_id` → `categories.id` |
| 100 | + - Relationships: |
| 101 | + - One-to-Many with Products |
| 102 | + - Hierarchical tree structure (parent-child) |
| 103 | + |
| 104 | +3. **Products** |
| 105 | + - Primary Key: `id` |
| 106 | + - Foreign Keys: `category_id` → `categories.id`, `seller_id` → `users.id` |
| 107 | + - Relationships: |
| 108 | + - Many-to-One with Categories |
| 109 | + - Many-to-One with Users (seller) |
| 110 | + - One-to-Many with Order Items |
| 111 | + - One-to-Many with Cart Items |
| 112 | + |
| 113 | +4. **Orders** |
| 114 | + - Primary Key: `id` |
| 115 | + - Foreign Key: `user_id` → `users.id` |
| 116 | + - Relationships: |
| 117 | + - Many-to-One with Users |
| 118 | + - One-to-Many with Order Items |
| 119 | + |
| 120 | +5. **Order Items** |
| 121 | + - Composite Key: `order_id` + `product_id` |
| 122 | + - Foreign Keys: `order_id` → `orders.id`, `product_id` → `products.id` |
| 123 | + - Relationships: |
| 124 | + - Many-to-One with Orders |
| 125 | + - Many-to-One with Products |
| 126 | + |
| 127 | +6. **Cart Items** |
| 128 | + - Composite Key: `user_id` + `product_id` |
| 129 | + - Foreign Keys: `user_id` → `users.id`, `product_id` → `products.id` |
| 130 | + - Relationships: |
| 131 | + - Many-to-One with Users |
| 132 | + - Many-to-One with Products |
| 133 | + |
| 134 | +## Enumerated Access Patterns for DynamoDB Design (48 Total API Methods) |
| 135 | + |
| 136 | +### User Management (7 patterns) |
| 137 | +- **AP1**: Create user account (POST /api/auth/register) |
| 138 | +- **AP2**: Authenticate user by username (POST /api/auth/login) |
| 139 | +- **AP3**: Get user profile by user ID (GET /api/auth/profile) |
| 140 | +- **AP4**: Update user profile by user ID (PUT /api/auth/profile) |
| 141 | +- **AP5**: Upgrade user to seller status (POST /api/auth/upgrade-seller) |
| 142 | +- **AP6**: Logout user (POST /api/auth/logout) |
| 143 | +- **AP7**: Verify user token (GET /api/auth/verify) |
| 144 | + |
| 145 | +### Product Catalog (12 patterns) |
| 146 | +- **AP8**: Get all products with filtering and pagination (GET /api/products) |
| 147 | +- **AP9**: Search products by text (GET /api/products/search) |
| 148 | +- **AP10**: Get products by category (GET /api/products/category/:categoryId) |
| 149 | +- **AP11**: Get single product by ID (GET /api/products/:id) |
| 150 | +- **AP12**: Create new product (POST /api/products) |
| 151 | +- **AP13**: Update product (PUT /api/products/:id) |
| 152 | +- **AP14**: Delete product (DELETE /api/products/:id) |
| 153 | +- **AP15**: Get products by seller ID (GET /api/products/seller/my-products) |
| 154 | +- **AP16**: Update product inventory (PUT /api/products/:id/inventory) |
| 155 | +- **AP17**: Get seller product statistics (GET /api/products/seller/stats) |
| 156 | +- **AP18**: Upload product image (POST /api/products/upload-image) |
| 157 | + |
| 158 | +### Category Management (9 patterns) |
| 159 | +- **AP19**: Search categories by name (GET /api/categories/search) |
| 160 | +- **AP20**: Get all categories flat list (GET /api/categories/flat) |
| 161 | +- **AP21**: Get root categories (GET /api/categories/roots) |
| 162 | +- **AP22**: Get child categories by parent ID (GET /api/categories/:id/children) |
| 163 | +- **AP23**: Get category path breadcrumb (GET /api/categories/:id/path) |
| 164 | +- **AP24**: Get single category by ID (GET /api/categories/:id) |
| 165 | +- **AP25**: Get category hierarchy tree (GET /api/categories) |
| 166 | +- **AP26**: Create category (POST /api/categories) |
| 167 | +- **AP27**: Update category (PUT /api/categories/:id) |
| 168 | +- **AP28**: Delete category (DELETE /api/categories/:id) |
| 169 | + |
| 170 | +### Order Management (9 patterns) |
| 171 | +- **AP29**: Create order from cart checkout (POST /api/orders/checkout) |
| 172 | +- **AP30**: Get user's order history with pagination (GET /api/orders) |
| 173 | +- **AP31**: Get single order by ID (GET /api/orders/:orderId) |
| 174 | +- **AP32**: Cancel order (PUT /api/orders/:orderId/cancel) |
| 175 | +- **AP33**: Get user order summary/statistics (GET /api/orders/user/summary) |
| 176 | +- **AP34**: Update order status (PUT /api/orders/:orderId/status) |
| 177 | +- **AP35**: Get recent orders for user (GET /api/orders/user/recent) |
| 178 | +- **AP36**: Search user orders by text (GET /api/orders/user/search) |
| 179 | +- **AP37**: Validate checkout eligibility (GET /api/orders/checkout/validate) |
| 180 | + |
| 181 | +### Shopping Cart (7 patterns) |
| 182 | +- **AP38**: Get user's cart with items (GET /api/cart) |
| 183 | +- **AP39**: Add item to cart (POST /api/cart/items) |
| 184 | +- **AP40**: Update cart item quantity (PUT /api/cart/items/:productId) |
| 185 | +- **AP41**: Remove item from cart (DELETE /api/cart/items/:productId) |
| 186 | +- **AP42**: Clear entire cart (DELETE /api/cart) |
| 187 | +- **AP43**: Get cart summary (GET /api/cart/summary) |
| 188 | +- **AP44**: Validate cart inventory (GET /api/cart/validate) |
| 189 | + |
| 190 | +### Seller Operations (4 patterns) |
| 191 | +- **AP45**: Upgrade to seller (POST /api/seller/upgrade) |
| 192 | +- **AP46**: Get seller profile (GET /api/seller/profile) |
| 193 | +- **AP47**: Get seller dashboard statistics (GET /api/seller/dashboard) |
| 194 | +- **AP48**: Update seller profile (PUT /api/seller/profile) |
| 195 | + |
| 196 | +## Key Access Pattern Characteristics |
| 197 | + |
| 198 | +### Query Types Required: |
| 199 | +1. **Point Lookups**: Single item by primary key |
| 200 | +2. **Range Queries**: Pagination, date ranges, price ranges |
| 201 | +3. **Filter Queries**: Multiple filter conditions |
| 202 | +4. **Text Search**: Product names, descriptions, category names |
| 203 | +5. **Hierarchical Queries**: Category trees, paths |
| 204 | +6. **Aggregate Queries**: Counts, sums, statistics |
| 205 | +7. **Composite Key Queries**: Cart items, order items |
| 206 | + |
| 207 | +### Performance Requirements: |
| 208 | +1. **High Read Volume**: Product browsing, search |
| 209 | +2. **Moderate Write Volume**: Cart operations, orders |
| 210 | +3. **Real-time Inventory**: Stock validation |
| 211 | +4. **Pagination Support**: All list endpoints |
| 212 | +5. **Search Performance**: Text-based product/category search |
| 213 | + |
| 214 | +### Security Requirements: |
| 215 | +1. **Owner Validation**: Users can only access their own data |
| 216 | +2. **Role-based Access**: Seller vs regular user permissions |
| 217 | +3. **Authentication**: JWT token validation |
| 218 | + |
| 219 | +**CRITICAL STATEMENT**: These patterns represent ALL access patterns that must be supported in the DynamoDB design. Any DynamoDB table structure must efficiently support all 48 enumerated access patterns while maintaining performance, security, and consistency requirements. |
0 commit comments