# tamanna456760-it/tamanna-server architecture

> Architecture diagram of the GitHub repository tamanna456760-it/tamanna-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tamanna456760-it/tamanna-server
- Repository: https://github.com/tamanna456760-it/tamanna-server

## Overview

1. **Overall shape**
   This repository is not a single app; it is an operations/control-plane package for **bd-king-r7**. The core architecture is a **central orchestrator** plus **per-server agents** that automate sync, fix/build, commit, and reporting across multiple machines.

2. **Central orchestrator**
   The orchestrator is the system-of-record for automated runs. The README describes it as a **Flask service** that accepts JSON reports and serves a small dashboard on port 8000. The tree also contains a **.NET 8 orchestrator project** (`bd-king-orchestrator.csproj`, `program.cs`, `appsettings.json`, `appdbcontext.cs`), so this repo appears to carry both an orchestrator implementation and build artifacts/variants around it.

3. **Agent runtime on each host**
   `agent.py` is the per-server worker. It reads machine-specific config from `agent.example.yml` / `agent.yml`, runs on a timer or as a service, and uses the local repo checkout to perform:
   - safe sync/update
   - optional fix commands
   - build/test commands
   - marker/version updates
   - git commit and optional push
   - JSON status reporting back to the orchestrator

4. **Primary data flow**
   The main flow is:
   **source repo on a server → agent executes commands locally → agent emits report JSON → orchestrator stores/displays history**.  
   The report path is the main boundary between distributed workers and the central dashboard.

5. **Safety and concurrency boundaries**
   The design is intentionally cautious:
   - per-run locking prevents overlapping executions
   - push is disabled by default
   - dedicated automation branch is recommended
   - logs go to `/var/log`
   - token-based auth gates agent-to-orchestrator traffic  
   These controls are central to the architecture because the system is allowed to modify code automatically.

6. **Configuration model**
   Configuration is heavily file-driven and split by concern:
   - `agent.example.yml`, `ai_sync_config.json`, `sync_config.json`, `monitoring.json`
   - `Config/Config.json`, `app_config.json`, `appsettings.json`
   - `.env`, `.env.example`
   - many domain-specific JSON files such as `Metadata.json`, `system_identity.json`, `reports.db`, `symptoms_db.json`  
   This suggests the system is designed to be redeployed across many hosts with different repo paths, branches, and command hooks.

7. **Persistence and state**
   Persistent state is mostly lightweight and local:
   - `reports.db` for run history/records
   - JSON files for configuration and monitoring state
   - marker/text files used by sync flows and status tracking  
   The orchestrator likely keeps central history, while agents keep local runtime state and logs.

8. **Deployment and runtime plumbing**
   Operational deployment is built around:
   - `docker-compose.yml` / `dockerfile` for central orchestration
   - `bd-king-agent.service`, `sync_and_add.service`, `sync_and_add.timer`, `autometick.service` for systemd-based agent execution
   - shell wrappers like `autorun.sh`, `autosync.sh`, `setup_service.sh`, `install_orchestrator.sh`  
   The repo is optimized for headless server automation rather than interactive use.

9. **Supporting automation ecosystem**
   The tree contains many adjunct scripts in Python, JS, and shell (`auto_sync.py`, `cloud_auto_sync.py`, `monitor.py`, `power_engine.py`, `server.py`, `server.js`, `ai_control.py`, `ai_engine.py`, etc.). These look like a broader toolbox around the same domain: synchronization, monitoring, power/control flows, and AI-assisted coordination. They are adjacent subsystems, not all part of the core agent/orchestrator path.

10. **Network and name-resolution sidecar**
   The `Dns/` directory (`named.conf`, zone files) and related shell scripts (`check_domen.sh`, `firewall_chant.sh`, `gcp_security_audit.sh`) indicate the repo also contains infrastructure support for DNS and host/network hardening. These are operational dependencies around the sync platform rather than its main business logic.

11. **UI and presentation surfaces**
   There are several small presentation assets (`Wabsite/Index.html`, `index.html`, `style.css`, `bd-king-r7.html`, `bd-king-r7_login.html`, `device_location.html`) plus an Android/Java entrypoint (`mainactivity.java`, `androidmanifest.xml`, `activity_main.xml`). These appear to be auxiliary interfaces or demos, not the primary control path.

