Business Logic API Documentation Base URL: /api/modules/{module_id}/functions/{function_id}/business-logic 1. Generate Business Logic Endpoint: POST /api/modules/{module_id}/functions/{function_id}/business-logic/generate Example: POST http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/generate Description: Generates business logic using Claude AI Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) Request Body: { "custom_instructions": string (optional) - Custom generation instructions } Response: { "status": "success", "message": "Business Logic generated and saved successfully", "data": { "business_logic": string, "metadata": { "input_tokens": integer, "output_tokens": integer, "total_tokens": integer, "module_id": string, "function_id": string, "created_at": datetime, "updated_at": datetime, "version": string, "version_number": integer, "function_current_version": integer, "prompt_data": object, "raw_prompt": string, "status": string, "selected": boolean, "selected_by": string, "selected_at": datetime, "custom_instructions": string }, "version": { "ID": string, "module_id": string, "function_id": string, "business_logic_id": string, "content": string, "version": string, "version_number": integer, "function_version": integer, "created_by": string, "created_at": datetime, "comment": string, "is_current": boolean, "metadata": object } } } 2. Create Business Logic Manually Endpoint: POST /api/modules/{module_id}/functions/{function_id}/business-logic/manual/create Example: POST http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/manual/create Description: Create new business logic manually Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) Request Body: { "Business_logic": string (required) - Business logic content, "title": string (required) - Business logic title, "description": string (required) - Business logic description, "created_by": string (required) - Creator identifier } Response: { "status": "success", "message": "Business logic created successfully", "data": { "business_logic": { "results": { "ID": string, "business_logic": string, "generated_at": datetime, "title": string, "description": string }, "metadata": { "module_id": string, "function_id": string, "created_at": datetime, "updated_at": datetime, "created_by": string, "updated_by": string, "version": string, "version_number": integer, "function_current_version": integer, "type": "manual", "status": string } }, "version": { "ID": string, "module_id": string, "function_id": string, "business_logic_id": string, "content": string, "version": string, "version_number": integer, "function_version": integer, "created_by": string, "created_at": datetime, "comment": string, "is_current": boolean, "metadata": object } } } 3. List Business Logic Endpoint: GET /api/modules/{module_id}/functions/{function_id}/business-logic/list Example: GET http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/list Description: List business logic for a module/function Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) Response: { "status": "success", "message": "Business logic retrieved successfully", "data": { "ID": string, "business_logic": string, "metadata": { "module_id": string, "function_id": string, "created_at": datetime, "updated_at": datetime, "version": string, "version_number": integer, "function_current_version": integer, "status": string, "selected": boolean, "selected_by": string, "selected_at": datetime } } } 4. Update Business Logic Endpoint: PUT /api/modules/{module_id}/functions/{function_id}/business-logic/update/{business_logic_id} Example: PUT http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/update/BL_12345678 Description: Update existing business logic content Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - business_logic_id (required): The ID of the business logic (e.g., BL_12345678) Request Body: { "updated_by": string (required) - User updating the business logic, "content": string (required) - Updated business logic content } Response: { "status": "success", "message": "Business logic updated successfully", "data": { "business_logic": string, "metadata": object, "version": object } } 5. List Business Logic Versions Endpoint: GET /api/modules/{module_id}/functions/{function_id}/business-logic/versions Example: GET http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/versions Description: List all versions of business logic for a function Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) Response: { "status": "success", "message": "Business logic versions retrieved successfully", "data": { "total": integer, "versions": [ { "ID": string, "module_id": string, "function_id": string, "business_logic_id": string, "content": string, "version": string, "version_number": integer, "function_version": integer, "created_by": string, "created_at": datetime, "comment": string, "is_current": boolean, "metadata": object } ] } } 6. Restore Business Logic Version Endpoint: POST /api/modules/{module_id}/functions/{function_id}/business-logic/restore/{business_logic_id}/{version_id} Example: POST http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/restore/BL_12345678/VER_87654321 Description: Restore business logic to a specific version Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - business_logic_id (required): The ID of the business logic (e.g., BL_12345678) - version_id (required): The ID of the version to restore (e.g., VER_87654321) Request Body: { "updated_by": string (required) - User restoring the version } Response: { "status": "success", "message": "Business logic version restored successfully", "data": { "business_logic": string, "metadata": object, "version": object } } 7. Mark Business Logic for Development Endpoint: PUT /api/modules/{module_id}/functions/{function_id}/business-logic/mark-for-development/{fsd_id} Example: PUT http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/mark-for-development/FSD_12345678 Description: Mark business logic for development and track development info Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - fsd_id (required): The ID of the FSD (e.g., FSD_12345678) Request Body: { "updated_by": string (required) - User marking for development, "development_info": { "version": string (required) - Development version, "notes": string (optional) - Development notes, "status": string (required) - Development status } } Response: { "status": "success", "message": "Business logic marked for development", "data": { "metadata": object, "version": object } } 8. Activate Business Logic Endpoint: PUT /api/modules/{module_id}/functions/{function_id}/business-logic/activate/{business_logic_id} Example: PUT http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/activate/BL_12345678 Description: Activate a business logic document Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - business_logic_id (required): The ID of the business logic (e.g., BL_12345678) Request Body: { "updated_by": string (required) - User activating the business logic } Response: { "status": "success", "message": "Business logic activated successfully", "data": { "metadata": object, "version": object } } 9. Deactivate Business Logic Endpoint: PUT /api/modules/{module_id}/functions/{function_id}/business-logic/deactivate/{business_logic_id} Example: PUT http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/deactivate/BL_12345678 Description: Deactivate a business logic document Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - business_logic_id (required): The ID of the business logic (e.g., BL_12345678) Request Body: { "updated_by": string (required) - User deactivating the business logic } Response: { "status": "success", "message": "Business logic deactivated successfully", "data": { "metadata": object, "version": object } } 10. Select Business Logic Endpoint: PUT /api/modules/{module_id}/functions/{function_id}/business-logic/select/{business_logic_id} Example: PUT http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/select/BL_12345678 Description: Select a business logic document Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - business_logic_id (required): The ID of the business logic (e.g., BL_12345678) Request Body: { "updated_by": string (required) - User selecting the business logic } Response: { "status": "success", "message": "Business logic selected successfully", "data": { "metadata": object, "version": object } } 11. Deselect Business Logic Endpoint: PUT /api/modules/{module_id}/functions/{function_id}/business-logic/deselect/{business_logic_id} Example: PUT http://localhost:8000/api/modules/MOD-40/functions/func_c5a8e0c6/business-logic/deselect/BL_12345678 Description: Deselect a business logic document Path Parameters: - module_id (required): The ID of the module (e.g., MOD-40) - function_id (required): The ID of the function (e.g., func_c5a8e0c6) - business_logic_id (required): The ID of the business logic (e.g., BL_12345678) Request Body: { "updated_by": string (required) - User deselecting the business logic } Response: { "status": "success", "message": "Business logic deselected successfully", "data": { "metadata": object, "version": object } } Models: Business Logic Document: { "results": { "ID": string (required) - Unique identifier, "business_logic": string (required) - Business logic content, "generated_at": datetime (required) - Generation timestamp, "title": string (optional) - Title for manual creation, "description": string (optional) - Description for manual creation }, "metadata": { "module_id": string (required) - Associated module ID, "function_id": string (required) - Associated function ID, "created_at": datetime (required) - Creation timestamp, "updated_at": datetime (required) - Last update timestamp, "created_by": string (required) - Creator identifier, "updated_by": string (required) - Last updater identifier, "version": string (required) - Version string (e.g., "1.0.0"), "version_number": integer (required) - Version number, "function_current_version": integer (required) - Function version, "type": string (optional) - Document type (manual/generated), "status": string (required) - Document status, "selected": boolean (required) - Selection state, "selected_by": string (optional) - User who selected, "selected_at": datetime (optional) - Selection timestamp, "development_info": object (optional) - Development tracking info } } Version Document: { "ID": string (required) - Unique version identifier, "module_id": string (required) - Associated module ID, "function_id": string (required) - Associated function ID, "business_logic_id": string (required) - Associated business logic ID, "content": string (required) - Version content, "version": string (required) - Version string, "version_number": integer (required) - Version number, "function_version": integer (required) - Function version, "created_by": string (required) - Creator identifier, "created_at": datetime (required) - Creation timestamp, "comment": string (required) - Version comment, "is_current": boolean (required) - Current version flag, "metadata": object (required) - Copy of business logic metadata } Development Info: { "version": string (required) - Development version, "notes": string (optional) - Development notes, "status": string (required) - Development status, "fsd_id": string (required) - Associated FSD ID } Status Codes: - 200: Successful operation - 201: Resource created successfully - 400: Bad request (invalid input) - 404: Resource not found - 500: Internal server error Error Response Format: { "status": "error", "message": string, "error_code": string } Business Logic Status Values: - "active": Currently active - "inactive": Not active - "under_development": In development state Development Status Values: - "not_started": Development not started - "in_development": Currently being developed - "completed": Development completed - "archived": Development archived Authentication: - All endpoints require authentication via Bearer token - Include token in Authorization header: "Authorization: Bearer " Notes: - All datetime values are in ISO 8601 format - All string fields have a maximum length of 1000 characters unless specified otherwise - The system automatically handles versioning when updates are made - Business logic is associated with specific modules and functions - The API supports CORS with OPTIONS preflight requests - Version history is maintained for all changes - Only one business logic can be selected at a time per function - Status changes are tracked with timestamps and user information