khitish-backend-core 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. khitish_backend_core-0.1.0/.gitignore +18 -0
  2. khitish_backend_core-0.1.0/CHANGELOG.md +16 -0
  3. khitish_backend_core-0.1.0/CONTRIBUTING.md +14 -0
  4. khitish_backend_core-0.1.0/LICENSE +6 -0
  5. khitish_backend_core-0.1.0/PKG-INFO +204 -0
  6. khitish_backend_core-0.1.0/README.md +78 -0
  7. khitish_backend_core-0.1.0/SECURITY.md +13 -0
  8. khitish_backend_core-0.1.0/pyproject.toml +271 -0
  9. khitish_backend_core-0.1.0/src/khitish_backend/__init__.py +15 -0
  10. khitish_backend_core-0.1.0/src/khitish_backend/adapters/__init__.py +5 -0
  11. khitish_backend_core-0.1.0/src/khitish_backend/adapters/database/__init__.py +8 -0
  12. khitish_backend_core-0.1.0/src/khitish_backend/adapters/database/django_repo.py +96 -0
  13. khitish_backend_core-0.1.0/src/khitish_backend/adapters/database/sqlalchemy_repo.py +106 -0
  14. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/__init__.py +7 -0
  15. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/admin.py +118 -0
  16. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/apps.py +23 -0
  17. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/exceptions.py +57 -0
  18. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/middleware.py +77 -0
  19. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/migrations/0001_initial.py +365 -0
  20. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/migrations/__init__.py +3 -0
  21. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/models.py +314 -0
  22. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/pagination.py +46 -0
  23. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/permissions.py +71 -0
  24. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/serializers.py +256 -0
  25. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/settings.py +85 -0
  26. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/signals.py +29 -0
  27. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/urls.py +28 -0
  28. khitish_backend_core-0.1.0/src/khitish_backend/adapters/django/views.py +324 -0
  29. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/__init__.py +19 -0
  30. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/app.py +118 -0
  31. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/dependencies.py +212 -0
  32. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/exceptions.py +94 -0
  33. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/middleware.py +76 -0
  34. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/routers/__init__.py +17 -0
  35. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/routers/auth.py +238 -0
  36. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/routers/health.py +39 -0
  37. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/routers/organizations.py +76 -0
  38. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/routers/users.py +92 -0
  39. khitish_backend_core-0.1.0/src/khitish_backend/adapters/fastapi/schemas.py +195 -0
  40. khitish_backend_core-0.1.0/src/khitish_backend/application/__init__.py +13 -0
  41. khitish_backend_core-0.1.0/src/khitish_backend/application/events/__init__.py +830 -0
  42. khitish_backend_core-0.1.0/src/khitish_backend/application/interfaces/__init__.py +610 -0
  43. khitish_backend_core-0.1.0/src/khitish_backend/application/services/__init__.py +9 -0
  44. khitish_backend_core-0.1.0/src/khitish_backend/application/use_cases/__init__.py +396 -0
  45. khitish_backend_core-0.1.0/src/khitish_backend/cli/__init__.py +7 -0
  46. khitish_backend_core-0.1.0/src/khitish_backend/cli/commands/__init__.py +7 -0
  47. khitish_backend_core-0.1.0/src/khitish_backend/cli/commands/create.py +491 -0
  48. khitish_backend_core-0.1.0/src/khitish_backend/cli/main.py +30 -0
  49. khitish_backend_core-0.1.0/src/khitish_backend/core/__init__.py +9 -0
  50. khitish_backend_core-0.1.0/src/khitish_backend/core/config/__init__.py +244 -0
  51. khitish_backend_core-0.1.0/src/khitish_backend/core/contracts/__init__.py +761 -0
  52. khitish_backend_core-0.1.0/src/khitish_backend/core/exceptions/__init__.py +1117 -0
  53. khitish_backend_core-0.1.0/src/khitish_backend/core/logging/__init__.py +380 -0
  54. khitish_backend_core-0.1.0/src/khitish_backend/core/observability/__init__.py +456 -0
  55. khitish_backend_core-0.1.0/src/khitish_backend/core/security/__init__.py +638 -0
  56. khitish_backend_core-0.1.0/src/khitish_backend/core/types/__init__.py +391 -0
  57. khitish_backend_core-0.1.0/src/khitish_backend/core/utils/__init__.py +531 -0
  58. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/__init__.py +5 -0
  59. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/email/__init__.py +7 -0
  60. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/email/smtp.py +109 -0
  61. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/payments/__init__.py +7 -0
  62. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/payments/stripe_adapter.py +93 -0
  63. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/postgres/__init__.py +19 -0
  64. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/postgres/engine.py +174 -0
  65. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/queue/__init__.py +7 -0
  66. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/queue/celery_app.py +57 -0
  67. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/redis/__init__.py +11 -0
  68. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/redis/client.py +219 -0
  69. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/storage/__init__.py +16 -0
  70. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/storage/local.py +92 -0
  71. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/storage/s3.py +97 -0
  72. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/telemetry/__init__.py +11 -0
  73. khitish_backend_core-0.1.0/src/khitish_backend/infrastructure/telemetry/otel.py +94 -0
  74. khitish_backend_core-0.1.0/src/khitish_backend/modules/__init__.py +5 -0
  75. khitish_backend_core-0.1.0/src/khitish_backend/modules/audit/__init__.py +13 -0
  76. khitish_backend_core-0.1.0/src/khitish_backend/modules/audit/models.py +103 -0
  77. khitish_backend_core-0.1.0/src/khitish_backend/modules/audit/service.py +219 -0
  78. khitish_backend_core-0.1.0/src/khitish_backend/modules/authentication/__init__.py +37 -0
  79. khitish_backend_core-0.1.0/src/khitish_backend/modules/authentication/models.py +205 -0
  80. khitish_backend_core-0.1.0/src/khitish_backend/modules/authentication/service.py +229 -0
  81. khitish_backend_core-0.1.0/src/khitish_backend/modules/authorization/__init__.py +23 -0
  82. khitish_backend_core-0.1.0/src/khitish_backend/modules/authorization/models.py +126 -0
  83. khitish_backend_core-0.1.0/src/khitish_backend/modules/authorization/service.py +333 -0
  84. khitish_backend_core-0.1.0/src/khitish_backend/modules/background_jobs/__init__.py +23 -0
  85. khitish_backend_core-0.1.0/src/khitish_backend/modules/background_jobs/config.py +60 -0
  86. khitish_backend_core-0.1.0/src/khitish_backend/modules/background_jobs/tasks.py +115 -0
  87. khitish_backend_core-0.1.0/src/khitish_backend/modules/email/__init__.py +21 -0
  88. khitish_backend_core-0.1.0/src/khitish_backend/modules/email/models.py +77 -0
  89. khitish_backend_core-0.1.0/src/khitish_backend/modules/email/service.py +208 -0
  90. khitish_backend_core-0.1.0/src/khitish_backend/modules/file_storage/__init__.py +17 -0
  91. khitish_backend_core-0.1.0/src/khitish_backend/modules/file_storage/models.py +93 -0
  92. khitish_backend_core-0.1.0/src/khitish_backend/modules/file_storage/service.py +190 -0
  93. khitish_backend_core-0.1.0/src/khitish_backend/modules/notifications/__init__.py +19 -0
  94. khitish_backend_core-0.1.0/src/khitish_backend/modules/notifications/models.py +72 -0
  95. khitish_backend_core-0.1.0/src/khitish_backend/modules/notifications/service.py +218 -0
  96. khitish_backend_core-0.1.0/src/khitish_backend/modules/organizations/__init__.py +21 -0
  97. khitish_backend_core-0.1.0/src/khitish_backend/modules/organizations/models.py +289 -0
  98. khitish_backend_core-0.1.0/src/khitish_backend/modules/payments/__init__.py +31 -0
  99. khitish_backend_core-0.1.0/src/khitish_backend/modules/payments/models.py +195 -0
  100. khitish_backend_core-0.1.0/src/khitish_backend/modules/payments/providers/__init__.py +7 -0
  101. khitish_backend_core-0.1.0/src/khitish_backend/modules/payments/providers/mock.py +73 -0
  102. khitish_backend_core-0.1.0/src/khitish_backend/modules/payments/service.py +283 -0
  103. khitish_backend_core-0.1.0/src/khitish_backend/modules/users/__init__.py +23 -0
  104. khitish_backend_core-0.1.0/src/khitish_backend/modules/users/models.py +329 -0
  105. khitish_backend_core-0.1.0/src/khitish_backend/modules/users/service.py +212 -0
  106. khitish_backend_core-0.1.0/src/khitish_backend/version.py +4 -0
  107. khitish_backend_core-0.1.0/tests/architecture/test_architecture.py +64 -0
  108. khitish_backend_core-0.1.0/tests/conftest.py +54 -0
  109. khitish_backend_core-0.1.0/tests/contract/test_contracts.py +51 -0
  110. khitish_backend_core-0.1.0/tests/e2e/test_django_e2e.py +113 -0
  111. khitish_backend_core-0.1.0/tests/e2e/test_fastapi_e2e.py +110 -0
  112. khitish_backend_core-0.1.0/tests/integration/test_storage_and_db.py +64 -0
  113. khitish_backend_core-0.1.0/tests/packaging/test_cli_and_packaging.py +91 -0
  114. khitish_backend_core-0.1.0/tests/security/test_security.py +170 -0
  115. khitish_backend_core-0.1.0/tests/unit/test_adapters_and_infra.py +479 -0
  116. khitish_backend_core-0.1.0/tests/unit/test_core.py +199 -0
  117. khitish_backend_core-0.1.0/tests/unit/test_coverage_boost.py +366 -0
  118. khitish_backend_core-0.1.0/tests/unit/test_modules.py +236 -0