12. **How to diagram it**
   A good architecture diagram should center on:
   - **Agent nodes** running on multiple servers
   - **Central orchestrator** receiving authenticated reports
   - **Local repo checkout and build/fix execution** on each node
   - **Config/filesystem state**, **logs**, and **report storage**
   - **Deployment layer** via Docker and systemd
   - Optional supporting boxes for **DNS/network tooling** and the **extra automation scripts** around the core loop

Main entry points: [`program.cs`](https://github.com/tamanna456760-it/tamanna-server/blob/main/program.cs) (Orchestrator), [`agent.py`](https://github.com/tamanna456760-it/tamanna-server/blob/main/agent.py) (Agent), [`firewall_chant.sh`](https://github.com/tamanna456760-it/tamanna-server/blob/main/firewall_chant.sh) (Firewall), [`monitor.py`](https://github.com/tamanna456760-it/tamanna-server/blob/main/monitor.py) (Monitor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration"]
  node_program_cs["Orchestrator<br/>.NET control-plane<br/>[program.cs]"]
  node_appdbcontext_cs["DB context<br/>data access<br/>[appdbcontext.cs]"]
  node_appsettings_json["App config<br/>runtime config<br/>[appsettings.json]"]
  node_reports_db[("Reports DB<br/>history store<br/>[reports.db]")]
  node_readme_md["README<br/>operator docs<br/>[README.md]"]
end

subgraph group_agent["Agent runtime"]
  node_agent_py["Agent<br/>worker runtime<br/>[agent.py]"]
  node_agent_example_yml["Agent config<br/>host config<br/>[agent.example.yml]"]
  node_sync_config_json["Sync config<br/>sync policy<br/>[sync_config.json]"]
  node_monitoring_json["Monitor config<br/>monitoring config<br/>[monitoring.json]"]
  node_auto_sync_py["Sync flow<br/>automation script<br/>[auto_sync.py]"]
  node_fix_yml["Fix rules<br/>command config<br/>[fix.yml]"]
  node_monitor_py["Monitor<br/>status collector<br/>[monitor.py]"]
end

subgraph group_ops["Operations"]
  node_docker_compose_yml["Compose<br/>deployment<br/>[docker-compose.yml]"]
  node_bd_king_agent_service["Agent service<br/>systemd unit"]
  node_setup_service_sh["Setup service<br/>bootstrap script<br/>[setup_service.sh]"]
  node_dns_dir[("DNS<br/>network config")]
  node_firewall_chant_sh["Firewall<br/>hardening script<br/>[firewall_chant.sh]"]
end

subgraph group_ui["Interfaces"]
  node_index_html["Web UI<br/>static page<br/>[index.html]"]
  node_wabsite_index_html["Site home<br/>static page<br/>[Index.html]"]
  node_mainactivity_java["Android UI<br/>mobile entrypoint<br/>[mainactivity.java]"]
end

node_readme_md -->|"describes"| node_program_cs
node_program_cs -->|"uses"| node_appdbcontext_cs
node_program_cs -->|"reads"| node_appsettings_json
node_program_cs -->|"stores"| node_reports_db
node_program_cs -->|"serves"| node_index_html
node_agent_example_yml -->|"configures"| node_agent_py
node_sync_config_json -->|"configures"| node_agent_py
node_monitoring_json -->|"configures"| node_monitor_py
node_agent_py -->|"invokes"| node_auto_sync_py
node_agent_py -->|"applies"| node_fix_yml
node_agent_py -->|"reports"| node_monitor_py
node_agent_py -->|"sends report"| node_program_cs
node_agent_py -->|"runs as"| node_bd_king_agent_service
node_setup_service_sh -->|"installs"| node_bd_king_agent_service
node_docker_compose_yml -->|"deploys"| node_program_cs
node_dns_dir -.->|"supports"| node_firewall_chant_sh
node_firewall_chant_sh -.->|"protects"| node_agent_py
node_wabsite_index_html -.->|"fronts"| node_program_cs
node_mainactivity_java -.->|"clients"| node_program_cs

click node_program_cs "https://github.com/tamanna456760-it/tamanna-server/blob/main/program.cs"
click node_appdbcontext_cs "https://github.com/tamanna456760-it/tamanna-server/blob/main/appdbcontext.cs"
click node_appsettings_json "https://github.com/tamanna456760-it/tamanna-server/blob/main/appsettings.json"
click node_reports_db "https://github.com/tamanna456760-it/tamanna-server/blob/main/reports.db"
click node_readme_md "https://github.com/tamanna456760-it/tamanna-server/blob/main/README.md"
click node_agent_py "https://github.com/tamanna456760-it/tamanna-server/blob/main/agent.py"
click node_agent_example_yml "https://github.com/tamanna456760-it/tamanna-server/blob/main/agent.example.yml"
click node_sync_config_json "https://github.com/tamanna456760-it/tamanna-server/blob/main/sync_config.json"
click node_monitoring_json "https://github.com/tamanna456760-it/tamanna-server/blob/main/monitoring.json"
click node_auto_sync_py "https://github.com/tamanna456760-it/tamanna-server/blob/main/auto_sync.py"
click node_fix_yml "https://github.com/tamanna456760-it/tamanna-server/blob/main/fix.yml"
click node_monitor_py "https://github.com/tamanna456760-it/tamanna-server/blob/main/monitor.py"
click node_docker_compose_yml "https://github.com/tamanna456760-it/tamanna-server/blob/main/docker-compose.yml"
click node_bd_king_agent_service "https://github.com/tamanna456760-it/tamanna-server/blob/main/bd-king-agent.service"
click node_setup_service_sh "https://github.com/tamanna456760-it/tamanna-server/blob/main/setup_service.sh"
click node_dns_dir "https://github.com/tamanna456760-it/tamanna-server/tree/main/Dns"
click node_firewall_chant_sh "https://github.com/tamanna456760-it/tamanna-server/blob/main/firewall_chant.sh"
click node_index_html "https://github.com/tamanna456760-it/tamanna-server/blob/main/index.html"
click node_wabsite_index_html "https://github.com/tamanna456760-it/tamanna-server/blob/main/Wabsite/Index.html"
click node_mainactivity_java "https://github.com/tamanna456760-it/tamanna-server/blob/main/mainactivity.java"

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_program_cs,node_appdbcontext_cs,node_appsettings_json,node_reports_db,node_readme_md toneBlue
class node_agent_py,node_agent_example_yml,node_sync_config_json,node_monitoring_json,node_auto_sync_py,node_fix_yml,node_monitor_py toneAmber
class node_docker_compose_yml,node_bd_king_agent_service,node_setup_service_sh,node_dns_dir,node_firewall_chant_sh toneMint
class node_index_html,node_wabsite_index_html,node_mainactivity_java toneRose
```

## Components

### Orchestration

Central service that records runs and serves the operator view.

- [Orchestrator](https://github.com/tamanna456760-it/tamanna-server/blob/main/program.cs): .NET control-plane · Central service entrypoint for run ingestion and dashboard behavior. · `program.cs`
- [DB context](https://github.com/tamanna456760-it/tamanna-server/blob/main/appdbcontext.cs): data access · Persistence layer used by the orchestrator. · `appdbcontext.cs`
- [App config](https://github.com/tamanna456760-it/tamanna-server/blob/main/appsettings.json): runtime config · Service settings for the orchestrator. · `appsettings.json`
- [Reports DB](https://github.com/tamanna456760-it/tamanna-server/blob/main/reports.db): history store · Stored run history and local records. · `reports.db`
- [README](https://github.com/tamanna456760-it/tamanna-server/blob/main/README.md): operator docs · Describes the control-plane and reporting workflow. · `README.md`

### Agent runtime

Per-host automation that syncs, fixes, builds, commits, and reports.

- [Agent](https://github.com/tamanna456760-it/tamanna-server/blob/main/agent.py): worker runtime · Per-server automation worker that executes the local run loop. · `agent.py`
- [Agent config](https://github.com/tamanna456760-it/tamanna-server/blob/main/agent.example.yml): host config · Example machine-specific agent configuration. · `agent.example.yml`
- [Sync config](https://github.com/tamanna456760-it/tamanna-server/blob/main/sync_config.json): sync policy · Settings for repository sync and update behavior. · `sync_config.json`
- [Monitor config](https://github.com/tamanna456760-it/tamanna-server/blob/main/monitoring.json): monitoring config · Monitoring and reporting thresholds for the automation loop. · `monitoring.json`
- [Sync flow](https://github.com/tamanna456760-it/tamanna-server/blob/main/auto_sync.py): automation script · Representative sync/update automation used by the agent ecosystem. · `auto_sync.py`
- [Fix rules](https://github.com/tamanna456760-it/tamanna-server/blob/main/fix.yml): command config · Representative fix/build command configuration. · `fix.yml`
- [Monitor](https://github.com/tamanna456760-it/tamanna-server/blob/main/monitor.py): status collector · Representative runtime for health and progress observation. · `monitor.py`

### Operations

Deployment, service management, and infrastructure support.

- [Compose](https://github.com/tamanna456760-it/tamanna-server/blob/main/docker-compose.yml): deployment · Containerized deployment for the orchestrator stack. · `docker-compose.yml`
- [Agent service](https://github.com/tamanna456760-it/tamanna-server/blob/main/bd-king-agent.service): systemd unit · System service for unattended agent execution. · `bd-king-agent.service`
- [Setup service](https://github.com/tamanna456760-it/tamanna-server/blob/main/setup_service.sh): bootstrap script · Installs and wires the headless runtime services. · `setup_service.sh`
- [DNS](https://github.com/tamanna456760-it/tamanna-server/tree/main/Dns): network config · Name-resolution and zone configuration support. · `Dns`
- [Firewall](https://github.com/tamanna456760-it/tamanna-server/blob/main/firewall_chant.sh): hardening script · Host/network access control and security hardening. · `firewall_chant.sh`

### Interfaces

Small presentation and client surfaces.

- [Web UI](https://github.com/tamanna456760-it/tamanna-server/blob/main/index.html): static page · Small presentation surface for the broader project. · `index.html`
- [Site home](https://github.com/tamanna456760-it/tamanna-server/blob/main/Wabsite/Index.html): static page · Alternative website landing page. · `Wabsite/Index.html`
- [Android UI](https://github.com/tamanna456760-it/tamanna-server/blob/main/mainactivity.java): mobile entrypoint · Android client entrypoint bundled with the repo. · `mainactivity.java`

## Connections

- README → Orchestrator: describes · Documentation explains the central orchestrator and reporting model.
- Orchestrator → DB context: uses · Orchestrator persists run history through its data layer.
- Orchestrator → App config: reads · Service behavior is configured through app settings.
- Orchestrator → Reports DB: stores · Central history and run records are kept in the reports database.
- Orchestrator → Web UI: serves · Dashboard and operator-facing pages are exposed by the control plane.
- Agent config → Agent: configures · Host-specific values drive the agent runtime.
- Sync config → Agent: configures · Sync policies shape local update behavior.
- Monitor config → Monitor: configures · Monitoring thresholds and state feed the observer loop.
- Agent → Sync flow: invokes · The agent executes sync/update automation locally.
- Agent → Fix rules: applies · Optional fix/build command sequences are part of the run loop.
- Agent → Monitor: reports · Worker status is collected and emitted by monitoring logic.
- Agent → Orchestrator: sends report · Authenticated JSON reports flow back to the central orchestrator.
- Agent → Agent service: runs as · Per-host execution is commonly managed as a systemd service.
- Setup service → Agent service: installs · Bootstrap scripts provision the agent service.
- Compose → Orchestrator: deploys · Container orchestration supports the central service stack.
- DNS → Firewall: supports · Network and DNS setup depends on host hardening and access rules.
- Firewall → Agent: protects · Agent traffic and host access are constrained by firewall policy.
- Site home → Orchestrator: fronts · A small site surface sits alongside the orchestrator.
- Android UI → Orchestrator: clients · Mobile client code connects to the broader control-plane ecosystem.
