Sprint 1 : scaffolding complet de Glibredecision
Plateforme de decisions collectives pour Duniter/G1. Backend FastAPI async + PostgreSQL (14 tables, 8 routers, 6 services, moteur de vote avec formule d'inertie WoT/Smith/TechComm). Frontend Nuxt 4 + Nuxt UI v3 + Pinia (9 pages, 5 stores). Infrastructure Docker + Woodpecker CI + Traefik. Documentation technique et utilisateur (15 fichiers). Seed : Licence G1, Engagement Forgeron v2.0.0, 4 protocoles de vote. 30 tests unitaires (formules, mode params, vote nuance) -- tous verts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
0
backend/app/schemas/__init__.py
Normal file
0
backend/app/schemas/__init__.py
Normal file
53
backend/app/schemas/auth.py
Normal file
53
backend/app/schemas/auth.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Request schemas ──────────────────────────────────────────────
|
||||
|
||||
|
||||
class ChallengeRequest(BaseModel):
|
||||
"""Request a challenge nonce for Ed25519 authentication."""
|
||||
|
||||
address: str = Field(..., min_length=1, max_length=64, description="Duniter V2 SS58 address")
|
||||
|
||||
|
||||
class VerifyRequest(BaseModel):
|
||||
"""Submit the signed challenge to obtain a session token."""
|
||||
|
||||
address: str = Field(..., min_length=1, max_length=64)
|
||||
signature: str = Field(..., description="Ed25519 signature of the challenge (hex)")
|
||||
challenge: str = Field(..., description="The challenge string that was signed")
|
||||
|
||||
|
||||
# ── Response schemas ─────────────────────────────────────────────
|
||||
|
||||
|
||||
class ChallengeResponse(BaseModel):
|
||||
"""Returned after requesting a challenge."""
|
||||
|
||||
challenge: str
|
||||
expires_at: datetime
|
||||
|
||||
|
||||
class IdentityOut(BaseModel):
|
||||
"""Public representation of a Duniter identity."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
address: str
|
||||
display_name: str | None = None
|
||||
wot_status: str
|
||||
is_smith: bool
|
||||
is_techcomm: bool
|
||||
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
"""Returned after successful challenge verification."""
|
||||
|
||||
token: str
|
||||
identity: IdentityOut
|
||||
72
backend/app/schemas/decision.py
Normal file
72
backend/app/schemas/decision.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Decision ─────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class DecisionStepCreate(BaseModel):
|
||||
"""Payload for creating a step within a decision process."""
|
||||
|
||||
step_order: int = Field(..., ge=0)
|
||||
step_type: str = Field(..., max_length=32, description="qualification, review, vote, execution, reporting")
|
||||
title: str | None = Field(default=None, max_length=256)
|
||||
description: str | None = None
|
||||
|
||||
|
||||
class DecisionStepOut(BaseModel):
|
||||
"""Full decision step representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
decision_id: UUID
|
||||
step_order: int
|
||||
step_type: str
|
||||
title: str | None = None
|
||||
description: str | None = None
|
||||
status: str
|
||||
vote_session_id: UUID | None = None
|
||||
outcome: str | None = None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class DecisionCreate(BaseModel):
|
||||
"""Payload for creating a new decision."""
|
||||
|
||||
title: str = Field(..., min_length=1, max_length=256)
|
||||
description: str | None = None
|
||||
context: str | None = None
|
||||
decision_type: str = Field(..., max_length=64, description="runtime_upgrade, document_change, mandate_vote, custom")
|
||||
voting_protocol_id: UUID | None = None
|
||||
|
||||
|
||||
class DecisionUpdate(BaseModel):
|
||||
"""Partial update for a decision."""
|
||||
|
||||
title: str | None = Field(default=None, max_length=256)
|
||||
description: str | None = None
|
||||
status: str | None = Field(default=None, max_length=32)
|
||||
voting_protocol_id: UUID | None = None
|
||||
|
||||
|
||||
class DecisionOut(BaseModel):
|
||||
"""Full decision representation returned by the API."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
title: str
|
||||
description: str | None = None
|
||||
context: str | None = None
|
||||
decision_type: str
|
||||
status: str
|
||||
voting_protocol_id: UUID | None = None
|
||||
created_by_id: UUID | None = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
steps: list[DecisionStepOut] = Field(default_factory=list)
|
||||
103
backend/app/schemas/document.py
Normal file
103
backend/app/schemas/document.py
Normal file
@@ -0,0 +1,103 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Document ─────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class DocumentCreate(BaseModel):
|
||||
"""Payload for creating a new reference document."""
|
||||
|
||||
slug: str = Field(..., min_length=1, max_length=128)
|
||||
title: str = Field(..., min_length=1, max_length=256)
|
||||
doc_type: str = Field(..., max_length=64, description="licence, engagement, reglement, constitution")
|
||||
description: str | None = None
|
||||
version: str | None = Field(default="0.1.0", max_length=32)
|
||||
|
||||
|
||||
class DocumentUpdate(BaseModel):
|
||||
"""Partial update for a document."""
|
||||
|
||||
title: str | None = Field(default=None, max_length=256)
|
||||
status: str | None = Field(default=None, max_length=32)
|
||||
description: str | None = None
|
||||
version: str | None = Field(default=None, max_length=32)
|
||||
|
||||
|
||||
class DocumentOut(BaseModel):
|
||||
"""Full document representation returned by the API."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
slug: str
|
||||
title: str
|
||||
doc_type: str
|
||||
version: str
|
||||
status: str
|
||||
description: str | None = None
|
||||
ipfs_cid: str | None = None
|
||||
chain_anchor: str | None = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
items_count: int = Field(default=0, description="Number of items in this document")
|
||||
|
||||
|
||||
# ── Document Item ────────────────────────────────────────────────
|
||||
|
||||
|
||||
class DocumentItemCreate(BaseModel):
|
||||
"""Payload for creating a document item (clause, rule, etc.)."""
|
||||
|
||||
position: str = Field(..., max_length=16, description='Hierarchical position e.g. "1", "1.1", "3.2"')
|
||||
item_type: str = Field(default="clause", max_length=32, description="clause, rule, verification, preamble, section")
|
||||
title: str | None = Field(default=None, max_length=256)
|
||||
current_text: str = Field(..., min_length=1)
|
||||
voting_protocol_id: UUID | None = None
|
||||
|
||||
|
||||
class DocumentItemOut(BaseModel):
|
||||
"""Full document item representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
document_id: UUID
|
||||
position: str
|
||||
item_type: str
|
||||
title: str | None = None
|
||||
current_text: str
|
||||
voting_protocol_id: UUID | None = None
|
||||
sort_order: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# ── Item Version ─────────────────────────────────────────────────
|
||||
|
||||
|
||||
class ItemVersionCreate(BaseModel):
|
||||
"""Payload for proposing a new version of a document item."""
|
||||
|
||||
proposed_text: str = Field(..., min_length=1)
|
||||
rationale: str | None = None
|
||||
|
||||
|
||||
class ItemVersionOut(BaseModel):
|
||||
"""Full item version representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
item_id: UUID
|
||||
proposed_text: str
|
||||
diff_text: str | None = None
|
||||
rationale: str | None = None
|
||||
status: str
|
||||
decision_id: UUID | None = None
|
||||
proposed_by_id: UUID | None = None
|
||||
created_at: datetime
|
||||
70
backend/app/schemas/mandate.py
Normal file
70
backend/app/schemas/mandate.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Mandate Step ─────────────────────────────────────────────────
|
||||
|
||||
|
||||
class MandateStepCreate(BaseModel):
|
||||
"""Payload for creating a step within a mandate process."""
|
||||
|
||||
step_order: int = Field(..., ge=0)
|
||||
step_type: str = Field(
|
||||
...,
|
||||
max_length=32,
|
||||
description="formulation, candidacy, vote, assignment, reporting, completion, revocation",
|
||||
)
|
||||
title: str | None = Field(default=None, max_length=256)
|
||||
description: str | None = None
|
||||
|
||||
|
||||
class MandateStepOut(BaseModel):
|
||||
"""Full mandate step representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
mandate_id: UUID
|
||||
step_order: int
|
||||
step_type: str
|
||||
title: str | None = None
|
||||
description: str | None = None
|
||||
status: str
|
||||
vote_session_id: UUID | None = None
|
||||
outcome: str | None = None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
# ── Mandate ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class MandateCreate(BaseModel):
|
||||
"""Payload for creating a new mandate."""
|
||||
|
||||
title: str = Field(..., min_length=1, max_length=256)
|
||||
description: str | None = None
|
||||
mandate_type: str = Field(..., max_length=64, description="techcomm, smith, custom")
|
||||
decision_id: UUID | None = None
|
||||
|
||||
|
||||
class MandateOut(BaseModel):
|
||||
"""Full mandate representation returned by the API."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
title: str
|
||||
description: str | None = None
|
||||
mandate_type: str
|
||||
status: str
|
||||
mandatee_id: UUID | None = None
|
||||
decision_id: UUID | None = None
|
||||
starts_at: datetime | None = None
|
||||
ends_at: datetime | None = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
steps: list[MandateStepOut] = Field(default_factory=list)
|
||||
83
backend/app/schemas/protocol.py
Normal file
83
backend/app/schemas/protocol.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Formula Config ───────────────────────────────────────────────
|
||||
|
||||
|
||||
class FormulaConfigCreate(BaseModel):
|
||||
"""Payload for creating a WoT threshold formula configuration."""
|
||||
|
||||
name: str = Field(..., min_length=1, max_length=128)
|
||||
description: str | None = None
|
||||
|
||||
# WoT threshold params
|
||||
duration_days: int = Field(default=30, ge=1, description="Duration of the vote in days")
|
||||
majority_pct: int = Field(default=50, ge=1, le=100, description="Majority percentage required")
|
||||
base_exponent: float = Field(default=0.1, ge=0.0, le=1.0, description="Base exponent B in the formula")
|
||||
gradient_exponent: float = Field(default=0.2, ge=0.0, le=2.0, description="Gradient exponent G in the formula")
|
||||
constant_base: float = Field(default=0.0, ge=0.0, le=1.0, description="Constant base C in the formula")
|
||||
|
||||
# Smith criterion
|
||||
smith_exponent: float | None = Field(default=None, ge=0.0, le=1.0, description="Smith criterion exponent S")
|
||||
|
||||
# TechComm criterion
|
||||
techcomm_exponent: float | None = Field(default=None, ge=0.0, le=1.0, description="TechComm criterion exponent T")
|
||||
|
||||
# Nuanced vote
|
||||
nuanced_min_participants: int | None = Field(default=None, ge=0, description="Minimum participants for nuanced vote")
|
||||
nuanced_threshold_pct: int | None = Field(default=None, ge=0, le=100, description="Threshold percentage for nuanced vote")
|
||||
|
||||
|
||||
class FormulaConfigOut(BaseModel):
|
||||
"""Full formula configuration representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
name: str
|
||||
description: str | None = None
|
||||
duration_days: int
|
||||
majority_pct: int
|
||||
base_exponent: float
|
||||
gradient_exponent: float
|
||||
constant_base: float
|
||||
smith_exponent: float | None = None
|
||||
techcomm_exponent: float | None = None
|
||||
nuanced_min_participants: int | None = None
|
||||
nuanced_threshold_pct: int | None = None
|
||||
created_at: datetime
|
||||
|
||||
|
||||
# ── Voting Protocol ──────────────────────────────────────────────
|
||||
|
||||
|
||||
class VotingProtocolCreate(BaseModel):
|
||||
"""Payload for creating a voting protocol."""
|
||||
|
||||
name: str = Field(..., min_length=1, max_length=128)
|
||||
description: str | None = None
|
||||
vote_type: str = Field(..., max_length=32, description="binary, nuanced")
|
||||
formula_config_id: UUID = Field(..., description="Reference to the formula configuration")
|
||||
mode_params: str | None = Field(default=None, max_length=64, description='e.g. "D30M50B.1G.2T.1"')
|
||||
is_meta_governed: bool = Field(default=False, description="Whether this protocol is itself governed by meta-vote")
|
||||
|
||||
|
||||
class VotingProtocolOut(BaseModel):
|
||||
"""Full voting protocol representation including formula config."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
name: str
|
||||
description: str | None = None
|
||||
vote_type: str
|
||||
formula_config_id: UUID
|
||||
mode_params: str | None = None
|
||||
is_meta_governed: bool
|
||||
created_at: datetime
|
||||
formula_config: FormulaConfigOut
|
||||
35
backend/app/schemas/sanctuary.py
Normal file
35
backend/app/schemas/sanctuary.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Sanctuary Entry ──────────────────────────────────────────────
|
||||
|
||||
|
||||
class SanctuaryEntryCreate(BaseModel):
|
||||
"""Payload for creating a new sanctuary entry (IPFS + chain anchor)."""
|
||||
|
||||
entry_type: str = Field(..., max_length=64, description="document, decision, vote_result")
|
||||
reference_id: UUID = Field(..., description="ID of the referenced entity")
|
||||
title: str | None = Field(default=None, max_length=256)
|
||||
content_hash: str = Field(..., max_length=128, description="SHA-256 hash of the content")
|
||||
|
||||
|
||||
class SanctuaryEntryOut(BaseModel):
|
||||
"""Full sanctuary entry representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
entry_type: str
|
||||
reference_id: UUID
|
||||
title: str | None = None
|
||||
content_hash: str
|
||||
ipfs_cid: str | None = None
|
||||
chain_tx_hash: str | None = None
|
||||
chain_block: int | None = None
|
||||
metadata_json: str | None = None
|
||||
created_at: datetime
|
||||
89
backend/app/schemas/vote.py
Normal file
89
backend/app/schemas/vote.py
Normal file
@@ -0,0 +1,89 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
# ── Vote Session ─────────────────────────────────────────────────
|
||||
|
||||
|
||||
class VoteSessionCreate(BaseModel):
|
||||
"""Payload for opening a new vote session."""
|
||||
|
||||
decision_id: UUID | None = None
|
||||
item_version_id: UUID | None = None
|
||||
voting_protocol_id: UUID = Field(..., description="ID of the voting protocol to apply")
|
||||
|
||||
|
||||
class VoteSessionOut(BaseModel):
|
||||
"""Full vote session representation including tallies."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
decision_id: UUID | None = None
|
||||
item_version_id: UUID | None = None
|
||||
voting_protocol_id: UUID
|
||||
|
||||
# Snapshot at session start
|
||||
wot_size: int
|
||||
smith_size: int
|
||||
techcomm_size: int
|
||||
|
||||
# Dates
|
||||
starts_at: datetime
|
||||
ends_at: datetime
|
||||
|
||||
# Status
|
||||
status: str
|
||||
|
||||
# Tallies
|
||||
votes_for: int
|
||||
votes_against: int
|
||||
votes_total: int
|
||||
smith_votes_for: int
|
||||
techcomm_votes_for: int
|
||||
threshold_required: float
|
||||
result: str | None = None
|
||||
|
||||
# Chain recording
|
||||
chain_recorded: bool
|
||||
chain_tx_hash: str | None = None
|
||||
|
||||
created_at: datetime
|
||||
|
||||
|
||||
# ── Vote ─────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class VoteCreate(BaseModel):
|
||||
"""Payload for casting a vote (with cryptographic proof)."""
|
||||
|
||||
session_id: UUID
|
||||
vote_value: str = Field(..., max_length=32, description="for, against, or nuanced level")
|
||||
nuanced_level: int | None = Field(default=None, ge=0, le=5, description="0-5 for nuanced votes")
|
||||
comment: str | None = None
|
||||
signature: str = Field(..., description="Ed25519 signature of signed_payload")
|
||||
signed_payload: str = Field(..., description="The exact payload that was signed")
|
||||
|
||||
|
||||
class VoteOut(BaseModel):
|
||||
"""Full vote representation."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
session_id: UUID
|
||||
voter_id: UUID
|
||||
vote_value: str
|
||||
nuanced_level: int | None = None
|
||||
comment: str | None = None
|
||||
signature: str
|
||||
signed_payload: str
|
||||
voter_wot_status: str
|
||||
voter_is_smith: bool
|
||||
voter_is_techcomm: bool
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
Reference in New Issue
Block a user