Problem
Provide an API for departments and employees where clients can fetch subtrees, move nodes, and delete departments without corrupting the hierarchy.
A REST API for departments and employees. Its central engineering problem is changing an arbitrary-depth tree without violating structural invariants.
Creating and reading nodes is straightforward until moves, cascading deletion, and cycle prevention are introduced.
Provide an API for departments and employees where clients can fetch subtrees, move nodes, and delete departments without corrupting the hierarchy.
FastAPI and Pydantic own the contract, a service layer checks invariants, SQLAlchemy handles persistence, and Alembic controls schema evolution.
The operation is treated as a structural mutation with invariants rather than a simple parent_id update.
FastAPI validates identifiers, department fields, and operation mode through Pydantic schemas.
The service confirms that the parent exists and that the moved node will not become its own descendant.
The department name is checked within the new parent scope rather than globally across the organisation.
After validation, the ORM persists the new relation and associated changes in PostgreSQL.
The API returns the updated structure only after a successful mutation, otherwise it exposes a clear error.
The project's main value is making valid and invalid hierarchy changes explicit.
Move, delete, and employee rules are not tied to one particular HTTP endpoint.
Before changing the parent, the service ensures the new location is not inside the node's own subtree.
The same name may exist in separate branches, but not among sibling departments.
Database schema changes are versioned and do not rely on manual environment updates.
Tests target observable service behaviour across CRUD, tree mutation, employees, and invalid operations.
Integration scenarios go through the HTTP contract and assert the results of hierarchy operations.
The PostgreSQL schema evolves reproducibly and remains versioned alongside the source code.
The application and database run as one local environment with Swagger UI available after startup.
Current code is separated from capabilities and figures that still need implementation or reproducible evidence.
Authentication appears in the repository roadmap and is not presented here as an implemented capability.
Tree caching and employee pagination remain next steps rather than part of the current critical path.
README figures are not treated as production guarantees until a public methodology and runnable benchmark are included.
An automated pipeline, observability, and a tree frontend logically follow API contract stabilisation.
The project is valuable not for the number of technologies, but for treating ordinary CRUD operations through the integrity of a mutable tree.
The README includes endpoints, Docker setup, project structure, and an explicit list of next steps.