--- description: globs: alwaysApply: true --- # TCA Architecture Guidelines - Use The Composable Architecture (TCA) for state management and side effect handling. - Define reducers for each feature and use @Reducer annotation. - Use stores to manage state. - Follow unidirectional data flow (state -> view -> action -> reducer -> state). - Use @State to manage local state and @ObservedObject or @EnvironmentObject to manage shared state. - Make sure all side effects (such as network requests) are handled in reducers using Effects. - Divide reducers by functionality and define a root reducer. - Use Dependency Injection to manage external dependencies (such as network, database). - Write tests for reducers to ensure correct state transitions. ## Feature Structure Each feature must include: 1. A `State` struct 2. An `Action` enum 3. A `Reducer` 4. A `View` (if applicable) ## Naming Conventions - Feature: `{{FeatureName}}Feature` - State: `{{FeatureName}}Feature.State` - Action: `{{FeatureName}}Feature.Action` - Reducer: `{{FeatureName}}Feature.reducer` ## Example ```swift struct CounterFeature { struct State: Equatable { var count = 0 } enum Action: Equatable { case increment case decrement } static let reducer = Reducer { state, action, _ in switch action { case .increment: state.count += 1 return .none case .decrement: state.count -= 1 return .none } } }