{"id":21184944,"url":"https://github.com/othmane099/hexagonal-architecture-python","last_synced_at":"2026-05-14T20:33:33.676Z","repository":{"id":255562192,"uuid":"851235504","full_name":"othmane099/hexagonal-architecture-python","owner":"othmane099","description":"Sample Python REST API implemented according to hexagonal architecture.","archived":false,"fork":false,"pushed_at":"2026-01-24T08:39:06.000Z","size":113,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-24T19:14:51.103Z","etag":null,"topics":["clean-architecture","clean-code","code-design","code-pattern","fastapi","hexagonal-architecture","ports-and-adapters","python","repository-pattern","rest-api","sample-code","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/othmane099.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-02T17:29:40.000Z","updated_at":"2026-01-24T08:39:11.000Z","dependencies_parsed_at":"2024-11-20T22:52:42.589Z","dependency_job_id":null,"html_url":"https://github.com/othmane099/hexagonal-architecture-python","commit_stats":null,"previous_names":["othmane099/stock-management-system","othmane099/stock-management-system-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/othmane099/hexagonal-architecture-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othmane099%2Fhexagonal-architecture-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othmane099%2Fhexagonal-architecture-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othmane099%2Fhexagonal-architecture-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othmane099%2Fhexagonal-architecture-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/othmane099","download_url":"https://codeload.github.com/othmane099/hexagonal-architecture-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othmane099%2Fhexagonal-architecture-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33042231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-architecture","clean-code","code-design","code-pattern","fastapi","hexagonal-architecture","ports-and-adapters","python","repository-pattern","rest-api","sample-code","sqlalchemy"],"created_at":"2024-11-20T18:14:07.826Z","updated_at":"2026-05-14T20:33:33.671Z","avatar_url":"https://github.com/othmane099.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hexagonal Architecture in Python\nThis repository contains a sample Python REST API implemented according to hexagonal architecture.\n\n## Commands\n\n```bash\nmake install       # Install dependencies (requires .venv)\nmake format        # Format code (isort, autoflake, black)\nmake test          # Run all tests with pytest\nmake migrations    # Create alembic migration\nmake migrate       # Run alembic migrations\nmake run           # Start FastAPI server on port 8000\n```\n\n## Project Structure\n\n```\nsrc/sms/\n├── core/           # Domain logic (business rules, independent of infrastructure)\n│   ├── domain/     # Models (dataclasses) and DTOs (Pydantic)\n│   ├── ports/      # Interfaces: repositories.py, services.py, unit_of_works.py\n│   └── services/   # Service implementations (business logic)\n├── adapters/       # Infrastructure implementations\n│   ├── db/orm.py   # SQLAlchemy Data Mapper (imperative mapping)\n│   ├── repositories/  # Repository implementations\n│   ├── unit_of_works.py  # UoW implementations with AsyncSession\n│   └── entry_points/api/  # FastAPI endpoints\n└── config/\n    ├── containers.py  # dependency-injector DI container\n    └── settings.py    # Database and app configuration\n```\n\n## Key Patterns\n\n- **SQLAlchemy Data Mapper Pattern**: Tables are defined separately from domain models (dataclasses) and mapped imperatively in `orm.py`. Domain models remain free of ORM dependencies.\n- **Dependency Injection**: Uses `dependency-injector` library to decouple core business logic from infrastructure code. This makes the core logic independent of external systems, which can be easily swapped or modified without affecting the core.\n- **Unit of Work**: Transaction management via async context managers.\n- **Soft Deletes**: All entities have `deleted_at` field for logical deletion.\n- **Fakes for Testing**: In-memory fake implementations of repositories in `adapters/repositories/fakes/` for unit testing services without a database.\n\n## Database\n\n- PostgreSQL with asyncpg driver\n- Production: port 5435, Test: port 5436\n- Alembic for migrations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothmane099%2Fhexagonal-architecture-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fothmane099%2Fhexagonal-architecture-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothmane099%2Fhexagonal-architecture-python/lists"}