6.4 KiB
6.4 KiB
Aether API Rewrite Plan (v2) - Revised
1. Core Principles of the Rewrite
id_randomFirst: Theid_randomwill be the primary public identifier for all Aether objects. The internal, auto-incrementingidwill be treated as a private implementation detail and never exposed to the API consumer.- Standardized Core Object: All Aether objects will share a common set of base properties. This will be enforced through a base Pydantic model that all other object models will inherit from.
- Explicit and Organized Routers: Each Aether object type will have its own dedicated router file, promoting a clean and maintainable codebase.
- Clear Separation of Concerns: The API will be structured with a clear separation between the API/routing layer, the business logic/CRUD layer, and the data access layer.
- Modern, Explicit Configuration: Configuration will be managed through a modern, explicit system (e.g., Pydantic's
BaseSettings), moving away from the complex and inconsistentobj_type_kv_lidictionary.
2. Updated Rewrite Plan - Revised for Incremental Progress
Learnings from Previous Session (December 2, 2025):
- Debugging in a Dockerized environment (where
uvicornis symlinked within Docker) is challenging for local troubleshooting. We need to focus on methods that validate code before full application integration. - The
422 Unprocessable Entityerrors encountered were from legacy/crud/site/domainendpoints, highlighting that issues can arise from existing code interactions even when introducing new, theoretically sound patterns. - Small, atomic changes with immediate, verifiable feedback are critical.
Phase 1: Foundation and Standardization (Revised Approach)
The goal of this phase is to establish the core architecture without introducing runtime errors, focusing on isolated testing.
-
Isolated Model Validation (
app/models/core_object.py,app/models/journal.py,app/models/journal_entry.py,app/models/site_domain.py):- Action: Re-create the
app/models/core_object.pyfile first, ensuring all imports are correct andPydantic.BaseModelis explicitly imported where needed. - Action: Re-create
app/models/journal.py,app/models/journal_entry.py, andapp/models/site_domain.py, ensuring they correctly inherit fromCoreObjectand have all necessary imports. - Verification: Create and run an isolated Python script (e.g.,
model_test.py) that imports only these new Pydantic models (and their dependencies likedatetime,typing,pydantic) and attempts to instantiate them with sample data. This script must not importapp.logorapp.configto avoid environment-specific issues and allow local execution. This step will validate model definitions in isolation. - Success Criteria: The
model_test.pyscript runs without anyImportErroror Pydantic validation errors.
- Action: Re-create the
-
Isolated AE Object Registry Validation (
app/ae_object_registry.py):- Action: Re-create
app/ae_object_registry.py, ensuring it correctly definesAEObjectConfigwith thechildrenfield and uses singular prefixes. Thejournal_entry_configwill be defined as a child ofjournal_config, andsite_domain_configwill be a top-level entry. - Verification: Extend the
model_test.pyscript (or create a new one) to importapp.ae_object_registryand access theAE_OBJECT_REGISTRYdictionary, verifying its structure and the object configurations. - Success Criteria: The script runs without errors, and the registry structure is as expected.
- Action: Re-create
-
Dummy CRUD Layer (
app/crud/base.py):- Action: Re-create
app/crud/base.py. Implement placeholder CRUD functions (create_object,get_object,list_objects,update_object,delete_object) that acceptAEObjectConfig,data,id_random,parent_id_random, andparent_table_name. These functions will not interact with the database; they will only print their arguments and return dummy data that conforms to the expected Pydantic models (e.g.,config.modelorlist[config.model]). - Verification: Write a dedicated script (
crud_test.py) that importsapp.crud.baseandapp.ae_object_registry, then calls these dummy CRUD functions with sample data, including nested object scenarios. - Success Criteria: The
crud_test.pyscript runs without errors, and the print statements confirm correct argument passing.
- Action: Re-create
-
Router Factory Verification (
app/routers/factory.py):- Action: Re-create
app/routers/factory.pywith the correctedcreate_crud_routerfunction that handles both top-level and nested router generation, ensuringparent_configis passed correctly to child calls andparent_table_nameis passed to CRUD functions. - Verification: This step is harder to verify in isolation without FastAPI's full context. The primary verification will come in the next step when integrating with
main.py.
- Action: Re-create
-
Integration with
main.py:- Action: Modify
app/main.pyto include the router factory. Uncomment the loop that iterates throughAE_OBJECT_REGISTRYand includes the routers generated bycreate_crud_router. - Verification:
- Confirm the FastAPI application loads successfully within the Docker container (by observing logs).
- Use
curlor a simple Pythonrequestsscript to manually test the new/journaland/journal_entryendpoints (e.g.,POST /journal,GET /journal/{id_random},POST /journal/{id_random}/journal_entry).
- Success Criteria: The application starts without errors, and the new endpoints respond correctly (returning dummy data from
crud/base.py).
- Action: Modify
Phase 2: Implement Real Database Logic for Journals
- Database Connection: Integrate the database connection logic into
app/crud/base.py(or a more specificapp/crud/journals.py). - SQL Operations: Replace dummy CRUD logic with actual
sql_insert,sql_select,sql_update, andsql_deletecalls, ensuringid_randomtoidlookups are correctly handled using Redis. - Verification: Thoroughly test the new endpoints using integration tests or manual
curlrequests against the Dockerized environment, confirming data persistence and retrieval.
Phase 3: Gradual Migration of Other Aether Objects
(As originally outlined in REWRITE_PLAN_V2.md)
This revised plan prioritizes stability and verifiable progress, ensuring each component works in isolation before integration.