refactor: conform standards docs to doc-forge wiki/lib layout; generic build.py; static kind links

This commit is contained in:
2026-10-11 23:04:56 +05:30
parent 1208945e1d
commit 74aaf2f53e
181 changed files with 8649 additions and 1873 deletions

View File

@@ -0,0 +1,19 @@
"""# Summary
Item domain model — the neutral resource used throughout the template.
"""
from pydantic import BaseModel, Field
class Item(BaseModel):
"""A single countable resource.
Attributes:
name (str): Item name.
quantity (int): Item quantity. Defaults to 1.
"""
name: str
quantity: int = Field(default=1)
model_config = {"extra": "ignore"}

View File

@@ -0,0 +1,20 @@
"""# Summary
Mongo persistence for items: document schema and repository factory.
"""
from domain.item.models import Item
from infra.db.repos.mongo import _repo_factory as mongo_repo_factory
from mongo_ops import BaseDocument, BaseRepository
class ItemDocument(Item, BaseDocument):
"""Mongo document form of :class:`Item`."""
def create_item_repo() -> BaseRepository:
"""Create the Mongo-backed item repository.
Returns:
BaseRepository: Repository wired to the ``items`` collection.
"""
return mongo_repo_factory("items", ItemDocument)

View File

@@ -0,0 +1,33 @@
"""# Summary
CRUD service wiring for the item aggregate via the hexa container.
"""
from hexa import build
from domain.item.models import Item
from domain.item.ports.db import ItemDocument
from infra.adapters.service import CrudsServiceAdaptor
class ItemCrudsService(CrudsServiceAdaptor[Item, ItemDocument]):
"""Item CRUD service resolving :class:`ItemDocument` from a repo.
Notes:
Instances are created by :func:`get_item_service`. The ``model`` and
``schema`` class attributes bind the domain model and its document type.
"""
model = Item
schema = ItemDocument
def get_item_service(repo) -> ItemCrudsService:
"""Build an item CRUD service wired to ``repo``.
Args:
repo (Any): Mongo-backed item repository from :func:`create_item_repo`.
Returns:
ItemCrudsService: Ready-to-use item CRUD service.
"""
return build(ItemCrudsService, instances={"repo": repo})

View File

@@ -0,0 +1,26 @@
"""# Summary
Job domain model — a pipeline work item consumed by the background worker.
"""
from typing import Literal
from pydantic import BaseModel, Field
class Job(BaseModel):
"""A unit of background work.
Attributes:
name (str): Job name.
status (str): Lifecycle status. Defaults to "pending".
retry_count (int): Times the job failed. Defaults to 0.
error_message (str | None): Last failure message. Defaults to None.
payload (dict | None): Arbitrary job payload. Defaults to None.
"""
name: str
status: Literal["pending", "processing", "done", "failed"] = "pending"
retry_count: int = Field(default=0)
error_message: str | None = None
payload: dict | None = None
model_config = {"extra": "ignore"}

View File

@@ -0,0 +1,20 @@
"""# Summary
Mongo persistence for jobs: document schema and repository factory.
"""
from domain.job.models import Job
from infra.db.repos.mongo import _repo_factory as mongo_repo_factory
from mongo_ops import BaseDocument, BaseRepository
class JobDocument(Job, BaseDocument):
"""Mongo document form of :class:`Job`."""
def create_job_repo() -> BaseRepository:
"""Create the Mongo-backed job repository.
Returns:
BaseRepository: Repository wired to the ``jobs`` collection.
"""
return mongo_repo_factory("jobs", JobDocument)

View File

@@ -0,0 +1,33 @@
"""# Summary
CRUD service wiring for the job aggregate via the hexa container.
"""
from hexa import build
from domain.job.models import Job
from domain.job.ports.db import JobDocument
from infra.adapters.service import CrudsServiceAdaptor
class JobCrudsService(CrudsServiceAdaptor[Job, JobDocument]):
"""Job CRUD service resolving :class:`JobDocument` from a repo.
Notes:
Instances are created by :func:`get_job_service`. The ``model`` and
``schema`` class attributes bind the domain model and its document type.
"""
model = Job
schema = JobDocument
def get_job_service(repo) -> JobCrudsService:
"""Build a job CRUD service wired to ``repo``.
Args:
repo (Any): Mongo-backed job repository from :func:`create_job_repo`.
Returns:
JobCrudsService: Ready-to-use job CRUD service.
"""
return build(JobCrudsService, instances={"repo": repo})