# Redux Integration with IndexedDB and Flask API ## Overview This project implements a comprehensive Redux Toolkit integration with: - **IndexedDB** for local browser storage - **Flask API** for remote server synchronization - **Atomic component trees** from JSON structures ## Architecture ``` ┌─────────────────────────────────────────────────────────────┐ │ React Components │ │ (UI Layer with Hooks) │ └────────────────────────┬────────────────────────────────────┘ │ ┌────────────────────────▼────────────────────────────────────┐ │ Redux Toolkit Store │ │ ┌──────────┬──────────┬────────────┬──────────┬─────────┐ │ │ │ Project │ Files │ Models │Components│ Theme │ │ │ │ Slice │ Slice │ Slice │ Slice │ Slice │ │ │ └──────────┴──────────┴────────────┴──────────┴─────────┘ │ │ ┌───────────────┬─────────────┬─────────────┬───────────┐ │ │ │ ComponentTrees│ Workflows │ Lambdas │ Sync │ │ │ │ Slice │ Slice │ Slice │ Slice │ │ │ └───────────────┴─────────────┴─────────────┴───────────┘ │ └────────────────────────┬────────────────────────────────────┘ │ ┌───────────────┴───────────────┐ │ │ ┌────────▼────────┐ ┌────────▼────────┐ │ IndexedDB │ │ Flask API │ │ (Local Store) │◄──Sync────►│ (Remote Store) │ └─────────────────┘ └─────────────────┘ ``` ## Redux Slices ### 1. Project Slice (`projectSlice.ts`) Manages project metadata and overall project state. ```typescript import { useAppDispatch, useAppSelector } from '@/store' import { createProject, loadProjects } from '@/store/slices/projectSlice' // Usage const dispatch = useAppDispatch() const projects = useAppSelector(state => state.project.projects) // Create a new project dispatch(createProject({ name: 'My Project', description: 'Description' })) // Load all projects dispatch(loadProjects()) ``` ### 2. Files Slice (`filesSlice.ts`) Manages file operations with IndexedDB and Flask sync. ```typescript import { useReduxFiles } from '@/hooks/use-redux-files' const { files, save, remove, setActive } = useReduxFiles() // Save a file save({ id: 'file-1', name: 'Component.tsx', content: 'export default function() {}', language: 'typescript', path: '/src/components', updatedAt: Date.now() }) ``` ### 3. Component Trees Slice (`componentTreesSlice.ts`) Manages JSON component trees for atomic component rendering. ```typescript import { useReduxComponentTrees } from '@/hooks/use-redux-component-trees' const { trees, updateNode, setActive } = useReduxComponentTrees() // Update a node in the tree updateNode('tree-1', 'node-1', { props: { className: 'updated-class' } }) ``` ### 4. Models Slice (`modelsSlice.ts`) Manages data models and schemas. ```typescript import { useAppDispatch } from '@/store' import { saveModel } from '@/store/slices/modelsSlice' dispatch(saveModel({ id: 'model-1', name: 'User', fields: [ { id: 'f1', name: 'email', type: 'string', required: true }, { id: 'f2', name: 'name', type: 'string', required: true } ], updatedAt: Date.now() })) ``` ### 5. Components Slice (`componentsSlice.ts`) Manages atomic/molecule/organism components. ```typescript import { useAppDispatch } from '@/store' import { saveComponent } from '@/store/slices/componentsSlice' dispatch(saveComponent({ id: 'comp-1', name: 'Button', type: 'atom', code: 'export function Button() { return