At first, you can have a look to the following thematic tutorials about implementing your own algebraic structure in Sage:
- https://doc.sagemath.org/html/en/thematic_tutorials/tutorial-implementing-algebraic-structures.html
- https://doc.sagemath.org/html/en/thematic_tutorials/coercion_and_categories.html