# hirushiharan/python-testbed architecture

> Architecture diagram of the GitHub repository hirushiharan/python-testbed, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hirushiharan/python-testbed
- Repository: https://github.com/hirushiharan/python-testbed

## Overview

#### 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: [`src/auth/application/service.py`](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/application/service.py) (Auth application service), [`.env.example`](https://github.com/hirushiharan/python-testbed/blob/main/.env.example) (Environment contract), [`pyproject.toml`](https://github.com/hirushiharan/python-testbed/blob/main/pyproject.toml) (Package commands), [`src/main.py`](https://github.com/hirushiharan/python-testbed/blob/main/src/main.py) (Main FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["HTTP integrations"]
  node_main_app["Main FastAPI app<br/>http app<br/>[main.py]"]
  node_sharepoint_api["SharePoint routes<br/>api router<br/>[api.py]"]
  node_sharepoint_service["SharePoint use cases<br/>[service.py]"]
  node_sharepoint_client{{"SharePoint client<br/>external client<br/>[client.py]"}}
  node_sharepoint_settings["SharePoint settings<br/>[settings.py]"]
  node_email_api["Outlook API<br/>api router<br/>[api.py]"]
  node_email_service["Mailbox service<br/>[service.py]"]
  node_email_client{{"Outlook client<br/>external client<br/>[client.py]"}}
end

subgraph group_auth["Authentication"]
  node_auth_app["Auth FastAPI app<br/>http app<br/>[main.py]"]
  node_auth_api["Auth routes<br/>api router<br/>[router.py]"]
  node_auth_service["Auth application service<br/>[service.py]"]
  node_entra_adapter{{"Entra adapter<br/>identity adapter"}}
  node_oauth_adapter{{"OAuth adapter<br/>[oauth_adapter.py]"}}
  node_user_repository[("User repository<br/>[repository.py]")]
end

subgraph group_tools["CLI utilities"]
  node_ai_clis["AI provider CLIs<br/>CLI modules<br/>[anthropic_chat.py]"]
  node_document_pipeline["Document conversion tools<br/>CLI pipeline<br/>[pdf_to_text.py]"]
  node_s3_cleanup{{"S3 document cleanup<br/>destructive CLI"}}
  node_structure_tools["Project structure tools<br/>CLI tools"]
  node_jwt_secret_cli["JWT secret generator<br/>security CLI"]
end

subgraph group_operations["Operations"]
  node_package["Package commands<br/>packaging<br/>[pyproject.toml]"]
  node_env_contract["Environment contract<br/>environment template<br/>[.env.example]"]
  node_ci["CI workflow<br/>automation<br/>[ci.yml]"]
end

node_package -->|"defines runtime"| node_main_app
node_package -->|"registers commands"| node_ai_clis
node_main_app -->|"mounts"| node_sharepoint_api
node_sharepoint_api -->|"orchestrates"| node_sharepoint_service
node_sharepoint_service -->|"uses"| node_sharepoint_client
node_sharepoint_settings -.->|"configures"| node_sharepoint_client
node_email_api -->|"orchestrates"| node_email_service
node_email_service -->|"uses"| node_email_client
node_auth_app -->|"mounts"| node_auth_api
node_auth_api -->|"delegates"| node_auth_service
node_auth_service -->|"validates identity"| node_entra_adapter
node_auth_service -->|"exchanges codes"| node_oauth_adapter
node_auth_service -->|"looks up users"| node_user_repository
node_env_contract -.->|"supplies credentials"| node_sharepoint_settings
node_env_contract -.->|"supplies credentials"| node_ai_clis
node_env_contract -.->|"supplies secrets"| node_auth_app
node_ci -.->|"validates"| node_package
node_document_pipeline -.->|"operates alongside"| node_s3_cleanup

