How hirushiharan/python-testbed works
Purpose and Execution Model
A Python 3.11+ toolkit of independently runnable CLIs plus a small FastAPI service. Console-script packaging is defined in pyproject.toml; scripts can also be invoked directly. The HTTP entry point is src/main.py, while auth has a separately composed application in src/auth/main.py.
SharePoint HTTP Integration
The primary web-facing flow is the FastAPI application in src/main.py, exposing SharePoint document-library operations under /api/v1/sharepoint. Routing, request/response schemas, and use-case orchestration are separated across:
• src/integrations/sharepoint/api.py
• src/integrations/sharepoint/service.py
• src/integrations/sharepoint/client.py
Requests create folders, list folder files, or upload files; the client forms the boundary to SharePoint/Microsoft Graph-style external APIs. Settings are isolated in src/integrations/sharepoint/settings.py.
Authentication Subsystem
src/auth is a layered Microsoft Entra ID authentication module: API endpoints and dependencies delegate to application services, with domain roles/errors kept independent of provider and database details.
• src/auth/api/router.py
• src/auth/application/service.py
• src/auth/integrations/entra_id_adapter.py
Its control flow covers login URL generation, authorization-code exchange, bearer-token validation, then user lookup. OAuth/Entra communication is behind adapters (src/auth/integrations/oauth_adapter.py), and MySQL persistence is behind src/auth/infrastructure/repository.py. API error translation is centralized in src/auth/exception_handlers.py.
AI Provider Utilities
Provider-specific CLI modules encapsulate interactions with Anthropic, OpenRouter, and Google AI Studio:
• src/ai/providers/anthropic_chat.py
• src/ai/providers/openrouter_chat.py
• src/ai/providers/google_ai_studio.py
These are direct external-service boundaries rather than a shared application service layer. Credentials are expected from environment configuration, with .env.example defining the deployment contract.
Microsoft 365 Email Integration
The email connector follows a compact API/service/client split, providing Outlook mailbox retrieval with folder and JSON-output controls:
• src/integrations/email/outlook_mailbox.py
• src/integrations/email/service.py
• src/integrations/email/client.py
This subsystem is separate from the SharePoint API but shares the Microsoft ecosystem and likely token/configuration concerns. Its API-facing surface is represented by src/integrations/email/api.py.
Document and Storage Pipeline
Document utilities are file-oriented, composable stages: extract PDF text, normalize/clean text, serialize extracted text to JSON, or render Markdown to DOCX.
• src/document_processing/extraction/pdf_to_text.py
• src/document_processing/conversion/garbage_text_cleaner.py
• src/document_processing/conversion/markdown_to_docx.py
Storage cleanup is intentionally isolated because it is destructive: src/document_processing/storage/delete_s3_bucket_documents.py deletes AWS S3 objects, optionally constrained by prefix and guarded by confirmation.
Local Generation and Security Utilities
Project-structure tools convert a JSON tree into directories/files or traverse a repository into Markdown:
• src/project_structure/create_structure_from_json.py
• src/project_structure/export_project_structure.py
JWT-secret generation is an isolated security CLI at src/security/tokens/generate_jwt_secret_key.py; it produces secret material locally rather than acting as a token issuer.
Operational Boundaries
Runtime dependencies and command registration live in pyproject.toml; environment-specific secrets stay outside source via .env.example. GitHub Actions at .github/workflows/ci.yml validates linting, smoke execution, and secret-scanning hooks. The main material infrastructure is MySQL for auth user lookup, AWS S3 for document deletion, Microsoft Entra ID/OAuth and Outlook/SharePoint services, and AI-provider APIs.
Main entry points: service.py Auth application service · .env.example Environment contract · pyproject.toml Package commands · main.py Main FastAPI app
Components 22
HTTP integrations
- Main FastAPI app
src/main.py - SharePoint routes
src/integrations/sharepoint/api.py - SharePoint use cases
src/integrations/sharepoint/service.py - SharePoint client
src/integrations/sharepoint/client.py - SharePoint settings
src/integrations/sharepoint/settings.py - Outlook API
src/integrations/email/api.py - Mailbox service
src/integrations/email/service.py - Outlook client
src/integrations/email/client.py
Authentication
- Auth FastAPI app · Separately composed authentication application.
src/auth/main.py - Auth routes
src/auth/api/router.py - Auth application service
src/auth/application/service.py - Entra adapter
src/auth/integrations/entra_id_adapter.py - OAuth adapter
src/auth/integrations/oauth_adapter.py - User repository
src/auth/infrastructure/repository.py
CLI utilities
- AI provider CLIs · Direct Anthropic, OpenRouter, and Google AI Studio integrations.
src/ai/providers/anthropic_chat.py - Document conversion tools · PDF extraction, text cleanup, and Markdown-to-DOCX conversion.
src/document_processing/extraction/pdf_to_text.py - S3 document cleanup · Deletes prefix-scoped S3 objects after confirmation.
src/document_processing/storage/delete_s3_bucket_documents.py - Project structure tools · Create a tree from JSON or export a repository as Markdown.
src/project_structure/create_structure_from_json.py - JWT secret generator · Generates secret material locally.
src/security/tokens/generate_jwt_secret_key.py
Operations
- Package commands · Registers independently runnable CLI commands and dependencies.
pyproject.toml - Environment contract · Defines required deployment credentials.
.env.example - CI workflow · Runs linting, smoke execution, and secret scanning.
.github/workflows/ci.yml
Connections 18
- Package commands → Main FastAPI app: defines runtime
- Package commands → AI provider CLIs: registers commands
- Main FastAPI app → SharePoint routes: mounts
- SharePoint routes → SharePoint use cases: orchestrates
- SharePoint use cases → SharePoint client: uses
- SharePoint settings → SharePoint client: configures
- Outlook API → Mailbox service: orchestrates
- Mailbox service → Outlook client: uses
- Auth FastAPI app → Auth routes: mounts
- Auth routes → Auth application service: delegates
- Auth application service → Entra adapter: validates identity
- Auth application service → OAuth adapter: exchanges codes
- Auth application service → User repository: looks up users
- Environment contract → SharePoint settings: supplies credentials
- Environment contract → AI provider CLIs: supplies credentials
- Environment contract → Auth FastAPI app: supplies secrets
- CI workflow → Package commands: validates
- Document conversion tools → S3 document cleanup: operates alongside