@@ -0,0 +1,18 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .eggs/
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ .coverage
13
+ htmlcov/
14
+ coverage.xml
15
+ .env
16
+ *.sqlite3
17
+ media/
18
+ .DS_Store
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to **Khitish Backend Core** will be documented in this file.
4
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [0.1.0] - 2026-12-01
7
+
8
+ ### Added
9
+ - Core layer: Pydantic v2 settings (`AppSettings`), custom exception hierarchy, Argon2id & PyJWT security utilities, structlog JSON logging with correlation IDs and sensitive-data redaction, observability health registry & metrics, pagination/retry/string/datetime utilities, and protocol contracts.
10
+ - Application layer: Domain events, sync/async `EventBus`, service protocols, and authentication use cases.
11
+ - Domain modules: `authentication`, `authorization`, `users`, `organizations`, `email`, `notifications`, `audit`, `payments` (with `MockPaymentProvider`), `file_storage`, and `background_jobs`.
12
+ - Infrastructure layer: `AsyncDatabase` (SQLAlchemy 2.x), `RedisClient` / `RedisCache`, `LocalStorage` / `S3Storage`, `SMTPEmailBackend` / `ConsoleEmailBackend`, `StripePaymentAdapter`, `create_celery_app`, and OpenTelemetry setup.
13
+ - Framework adapters: Complete Django + DRF adapter (models, migrations, serializers, viewsets, admin, middleware, permissions) and FastAPI adapter (app factory, lifespan, dependencies, middleware, exception handlers, v1 routers).
14
+ - CLI: `khitish-backend` with `version` and `create` commands for Django and FastAPI project generation.
15
+ - Test suite: Unit, integration, contract, security, architecture, packaging, and E2E tests (>=85% coverage).
16
+ - Docker & CI: `Dockerfile`, `docker-compose.yml`, `.pre-commit-config.yaml`, and GitHub Actions workflows (`ci.yml`, `security.yml`, `release.yml`).
@@ -0,0 +1,14 @@
1
+ # Contributing to Khitish Backend Core
2
+
3
+ ## Development Setup
4
+
5
+ ```bash
6
+ uv sync --all-extras --python 3.12
7
+ uv run pre-commit install
8
+ ```
9
+
10
+ ## Engineering Standards
11
+
12
+ 1. `core/`, `application/`, and `modules/` must never import `django` or `fastapi`.
13
+ 2. All public classes and functions require full type annotations and docstrings.
14
+ 3. All PRs must pass `pytest` (>=85% coverage), `ruff check`, `ruff format --check`, `bandit`, and architecture tests.
@@ -0,0 +1,6 @@
1
+ LICENSING & VISIBILITY NOTICE
2
+
3
+ This repository does not yet have a finalized open-source or proprietary license.
4
+ Before publishing to PyPI or making the GitHub repository public, the repository
5
+ owner must select and place the final license text here (for example, MIT or
6
+ Apache-2.0) or retain proprietary all-rights-reserved terms for private use.
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.5
2
+ Name: khitish-backend-core
3
+ Version: 0.1.0
4
+ Summary: Enterprise-grade Python backend platform for Django and FastAPI
5
+ Project-URL: Homepage, https://github.com/khitishkumar/khitish-backend-core
6
+ Project-URL: Documentation, https://github.com/khitishkumar/khitish-backend-core/docs
7
+ Project-URL: Repository, https://github.com/khitishkumar/khitish-backend-core
8
+ Project-URL: Issues, https://github.com/khitishkumar/khitish-backend-core/issues
9
+ Project-URL: Changelog, https://github.com/khitishkumar/khitish-backend-core/blob/main/CHANGELOG.md
10
+ Author-email: Khitish Kumar <khitish@khitish-backend-core.dev>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: authentication,authorization,backend,django,enterprise,fastapi
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Framework :: Django
16
+ Classifier: Framework :: FastAPI
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.12
25
+ Requires-Dist: argon2-cffi<24,>=23.1
26
+ Requires-Dist: click<9,>=8.1
27
+ Requires-Dist: pydantic-settings<3,>=2.6
28
+ Requires-Dist: pydantic<3,>=2.9
29
+ Requires-Dist: pyjwt[crypto]<3,>=2.9
30
+ Requires-Dist: python-dotenv<2,>=1.0
31
+ Requires-Dist: rich<14,>=13.9
32
+ Requires-Dist: structlog<25,>=24.4
33
+ Requires-Dist: typing-extensions<5,>=4.12
34
+ Provides-Extra: all
35
+ Requires-Dist: aiofiles<25,>=24.1; extra == 'all'
36
+ Requires-Dist: aiosmtplib<6,>=5.1.2; extra == 'all'
37
+ Requires-Dist: alembic<2,>=1.14; extra == 'all'
38
+ Requires-Dist: argon2-cffi<24,>=23.1; extra == 'all'
39
+ Requires-Dist: asyncpg<1,>=0.30; extra == 'all'
40
+ Requires-Dist: boto3<2,>=1.35; extra == 'all'
41
+ Requires-Dist: botocore<2,>=1.35; extra == 'all'
42
+ Requires-Dist: celery[redis]<6,>=5.4; extra == 'all'
43
+ Requires-Dist: django-cors-headers<5,>=4.6; extra == 'all'
44
+ Requires-Dist: django-filter<25,>=24.3; extra == 'all'
45
+ Requires-Dist: django<6,>=5.1; extra == 'all'
46
+ Requires-Dist: djangorestframework-simplejwt<6,>=5.3; extra == 'all'
47
+ Requires-Dist: djangorestframework<4,>=3.15; extra == 'all'
48
+ Requires-Dist: email-validator<3,>=2.2; extra == 'all'
49
+ Requires-Dist: fastapi<1,>=0.115; extra == 'all'
50
+ Requires-Dist: httpx<1,>=0.28; extra == 'all'
51
+ Requires-Dist: jinja2<4,>=3.1; extra == 'all'
52
+ Requires-Dist: kombu<6,>=5.4; extra == 'all'
53
+ Requires-Dist: opentelemetry-api<2,>=1.28; extra == 'all'
54
+ Requires-Dist: opentelemetry-exporter-otlp<2,>=1.28; extra == 'all'
55
+ Requires-Dist: opentelemetry-instrumentation-django<1,>=0.49b0; extra == 'all'
56
+ Requires-Dist: opentelemetry-instrumentation-fastapi<1,>=0.49b0; extra == 'all'
57
+ Requires-Dist: opentelemetry-sdk<2,>=1.28; extra == 'all'
58
+ Requires-Dist: prometheus-client<1,>=0.21; extra == 'all'
59
+ Requires-Dist: psycopg[binary]<4,>=3.2; extra == 'all'
60
+ Requires-Dist: python-multipart<1,>=0.0.17; extra == 'all'
61
+ Requires-Dist: redis[hiredis]<6,>=5.2; extra == 'all'
62
+ Requires-Dist: sqlalchemy[asyncio]<3,>=2.0.36; extra == 'all'
63
+ Requires-Dist: uvicorn[standard]<1,>=0.32; extra == 'all'
64
+ Provides-Extra: database
65
+ Requires-Dist: alembic<2,>=1.14; extra == 'database'
66
+ Requires-Dist: asyncpg<1,>=0.30; extra == 'database'
67
+ Requires-Dist: psycopg[binary]<4,>=3.2; extra == 'database'
68
+ Requires-Dist: sqlalchemy[asyncio]<3,>=2.0.36; extra == 'database'
69
+ Provides-Extra: dev
70
+ Requires-Dist: aiosqlite<1,>=0.20; extra == 'dev'
71
+ Requires-Dist: bandit<2,>=1.8; extra == 'dev'
72
+ Requires-Dist: django-stubs[compatible-mypy]<6,>=5.1; extra == 'dev'
73
+ Requires-Dist: djangorestframework-stubs[compatible-mypy]<4,>=3.15; extra == 'dev'
74
+ Requires-Dist: factory-boy<4,>=3.3; extra == 'dev'
75
+ Requires-Dist: faker<34,>=33.0; extra == 'dev'
76
+ Requires-Dist: hypothesis<7,>=6.119; extra == 'dev'
77
+ Requires-Dist: mypy<2,>=1.13; extra == 'dev'
78
+ Requires-Dist: pip-audit<3,>=2.7; extra == 'dev'
79
+ Requires-Dist: pre-commit<5,>=4.0; extra == 'dev'
80
+ Requires-Dist: pytest-asyncio<2,>=0.24; extra == 'dev'
81
+ Requires-Dist: pytest-cov<8,>=6.0; extra == 'dev'
82
+ Requires-Dist: pytest-django<5,>=4.9; extra == 'dev'
83
+ Requires-Dist: pytest-httpx<1,>=0.35; extra == 'dev'
84
+ Requires-Dist: pytest<10,>=9.0.3; extra == 'dev'
85
+ Requires-Dist: respx<1,>=0.21; extra == 'dev'
86
+ Requires-Dist: ruff<1,>=0.8; extra == 'dev'
87
+ Requires-Dist: time-machine<3,>=2.16; extra == 'dev'
88
+ Requires-Dist: types-boto3<2,>=1.0; extra == 'dev'
89
+ Requires-Dist: types-passlib<2,>=1.7; extra == 'dev'
90
+ Requires-Dist: types-python-jose<4,>=3.3; extra == 'dev'
91
+ Requires-Dist: types-redis<5,>=4.6; extra == 'dev'
92
+ Provides-Extra: django
93
+ Requires-Dist: argon2-cffi<24,>=23.1; extra == 'django'
94
+ Requires-Dist: django-cors-headers<5,>=4.6; extra == 'django'
95
+ Requires-Dist: django-filter<25,>=24.3; extra == 'django'
96
+ Requires-Dist: django<6,>=5.1; extra == 'django'
97
+ Requires-Dist: djangorestframework-simplejwt<6,>=5.3; extra == 'django'
98
+ Requires-Dist: djangorestframework<4,>=3.15; extra == 'django'
99
+ Requires-Dist: psycopg[binary]<4,>=3.2; extra == 'django'
100
+ Provides-Extra: email
101
+ Requires-Dist: aiosmtplib<6,>=5.1.2; extra == 'email'
102
+ Requires-Dist: jinja2<4,>=3.1; extra == 'email'
103
+ Provides-Extra: fastapi
104
+ Requires-Dist: email-validator<3,>=2.2; extra == 'fastapi'
105
+ Requires-Dist: fastapi<1,>=0.115; extra == 'fastapi'
106
+ Requires-Dist: httpx<1,>=0.28; extra == 'fastapi'
107
+ Requires-Dist: python-multipart<1,>=0.0.17; extra == 'fastapi'
108
+ Requires-Dist: uvicorn[standard]<1,>=0.32; extra == 'fastapi'
109
+ Provides-Extra: observability
110
+ Requires-Dist: opentelemetry-api<2,>=1.28; extra == 'observability'
111
+ Requires-Dist: opentelemetry-exporter-otlp<2,>=1.28; extra == 'observability'
112
+ Requires-Dist: opentelemetry-instrumentation-django<1,>=0.49b0; extra == 'observability'
113
+ Requires-Dist: opentelemetry-instrumentation-fastapi<1,>=0.49b0; extra == 'observability'
114
+ Requires-Dist: opentelemetry-sdk<2,>=1.28; extra == 'observability'
115
+ Requires-Dist: prometheus-client<1,>=0.21; extra == 'observability'
116
+ Provides-Extra: redis
117
+ Requires-Dist: redis[hiredis]<6,>=5.2; extra == 'redis'
118
+ Provides-Extra: storage
119
+ Requires-Dist: aiofiles<25,>=24.1; extra == 'storage'
120
+ Requires-Dist: boto3<2,>=1.35; extra == 'storage'
121
+ Requires-Dist: botocore<2,>=1.35; extra == 'storage'
122
+ Provides-Extra: workers
123
+ Requires-Dist: celery[redis]<6,>=5.4; extra == 'workers'
124
+ Requires-Dist: kombu<6,>=5.4; extra == 'workers'
125
+ Description-Content-Type: text/markdown
126
+
127
+ # Khitish Backend Core
128
+
129
+ **Khitish Backend Core** (`khitish-backend-core` / `import khitish_backend`) is an enterprise-grade, reusable Python 3.12+ backend platform supporting both **Django + Django REST Framework** and **FastAPI** through clean, decoupled adapters.
130
+
131
+ ## Key Features
132
+
133
+ - **Framework-Independent Core**: Configuration (Pydantic v2), exceptions, Argon2id password hashing, PyJWT token management, structured JSON logging (structlog), OpenTelemetry & health checks, and protocol contracts with zero Django/FastAPI imports.
134
+ - **Domain Modules**: Authentication (registration, login, refresh-token rotation & reuse detection, email verification, password reset), RBAC/resource/tenant Authorization, User Management, Multi-tenant Organizations, Email & Notifications, File Storage (local + S3), Payments (provider-independent + Stripe & Mock), Audit Logging, and Background Jobs (Celery + Redis).
135
+ - **Dual Framework Adapters**:
136
+ - **Django + DRF**: Custom `KhitishUser`, migrations, serializers, viewsets, middleware, permissions, pagination, and Django Admin integration.
137
+ - **FastAPI**: Application factory, lifespan management, dependency injection, middleware, exception handlers, and v1 routers.
138
+ - **CLI Project Generator**: `khitish-backend create <name> --framework django|fastapi --modules ...`
139
+
140
+ ## Installation
141
+
142
+ ```bash
143
+ # Base core package
144
+ pip install khitish-backend-core
145
+
146
+ # With FastAPI + SQLAlchemy + Redis
147
+ pip install "khitish-backend-core[fastapi,database,redis]"
148
+
149
+ # With Django + DRF + Redis
150
+ pip install "khitish-backend-core[django,redis]"
151
+
152
+ # Everything
153
+ pip install "khitish-backend-core[all]"
154
+ ```
155
+
156
+ ## Quick Start
157
+
158
+ ### CLI Generator
159
+
160
+ ```bash
161
+ khitish-backend --help
162
+ khitish-backend version
163
+ khitish-backend create myproject --framework fastapi --modules auth,users,notifications
164
+ khitish-backend create myproject --framework django
165
+ ```
166
+
167
+ ### FastAPI Example
168
+
169
+ ```bash
170
+ uvicorn examples.fastapi_example.main:app --reload
171
+ ```
172
+
173
+ ### Django Example
174
+
175
+ ```bash
176
+ python examples/django_example/manage.py migrate
177
+ python examples/django_example/manage.py runserver
178
+ ```
179
+
180
+ ## Architecture
181
+
182
+ - `src/khitish_backend/core/`: Framework-agnostic primitives (config, contracts, exceptions, security, logging, observability, types, utils).
183
+ - `src/khitish_backend/application/`: Domain events, event bus, service interfaces, and use cases.
184
+ - `src/khitish_backend/modules/`: Business domain services and models.
185
+ - `src/khitish_backend/infrastructure/`: Concrete adapters for PostgreSQL (SQLAlchemy 2.x), Redis, Local/S3 storage, SMTP, Stripe, Celery, and OpenTelemetry.
186
+ - `src/khitish_backend/adapters/`: Framework-specific integrations (`django/`, `fastapi/`, `database/`).
187
+ - `src/khitish_backend/cli/`: Click-based project generator CLI.
188
+
189
+ See [docs/architecture/overview.md](docs/architecture/overview.md) for C4 diagrams and dependency rules.
190
+
191
+ ## Testing & Quality
192
+
193
+ ```bash
194
+ uv sync --all-extras --python 3.12
195
+ uv run pytest --cov=src/khitish_backend
196
+ uv run ruff check src tests
197
+ uv run ruff format --check src tests
198
+ uv run bandit -c pyproject.toml -r src
199
+ uv run pip-audit
200
+ ```
201
+
202
+ ## Licensing & Visibility Notice
203
+
204
+ Before publishing to PyPI or a public GitHub repository, finalize the repository visibility (private vs. public) and replace the placeholder notice in `LICENSE` with your chosen license (e.g., MIT or Apache-2.0) and verify `khitish-backend-core` name availability on PyPI.
@@ -0,0 +1,78 @@
1
+ # Khitish Backend Core
2
+
3
+ **Khitish Backend Core** (`khitish-backend-core` / `import khitish_backend`) is an enterprise-grade, reusable Python 3.12+ backend platform supporting both **Django + Django REST Framework** and **FastAPI** through clean, decoupled adapters.
4
+
5
+ ## Key Features
6
+
7
+ - **Framework-Independent Core**: Configuration (Pydantic v2), exceptions, Argon2id password hashing, PyJWT token management, structured JSON logging (structlog), OpenTelemetry & health checks, and protocol contracts with zero Django/FastAPI imports.
8
+ - **Domain Modules**: Authentication (registration, login, refresh-token rotation & reuse detection, email verification, password reset), RBAC/resource/tenant Authorization, User Management, Multi-tenant Organizations, Email & Notifications, File Storage (local + S3), Payments (provider-independent + Stripe & Mock), Audit Logging, and Background Jobs (Celery + Redis).
9
+ - **Dual Framework Adapters**:
10
+ - **Django + DRF**: Custom `KhitishUser`, migrations, serializers, viewsets, middleware, permissions, pagination, and Django Admin integration.
11
+ - **FastAPI**: Application factory, lifespan management, dependency injection, middleware, exception handlers, and v1 routers.
12
+ - **CLI Project Generator**: `khitish-backend create <name> --framework django|fastapi --modules ...`
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ # Base core package
18
+ pip install khitish-backend-core
19
+
20
+ # With FastAPI + SQLAlchemy + Redis
21
+ pip install "khitish-backend-core[fastapi,database,redis]"
22
+
23
+ # With Django + DRF + Redis
24
+ pip install "khitish-backend-core[django,redis]"
25
+
26
+ # Everything
27
+ pip install "khitish-backend-core[all]"
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ### CLI Generator
33
+
34
+ ```bash
35
+ khitish-backend --help
36
+ khitish-backend version
37
+ khitish-backend create myproject --framework fastapi --modules auth,users,notifications
38
+ khitish-backend create myproject --framework django
39
+ ```
40
+
41
+ ### FastAPI Example
42
+
43
+ ```bash
44
+ uvicorn examples.fastapi_example.main:app --reload
45
+ ```
46
+
47
+ ### Django Example
48
+
49
+ ```bash
50
+ python examples/django_example/manage.py migrate
51
+ python examples/django_example/manage.py runserver
52
+ ```
53
+
54
+ ## Architecture
55
+
56
+ - `src/khitish_backend/core/`: Framework-agnostic primitives (config, contracts, exceptions, security, logging, observability, types, utils).
57
+ - `src/khitish_backend/application/`: Domain events, event bus, service interfaces, and use cases.
58
+ - `src/khitish_backend/modules/`: Business domain services and models.
59
+ - `src/khitish_backend/infrastructure/`: Concrete adapters for PostgreSQL (SQLAlchemy 2.x), Redis, Local/S3 storage, SMTP, Stripe, Celery, and OpenTelemetry.
60
+ - `src/khitish_backend/adapters/`: Framework-specific integrations (`django/`, `fastapi/`, `database/`).
61
+ - `src/khitish_backend/cli/`: Click-based project generator CLI.
62
+
63
+ See [docs/architecture/overview.md](docs/architecture/overview.md) for C4 diagrams and dependency rules.
64
+
65
+ ## Testing & Quality
66
+
67
+ ```bash
68
+ uv sync --all-extras --python 3.12
69
+ uv run pytest --cov=src/khitish_backend
70
+ uv run ruff check src tests
71
+ uv run ruff format --check src tests
72
+ uv run bandit -c pyproject.toml -r src
73
+ uv run pip-audit
74
+ ```
75
+
76
+ ## Licensing & Visibility Notice
77
+
78
+ Before publishing to PyPI or a public GitHub repository, finalize the repository visibility (private vs. public) and replace the placeholder notice in `LICENSE` with your chosen license (e.g., MIT or Apache-2.0) and verify `khitish-backend-core` name availability on PyPI.
@@ -0,0 +1,13 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Please report security vulnerabilities privately to the maintainers rather than opening a public GitHub issue.
6
+
7
+ ## Security Controls Built Into This Platform
8
+
9
+ - **Password Hashing**: Argon2id via `argon2-cffi` (and Django's `Argon2PasswordHasher`).
10
+ - **Token Lifecycle**: Short-lived access JWTs, refresh token rotation, and reuse detection that revokes all user tokens on replay.
11
+ - **Multi-Tenant Isolation**: Explicit tenant membership checks (`enforce_tenant` / `enforce_tenant_isolation`).
12
+ - **Log Redaction**: `SensitiveDataFilter` automatically masks `password`, `token`, `secret`, `api_key`, `authorization`, `cookie`, and `ssn` fields.
13
+ - **Upload & Webhook Safety**: Path-traversal prevention, MIME/size/extension validation, and constant-time HMAC verification with idempotent webhook deduplication.
@@ -0,0 +1,271 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "khitish-backend-core"
7
+ version = "0.1.0"
8
+ description = "Enterprise-grade Python backend platform for Django and FastAPI"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [{ name = "Khitish Kumar", email = "khitish@khitish-backend-core.dev" }]
12
+ keywords = ["django", "fastapi", "backend", "enterprise", "authentication", "authorization"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Framework :: Django",
21
+ "Framework :: FastAPI",
22
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
23
+ "Typing :: Typed",
24
+ ]
25
+ requires-python = ">=3.12"
26
+ dependencies = [
27
+ "pydantic>=2.9,<3",
28
+ "pydantic-settings>=2.6,<3",
29
+ "structlog>=24.4,<25",
30
+ "python-dotenv>=1.0,<2",
31
+ "click>=8.1,<9",
32
+ "rich>=13.9,<14",
33
+ "typing-extensions>=4.12,<5",
34
+ "pyjwt[crypto]>=2.9,<3",
35
+ "argon2-cffi>=23.1,<24",
36
+ ]
37
+
38
+ [project.optional-dependencies]
39
+ django = [
40
+ "django>=5.1,<6",
41
+ "djangorestframework>=3.15,<4",
42
+ "django-cors-headers>=4.6,<5",
43
+ "django-filter>=24.3,<25",
44
+ "djangorestframework-simplejwt>=5.3,<6",
45
+ "argon2-cffi>=23.1,<24",
46
+ "psycopg[binary]>=3.2,<4",
47
+ ]
48
+ fastapi = [
49
+ "fastapi>=0.115,<1",
50
+ "uvicorn[standard]>=0.32,<1",
51
+ "httpx>=0.28,<1",
52
+ "python-multipart>=0.0.17,<1",
53
+ "email-validator>=2.2,<3",
54
+ ]
55
+ database = [
56
+ "sqlalchemy[asyncio]>=2.0.36,<3",
57
+ "alembic>=1.14,<2",
58
+ "asyncpg>=0.30,<1",
59
+ "psycopg[binary]>=3.2,<4",
60
+ ]
61
+ redis = [
62
+ "redis[hiredis]>=5.2,<6",
63
+ ]
64
+ workers = [
65
+ "celery[redis]>=5.4,<6",
66
+ "kombu>=5.4,<6",
67
+ ]
68
+ storage = [
69
+ "boto3>=1.35,<2",
70
+ "botocore>=1.35,<2",
71
+ "aiofiles>=24.1,<25",
72
+ ]
73
+ observability = [
74
+ "opentelemetry-api>=1.28,<2",
75
+ "opentelemetry-sdk>=1.28,<2",
76
+ "opentelemetry-exporter-otlp>=1.28,<2",
77
+ "opentelemetry-instrumentation-fastapi>=0.49b0,<1",
78
+ "opentelemetry-instrumentation-django>=0.49b0,<1",
79
+ "prometheus-client>=0.21,<1",
80
+ ]
81
+ email = [
82
+ "jinja2>=3.1,<4",
83
+ "aiosmtplib>=5.1.2,<6",
84
+ ]
85
+ all = [
86
+ "khitish-backend-core[django,fastapi,database,redis,workers,storage,observability,email]",
87
+ ]
88
+ dev = [
89
+ "pytest>=9.0.3,<10",
90
+ "pytest-cov>=6.0,<8",
91
+ "pytest-asyncio>=0.24,<2",
92
+ "pytest-django>=4.9,<5",
93
+ "pytest-httpx>=0.35,<1",
94
+ "aiosqlite>=0.20,<1",
95
+ "factory-boy>=3.3,<4",
96
+ "faker>=33.0,<34",
97
+ "hypothesis>=6.119,<7",
98
+ "ruff>=0.8,<1",
99
+ "mypy>=1.13,<2",
100
+ "bandit>=1.8,<2",
101
+ "pip-audit>=2.7,<3",
102
+ "pre-commit>=4.0,<5",
103
+ "time-machine>=2.16,<3",
104
+ "respx>=0.21,<1",
105
+ "django-stubs[compatible-mypy]>=5.1,<6",
106
+ "djangorestframework-stubs[compatible-mypy]>=3.15,<4",
107
+ "types-redis>=4.6,<5",
108
+ "types-boto3>=1.0,<2",
109
+ "types-passlib>=1.7,<2",
110
+ "types-python-jose>=3.3,<4",
111
+ ]
112
+
113
+ [project.scripts]
114
+ khitish-backend = "khitish_backend.cli.main:cli"
115
+
116
+ [project.urls]
117
+ Homepage = "https://github.com/khitishkumar/khitish-backend-core"
118
+ Documentation = "https://github.com/khitishkumar/khitish-backend-core/docs"
119
+ Repository = "https://github.com/khitishkumar/khitish-backend-core"
120
+ Issues = "https://github.com/khitishkumar/khitish-backend-core/issues"
121
+ Changelog = "https://github.com/khitishkumar/khitish-backend-core/blob/main/CHANGELOG.md"
122
+
123
+ [tool.hatch.build.targets.wheel]
124
+ packages = ["src/khitish_backend"]
125
+
126
+ [tool.hatch.build.targets.sdist]
127
+ include = [
128
+ "/src",
129
+ "/tests",
130
+ "/README.md",
131
+ "/CHANGELOG.md",
132
+ "/CONTRIBUTING.md",
133
+ "/SECURITY.md",
134
+ "/LICENSE",
135
+ "/pyproject.toml",
136
+ ]
137
+
138
+ [tool.ruff]
139
+ target-version = "py312"
140
+ line-length = 100
141
+ src = ["src", "tests"]
142
+
143
+ [tool.ruff.lint]
144
+ select = [
145
+ "E", "W", # pycodestyle
146
+ "F", # pyflakes
147
+ "I", # isort
148
+ "N", # pep8-naming
149
+ "UP", # pyupgrade
150
+ "B", # flake8-bugbear
151
+ "S", # flake8-bandit
152
+ "T20", # flake8-print
153
+ "C90", # mccabe complexity
154
+ "ANN", # annotations
155
+ "ARG", # unused args
156
+ "RUF", # ruff-specific
157
+ ]
158
+ ignore = [
159
+ "S101", # assert usage (OK in tests)
160
+ "B008", # function calls in default args (OK for FastAPI Depends)
161
+ "ANN401", # Any in generic/framework adapter signatures
162
+ "RUF012", # Mutable class attributes in Django/DRF Meta & settings
163
+ "S105", # False positives on token_type="access"/"refresh"
164
+ "S106", # False positives on token_type keyword args
165
+ "S107", # False positives on default test/local signing secret params
166
+ "E501", # Line length handled by formatter / docstrings
167
+ "RUF001", # En-dash in human-readable strings
168
+ "RUF002", # En-dash in docstrings
169
+ "RUF003", # En-dash in comments
170
+ "UP046", # Generic[T] style compatibility
171
+ "UP042", # str, Enum compatibility
172
+ "UP040", # TypeAlias compatibility
173
+ "N802", # Allow camelCase method names where matching external APIs
174
+ "B905",
175
+ "RUF022", # Preserve grouped __all__ ordering with section comments
176
+ "ARG001", # Structlog processor signature parameters
177
+ "ARG002", # Protocol-mandated method parameters
178
+ "RUF006", # Fire-and-forget async event bus dispatch
179
+ ]
180
+
181
+ [tool.ruff.lint.per-file-ignores]
182
+ "tests/**/*.py" = ["ANN", "S", "ARG", "C901"]
183
+ "examples/**/*.py" = ["ANN", "T20"]
184
+
185
+ [tool.mypy]
186
+ python_version = "3.12"
187
+ strict = true
188
+ warn_return_any = true
189
+ warn_unused_configs = true
190
+ disallow_untyped_defs = true
191
+ disallow_incomplete_defs = true
192
+ check_untyped_defs = true
193
+ no_implicit_optional = true
194
+ warn_redundant_casts = true
195
+ warn_unused_ignores = true
196
+ show_error_codes = true
197
+ namespace_packages = true
198
+ explicit_package_bases = true
199
+ mypy_path = "src"
200
+ plugins = ["pydantic.mypy", "mypy_django_plugin.main"]
201
+
202
+ [tool.django-stubs]
203
+ django_settings_module = "examples.django_example.settings"
204
+
205
+ # ignore missing stubs for third-party packages
206
+ [[tool.mypy.overrides]]
207
+ module = [
208
+ "celery.*",
209
+ "kombu.*",
210
+ "boto3.*",
211
+ "botocore.*",
212
+ "opentelemetry.*",
213
+ "prometheus_client.*",
214
+ "aiosmtplib.*",
215
+ "jinja2.*",
216
+ "alembic.*",
217
+ "asyncpg.*",
218
+ "factory.*",
219
+ "hypothesis.*",
220
+ ]
221
+ ignore_missing_imports = true
222
+
223
+ [tool.pytest.ini_options]
224
+ testpaths = ["tests"]
225
+ asyncio_mode = "auto"
226
+ asyncio_default_fixture_loop_scope = "function"
227
+ addopts = [
228
+ "--strict-markers",
229
+ "--tb=short",
230
+ "-ra",
231
+ ]
232
+ markers = [
233
+ "unit: Unit tests (no external services)",
234
+ "integration: Integration tests (requires Docker services)",
235
+ "contract: Contract tests for interfaces",
236
+ "security: Security-focused tests",
237
+ "architecture: Architecture enforcement tests",
238
+ "packaging: Package build and install tests",
239
+ "e2e: End-to-end tests",
240
+ "slow: Slow tests",
241
+ ]
242
+ filterwarnings = [
243
+ "error",
244
+ "ignore::DeprecationWarning:django.*",
245
+ "ignore::starlette.exceptions.StarletteDeprecationWarning",
246
+ "ignore::PendingDeprecationWarning",
247
+ ]
248
+
249
+ [tool.coverage.run]
250
+ source = ["src/khitish_backend"]
251
+ omit = ["*/migrations/*", "*/tests/*"]
252
+ branch = true
253
+
254
+ [tool.coverage.report]
255
+ show_missing = true
256
+ skip_covered = false
257
+ fail_under = 85
258
+ exclude_lines = [
259
+ "pragma: no cover",
260
+ "if TYPE_CHECKING:",
261
+ "raise NotImplementedError",
262
+ "@(abc\\.)?abstractmethod",
263
+ "\\.\\.\\.",
264
+ ]
265
+
266
+ [tool.bandit]
267
+ targets = ["src"]
268
+ exclude_dirs = ["tests"]
269
+ severity = "medium"
270
+ confidence = "medium"
271
+ skips = ["B101"] # assert_used - OK in test helpers
@@ -0,0 +1,15 @@
1
+ """Khitish Backend Core — enterprise-grade Python backend platform.
2
+
3
+ Provides authentication, authorization, configuration, storage,
4
+ email, payment, audit, and notification abstractions for Django
5
+ and FastAPI applications.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from khitish_backend.version import __version__, __version_info__
11
+
12
+ __all__: list[str] = [
13
+ "__version__",
14
+ "__version_info__",
15
+ ]
@@ -0,0 +1,5 @@
1
+ """Framework and database adapters for Khitish Backend Core."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__: list[str] = []
@@ -0,0 +1,8 @@
1
+ """Database repository adapters for SQLAlchemy 2.x and Django ORM."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from khitish_backend.adapters.database.django_repo import DjangoRepository
6
+ from khitish_backend.adapters.database.sqlalchemy_repo import SQLAlchemyRepository
7
+
8
+ __all__ = ["DjangoRepository", "SQLAlchemyRepository"]