chore(v2): restructure monorepo to src/ layout with uv
Aligns the repo with the python-project-spec-design.md template chosen for V2.0.0. Big move, no logic changes. The 3 pre-existing test failures (test_recipes::test_update_recipe, test_recipes:: test_recipe_versioning, test_tasks::test_reorder_tasks, plus the client test_save_measurement_proxy) survive unchanged. Layout changes - server/ -> src/backend/ - server/middleware/ -> src/backend/api/middleware/ - server/routers/ -> src/backend/api/routers/ - server/models/ -> src/backend/models/orm/ - server/schemas/ -> src/backend/models/api/ - server/uploads/ -> uploads/ (project root, mounted volume) - server/tests/ -> src/backend/tests/ - client/ -> src/frontend/flask_app/ (Flask kept; React deroga is documented in CLAUDE.md, justified by tablet UX, USB caliper/barcode workflow and Fabric.js integration) Tooling - pyproject.toml: monorepo with [project] core deps and optional-dependencies server / client / dev. Replaces both server/requirements.txt and client/requirements.txt. - uv.lock + .python-version (3.11) committed for reproducible builds. - Dockerfile (root, backend) and Dockerfile.frontend rewritten to use uv sync --frozen --no-dev --extra server|client; legacy Dockerfiles preserved as Dockerfile.legacy for reference but excluded from build context via .dockerignore. - docker-compose.dev.yml + docker-compose.yml: build context now ".", dockerfile pointing to the root files. Code adjustments forced by the move - Every "from config|database|models|schemas|services|routers|middleware import ..." rewritten to its src.backend.* equivalent (50+ files including indented inline imports inside test bodies). - src/backend/migrations/env.py: insert project root into sys.path so alembic can resolve src.backend.* imports regardless of cwd. - src/backend/config.py: env_file ../../.env (was ../.env), upload_path resolves project root via parents[2]. - src/backend/tests/conftest.py + tests: import ... from src.backend.* instead of bare names; old per-directory pytest.ini files removed in favor of root pyproject.toml [tool.pytest.ini_options]. - .gitignore: uploads/ at root, src/frontend/flask_app/static/css/ tailwind.css path; .dockerignore tightened. - CLAUDE.md: rewrote sections "Layout del repository", "Comandi di Sviluppo", "Database & Migrations", "Test", "i18n", and all path references throughout the architecture sections. Verified - uv lock resolves 77 packages; uv sync --extra server --extra client --extra dev installs cleanly. - uv run pytest: 171 passed, 4 pre-existing failures. - uv run alembic -c src/backend/migrations/alembic.ini check loads config and metadata (errors only on the absent local MySQL). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
"""Pydantic schemas for TieMeasureFlow API."""
|
||||
from src.backend.models.api.measurement import (
|
||||
MeasurementBatchCreate,
|
||||
MeasurementCreate,
|
||||
MeasurementListResponse,
|
||||
MeasurementQuery,
|
||||
MeasurementResponse,
|
||||
)
|
||||
from src.backend.models.api.recipe import (
|
||||
RecipeCreate,
|
||||
RecipeListResponse,
|
||||
RecipeResponse,
|
||||
RecipeUpdate,
|
||||
RecipeVersionResponse,
|
||||
)
|
||||
from src.backend.models.api.statistics import (
|
||||
AlertData,
|
||||
CapabilityData,
|
||||
ControlChartData,
|
||||
HistogramData,
|
||||
StatisticsQuery,
|
||||
StatisticsResponse,
|
||||
SummaryData,
|
||||
TrendData,
|
||||
)
|
||||
from src.backend.models.api.task import (
|
||||
SubtaskCreate,
|
||||
SubtaskResponse,
|
||||
SubtaskUpdate,
|
||||
TaskCreate,
|
||||
TaskReorderRequest,
|
||||
TaskResponse,
|
||||
TaskUpdate,
|
||||
)
|
||||
from src.backend.models.api.user import (
|
||||
LoginRequest,
|
||||
LoginResponse,
|
||||
UserCreate,
|
||||
UserProfileUpdate,
|
||||
UserResponse,
|
||||
UserUpdate,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# User schemas
|
||||
"UserCreate",
|
||||
"UserUpdate",
|
||||
"UserProfileUpdate",
|
||||
"UserResponse",
|
||||
"LoginRequest",
|
||||
"LoginResponse",
|
||||
# Recipe schemas
|
||||
"RecipeCreate",
|
||||
"RecipeUpdate",
|
||||
"RecipeResponse",
|
||||
"RecipeVersionResponse",
|
||||
"RecipeListResponse",
|
||||
# Task schemas
|
||||
"TaskCreate",
|
||||
"TaskUpdate",
|
||||
"TaskResponse",
|
||||
"TaskReorderRequest",
|
||||
"SubtaskCreate",
|
||||
"SubtaskUpdate",
|
||||
"SubtaskResponse",
|
||||
# Measurement schemas
|
||||
"MeasurementCreate",
|
||||
"MeasurementBatchCreate",
|
||||
"MeasurementResponse",
|
||||
"MeasurementListResponse",
|
||||
"MeasurementQuery",
|
||||
# Statistics schemas
|
||||
"StatisticsQuery",
|
||||
"ControlChartData",
|
||||
"HistogramData",
|
||||
"CapabilityData",
|
||||
"TrendData",
|
||||
"SummaryData",
|
||||
"AlertData",
|
||||
"StatisticsResponse",
|
||||
]
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Pydantic schemas for Measurement operations."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class MeasurementCreate(BaseModel):
|
||||
"""Schema for creating a single measurement."""
|
||||
subtask_id: int
|
||||
version_id: int
|
||||
value: float
|
||||
lot_number: Optional[str] = Field(None, max_length=100)
|
||||
serial_number: Optional[str] = Field(None, max_length=100)
|
||||
input_method: str = Field("manual", pattern="^(usb_caliper|manual)$")
|
||||
|
||||
|
||||
class MeasurementBatchCreate(BaseModel):
|
||||
"""Schema for creating multiple measurements at once."""
|
||||
measurements: list[MeasurementCreate]
|
||||
|
||||
|
||||
class MeasurementResponse(BaseModel):
|
||||
"""Schema for measurement response."""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
subtask_id: int
|
||||
version_id: int
|
||||
measured_by: int
|
||||
value: float
|
||||
pass_fail: str
|
||||
deviation: Optional[float] = None
|
||||
lot_number: Optional[str] = None
|
||||
serial_number: Optional[str] = None
|
||||
input_method: str
|
||||
measured_at: datetime
|
||||
synced_to_csv: bool
|
||||
|
||||
|
||||
class MeasurementListResponse(BaseModel):
|
||||
"""Schema for paginated measurement list."""
|
||||
items: list[MeasurementResponse]
|
||||
total: int
|
||||
page: int
|
||||
per_page: int
|
||||
pages: int
|
||||
|
||||
|
||||
class MeasurementQuery(BaseModel):
|
||||
"""Schema for measurement query filters."""
|
||||
recipe_id: Optional[int] = None
|
||||
version_id: Optional[int] = None
|
||||
subtask_id: Optional[int] = None
|
||||
measured_by: Optional[int] = None
|
||||
lot_number: Optional[str] = None
|
||||
serial_number: Optional[str] = None
|
||||
date_from: Optional[datetime] = None
|
||||
date_to: Optional[datetime] = None
|
||||
pass_fail: Optional[str] = Field(None, pattern="^(pass|warning|fail)$")
|
||||
page: int = Field(1, ge=1)
|
||||
per_page: int = Field(50, ge=1, le=500)
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Pydantic schemas for Recipe and RecipeVersion operations."""
|
||||
from datetime import datetime
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from src.backend.models.api.task import TaskResponse
|
||||
|
||||
|
||||
class RecipeCreate(BaseModel):
|
||||
"""Schema for creating a new recipe."""
|
||||
code: str = Field(..., min_length=1, max_length=100)
|
||||
name: str = Field(..., min_length=1, max_length=255)
|
||||
description: Optional[str] = None
|
||||
image_path: Optional[str] = Field(None, max_length=500)
|
||||
# Optional task-level fields for the initial technical drawing
|
||||
file_path: Optional[str] = Field(None, max_length=500)
|
||||
file_type: Optional[str] = Field(None, pattern="^(image|pdf)$")
|
||||
annotations_json: Optional[dict] = None
|
||||
|
||||
|
||||
class RecipeUpdate(BaseModel):
|
||||
"""Schema for updating a recipe (creates new version)."""
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
description: Optional[str] = None
|
||||
image_path: Optional[str] = Field(None, max_length=500)
|
||||
change_notes: Optional[str] = None
|
||||
# Task-level fields: saved to the first task of the new version
|
||||
file_path: Optional[str] = Field(None, max_length=500)
|
||||
file_type: Optional[str] = Field(None, pattern="^(image|pdf)$")
|
||||
annotations_json: Optional[dict] = None
|
||||
|
||||
|
||||
class RecipeVersionResponse(BaseModel):
|
||||
"""Schema for recipe version response."""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
recipe_id: int
|
||||
version_number: int
|
||||
is_current: bool
|
||||
created_by: int
|
||||
created_at: datetime
|
||||
change_notes: Optional[str] = None
|
||||
tasks: list["TaskResponse"] = []
|
||||
|
||||
|
||||
class RecipeResponse(BaseModel):
|
||||
"""Schema for recipe response."""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
code: str
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
image_path: Optional[str] = None
|
||||
created_by: int
|
||||
created_at: datetime
|
||||
active: bool
|
||||
current_version: Optional[RecipeVersionResponse] = None
|
||||
|
||||
|
||||
class RecipeListResponse(BaseModel):
|
||||
"""Schema for paginated recipe list."""
|
||||
items: list[RecipeResponse]
|
||||
total: int
|
||||
page: int
|
||||
per_page: int
|
||||
pages: int
|
||||
|
||||
|
||||
# Forward reference imports for model_rebuild
|
||||
from src.backend.models.api.task import TaskResponse # noqa: E402
|
||||
RecipeVersionResponse.model_rebuild()
|
||||
RecipeResponse.model_rebuild()
|
||||
@@ -0,0 +1,57 @@
|
||||
"""Pydantic schemas for Station and StationRecipeAssignment."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class StationCreate(BaseModel):
|
||||
code: str = Field(..., min_length=1, max_length=100)
|
||||
name: str = Field(..., min_length=1, max_length=255)
|
||||
location: Optional[str] = Field(default=None, max_length=255)
|
||||
notes: Optional[str] = None
|
||||
active: bool = True
|
||||
|
||||
|
||||
class StationUpdate(BaseModel):
|
||||
name: Optional[str] = Field(default=None, min_length=1, max_length=255)
|
||||
location: Optional[str] = Field(default=None, max_length=255)
|
||||
notes: Optional[str] = None
|
||||
active: Optional[bool] = None
|
||||
|
||||
|
||||
class StationResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
code: str
|
||||
name: str
|
||||
location: Optional[str]
|
||||
notes: Optional[str]
|
||||
active: bool
|
||||
created_by: int
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class StationRecipeAssignmentCreate(BaseModel):
|
||||
recipe_id: int = Field(..., gt=0)
|
||||
|
||||
|
||||
class StationRecipeAssignmentResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
station_id: int
|
||||
recipe_id: int
|
||||
assigned_by: int
|
||||
assigned_at: datetime
|
||||
|
||||
|
||||
class RecipeSummary(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
code: str
|
||||
name: str
|
||||
active: bool
|
||||
|
||||
|
||||
class StationWithRecipesResponse(StationResponse):
|
||||
recipes: list[RecipeSummary] = Field(default_factory=list)
|
||||
@@ -0,0 +1,94 @@
|
||||
"""Pydantic schemas for SPC statistics responses."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class StatisticsQuery(BaseModel):
|
||||
"""Common query parameters for statistics endpoints."""
|
||||
recipe_id: int
|
||||
version_id: Optional[int] = None
|
||||
subtask_id: Optional[int] = None
|
||||
date_from: Optional[datetime] = None
|
||||
date_to: Optional[datetime] = None
|
||||
operator_id: Optional[int] = None
|
||||
lot_number: Optional[str] = None
|
||||
serial_number: Optional[str] = None
|
||||
|
||||
|
||||
class ControlChartData(BaseModel):
|
||||
"""Data for X-bar/R control chart."""
|
||||
values: list[float]
|
||||
timestamps: list[datetime]
|
||||
mean: float
|
||||
ucl: float # Upper Control Limit
|
||||
lcl: float # Lower Control Limit
|
||||
utl: Optional[float] = None
|
||||
uwl: Optional[float] = None
|
||||
lwl: Optional[float] = None
|
||||
ltl: Optional[float] = None
|
||||
nominal: Optional[float] = None
|
||||
out_of_control: list[int] = [] # Indices of OOC points
|
||||
|
||||
|
||||
class HistogramData(BaseModel):
|
||||
"""Data for histogram with normal curve."""
|
||||
bins: list[float]
|
||||
counts: list[int]
|
||||
normal_x: list[float]
|
||||
normal_y: list[float]
|
||||
mean: float
|
||||
std_dev: float
|
||||
n: int
|
||||
|
||||
|
||||
class CapabilityData(BaseModel):
|
||||
"""Capability indices."""
|
||||
cp: Optional[float] = None
|
||||
cpk: Optional[float] = None
|
||||
pp: Optional[float] = None
|
||||
ppk: Optional[float] = None
|
||||
mean: float
|
||||
std_dev: float
|
||||
n: int
|
||||
utl: Optional[float] = None
|
||||
ltl: Optional[float] = None
|
||||
nominal: Optional[float] = None
|
||||
|
||||
|
||||
class TrendData(BaseModel):
|
||||
"""Temporal trend data for capability indices."""
|
||||
dates: list[datetime]
|
||||
cpk_values: list[Optional[float]]
|
||||
ppk_values: list[Optional[float]]
|
||||
n_per_period: list[int]
|
||||
|
||||
|
||||
class SummaryData(BaseModel):
|
||||
"""Pass/fail/warning summary counts."""
|
||||
total: int
|
||||
pass_count: int
|
||||
warning_count: int
|
||||
fail_count: int
|
||||
pass_rate: float
|
||||
warning_rate: float
|
||||
fail_rate: float
|
||||
|
||||
|
||||
class AlertData(BaseModel):
|
||||
"""Western Electric rules violations."""
|
||||
rule: str
|
||||
description: str
|
||||
points: list[int] # Indices of violating points
|
||||
severity: str = Field(..., pattern="^(info|warning|critical)$")
|
||||
|
||||
|
||||
class StatisticsResponse(BaseModel):
|
||||
"""Combined statistics response."""
|
||||
summary: SummaryData
|
||||
capability: Optional[CapabilityData] = None
|
||||
control_chart: Optional[ControlChartData] = None
|
||||
histogram: Optional[HistogramData] = None
|
||||
trend: Optional[TrendData] = None
|
||||
alerts: list[AlertData] = []
|
||||
@@ -0,0 +1,93 @@
|
||||
"""Pydantic schemas for RecipeTask and RecipeSubtask operations."""
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class SubtaskCreate(BaseModel):
|
||||
"""Schema for creating a subtask."""
|
||||
marker_number: int = Field(..., ge=1)
|
||||
description: str = Field(..., min_length=1, max_length=500)
|
||||
measurement_type: Optional[str] = Field(None, max_length=100)
|
||||
nominal: Optional[float] = None
|
||||
utl: Optional[float] = None
|
||||
uwl: Optional[float] = None
|
||||
lwl: Optional[float] = None
|
||||
ltl: Optional[float] = None
|
||||
unit: str = Field("mm", max_length=20)
|
||||
image_path: Optional[str] = Field(None, max_length=500)
|
||||
|
||||
|
||||
class SubtaskUpdate(BaseModel):
|
||||
"""Schema for updating a subtask."""
|
||||
marker_number: Optional[int] = Field(None, ge=1)
|
||||
description: Optional[str] = Field(None, min_length=1, max_length=500)
|
||||
measurement_type: Optional[str] = Field(None, max_length=100)
|
||||
nominal: Optional[float] = None
|
||||
utl: Optional[float] = None
|
||||
uwl: Optional[float] = None
|
||||
lwl: Optional[float] = None
|
||||
ltl: Optional[float] = None
|
||||
unit: Optional[str] = Field(None, max_length=20)
|
||||
image_path: Optional[str] = Field(None, max_length=500)
|
||||
|
||||
|
||||
class SubtaskResponse(BaseModel):
|
||||
"""Schema for subtask response."""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
task_id: int
|
||||
marker_number: int
|
||||
description: str
|
||||
measurement_type: Optional[str] = None
|
||||
nominal: Optional[float] = None
|
||||
utl: Optional[float] = None
|
||||
uwl: Optional[float] = None
|
||||
lwl: Optional[float] = None
|
||||
ltl: Optional[float] = None
|
||||
unit: str
|
||||
image_path: Optional[str] = None
|
||||
|
||||
|
||||
class TaskCreate(BaseModel):
|
||||
"""Schema for creating a task."""
|
||||
title: str = Field(..., min_length=1, max_length=255)
|
||||
directive: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
file_path: Optional[str] = Field(None, max_length=500)
|
||||
file_type: Optional[str] = Field(None, pattern="^(image|pdf)$")
|
||||
annotations_json: Optional[dict[str, Any]] = None
|
||||
subtasks: list[SubtaskCreate] = []
|
||||
|
||||
|
||||
class TaskUpdate(BaseModel):
|
||||
"""Schema for updating a task."""
|
||||
title: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
directive: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
file_path: Optional[str] = Field(None, max_length=500)
|
||||
file_type: Optional[str] = Field(None, pattern="^(image|pdf)$")
|
||||
annotations_json: Optional[dict[str, Any]] = None
|
||||
|
||||
|
||||
class TaskResponse(BaseModel):
|
||||
"""Schema for task response."""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
version_id: int
|
||||
recipe_id: Optional[int] = None
|
||||
order_index: int
|
||||
title: str
|
||||
directive: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
file_path: Optional[str] = None
|
||||
file_type: Optional[str] = None
|
||||
annotations_json: Optional[dict[str, Any]] = None
|
||||
subtasks: list[SubtaskResponse] = []
|
||||
|
||||
|
||||
class TaskReorderRequest(BaseModel):
|
||||
"""Schema for reordering tasks."""
|
||||
task_ids: list[int] = Field(..., min_length=1)
|
||||
@@ -0,0 +1,70 @@
|
||||
"""Pydantic schemas for User operations."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class UserCreate(BaseModel):
|
||||
"""Schema for creating a new user."""
|
||||
username: str = Field(..., min_length=3, max_length=100)
|
||||
password: str = Field(..., min_length=6, max_length=128)
|
||||
email: Optional[str] = Field(None, max_length=255)
|
||||
display_name: str = Field(..., min_length=1, max_length=255)
|
||||
roles: list[str] = Field(default_factory=list)
|
||||
is_admin: bool = False
|
||||
language_pref: str = Field("it", pattern="^(it|en)$")
|
||||
theme_pref: str = Field("light", pattern="^(light|dark)$")
|
||||
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
"""Schema for updating a user (admin)."""
|
||||
email: Optional[str] = Field(None, max_length=255)
|
||||
display_name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
roles: Optional[list[str]] = None
|
||||
is_admin: Optional[bool] = None
|
||||
active: Optional[bool] = None
|
||||
language_pref: Optional[str] = Field(None, pattern="^(it|en)$")
|
||||
theme_pref: Optional[str] = Field(None, pattern="^(light|dark)$")
|
||||
|
||||
|
||||
class UserProfileUpdate(BaseModel):
|
||||
"""Schema for user self-update (profile)."""
|
||||
display_name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
language_pref: Optional[str] = Field(None, pattern="^(it|en)$")
|
||||
theme_pref: Optional[str] = Field(None, pattern="^(light|dark)$")
|
||||
|
||||
|
||||
class UserResponse(BaseModel):
|
||||
"""Schema for user response."""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
username: str
|
||||
email: Optional[str] = None
|
||||
display_name: str
|
||||
roles: list[str]
|
||||
is_admin: bool
|
||||
language_pref: str
|
||||
theme_pref: str
|
||||
active: bool
|
||||
created_at: datetime
|
||||
last_login: Optional[datetime] = None
|
||||
|
||||
|
||||
class UserPasswordChange(BaseModel):
|
||||
"""Schema for changing user password (admin only)."""
|
||||
password: str = Field(..., min_length=6, max_length=128)
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
"""Schema for login request."""
|
||||
username: str
|
||||
password: str
|
||||
|
||||
|
||||
class LoginResponse(BaseModel):
|
||||
"""Schema for login response."""
|
||||
user: UserResponse
|
||||
api_key: str
|
||||
message: str = "Login successful"
|
||||
Reference in New Issue
Block a user