Repository guidance for coding agents working in thin-controller.
thin-controller is a Python 3.12+ FastAPI application for viewing and controlling AWS EC2 instances from a small web UI. It is packaged as:
- a local web app served by uvicorn
- an AWS Lambda handler via Mangum
- a container image used by the Fargate deployment path
The app only acts on EC2 instances tagged with thin_controller_managed=true.
thin_controller/__init__.py: FastAPI app, static asset routes, instance list/update APIs, health checkthin_controller/__main__.py: CLI entrypoint for local development viathin-controllerthin_controller/handler.py: Lambda handler wrapperthin_controller/scheduler_handler.py: hourly scheduler Lambda handler for time-based power controlthin_controller/ec2.py: shared EC2 list/get/start/stop helpers used by manual and scheduled control pathsthin_controller/schedule.py: tag parsing and schedule evaluation logicthin_controller/models.py: Pydantic models and environment-backed configthin_controller/static/: HTML and CSS for the built-in UItests/: pytest coverage for API, CLI, and model parsingterraform/: AWS deployment code for Lambda and Fargate
- Use
uvfor dependency management and command execution. - Use
justtargets when they match the task. - Prefer small, direct changes over new abstractions.
Common commands:
uv sync
uv run thin-controller --reload
just test
just lint
just types
just check
just coverage
just build_containerTHIN_CONTROLLER_REGIONScontrols which AWS regions are scanned. If unset, the app defaults to all EC2 regions returned by boto3.- AWS credentials must be available to the running process for EC2 reads and state changes.
- Allowed state transitions are intentionally narrow:
stopped -> startrunning -> stop
- Other EC2 states are displayed but not actionable.
- Scheduled power control is tag-driven and only applies when both of these tags are present:
thin-controller-timezonethin-controller-on-hours
thin-controller-on-hoursuses a singleHH-HH24-hour window and supports overnight ranges such as22-06.thin-controller-always-onvalues1andtruedisable scheduler action for that instance.- Missing schedule tags mean "do nothing", not "force stop".
- Preserve the current FastAPI and Pydantic style unless there is a clear reason to refactor.
- Keep the UI simple. It is a static HTML page using htmx and Nunjucks, not a frontend app framework.
- Prefer updating tests alongside behavior changes.
- Avoid broad refactors unless they directly reduce local complexity.
- Keep manual control and scheduled control on the same backend EC2 helpers so they do not drift.
- In documentation and comments, always use project-relative paths. Never use full on-disk paths because they are not portable and may expose private information.
- Do not edit generated or vendored Terraform packaging artifacts unless the task is specifically about deployment packaging:
terraform/thin_controller_layer/terraform/thin_controller_layer.zipterraform/thin_controller.zip
- Terraform supports two hosting modes:
- Lambda via
thin_controller/handler.py - Fargate using
ghcr.io/yaleman/thin-controller:latest
- Lambda via
- Scheduled power control is a separate optional Terraform module under
terraform/modules/scheduled_power_control. - The scheduler Lambda is separate from the HTTP Lambda and can be enabled even when the UI is hosted on Fargate.
- The Lambda packaging step currently installs dependencies with local
python3.13while targeting the AWS Lambdapython3.12runtime.