Restructure Directories: Organize Character Bios
Hey guys! Let's talk about how we can make our project a whole lot cleaner and easier to manage. Currently, the way we store information about each character in our biographies is a bit scattered. This means more work for everyone and a higher chance of things going wrong. So, we're going to overhaul the directory structure to keep everything neat and tidy. Think of it as spring cleaning for our digital shelves!
π© The Current Mess: Scattered Information
Right now, the data related to each character is spread across multiple directories, creating a bit of a headache. Imagine you're trying to find everything about Harry S. Truman. You'd have to rummage through different folders to piece together his story. Hereβs a simplified look:
π bios/
βββ harry_s_truman/
β βββ chapter-01.md
β βββ chapter-02.md
β βββ ...
β βββ The biography of Harry S. Truman.md
β βββ sources.md
β
π schemes/
βββ harry_s_truman - sources.md
βββ harry_s_truman - work plan.md
βββ joseph_stalin - sources.md
βββ joseph_stalin - work plan.md
βββ winston_churchill - sources.md
This scattered approach leads to some serious problems:
- β Inconsistency: Information gets duplicated across directories. Ugh!
- β Maintenance Nightmare: Every change requires updating multiple locations. Double ugh!
- β Confusing Navigation: Developers have to hunt around to find what they need. Frustrating!
- β Risk of Desynchronization: Files can easily become outdated. Triple ugh!
π The Proposed Solution: A Unified Approach
To fix this, we're going to consolidate all the information for each character into a single directory under bios/[normalized_name]/. This is the key to getting organized! Let's see what the new structure looks like:
π bios/
βββ harry_s_truman/
β βββ π research/ # β Research information
β β βββ sources.md # β Moved from schemes/
β β βββ work-plan.md # β Moved from schemes/
β β βββ research-notes.md # β New: additional notes
β βββ π chapters/ # β Organized chapters
β β βββ chapter-01.md
β β βββ chapter-02.md
β β βββ ...
β βββ π sections/ # β Special sections
β β βββ prologue.md
β β βββ introduction.md
β β βββ epilogue.md
β β βββ chronology.md
β β βββ glossary.md
β β βββ dramatis-personae.md
β β βββ sources.md
β βββ π output/ # β Generated files
β β βββ The biography of Harry S. Truman.md
β β βββ metadata.json
β βββ π control/ # β Control files (existing)
β βββ π kdp/ # β Amazon KDP assets (existing)
This new setup will bring order to the chaos, making everything easier to find, update, and maintain.
π Detailed Structure: Breaking It Down
Let's dive into the specifics of each directory and file:
Main Directory: bios/[normalized_name]/
1. research/ - Research Information
This is where all the research-related stuff goes. Think of it as the foundation of the biography. It includes:
research/
βββ sources.md # Collected and validated sources
βββ work-plan.md # Structured work plan
βββ research-notes.md # Additional notes from the process
βββ validation-sources.json # Automatic validation results
2. chapters/ - Book Chapters
All the chapters of the book will be organized here:
chapters/
βββ chapter-01.md
βββ chapter-02.md
βββ ...
βββ chapter-20.md
3. sections/ - Special Sections
Special sections such as the prologue, introduction, and epilogue will be stored here:
sections/
βββ prologue.md
βββ introduction.md
βββ epilogue.md
βββ chronology.md
βββ glossary.md
βββ dramatis-personae.md
βββ sources.md
4. output/ - Final Generated Files
This directory will contain the final output, ready for publishing:
output/
βββ The biography of [Character].md # Complete biography
βββ metadata.json # Work metadata
βββ generation-log.txt # Generation process log
5. control/ and kdp/ - Existing Directories
These directories will stay as they are, maintaining their existing functions:
control/ # Quality control and validation
kdp/ # Assets for Amazon KDP
π οΈ Migration Plan: Step-by-Step Guide
We're going to follow a phased approach to ensure a smooth transition:
Phase 1: Preparation
- β Migration Script: Create a Python script to automate the file movement. We'll get to that in a bit.
- β Backup: Make a complete backup before we start. Always a good idea!
- β Validation: Verify the integrity of the existing files. Make sure everything's in good shape.
Phase 2: Restructuring
- β Create New Structure: Generate directories based on the new schema.
- β Move Files: Move files from the
schemes/directory to their new locations within thebios/structure. For example:schemes/[character] - sources.mdβbios/[character]/research/sources.mdschemes/[character] - work plan.mdβbios/[character]/research/work-plan.md
- β Reorganize Chapters: Move chapters to the
chapters/subdirectory. - β Reorganize Sections: Move special sections to the
sections/subdirectory.
Phase 3: Code Update
- β Application Paths: Update all references to file paths in the application.
- β Generation Scripts: Adapt the scripts used for generating biographies to the new structure.
- β Tests: Update any tests that rely on specific file paths.
- β Documentation: Update the documentation to reflect the new organization.
Phase 4: Validation
- β Integrity Tests: Verify that all files have been moved correctly.
- β Functionality: Confirm that the generation process works as expected with the new structure.
- β Cleanup: Remove the now-empty
schemes/directory. (Yay!)
π» Affected Files and Components
Here are the files and components that will be affected by this change. This is just a heads-up so you know where to focus your attention.
Scripts to Create/Modify
# scripts/migrate_structure.py
def migrate_character_files(character_name):
"""Migrate files of a character to the new structure"""
# scripts/validate_migration.py
def validate_file_integrity():
"""Validate that the migration was successful"""
Application Code
src/services/biography_generator.py: File paths.src/services/file_manager.py: Directory management.src/services/concatenation.py: File references.src/worker/tasks.py: Celery tasks with file paths.
Configuration
config/settings.py: Path constants.docker-compose.yml: Mounted volumes.- Tests: All tests that use specific file paths.
β Advantages of the New Structure: Why This Matters
This new organization isn't just about making things look pretty; it's about making our lives easier and our project more robust. Here's why:
π― Logical Organization
- All information for a character in one place. Perfect!
- Clear separation between research, content, and results.
- Scalable structure for future characters. Ready for anything!
π§ Simplified Maintenance
- One directory per character for backups/restores. Sweet and simple.
- Easy identification of missing or corrupted files.
- Permission management per character.
π Improved Development
- Intuitive navigation in the IDE. Makes coding a breeze.
- More efficient searches. Find what you need, fast!
- Fewer errors due to incorrect paths. Goodbye, headaches!
π Enhanced Operations
- Monitoring per character. Stay in the know.
- Storage metrics per biography. Keep an eye on things.
- Automated cleanup processes. Automatic win!
β‘ Proposed Migration Script: Let's Get Practical
Here's a basic Python script to get us started. We'll need to adapt this to our specific needs, but this gives you an idea of how the migration will work. Remember, back up your files first!
import os
import shutil
from pathlib import Path
def migrate_character_structure():
"""Migrate existing structure to new organization"""
# Existing characters
characters = ['harry_s_truman', 'joseph_stalin', 'winston_churchill']
for character in characters:
print(f"Migrating {character}...")
# Create new structure
base_path = Path(f"bios/{character}")
(base_path / "research").mkdir(exist_ok=True)
(base_path / "chapters").mkdir(exist_ok=True)
(base_path / "sections").mkdir(exist_ok=True)
(base_path / "output").mkdir(exist_ok=True)
# Move files from schemes/
source_files = Path("schemes").glob(f"{character} - *.md")
for file in source_files:
if "sources" in file.name:
shutil.move(file, base_path / "research" / "sources.md")
elif "work plan" in file.name:
shutil.move(file, base_path / "research" / "work-plan.md")
# Reorganize existing files in bios/
# ... (reorganization logic)
β Acceptance Criteria: Ensuring Success
How will we know we've successfully completed this migration?
- β Complete Migration: All files moved without any data loss.
- β Functionality Preserved: The biography generation still works correctly.
- β Updated Tests: All tests pass with the new structure.
- β Updated Documentation: Guides reflect the new organization.
- β Clean Code: References to the old structure are removed.
- β Performance Maintained: No slowdown in processing times.
π·οΈ Labels: Project Tags
refactorfile-structuremaintenanceorganization
π Priority: High
This is a high-priority task because it significantly improves the project's organization and maintainability. It's like setting up a well-organized workspace β it makes everything run more smoothly.
β οΈ Risk Considerations: Heads Up!
- Mandatory Backup: Always back up your files before starting the migration.
- Thorough Validation: Validate file integrity after the move.
- Rollback Plan: Have a plan to revert to the old structure if something goes wrong.
- Collaboration: Coordinate with developers actively working on the project.
π References: Where to Find More
- Current structure in
/biosand/schemes - Biography generation documentation
- Existing file handling scripts
This refactoring will not only make our project easier to manage but also set us up for future growth. Great work, team! Let's get organized!
For more detailed information about file organization, you can visit Wikipedia.