click node_package "https://github.com/hirushiharan/python-testbed/blob/main/pyproject.toml"
click node_main_app "https://github.com/hirushiharan/python-testbed/blob/main/src/main.py"
click node_sharepoint_api "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/api.py"
click node_sharepoint_service "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/service.py"
click node_sharepoint_client "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/client.py"
click node_sharepoint_settings "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/settings.py"
click node_email_api "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/email/api.py"
click node_email_service "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/email/service.py"
click node_email_client "https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/email/client.py"
click node_auth_app "https://github.com/hirushiharan/python-testbed/blob/main/src/auth/main.py"
click node_auth_api "https://github.com/hirushiharan/python-testbed/blob/main/src/auth/api/router.py"
click node_auth_service "https://github.com/hirushiharan/python-testbed/blob/main/src/auth/application/service.py"
click node_entra_adapter "https://github.com/hirushiharan/python-testbed/blob/main/src/auth/integrations/entra_id_adapter.py"
click node_oauth_adapter "https://github.com/hirushiharan/python-testbed/blob/main/src/auth/integrations/oauth_adapter.py"
click node_user_repository "https://github.com/hirushiharan/python-testbed/blob/main/src/auth/infrastructure/repository.py"
click node_ai_clis "https://github.com/hirushiharan/python-testbed/blob/main/src/ai/providers/anthropic_chat.py"
click node_document_pipeline "https://github.com/hirushiharan/python-testbed/blob/main/src/document_processing/extraction/pdf_to_text.py"
click node_s3_cleanup "https://github.com/hirushiharan/python-testbed/blob/main/src/document_processing/storage/delete_s3_bucket_documents.py"
click node_structure_tools "https://github.com/hirushiharan/python-testbed/blob/main/src/project_structure/create_structure_from_json.py"
click node_jwt_secret_cli "https://github.com/hirushiharan/python-testbed/blob/main/src/security/tokens/generate_jwt_secret_key.py"
click node_env_contract "https://github.com/hirushiharan/python-testbed/blob/main/.env.example"
click node_ci "https://github.com/hirushiharan/python-testbed/blob/main/.github/workflows/ci.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_app,node_sharepoint_api,node_sharepoint_service,node_sharepoint_client,node_sharepoint_settings,node_email_api,node_email_service,node_email_client toneBlue
class node_auth_app,node_auth_api,node_auth_service,node_entra_adapter,node_oauth_adapter,node_user_repository toneAmber
class node_ai_clis,node_document_pipeline,node_s3_cleanup,node_structure_tools,node_jwt_secret_cli toneMint
class node_package,node_env_contract,node_ci toneRose
```

## Components

### HTTP integrations

- [Main FastAPI app](https://github.com/hirushiharan/python-testbed/blob/main/src/main.py): http app · `src/main.py`
- [SharePoint routes](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/api.py): api router · `src/integrations/sharepoint/api.py`
- [SharePoint use cases](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/service.py): service · `src/integrations/sharepoint/service.py`
- [SharePoint client](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/client.py): external client · `src/integrations/sharepoint/client.py`
- [SharePoint settings](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/sharepoint/settings.py): settings · `src/integrations/sharepoint/settings.py`
- [Outlook API](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/email/api.py): api router · `src/integrations/email/api.py`
- [Mailbox service](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/email/service.py): service · `src/integrations/email/service.py`
- [Outlook client](https://github.com/hirushiharan/python-testbed/blob/main/src/integrations/email/client.py): external client · `src/integrations/email/client.py`

### Authentication

- [Auth FastAPI app](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/main.py): http app · Separately composed authentication application. · `src/auth/main.py`
- [Auth routes](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/api/router.py): api router · `src/auth/api/router.py`
- [Auth application service](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/application/service.py): application service · `src/auth/application/service.py`
- [Entra adapter](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/integrations/entra_id_adapter.py): identity adapter · `src/auth/integrations/entra_id_adapter.py`
- [OAuth adapter](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/integrations/oauth_adapter.py): oauth adapter · `src/auth/integrations/oauth_adapter.py`
- [User repository](https://github.com/hirushiharan/python-testbed/blob/main/src/auth/infrastructure/repository.py): repository · `src/auth/infrastructure/repository.py`

### CLI utilities

- [AI provider CLIs](https://github.com/hirushiharan/python-testbed/blob/main/src/ai/providers/anthropic_chat.py): CLI modules · Direct Anthropic, OpenRouter, and Google AI Studio integrations. · `src/ai/providers/anthropic_chat.py`
- [Document conversion tools](https://github.com/hirushiharan/python-testbed/blob/main/src/document_processing/extraction/pdf_to_text.py): CLI pipeline · PDF extraction, text cleanup, and Markdown-to-DOCX conversion. · `src/document_processing/extraction/pdf_to_text.py`
- [S3 document cleanup](https://github.com/hirushiharan/python-testbed/blob/main/src/document_processing/storage/delete_s3_bucket_documents.py): destructive CLI · Deletes prefix-scoped S3 objects after confirmation. · `src/document_processing/storage/delete_s3_bucket_documents.py`
- [Project structure tools](https://github.com/hirushiharan/python-testbed/blob/main/src/project_structure/create_structure_from_json.py): CLI tools · Create a tree from JSON or export a repository as Markdown. · `src/project_structure/create_structure_from_json.py`
- [JWT secret generator](https://github.com/hirushiharan/python-testbed/blob/main/src/security/tokens/generate_jwt_secret_key.py): security CLI · Generates secret material locally. · `src/security/tokens/generate_jwt_secret_key.py`

### Operations

- [Package commands](https://github.com/hirushiharan/python-testbed/blob/main/pyproject.toml): packaging · Registers independently runnable CLI commands and dependencies. · `pyproject.toml`
- [Environment contract](https://github.com/hirushiharan/python-testbed/blob/main/.env.example): environment template · Defines required deployment credentials. · `.env.example`
- [CI workflow](https://github.com/hirushiharan/python-testbed/blob/main/.github/workflows/ci.yml): automation · Runs linting, smoke execution, and secret scanning. · `.github/workflows/ci.yml`

## Connections

- 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
