# agicto/codingcto architecture

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

- Interactive diagram: https://gitdiagram.com/agicto/codingcto
- Repository: https://github.com/agicto/codingcto

## Overview

1. **Repository shape**
   - This is a two-service monorepo: `api/` is the Go backend, and `web/` is the Next.js 16 console.
   - They are deployed as separate units and communicate over HTTP; the README explicitly emphasizes “shares contracts, not code.”

2. **Backend entrypoints and runtime boundaries**
   - The Go side has multiple executable entrypoints under `api/cmd/`: main server, a local SpecForge runtime, a generator, and several tooling commands.
   - `internal/bootstrap` and `internal/wiring` assemble the app, routes, database, middleware, and dependency graph. `wire_gen.go` indicates DI is generated via Wire.
   - The HTTP API is exposed through `routes/api.go` and `internal/infra/router`, with middleware layered around it.

3. **Backend layering**
   - The backend is organized in a DDD-flavored structure:
     - `internal/domain` holds core entities, value objects, events, and invariants.
     - `internal/modules/*` contains feature modules such as auth-related user, workspace, project, planning, execution, GitHub integration, audit, API keys, and verification.
     - `internal/infra/*` contains cross-cutting infrastructure: database, Redis, cache, queue, scheduler, events, logging, metrics, tracing, HTTP client, storage, rate limiting, retry, plugin loading, and health/monitoring.
   - This separation is the main architectural boundary for the Go service.

4. **Core product workflow: SpecForge**
   - The main business flow is “idea → planning → prompt compilation → execution → CI feedback → fix attempts → delivery.”
   - On the API side, this is reflected by modules for `planning`, `execution`, `repocontext`, `project`, `workspace`, `githubintegration`, and `verification`.
   - The database migrations show the supporting persistence model: planning tables, compiled prompts, repo profiles, execution tables, fix attempts, task events, architecture snapshots, skills, runtimes, and project tables.

5. **Execution system and local runtime**
   - Execution is not just a queue job; it is a distributed claim/execute loop.
   - The API schedules and stores tasks, while `cmd/specforge-runtime` runs locally beside a checked-out repository, claims `codex_cli` tasks, sends heartbeats, streams task events, and submits results back to the API.
   - The `execution` module and `internal/infra/queue`, `schedule`, `workflow`, and `events` packages suggest orchestration is event- and task-driven rather than synchronous.

6. **GitHub integration boundary**
   - GitHub is a major external dependency, with dedicated integration code under `internal/modules/githubintegration`.
   - The repository models GitHub app configuration, settings, repository clients, webhook parsing, and webhook event storage.
   - This integration appears to be how CodingCTO links product plans and execution results back to repositories, pull requests, and CI signals.

7. **Security, identity, and audit**
   - Authentication and access control are handled by API keys, JWT, password reset tokens, user records, and workspace/project scoping.
   - `audit` persists business-relevant actions, and migrations add audit log business fields.
   - This indicates a strong separation between authenticated product usage and the execution/runtime credentials used by the local worker.

8. **Persistence and data model**
   - Persistence is migration-first, with an explicit `database/migrations` folder and seeders.
   - The backend supports multiple storage concerns: relational data in the main DB, Redis-backed rate limiting/cache, file/object storage, and event stores/logs where needed.
   - The presence of observed database logging and migration tooling suggests operational visibility is part of the architecture, not an afterthought.

9. **Configuration, observability, and resilience**
   - The infra layer includes config loading/watching, logging, metrics, tracing, health checks, circuit breaker, retry, singleflight, and request middleware.
   - These cross-cutting systems are applied around the API rather than embedded in business modules.
   - This matters for diagrams because the API is more like a platform service with many guardrails than a thin CRUD server.

10. **Web app structure**
   - The frontend is a Next.js App Router application with route groups for public site, auth, protected console, and devtools.
   - The console under `src/app/(protected)/(console)` mirrors the product domains: projects, SpecForge, skills, agents, settings, and codingcto-specific views.
   - `middleware.ts` and the auth route handlers show that session gating happens at the web edge as well as in the backend.

11. **Frontend feature architecture**
   - The web app is organized feature-first under `src/features/*`, not by page-only structure.
   - Major client-side domains include `auth`, `project`, `specforge`, `agents`, `skills`, and `example`, each with components, hooks, services, and domain logic.
   - This is important for an architecture diagram because much of the UI state and workflow logic lives in reusable feature packages rather than directly in page components.

12. **Frontend data flow**
   - The web app uses server-side API routes as a proxy layer for some auth/session operations and a catch-all `/api/v1/[...path]` bridge to the backend API.
   - Client features use hooks, stores, and services to consume backend data and drive console state.
   - There is a clear separation between presentation components, browser state, and server-side request/session handling.

