# adrian-cai/automation_platform architecture

> Architecture diagram of the GitHub repository adrian-cai/automation_platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adrian-cai/automation_platform
- Repository: https://github.com/adrian-cai/automation_platform

## Overview

#### 1. Purpose and Runtime Shape
AutoTest is a full-stack test-management and orchestration platform: it stores test assets and tasks, schedules or manually triggers work in Jenkins, receives results, and presents live dashboards and reports. Jenkins performs tests; this system owns lifecycle, persistence, visibility, and control.

Entry points are the React/Vite client at `src/main.tsx` and Express server at `server/index.ts`. Shared API/domain contracts reside in `shared/types/`.

#### 2. Frontend Application
The browser UI is a React 18 SPA with authentication, protected navigation, dashboard, case management, tasks, reports, and an AI workbench.

- Shell, routing, and global state: `src/App.tsx`, `src/contexts/AuthContext.tsx`, `src/components/ProtectedRoute.tsx`
- Operational screens: `src/pages/tasks/Tasks.tsx`, `src/pages/cases/AICases.tsx`, `src/pages/reports/Reports.tsx`
- API and real-time clients: `src/api/index.ts`, `src/services/websocket.ts`

UI actions call Express APIs; task and execution state is refreshed via polling and Socket.IO updates.

#### 3. API, Security, and Service Boundary
Express routes form the public control boundary. Middleware applies JWT authentication, callback-specific Jenkins authentication, validation, logging, and rate limits before business services execute.

- Server composition: `server/index.ts`, `server/middleware/auth.ts`, `server/middleware/JenkinsAuthMiddleware.ts`
- Core API domains: `server/routes/tasks.ts`, `server/routes/executions.ts`, `server/routes/jenkins.ts`
- Cross-cutting controls: `server/middleware/authRateLimiter.ts`, `server/middleware/RequestValidator.ts`

Auth supports user registration/login and password flows through `server/routes/auth.ts` and `server/services/AuthService.ts`.

#### 4. Task Scheduling and Execution Lifecycle
`TaskSchedulerService` is the central orchestration engine. It restores active jobs, polls persisted task definitions, evaluates five-field cron schedules, deduplicates scheduled windows, enforces FIFO/concurrency policy, and dispatches eligible runs. It also handles retries and cancellation state.

- Scheduler and queue policy: `server/services/TaskSchedulerService/service.ts`, `server/services/TaskSchedulerService/queuePolicy.ts`, `server/services/TaskSchedulerService/cron.ts`
- Execution lifecycle/state synchronization: `server/services/ExecutionService/service.ts`, `server/services/ExecutionService/statusSync.ts`
- Task/execution persistence access: `server/repositories/ExecutionRepository.ts`, `server/entities/TaskExecution.ts`, `server/entities/TestRun.ts`

Flow: UI/API or cron creates an execution request → scheduler admits it → Jenkins is triggered → callback/polling updates run and per-case results → live clients and reports observe the final state.

#### 5. Jenkins and External Execution Boundary
Jenkins is an external executor reached through the Jenkins service and routes. The platform records a local execution before/while triggering Jenkins, then accepts authenticated callbacks or uses hybrid polling/status diagnostics to reconcile asynchronous outcomes.

- Trigger and integration logic: `server/services/JenkinsService.ts`, `server/routes/jenkinsExecutionRoutes.ts`
- Callback and status handling: `server/routes/executions.ts`, `server/services/CallbackQueue.ts`, `server/services/HybridSyncService/service.ts`
- Monitoring/repair diagnostics: `server/services/ExecutionMonitorService.ts`, `server/services/JenkinsStatusService/service.ts`

Results may trigger email notification and Socket.IO broadcasts via `server/services/EmailService.ts` and `server/services/WebSocketService.ts`.

#### 6. Persistence, Reporting, and AI Requirement Flow
MariaDB is accessed through TypeORM configuration, entities, and repositories; it is the source of truth for users, cases, tasks, runs, results, workspaces, and daily summaries. Dashboard services derive operational aggregates from this data.

- Database boundary: `server/config/dataSource.ts`, `server/entities/index.ts`, `server/repositories/DashboardRepository.ts`
- Reporting: `server/services/DashboardService.ts`, `server/routes/dashboard.ts`
- AI/requirement ingestion and case generation: `server/routes/requirementFiles.ts`, `server/services/requirementFiles/uploadService.ts`, `server/services/AiCaseGenerationService/service.ts`

