Story 1.18: Codebase Structure Consolidation
Linear Issue: [BAT-6](https://linear.app/batbern/issue/BAT-6/codebase-structure-consolidation)
Status
Draft
Story
As a developer, I want the codebase structure to be organized, consistent, and aligned with maintainability best practices, so that the project is easier to navigate, understand, and maintain as it grows.
Domain Context
Primary Domain
Infrastructure & Development Operations - Codebase organization and structural improvements
Scope
This is a REFACTORING STORY focused on improving codebase organization without changing functionality:
- Service directory naming standardization
- Test consolidation into unified structure
- Infrastructure stack organization
- Documentation alignment with actual structure
What This Story Does NOT Include
- Excluded: Deleting or moving
BATspa-old/(legacy Angular app - keep as-is) - Excluded: Deleting or moving
apps/projectdoc/(project documentation - keep as-is) - Excluded: Functionality changes or feature additions
- Excluded: Breaking changes to deployed systems
Requirements Context
Problem Statement
Current codebase structure analysis (2025-11-01) revealed:
- Service Naming Inconsistency: All 5 services have
-servicesuffix not present in documentation - Test Fragmentation: E2E tests scattered across 3 locations (
bruno-tests/,web-frontend/e2e/,infrastructure/test/e2e/) - Infrastructure Organization: All CDK stacks flat in single directory, not organized by concern (global/core/domain)
- Documentation Misalignment:
source-tree.mddoesnβt match actual structure
Goals
- Maintainability: Reduce cognitive load for developers navigating the codebase
- Consistency: Align service naming with documentation standards
- Organization: Group related code together (tests, stacks)
- Clarity: Make project structure self-documenting
Related Documentation
- Source Tree:
docs/architecture/source-tree.md(needs update) - Analysis Report: Comprehensive structure analysis completed 2025-11-01 (see Dev Notes)
Architecture Context
Current Structure Issues
Services Directory:
services/
βββ attendee-experience-service/ # Should be: attendee-experience/
βββ company-user-management-service/ # Should be: company-management/
βββ event-management-service/ # Should be: event-management/
βββ partner-coordination-service/ # Should be: partner-coordination/
βββ speaker-coordination-service/ # Should be: speaker-coordination/
Test Fragmentation:
bruno-tests/- API integration tests (not documented)web-frontend/e2e/- Frontend e2e testsinfrastructure/test/e2e/- Infrastructure tests- Documentation expects: unified
e2e-tests/directory
Infrastructure Organization:
- Current: All stacks in flat
infrastructure/lib/stacks/(19 files) - Target: Organized by concern (
global/,core/,domain/, per documentation)
Target Structure (Meet in Middle Approach)
Services (Remove -service suffix):
services/
βββ attendee-experience/
βββ company-management/
βββ event-management/
βββ partner-coordination/
βββ speaker-coordination/
Tests (Consolidated):
e2e-tests/
βββ api/ # From bruno-tests/
βββ workflows/ # From web-frontend/e2e/
βββ infrastructure/ # From infrastructure/test/e2e/
βββ fixtures/ # Shared test data
βββ README.md # Test documentation
Infrastructure (Organized by Concern):
infrastructure/lib/stacks/
βββ global/ # DNS, Secrets, CI/CD
βββ core/ # Network, Database, Cognito, EventBus
βββ domain/ # Service-specific stacks
βββ frontend/ # Frontend deployment
Architecture Patterns
- DDD Alignment: Service names match bounded contexts (no technical suffixes)
- Test Organization: Tests organized by type (api, workflows, infrastructure)
- Infrastructure as Code: CDK stacks organized by deployment lifecycle
- Documentation Accuracy: source-tree.md reflects reality
Acceptance Criteria
Phase 1: Service Naming Standardization
-
AC1.1: All service directories renamed to remove
-serviceevent-management-service/βevent-management/speaker-coordination-service/βspeaker-coordination/partner-coordination-service/βpartner-coordination/attendee-experience-service/βattendee-experience/company-user-management-service/βcompany-management/
-
AC1.2: Fix
company-management- Consolidate duplicate
event/andevents/directories into singleevents/ - Update Java package name from
companyusertocompany(if feasible)
- Consolidate duplicate
-
AC1.3
- Gradle build files (
settings.gradle,build.gradle) - Docker Compose configurations
- CDK infrastructure stack references
- GitHub Actions workflows
- Documentation files
- Gradle build files (
-
AC1.4
./gradlew buildpasses for all services- No broken imports or package references
Phase 2: Test Consolidation
-
AC2.1: Create unified
e2e-tests/e2e-tests/ βββ api/ # API integration tests βββ workflows/ # User workflow tests βββ infrastructure/ # Infrastructure tests βββ fixtures/ # Shared test data βββ .env.example # Test environment template βββ README.md # Test documentation -
AC2.2
- Move
bruno-tests/*βe2e-tests/api/ - Update Bruno collection paths
- Verify API tests still run
- Move
-
AC2.3
- Move
web-frontend/e2e/*βe2e-tests/workflows/ - Update Playwright configuration paths
- Verify frontend e2e tests still run
- Move
-
AC2.4
- Move
infrastructure/test/e2e/*βe2e-tests/infrastructure/ - Update test import paths
- Verify infrastructure tests still run
- Move
-
AC2.5
- Update
package.jsontest scripts - Update
scripts/test/*paths - Update GitHub Actions test workflows
- Create
e2e-tests/README.mdwith test documentation
- Update
-
AC2.6
- Remove empty
bruno-tests/directory - Remove empty
web-frontend/e2e/directory - Remove empty
infrastructure/test/e2e/directory
- Remove empty
Phase 3: Infrastructure Reorganization
-
AC3.1
infrastructure/lib/stacks/ βββ global/ # Region-independent resources βββ core/ # Regional shared resources βββ domain/ # Service-specific stacks βββ frontend/ # Frontend deployment -
AC3.2
-
Global stacks β
global/- DNS/Route53 configurations
- Secrets/Parameter Store
- CI/CD pipeline stacks
-
Core stacks β
core/- Network/VPC stack
- Database stack
- Cognito stack
- EventBus stack
- Monitoring stack
-
Domain stacks β
domain/- Event management stack
- Company management stack
- Service-specific infrastructure
-
Frontend stack β
frontend/- CloudFront/S3 frontend deployment
-
-
AC3.3
- Update
bin/batbern-infrastructure.tsimport paths - Update stack file imports (cross-stack references)
- Verify CDK synth works:
npx cdk synth
- Update
-
AC3.4
- Document stack organization rationale
- Update deployment guides with new paths
Phase 4: Documentation Alignment
-
AC4.1: Update
- Reflect actual service names (without
-servicesuffix) - Document
e2e-tests/unified structure - Document infrastructure
stacks/organization - Add sections for undocumented directories:
.bmad-core/- Workflow automationsecurity-reports/- Trivy scan resultsconfig/- Checkstyle configurationmockups/- HTML mockups
- Note legacy directories as βarchiveβ (BATspa-old, apps/projectdoc)
- Reflect actual service names (without
-
AC4.2
- Add comments explaining pragmatic choices
- Note deviations from original architecture plan
- Document rationale for βmeet in middleβ decisions
-
AC4.3
- Update developer onboarding docs
- Update README.md if it references old structure
- Update contribution guidelines
Phase 5: Validation & Cleanup
-
AC5.1
./gradlew build- All services compilenpm run build- Frontend buildsnpx cdk synth- Infrastructure validates
-
AC5.2
- Run API tests from new
e2e-tests/api/location - Run frontend e2e tests from new
e2e-tests/workflows/location - Run infrastructure tests from new
e2e-tests/infrastructure/location - Run unit tests:
./gradlew test
- Run API tests from new
-
AC5.3
- Pre-commit hooks execute
- Commit message validation works
-
AC5.4
- Remove any empty directories created during migration
- Verify git status is clean
-
AC5.5
- Document all changes made
- Provide mapping of old β new paths
- Note breaking changes for other developers
Dev Notes
Analysis Summary (2025-11-01)
Comprehensive structure analysis identified:
- 5 services with naming mismatches (all have
-servicesuffix) - 3 test directories to consolidate (bruno-tests, web-frontend/e2e, infrastructure/test/e2e)
- 19 infrastructure stacks in flat directory structure
- 8+ undocumented directories that should be documented
User Preferences
- Keep as-is:
BATspa-old/andapps/projectdoc/(legacy/archive) - Priority: Service naming, test consolidation, infrastructure organization
- Approach: Meet in middle (some code changes, some doc updates)
- Environment: Development only (no production deployments to worry about)
Key Constraints
- Development-only environment (no live deployments)
- No functionality changes (refactoring only)
- Must maintain all existing tests passing
- Git history should be preserved (
git mvcommands)
Risk Mitigation
- Breaking Changes: Use
git mvto preserve history, update all references systematically - Build System: Update Gradle, CDK, package.json incrementally with validation
- Test Breakage: Verify tests after each phase before proceeding
- CI/CD: Update GitHub Actions workflows alongside code changes
Related Stories
- Story 1.1: Shared-Kernel Infrastructure Setup
- Story 1.3: Multi-Environment CDK Infrastructure
- Story 1.7: TDD Developer Workflow Setup
- Story 2.2: Event Management Service Architecture Compliance (naming reference)
Testing
Pre-Migration Tests (Baseline)
-
- API tests (bruno-tests)
- Frontend e2e tests (web-frontend/e2e)
- Infrastructure tests
- Unit tests (all services)
-
- Gradle build
- Frontend build
- CDK synth
Phase Testing Strategy
Each phase must validate:
- After Service Rename: All services build, imports resolve
- After Test Migration: All tests run from new locations
- After Infrastructure Reorganization: CDK synth succeeds
- After Documentation Update: No broken links
Post-Migration Validation
Tasks
Task 0: Preparation & Baseline
- Create feature branch:
Task 1: Service Naming Standardization
-
Rename service directories using
git mv services/event-management-service services/event-managementgit mv services/speaker-coordination-service services/speaker-coordinationgit mv services/partner-coordination-service services/partner-coordinationgit mv services/attendee-experience-service services/attendee-experiencegit mv services/company-user-management-service services/company-management
-
- Consolidate
event/andevents/directories
- Consolidate
-
- Update
settings.gradleproject names - Update any cross-service build dependencies
- Update
-
- Update service names in
docker-compose.yml - Update volume mappings
- Update network configurations
- Update service names in
-
- Search CDK code for old service paths
- Update Lambda function paths
- Update ECS service definitions
-
- Update GitHub Actions service paths
- Update test paths
- Update build paths
-
- Run
./gradlew build - Fix any broken imports
- Verify all services compile
- Run
Task 2: Test Consolidation
-
Create
e2e-tests/bashmkdir -p e2e-tests/{api,workflows,infrastructure,fixtures} -
git mv bruno-tests/* e2e-tests/api/- Update Bruno collection paths
- Test: Run API tests from new location
-
git mv web-frontend/e2e/* e2e-tests/workflows/- Update
playwright.config.tspaths - Test: Run frontend e2e tests from new location
-
git mv infrastructure/test/e2e/* e2e-tests/infrastructure/- Update test import paths
- Test: Run infrastructure tests from new location
-
- Create
e2e-tests/README.md - Document test organization
- Document how to run each test suite
- Create
.env.examplefor test configuration
- Create
-
- Update
package.jsontest scripts - Update
scripts/test/*paths - Update GitHub Actions test workflows
- Update
-
- Remove empty
bruno-tests/ - Remove empty
web-frontend/e2e/ - Remove empty
infrastructure/test/e2e/
- Remove empty
-
- Run API tests
- Run frontend e2e tests
- Run infrastructure tests
- Verify all pass from new locations
Task 3: Infrastructure Reorganization
-
bash
mkdir -p infrastructure/lib/stacks/{global,core,domain,frontend} -
- Review each stack in
infrastructure/lib/stacks/ - Categorize as global/core/domain/frontend
- Document categorization decisions
- Review each stack in
-
- Identify global stacks (DNS, Secrets, CI/CD)
git mvtostacks/global/- Update imports in moved files
-
- Identify core stacks (Network, Database, Cognito, EventBus)
git mvtostacks/core/- Update imports in moved files
-
- Identify domain stacks (service-specific)
git mvtostacks/domain/- Update imports in moved files
-
git mvfrontend stack tostacks/frontend/- Update imports in moved files
-
- Update imports in
bin/batbern-infrastructure.ts - Update stack instantiation paths
- Verify all stacks imported
- Update imports in
-
- Search for stack imports across all files
- Update import paths
- Fix any broken references
-
- Run
npx cdk synth - Fix any import errors
- Verify all stacks synthesize
- Run
Task 4: Documentation Alignment
-
- Update services section (remove
-servicesuffix) - Update test section (document
e2e-tests/) - Update infrastructure section (document stack organization)
- Add undocumented directories section
- Note legacy directories
- Update services section (remove
-
- Document βmeet in middleβ approach
- Explain pragmatic choices
- Note deviations from ideal structure
-
- Update onboarding guides
- Update README.md
- Update contribution guidelines
-
- Check all file paths in docs
- Verify no broken links
- Test documentation examples
Task 5: Final Validation & Migration Guide
-
- Unit tests:
./gradlew test - API tests:
e2e-tests/api/ - Frontend e2e:
e2e-tests/workflows/ - Infrastructure tests:
e2e-tests/infrastructure/ - Record and compare with baseline
- Unit tests:
-
- Gradle:
./gradlew build - Frontend:
npm run build - CDK:
npx cdk synth
- Gradle:
-
- Make test commit
- Verify pre-commit hooks run
- Verify commit message validation
-
- Remove any empty directories
- Verify
git statusclean - Remove temporary files
-
- Document all path changes (old β new)
- List breaking changes
- Provide migration checklist for other developers
- Add troubleshooting section
-
- Review all commits
- Ensure no functionality changes
- Verify tests pass
- Verify builds succeed
Dev Agent Record
Agent Model Used
[Claude model version used during implementation]
Debug Log References
[Links to debug log entries if debugging was needed]
Completion Notes
[Notes added by dev agent upon completion]
File List
[Complete list of all files created, modified, or deleted during this story]
Created:
Modified:
Deleted:
Change Log
[Detailed log of changes made during implementation]
Migration Path Reference
Service Directory Mappings
OLD PATH NEW PATH
services/event-management-service/ β services/event-management/
services/speaker-coordination-service/ β services/speaker-coordination/
services/partner-coordination-service/ β services/partner-coordination/
services/attendee-experience-service/ β services/attendee-experience/
services/company-user-management-service/ β services/company-management/
Test Directory Mappings
OLD PATH NEW PATH
bruno-tests/ β e2e-tests/api/
web-frontend/e2e/ β e2e-tests/workflows/
infrastructure/test/e2e/ β e2e-tests/infrastructure/
Infrastructure Stack Mappings
OLD PATH NEW PATH
infrastructure/lib/stacks/*.ts β infrastructure/lib/stacks/{category}/*.ts
(where category = global|core|domain|frontend)
Estimated Effort
- Task 0 (Preparation): 30 minutes
- Task 1 (Service Naming): 2-3 hours
- Task 2 (Test Consolidation): 1-2 hours
- Task 3 (Infrastructure Reorganization): 2-3 hours
- Task 4 (Documentation): 30 minutes
- Task 5 (Validation): 1 hour
Total: 7-10 hours