13. **Shared product concerns in the console**
   - The console is centered on operational views of the SpecForge pipeline: project onboarding, repository context, planning review, prompt compilation, runtime setup, execution health, CI review, and delivery status.
   - The UI is not just a dashboard; it is a workflow surface for manipulating the artifacts produced by the backend pipeline.

14. **Tooling, tests, and delivery**
   - The repo has strong automated support: Go unit/integration/feature tests, Kest flow tests, generated DI, and CI workflows in GitHub Actions.
   - The API also ships developer tools like APIDoc parsing, route helpers, and migration/testing utilities.
   - The web side includes linting, type-checking, Vitest, and a substantial design-system/component layer.

15. **How to draw the main system boundary**
   - The clearest high-level diagram is: user/browser → Next.js console → Go API → database/Redis/GitHub/external AI runtime.
   - The API owns durable state, orchestration, and integrations; the web app owns interaction and workflow visualization.
   - The local SpecForge runtime is a third operational actor that connects the API to real repository execution on a developer or runner machine.

Main entry points: [`api`](https://github.com/agicto/codingcto/tree/main/api) (API service), [`api/internal/modules`](https://github.com/agicto/codingcto/tree/main/api/internal/modules) (Feature modules), [`web`](https://github.com/agicto/codingcto/tree/main/web) (Web app), [`api/internal/bootstrap/app.go`](https://github.com/agicto/codingcto/blob/main/api/internal/bootstrap/app.go) (Bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_repo["Monorepo"]
  node_repo["codingcto<br/>monorepo"]
end

subgraph group_group_api["Go API"]
  node_api_service["API service<br/>backend service"]
  node_api_cmd_server["Server cmd<br/>api entrypoint<br/>[main.go]"]
  node_api_cmd_runtime["SpecForge runtime<br/>worker entrypoint<br/>[main.go]"]
  node_api_cmd_generator["Generator cmd<br/>tooling entrypoint<br/>[main.go]"]
  node_api_bootstrap["Bootstrap<br/>composition layer<br/>[app.go]"]
  node_api_wiring["Wiring<br/>di composition<br/>[wire_gen.go]"]
  node_api_routes["API routes<br/>http routing<br/>[api.go]"]
  node_api_router["Router<br/>http infra<br/>[router.go]"]
  node_api_domain{{"Domain model<br/>domain layer"}}
  node_api_modules["Feature modules<br/>module layer"]
  node_api_infra["Infrastructure<br/>cross-cutting infra"]
  node_api_db[("Database<br/>persistence")]
  node_api_redis[("Redis<br/>cache/rate-limit<br/>[redis.go]")]
  node_api_github["GitHub<br/>external integration"]
  node_api_ai{{"AI runtime<br/>external dependency<br/>[ai.go]"}}
end

subgraph group_group_web["Next.js Console"]
  node_web_app["Web app<br/>frontend service"]
  node_web_middleware["Web middleware<br/>edge auth<br/>[middleware.ts]"]
  node_web_api_bridge["API bridge<br/>server routes<br/>[route.ts]"]
  node_web_console["Console UI<br/>app router"]
  node_web_features["Feature packages<br/>feature layer"]
  node_web_state["Client state<br/>browser state"]
end

node_repo -->|"contains"| node_api_service
node_repo -->|"contains"| node_web_app
node_api_service -->|"starts"| node_api_cmd_server
node_api_service -->|"starts"| node_api_cmd_runtime
node_api_service -->|"starts"| node_api_cmd_generator
node_api_cmd_server -->|"boots"| node_api_bootstrap
node_api_bootstrap -->|"uses"| node_api_wiring
node_api_bootstrap -->|"mounts"| node_api_routes
node_api_routes -->|"runs on"| node_api_router
node_api_router -->|"dispatches"| node_api_modules
node_api_modules -->|"models"| node_api_domain
node_api_modules -->|"depends on"| node_api_infra
node_api_infra -->|"persists"| node_api_db
node_api_infra -->|"coordinates"| node_api_redis
node_api_modules -->|"integrates"| node_api_github
node_api_modules -->|"calls"| node_api_ai
node_api_cmd_runtime -->|"claims tasks"| node_api_service
node_web_app -->|"gates"| node_web_middleware
node_web_app -->|"proxies"| node_web_api_bridge
node_web_app -->|"renders"| node_web_console
node_web_console -->|"composes"| node_web_features
node_web_features -->|"uses"| node_web_state
node_web_api_bridge -.->|"HTTP to"| node_api_service
node_web_console -.->|"fetches from"| node_api_service
node_api_service -.->|"reads/writes"| node_api_db
node_api_service -.->|"uses"| node_api_redis
node_api_service -.->|"webhooks"| node_api_github

click node_api_service "https://github.com/agicto/codingcto/tree/main/api"
click node_api_cmd_server "https://github.com/agicto/codingcto/blob/main/api/cmd/server/main.go"
click node_api_cmd_runtime "https://github.com/agicto/codingcto/blob/main/api/cmd/specforge-runtime/main.go"
click node_api_cmd_generator "https://github.com/agicto/codingcto/blob/main/api/cmd/generator/main.go"
click node_api_bootstrap "https://github.com/agicto/codingcto/blob/main/api/internal/bootstrap/app.go"
click node_api_wiring "https://github.com/agicto/codingcto/blob/main/api/internal/wiring/wire_gen.go"
click node_api_routes "https://github.com/agicto/codingcto/blob/main/api/routes/api.go"
click node_api_router "https://github.com/agicto/codingcto/blob/main/api/internal/infra/router/router.go"
click node_api_domain "https://github.com/agicto/codingcto/tree/main/api/internal/domain"
click node_api_modules "https://github.com/agicto/codingcto/tree/main/api/internal/modules"
click node_api_infra "https://github.com/agicto/codingcto/tree/main/api/internal/infra"
click node_api_db "https://github.com/agicto/codingcto/tree/main/api/database"
click node_api_redis "https://github.com/agicto/codingcto/blob/main/api/internal/infra/redis/redis.go"
click node_api_github "https://github.com/agicto/codingcto/tree/main/api/internal/modules/githubintegration"
click node_api_ai "https://github.com/agicto/codingcto/blob/main/api/internal/capabilities/ai/ai.go"
click node_web_app "https://github.com/agicto/codingcto/tree/main/web"
click node_web_middleware "https://github.com/agicto/codingcto/blob/main/web/middleware.ts"
click node_web_api_bridge "https://github.com/agicto/codingcto/blob/main/web/src/app/v1/[...path]/route.ts"
click node_web_console "https://github.com/agicto/codingcto/tree/main/web/src/app/(protected)/(console)/console"
click node_web_features "https://github.com/agicto/codingcto/tree/main/web/src/features"
click node_web_state "https://github.com/agicto/codingcto/tree/main/web/src/store"

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_repo toneBlue
class node_api_service,node_api_cmd_server,node_api_cmd_runtime,node_api_cmd_generator,node_api_bootstrap,node_api_wiring,node_api_routes,node_api_router,node_api_domain,node_api_modules,node_api_infra,node_api_db,node_api_redis,node_api_github,node_api_ai toneAmber
class node_web_app,node_web_middleware,node_web_api_bridge,node_web_console,node_web_features,node_web_state toneMint
```

## Components

### Monorepo

Two deployable services plus shared operational tooling.

- **codingcto**: monorepo · Two-service monorepo: Go API plus Next.js console.

### Go API

Backend service with domain modules, infrastructure, and multiple command entrypoints.

- [API service](https://github.com/agicto/codingcto/tree/main/api): backend service · Main Go application boundary exposed over HTTP. · `api`
- [Server cmd](https://github.com/agicto/codingcto/blob/main/api/cmd/server/main.go): api entrypoint · Primary HTTP server executable. · `api/cmd/server/main.go`
- [SpecForge runtime](https://github.com/agicto/codingcto/blob/main/api/cmd/specforge-runtime/main.go): worker entrypoint · Local runtime that claims execution tasks beside a repository checkout. · `api/cmd/specforge-runtime/main.go`
- [Generator cmd](https://github.com/agicto/codingcto/blob/main/api/cmd/generator/main.go): tooling entrypoint · Code generation and scaffolding entrypoint. · `api/cmd/generator/main.go`
- [Bootstrap](https://github.com/agicto/codingcto/blob/main/api/internal/bootstrap/app.go): composition layer · Assembles app startup, HTTP, migration, and seeding flows. · `api/internal/bootstrap/app.go`
- [Wiring](https://github.com/agicto/codingcto/blob/main/api/internal/wiring/wire_gen.go): di composition · Generated dependency graph and module assembly. · `api/internal/wiring/wire_gen.go`
- [API routes](https://github.com/agicto/codingcto/blob/main/api/routes/api.go): http routing · Top-level route surface for the backend API. · `api/routes/api.go`
- [Router](https://github.com/agicto/codingcto/blob/main/api/internal/infra/router/router.go): http infra · HTTP router and middleware integration. · `api/internal/infra/router/router.go`
- [Domain model](https://github.com/agicto/codingcto/tree/main/api/internal/domain): domain layer · Core entities, value objects, events, and invariants. · `api/internal/domain`
- [Feature modules](https://github.com/agicto/codingcto/tree/main/api/internal/modules): module layer · Business modules such as auth, project, planning, execution, verification, and GitHub integration. · `api/internal/modules`
- [Infrastructure](https://github.com/agicto/codingcto/tree/main/api/internal/infra): cross-cutting infra · Database, cache, queue, scheduler, logging, metrics, tracing, HTTP clients, storage, and resilience primitives. · `api/internal/infra`
- [Database](https://github.com/agicto/codingcto/tree/main/api/database): persistence · Migration-first relational store for product, workflow, and audit data. · `api/database`
- [Redis](https://github.com/agicto/codingcto/blob/main/api/internal/infra/redis/redis.go): cache/rate-limit · Backing store for cache, limiter, and fast coordination. · `api/internal/infra/redis/redis.go`
- [GitHub](https://github.com/agicto/codingcto/tree/main/api/internal/modules/githubintegration): external integration · Repository, webhook, and CI integration boundary. · `api/internal/modules/githubintegration`
- [AI runtime](https://github.com/agicto/codingcto/blob/main/api/internal/capabilities/ai/ai.go): external dependency · Prompt compilation and execution-facing AI capability boundary. · `api/internal/capabilities/ai/ai.go`

### Next.js Console

Frontend console and edge proxy layer.

- [Web app](https://github.com/agicto/codingcto/tree/main/web): frontend service · Next.js console and API proxy boundary. · `web`
- [Web middleware](https://github.com/agicto/codingcto/blob/main/web/middleware.ts): edge auth · Session gating and request interception at the frontend edge. · `web/middleware.ts`
- [API bridge](https://github.com/agicto/codingcto/blob/main/web/src/app/v1/[...path]/route.ts): server routes · Auth routes and catch-all proxy to the backend API. · `web/src/app/v1/[...path]/route.ts`
- [Console UI](https://github.com/agicto/codingcto/tree/main/web/src/app/(protected)/(console)/console): app router · Protected console routes for projects, SpecForge, skills, agents, and settings. · `web/src/app/(protected)/(console)/console`
- [Feature packages](https://github.com/agicto/codingcto/tree/main/web/src/features): feature layer · Reusable client features for auth, project, SpecForge, agents, skills, and example flows. · `web/src/features`
- [Client state](https://github.com/agicto/codingcto/tree/main/web/src/store): browser state · Hooks, stores, query state, and feature services used by the console. · `web/src/store`

## Connections

- codingcto → API service: contains · Monorepo includes the Go backend service.
- codingcto → Web app: contains · Monorepo includes the Next.js console.
- API service → Server cmd: starts · Primary service is launched from the server command.
- API service → SpecForge runtime: starts · Execution worker runs as a separate runtime process.
- API service → Generator cmd: starts · Generator is a separate tooling entrypoint.
- Server cmd → Bootstrap: boots · Server entrypoint delegates startup assembly to bootstrap.
- Bootstrap → Wiring: uses · Bootstrap relies on generated dependency wiring.
- Bootstrap → API routes: mounts · Bootstrap connects the API route surface.
- API routes → Router: runs on · Top-level routes sit on the shared router and middleware stack.
- Router → Feature modules: dispatches · Router hands requests into feature modules.
- Feature modules → Domain model: models · Feature modules implement business logic over core domain types.
- Feature modules → Infrastructure: depends on · Modules use infra services for persistence, queueing, logging, and integrations.
- Infrastructure → Database: persists · Infrastructure layer manages database access and migrations.
- Infrastructure → Redis: coordinates · Infrastructure uses Redis for cache and distributed coordination.
- Feature modules → GitHub: integrates · Dedicated module boundary for GitHub repositories, webhooks, and settings.
- Feature modules → AI runtime: calls · Planning and execution flows depend on AI-backed capabilities.
- SpecForge runtime → API service: claims tasks · Local runtime exchanges heartbeats, events, and results with the API.
- Web app → Web middleware: gates · Frontend edge applies auth/session gating.
- Web app → API bridge: proxies · Web routes proxy auth and API traffic to the backend.
- Web app → Console UI: renders · Protected App Router console is the main user surface.
- Console UI → Feature packages: composes · Pages are built from feature-first UI packages.
- Feature packages → Client state: uses · Features share hooks, stores, and service clients.
- API bridge → API service: HTTP to · Frontend bridge forwards requests to the Go API.
- Console UI → API service: fetches from · Console workflow views are backed by the backend API.
- API service → Database: reads/writes · Backend owns durable product and workflow state.
- API service → Redis: uses · Backend uses Redis-backed coordination and rate limiting.
- API service → GitHub: webhooks · GitHub events and repository state feed product workflows.