The AI workbench accepts requirement files/text, parses and stores structured inputs, generates/normalizes case plans, and exposes workspace/case-map views through AI case APIs.

#### 7. Deployment and Automation
Node.js 20 runs both TypeScript services; Vite builds the client. Production uses PM2 and can be containerized. MariaDB, Jenkins, Git repositories, SMTP, and GitHub Actions are material integrations.

- Runtime/deployment: `Dockerfile`, `ecosystem.config.js`, `server/config/database.ts`
- CI/CD and smoke testing: `.github/workflows/github-ci.yml`, `.github/workflows/deploy.yml`, `perf/smoke.js`
- Repository-sync utility: `.github/scripts/sync_cases.py`

Main entry points: [`server/services/ExecutionService/service.ts`](https://github.com/adrian-cai/automation_platform/blob/master/server/services/ExecutionService/service.ts) (Execution lifecycle), [`server/middleware/auth.ts`](https://github.com/adrian-cai/automation_platform/blob/master/server/middleware/auth.ts) (Auth and request controls), [`server/index.ts`](https://github.com/adrian-cai/automation_platform/blob/master/server/index.ts) (Express server), [`server/config/dataSource.ts`](https://github.com/adrian-cai/automation_platform/blob/master/server/config/dataSource.ts) (MariaDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_client_entry["SPA entry and shell<br/>React/Vite<br/>[main.tsx]"]
  node_protected_ui["Protected operations UI<br/>React pages<br/>[Tasks.tsx]"]
  node_client_api["API and realtime clients<br/>HTTP + Socket.IO<br/>[index.ts]"]
end

subgraph group_api["Express control plane"]
  node_server["Express server<br/>Node.js API<br/>[index.ts]"]
  node_security["Auth and request controls<br/>Express middleware<br/>[auth.ts]"]
  node_auth["User authentication<br/>Auth service<br/>[AuthService.ts]"]
  node_task_api["Task and execution APIs<br/>Express routes<br/>[tasks.ts]"]
  node_jenkins_api["Jenkins integration APIs<br/>Express routes"]
end

subgraph group_execution["Execution orchestration"]
  node_scheduler{{"Task scheduler<br/>Orchestration engine<br/>[service.ts]"}}
  node_execution_service["Execution lifecycle<br/>Execution service<br/>[service.ts]"]
  node_jenkins_service["Jenkins trigger service<br/>Integration service<br/>[JenkinsService.ts]"]
  node_result_sync["Hybrid result sync<br/>Status reconciliation<br/>[service.ts]"]
  node_notifications["Live notifications<br/>WebSocket + email"]
end

subgraph group_data["Data and insights"]
  node_database[("MariaDB<br/>System of record<br/>[dataSource.ts]")]
  node_reporting["Dashboard and reports<br/>Analytics service"]
  node_ai_ingestion["Requirement ingestion<br/>AI input service<br/>[uploadService.ts]"]
  node_ai_generation["AI case generation<br/>AI service<br/>[service.ts]"]
end

subgraph group_external["External systems"]
  node_jenkins{{"Jenkins<br/>External executor"}}
  node_smtp["SMTP<br/>Email provider"]
  node_ci["GitHub Actions<br/>CI/CD<br/>[github-ci.yml]"]
end

node_client_entry -->|"renders routes"| node_protected_ui
node_protected_ui -->|"user actions"| node_client_api
node_client_api -->|"HTTP and Socket.IO"| node_server
node_server -->|"applies controls"| node_security
node_security -->|"auth flows"| node_auth
node_security -->|"authorized requests"| node_task_api
node_security -->|"authenticated callbacks"| node_jenkins_api
node_task_api -->|"manual execution requests"| node_scheduler
node_scheduler -->|"admits runs"| node_execution_service
node_scheduler -->|"loads tasks and persists scheduling state"| node_database
node_execution_service -->|"persists runs and results"| node_database
node_execution_service -->|"dispatches execution"| node_jenkins_service
node_jenkins_service -->|"triggers job"| node_jenkins
node_jenkins -->|"callbacks"| node_jenkins_api
node_jenkins_api -->|"outcomes and status requests"| node_result_sync
node_result_sync -.->|"polls status"| node_jenkins
node_result_sync -->|"reconciled state"| node_execution_service
node_execution_service -->|"execution changes"| node_notifications
node_notifications -->|"live updates"| node_client_api
node_notifications -->|"result email"| node_smtp
node_database -->|"operational data"| node_reporting
node_reporting -->|"dashboard APIs"| node_server
node_protected_ui -->|"requirement input"| node_ai_ingestion
node_ai_ingestion -->|"structured requirements"| node_ai_generation
node_ai_generation -->|"case plans and workspaces"| node_database
node_ci -.->|"build and deploy"| node_server

click node_client_entry "https://github.com/adrian-cai/automation_platform/blob/master/src/main.tsx"
click node_protected_ui "https://github.com/adrian-cai/automation_platform/blob/master/src/pages/tasks/Tasks.tsx"
click node_client_api "https://github.com/adrian-cai/automation_platform/blob/master/src/api/index.ts"
click node_server "https://github.com/adrian-cai/automation_platform/blob/master/server/index.ts"
click node_security "https://github.com/adrian-cai/automation_platform/blob/master/server/middleware/auth.ts"
click node_auth "https://github.com/adrian-cai/automation_platform/blob/master/server/services/AuthService.ts"
click node_task_api "https://github.com/adrian-cai/automation_platform/blob/master/server/routes/tasks.ts"
click node_jenkins_api "https://github.com/adrian-cai/automation_platform/blob/master/server/routes/jenkinsExecutionRoutes.ts"
click node_scheduler "https://github.com/adrian-cai/automation_platform/blob/master/server/services/TaskSchedulerService/service.ts"
click node_execution_service "https://github.com/adrian-cai/automation_platform/blob/master/server/services/ExecutionService/service.ts"
click node_jenkins_service "https://github.com/adrian-cai/automation_platform/blob/master/server/services/JenkinsService.ts"
click node_result_sync "https://github.com/adrian-cai/automation_platform/blob/master/server/services/HybridSyncService/service.ts"
click node_notifications "https://github.com/adrian-cai/automation_platform/blob/master/server/services/WebSocketService.ts"
click node_database "https://github.com/adrian-cai/automation_platform/blob/master/server/config/dataSource.ts"
click node_reporting "https://github.com/adrian-cai/automation_platform/blob/master/server/services/DashboardService.ts"
click node_ai_ingestion "https://github.com/adrian-cai/automation_platform/blob/master/server/services/requirementFiles/uploadService.ts"
click node_ai_generation "https://github.com/adrian-cai/automation_platform/blob/master/server/services/AiCaseGenerationService/service.ts"
click node_ci "https://github.com/adrian-cai/automation_platform/blob/master/.github/workflows/github-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_client_entry,node_protected_ui,node_client_api toneBlue
class node_server,node_security,node_auth,node_task_api,node_jenkins_api toneAmber
class node_scheduler,node_execution_service,node_jenkins_service,node_result_sync,node_notifications toneMint
class node_database,node_reporting,node_ai_ingestion,node_ai_generation toneRose
class node_jenkins,node_smtp,node_ci toneIndigo
```

## Components

### React client

- [SPA entry and shell](https://github.com/adrian-cai/automation_platform/blob/master/src/main.tsx): React/Vite · Routes and global application state. · `src/main.tsx`
- [Protected operations UI](https://github.com/adrian-cai/automation_platform/blob/master/src/pages/tasks/Tasks.tsx): React pages · Tasks, AI cases, and reports screens. · `src/pages/tasks/Tasks.tsx`
- [API and realtime clients](https://github.com/adrian-cai/automation_platform/blob/master/src/api/index.ts): HTTP + Socket.IO · Calls APIs and receives execution updates. · `src/api/index.ts`

### Express control plane

- [Express server](https://github.com/adrian-cai/automation_platform/blob/master/server/index.ts): Node.js API · Composes public APIs and Socket.IO. · `server/index.ts`
- [Auth and request controls](https://github.com/adrian-cai/automation_platform/blob/master/server/middleware/auth.ts): Express middleware · JWT, Jenkins callback auth, validation, and rate limits. · `server/middleware/auth.ts`
- [User authentication](https://github.com/adrian-cai/automation_platform/blob/master/server/services/AuthService.ts): Auth service · Registration, login, and password flows. · `server/services/AuthService.ts`
- [Task and execution APIs](https://github.com/adrian-cai/automation_platform/blob/master/server/routes/tasks.ts): Express routes · Creates and controls tasks and executions. · `server/routes/tasks.ts`
- [Jenkins integration APIs](https://github.com/adrian-cai/automation_platform/blob/master/server/routes/jenkinsExecutionRoutes.ts): Express routes · Trigger endpoints and authenticated callback entry. · `server/routes/jenkinsExecutionRoutes.ts`

### Execution orchestration

- [Task scheduler](https://github.com/adrian-cai/automation_platform/blob/master/server/services/TaskSchedulerService/service.ts): Orchestration engine · Cron admission, deduplication, FIFO concurrency, retries, and cancellation. · `server/services/TaskSchedulerService/service.ts`
- [Execution lifecycle](https://github.com/adrian-cai/automation_platform/blob/master/server/services/ExecutionService/service.ts): Execution service · Creates local runs and synchronizes lifecycle state. · `server/services/ExecutionService/service.ts`
- [Jenkins trigger service](https://github.com/adrian-cai/automation_platform/blob/master/server/services/JenkinsService.ts): Integration service · Dispatches eligible runs to Jenkins. · `server/services/JenkinsService.ts`
- [Hybrid result sync](https://github.com/adrian-cai/automation_platform/blob/master/server/services/HybridSyncService/service.ts): Status reconciliation · Reconciles callbacks, polling, and diagnostics. · `server/services/HybridSyncService/service.ts`
- [Live notifications](https://github.com/adrian-cai/automation_platform/blob/master/server/services/WebSocketService.ts): WebSocket + email · Broadcasts state changes and sends result email. · `server/services/WebSocketService.ts`

### Data and insights

- [MariaDB](https://github.com/adrian-cai/automation_platform/blob/master/server/config/dataSource.ts): System of record · Stores users, cases, tasks, runs, results, workspaces, and summaries. · `server/config/dataSource.ts`
- [Dashboard and reports](https://github.com/adrian-cai/automation_platform/blob/master/server/services/DashboardService.ts): Analytics service · Derives operational aggregates from persisted data. · `server/services/DashboardService.ts`
- [Requirement ingestion](https://github.com/adrian-cai/automation_platform/blob/master/server/services/requirementFiles/uploadService.ts): AI input service · Accepts, parses, and stores requirement files and text. · `server/services/requirementFiles/uploadService.ts`
- [AI case generation](https://github.com/adrian-cai/automation_platform/blob/master/server/services/AiCaseGenerationService/service.ts): AI service · Generates and normalizes case plans. · `server/services/AiCaseGenerationService/service.ts`

### External systems

- **Jenkins**: External executor · Runs test jobs and emits asynchronous outcomes.
- **SMTP**: Email provider
- [GitHub Actions](https://github.com/adrian-cai/automation_platform/blob/master/.github/workflows/github-ci.yml): CI/CD · Builds, deploys, and runs smoke automation. · `.github/workflows/github-ci.yml`

## Connections

- SPA entry and shell → Protected operations UI: renders routes
- Protected operations UI → API and realtime clients: user actions
- API and realtime clients → Express server: HTTP and Socket.IO
- Express server → Auth and request controls: applies controls
- Auth and request controls → User authentication: auth flows
- Auth and request controls → Task and execution APIs: authorized requests
- Auth and request controls → Jenkins integration APIs: authenticated callbacks
- Task and execution APIs → Task scheduler: manual execution requests
- Task scheduler → Execution lifecycle: admits runs
- Task scheduler → MariaDB: loads tasks and persists scheduling state
- Execution lifecycle → MariaDB: persists runs and results
- Execution lifecycle → Jenkins trigger service: dispatches execution
- Jenkins trigger service → Jenkins: triggers job
- Jenkins → Jenkins integration APIs: callbacks
- Jenkins integration APIs → Hybrid result sync: outcomes and status requests
- Hybrid result sync → Jenkins: polls status
- Hybrid result sync → Execution lifecycle: reconciled state
- Execution lifecycle → Live notifications: execution changes
- Live notifications → API and realtime clients: live updates
- Live notifications → SMTP: result email
- MariaDB → Dashboard and reports: operational data
- Dashboard and reports → Express server: dashboard APIs
- Protected operations UI → Requirement ingestion: requirement input
- Requirement ingestion → AI case generation: structured requirements
- AI case generation → MariaDB: case plans and workspaces
- GitHub Actions → Express server: build and deploy
