Plan 001

Source: ADR-001 - Risk Analysis Management System
Created: 2026-02-17
Authors: inful, Count


Overview

Build a risk analysis management daemon with cause-outcome-mitigation model, Systems/Components hierarchy, and flexible calculation service.


Work Breakdown

Phase 1: Project Setup & Infrastructure

# Task Estimate Status
1.1 Initialize Go module (go mod init) 10m
1.2 Set up project structure per golang-standards 20m
1.3 Create go.mod with dependencies (chi, huma, sqlite3, migrations, sqlc) 15m
1.4 Set up Makefile with build/test/coverage targets 20m
1.5 Create .golangci.yml with preferred linters 15m
1.6 Set up git repository on Forgejo 10m

Phase 2: Database Schema & Migrations

# Task Estimate Status
2.1 Create database/migrations/001_initial_schema.sql 45m
2.2 Define System table -
2.3 Define Component table -
2.4 Define RiskOutcome table -
2.5 Define Causality table -
2.6 Define RiskPair table -
2.7 Define Mitigation table -
2.8 Set up golang-migrate migration runner 30m

Phase 3: SQLc Queries & Types

# Task Estimate Status
3.1 Create sqlc.yaml configuration 15m
3.2 Write queries/system.sql 30m
3.3 Write queries/component.sql 30m
3.4 Write queries/risk_outcome.sql 30m
3.5 Write queries/causality.sql 30m
3.6 Write queries/risk_pair.sql 30m
3.7 Write queries/mitigation.sql 30m
3.8 Run sqlc generate and verify types 20m

Phase 4: Domain Models & Services

# Task Estimate Status
4.1 Create internal/models/ with domain types 30m
4.2 Implement internal/service/system.go 45m
4.3 Implement internal/service/component.go 45m
4.4 Implement internal/service/risk_outcome.go 45m
4.5 Implement internal/service/causality.go 45m
4.6 Implement internal/service/risk_pair.go 45m
4.7 Implement internal/service/mitigation.go 45m
4.8 Implement internal/service/risk_calculator.go 60m

Phase 5: HTTP API (Huma/Chi)

# Task Estimate Status
5.1 Create internal/api/server.go with Chi router 30m
5.2 Set up Huma API with OpenAPI spec 30m
5.3 Implement System handlers 60m
5.4 Implement Component handlers 60m
5.5 Implement RiskOutcome handlers 60m
5.6 Implement Causality handlers 60m
5.7 Implement RiskPair handlers 60m
5.8 Implement Mitigation handlers 60m
5.9 Add error handling middleware 30m
5.10 Add logging middleware 30m

Phase 6: Testing

# Task Estimate Status
6.1 Write Example function tests for System 45m
6.2 Write Example function tests for Component 45m
6.3 Write Example function tests for RiskOutcome 45m
6.4 Write Example function tests for Causality 45m
6.5 Write Example function tests for RiskPair 45m
6.6 Write Example function tests for Mitigation 45m
6.7 Write integration tests for risk calculation 60m
6.8 Achieve >70% coverage ongoing

Phase 7: Configuration & Deployment

# Task Estimate Status
7.1 Create cmd/riskyd/main.go 30m
7.2 Add environment configuration 30m
7.3 Add config file support 30m
7.4 Set up graceful shutdown 20m
7.5 Create Dockerfile 30m
7.6 Write README.md with setup instructions 45m
7.7 Write API documentation 30m

Completion Criteria

  • All API endpoints functional
  • Database migrations working
  • Risk calculation interface implemented
  • Tests passing with >70% coverage
  • Documentation complete
  • Code follows coding standards (linting passes)
  • Repository on Forgejo with inful as admin

Current Status

Last updated: 2026-02-18 16:10 UTC

Phase 5 (HTTP API) is now complete with:

  • Component handlers (CRUD)
  • Server.go with Chi/Huma setup
  • Logging and health check middleware

Phase 7 (Configuration & Deployment) in progress:

  • cmd/riskyd/main.go with SQLite init, migrations, graceful shutdown, env config
Phase Progress
Phase 1: Setup 6/6 ✅
Phase 2: Database 8/8 ✅
Phase 3: SQLc 8/8 ✅
Phase 4: Services 8/8 ✅
Phase 5: API 10/10 ✅
Phase 6: Testing 4/8 ⏳
Phase 7: Deploy 5/7 ✅

Overall: 48/55 tasks complete


Estimated Timeline

Phase Duration Cumulative
Phase 1 1.5h 1.5h
Phase 2 2.5h 4h
Phase 3 4h 8h
Phase 4 5.5h 13.5h
Phase 5 7.5h 21h
Phase 6 6h 27h
Phase 7 3.5h 30.5h

Total Estimated: ~30-35 hours


Next Action

Phases 1-5 and most of 7 complete. Remaining:

  • Phase 3.8: Run sqlc generate (awaiting local run)
  • Phase 6: Complete testing (add tests for remaining services, integration tests)
  • Phase 7.3: Config file support (optional)
  • Phase 7.5: Dockerfile

Recommended next: Run sqlc generate locally, then add integration tests to reach >70% coverage.