# ggingggang/svc-core architecture

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

- Interactive diagram: https://gitdiagram.com/ggingggang/svc-core
- Repository: https://github.com/ggingggang/svc-core

## Overview

svc-core is a schedule-domain HTTP API with Gemini-powered text extraction. The main flow is an authenticated request through the router and API handlers into schedule services, which persist user-scoped state and transactionally enqueue domain events; a background dispatcher publishes them to JetStream. Separate supported capabilities include ICS export, recurrence and reminder management, cloning, internal reminder validation, account-deletion cleanup, and health/metrics. Edges reflect README statements or shown wiring/calls; unsampled subsystems are represented only where documented, without inferring their internal calls.

Main entry points: [`internal/service/service.go`](https://github.com/ggingggang/svc-core/blob/main/internal/service/service.go) (Domain service), [`internal/api/router.go`](https://github.com/ggingggang/svc-core/blob/main/internal/api/router.go) (Routes), [`cmd/server/main.go`](https://github.com/ggingggang/svc-core/blob/main/cmd/server/main.go) (HTTP server), [`internal/outbox/outbox.go`](https://github.com/ggingggang/svc-core/blob/main/internal/outbox/outbox.go) (Transactional outbox)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP and access"]
  node_server["HTTP server<br/>[main.go]"]
  node_router["Routes<br/>[router.go]"]
  node_auth["JWT and introspection<br/>[jwtauth.go]"]
  node_handlers["Schedule handlers<br/>[schedules.go]"]
  node_extract_handler["Extraction endpoint<br/>[extract.go]"]
  node_recurrence["Recurrence API<br/>[recurrence.go]"]
  node_reminders["Reminder API<br/>[reminders.go]"]
  node_clone["Schedule cloning<br/>[clone.go]"]
  node_ics["ICS export<br/>[ics.go]"]
  node_internal_api["Internal services API"]
end

subgraph group_domain["Schedule domain"]
  node_service["Domain service<br/>[service.go]"]
  node_schedule_logic["Schedule logic<br/>[schedules.go]"]
  node_extract_logic["Extraction logic<br/>[extract.go]"]
  node_reminder_logic["Reminder logic<br/>[reminders.go]"]
  node_account_cleanup["Account deletion cleanup"]
end

subgraph group_persistence["Persistence and events"]
  node_repo["Schedule queries<br/>[schedules.sql.go]"]
  node_mysql[("MySQL database")]
  node_outbox["Transactional outbox<br/>[outbox.go]"]
  node_event_logic["Event coordination<br/>[events.go]"]
end

subgraph group_integrations["External integrations"]
  node_publisher["JetStream publisher<br/>[publisher.go]"]
  node_nats["NATS JetStream"]
  node_gemini_client["Gemini client<br/>[gemini.go]"]
  node_gemini["Gemini API"]
  node_account_consumer["Account deletion consumer<br/>[consumer.go]"]
  node_auth_service["Auth service"]
end

subgraph group_operations["Operations"]
  node_config["Runtime configuration<br/>[config.go]"]
  node_database_boot["Database connection and migrations<br/>[db.go]"]
  node_health_metrics["Health and metrics<br/>[health.go]"]
  node_observability["Metrics and tracing<br/>[metrics.go]"]
end

node_user(("API client"))

node_user -->|"sends HTTP"| node_server
node_server -->|"installs handler"| node_router
node_server -->|"configures JWT"| node_auth
node_router -->|"routes requests"| node_handlers
node_router -->|"routes extraction"| node_extract_handler
node_router -->|"routes recurrence"| node_recurrence
node_router -->|"routes reminders"| node_reminders
node_router -->|"routes cloning"| node_clone
node_router -->|"routes export"| node_ics
node_router -->|"routes internal"| node_internal_api
node_auth -->|"checks account"| node_auth_service
node_handlers -->|"calls domain"| node_service
node_extract_handler -->|"calls extraction"| node_service
node_recurrence -->|"calls domain"| node_service
node_reminders -->|"calls domain"| node_service
node_clone -->|"calls domain"| node_service
node_ics -->|"reads schedules"| node_service
node_internal_api -->|"validates reminder"| node_service
node_service -->|"owns mutations"| node_schedule_logic
node_service -->|"owns extraction"| node_extract_logic
node_service -->|"owns reminders"| node_reminder_logic
node_schedule_logic -->|"queries schedules"| node_repo
node_repo -->|"reads and writes"| node_mysql
node_extract_logic -->|"requests candidates"| node_gemini_client
node_gemini_client -->|"calls generateContent"| node_gemini
node_extract_logic -->|"stores extraction"| node_repo
node_schedule_logic -->|"enqueues mutations"| node_outbox
node_outbox -->|"claims and updates"| node_mysql
node_service -->|"runs dispatcher"| node_outbox
node_service -->|"coordinates events"| node_event_logic
node_outbox -->|"publishes committed rows"| node_publisher
node_publisher -->|"publishes events"| node_nats
node_account_consumer -->|"cleans deleted account"| node_service
node_account_consumer -.->|"consumes deletion"| node_nats
node_internal_api -->|"checks account status"| node_auth_service
node_server -->|"loads settings"| node_config
node_server -->|"migrates and connects"| node_database_boot
node_database_boot -->|"connects"| node_mysql
node_router -->|"routes health"| node_health_metrics
node_router -->|"installs metrics"| node_observability
node_server -->|"initializes stream"| node_publisher

click node_server "https://github.com/ggingggang/svc-core/blob/main/cmd/server/main.go"
click node_router "https://github.com/ggingggang/svc-core/blob/main/internal/api/router.go"
click node_auth "https://github.com/ggingggang/svc-core/blob/main/internal/middleware/jwtauth.go"
click node_handlers "https://github.com/ggingggang/svc-core/blob/main/internal/api/schedules.go"
click node_extract_handler "https://github.com/ggingggang/svc-core/blob/main/internal/api/extract.go"
click node_recurrence "https://github.com/ggingggang/svc-core/blob/main/internal/api/recurrence.go"
click node_reminders "https://github.com/ggingggang/svc-core/blob/main/internal/api/reminders.go"
click node_clone "https://github.com/ggingggang/svc-core/blob/main/internal/api/clone.go"
click node_ics "https://github.com/ggingggang/svc-core/blob/main/internal/api/ics.go"
click node_internal_api "https://github.com/ggingggang/svc-core/blob/main/internal/api/internal_services.go"
click node_service "https://github.com/ggingggang/svc-core/blob/main/internal/service/service.go"
click node_schedule_logic "https://github.com/ggingggang/svc-core/blob/main/internal/service/schedules.go"
click node_extract_logic "https://github.com/ggingggang/svc-core/blob/main/internal/service/extract.go"
click node_reminder_logic "https://github.com/ggingggang/svc-core/blob/main/internal/service/reminders.go"
click node_account_cleanup "https://github.com/ggingggang/svc-core/blob/main/internal/service/account_deletion.go"
click node_repo "https://github.com/ggingggang/svc-core/blob/main/internal/repo/schedules.sql.go"
click node_outbox "https://github.com/ggingggang/svc-core/blob/main/internal/outbox/outbox.go"
click node_event_logic "https://github.com/ggingggang/svc-core/blob/main/internal/service/events.go"
click node_publisher "https://github.com/ggingggang/svc-core/blob/main/internal/events/publisher.go"
click node_gemini_client "https://github.com/ggingggang/svc-core/blob/main/internal/ai/gemini.go"
click node_account_consumer "https://github.com/ggingggang/svc-core/blob/main/internal/accountdeletion/consumer.go"
click node_config "https://github.com/ggingggang/svc-core/blob/main/internal/config/config.go"
click node_database_boot "https://github.com/ggingggang/svc-core/blob/main/internal/db/db.go"
click node_health_metrics "https://github.com/ggingggang/svc-core/blob/main/internal/api/health.go"
click node_observability "https://github.com/ggingggang/svc-core/blob/main/internal/observability/metrics.go"

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_server,node_router,node_auth,node_handlers,node_extract_handler,node_recurrence,node_reminders,node_clone,node_ics,node_internal_api,node_user toneBlue
class node_service,node_schedule_logic,node_extract_logic,node_reminder_logic,node_account_cleanup toneAmber
class node_repo,node_mysql,node_outbox,node_event_logic toneMint
class node_publisher,node_nats,node_gemini_client,node_gemini,node_account_consumer,node_auth_service toneRose
class node_config,node_database_boot,node_health_metrics,node_observability toneIndigo
```

## Components

### HTTP and access

- [HTTP server](https://github.com/ggingggang/svc-core/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [Routes](https://github.com/ggingggang/svc-core/blob/main/internal/api/router.go): `internal/api/router.go`
- [JWT and introspection](https://github.com/ggingggang/svc-core/blob/main/internal/middleware/jwtauth.go): `internal/middleware/jwtauth.go`
- [Schedule handlers](https://github.com/ggingggang/svc-core/blob/main/internal/api/schedules.go): `internal/api/schedules.go`
- [Extraction endpoint](https://github.com/ggingggang/svc-core/blob/main/internal/api/extract.go): `internal/api/extract.go`
- [Recurrence API](https://github.com/ggingggang/svc-core/blob/main/internal/api/recurrence.go): `internal/api/recurrence.go`
- [Reminder API](https://github.com/ggingggang/svc-core/blob/main/internal/api/reminders.go): `internal/api/reminders.go`
- [Schedule cloning](https://github.com/ggingggang/svc-core/blob/main/internal/api/clone.go): `internal/api/clone.go`
- [ICS export](https://github.com/ggingggang/svc-core/blob/main/internal/api/ics.go): `internal/api/ics.go`
- [Internal services API](https://github.com/ggingggang/svc-core/blob/main/internal/api/internal_services.go): `internal/api/internal_services.go`

### Schedule domain

- [Domain service](https://github.com/ggingggang/svc-core/blob/main/internal/service/service.go): `internal/service/service.go`
- [Schedule logic](https://github.com/ggingggang/svc-core/blob/main/internal/service/schedules.go): `internal/service/schedules.go`
- [Extraction logic](https://github.com/ggingggang/svc-core/blob/main/internal/service/extract.go): `internal/service/extract.go`
- [Reminder logic](https://github.com/ggingggang/svc-core/blob/main/internal/service/reminders.go): `internal/service/reminders.go`
- [Account deletion cleanup](https://github.com/ggingggang/svc-core/blob/main/internal/service/account_deletion.go): `internal/service/account_deletion.go`

### Persistence and events

- [Schedule queries](https://github.com/ggingggang/svc-core/blob/main/internal/repo/schedules.sql.go): `internal/repo/schedules.sql.go`
- **MySQL database**
- [Transactional outbox](https://github.com/ggingggang/svc-core/blob/main/internal/outbox/outbox.go): `internal/outbox/outbox.go`
- [Event coordination](https://github.com/ggingggang/svc-core/blob/main/internal/service/events.go): `internal/service/events.go`

### External integrations

- [JetStream publisher](https://github.com/ggingggang/svc-core/blob/main/internal/events/publisher.go): `internal/events/publisher.go`
- **NATS JetStream**
- [Gemini client](https://github.com/ggingggang/svc-core/blob/main/internal/ai/gemini.go): `internal/ai/gemini.go`
- **Gemini API**
- [Account deletion consumer](https://github.com/ggingggang/svc-core/blob/main/internal/accountdeletion/consumer.go): `internal/accountdeletion/consumer.go`
- **Auth service**

### Operations

- [Runtime configuration](https://github.com/ggingggang/svc-core/blob/main/internal/config/config.go): `internal/config/config.go`
- [Database connection and migrations](https://github.com/ggingggang/svc-core/blob/main/internal/db/db.go): `internal/db/db.go`
- [Health and metrics](https://github.com/ggingggang/svc-core/blob/main/internal/api/health.go): `internal/api/health.go`
- [Metrics and tracing](https://github.com/ggingggang/svc-core/blob/main/internal/observability/metrics.go): `internal/observability/metrics.go`

### Other components

- **API client**

## Connections

- API client → HTTP server: sends HTTP (evidence: `README.md`)
- HTTP server → Routes: installs handler (evidence: `cmd/server/main.go`)
- HTTP server → JWT and introspection: configures JWT (evidence: `cmd/server/main.go`)
- Routes → Schedule handlers: routes requests (evidence: `internal/api/router.go`)
- Routes → Extraction endpoint: routes extraction (evidence: `internal/api/router.go`)
- Routes → Recurrence API: routes recurrence (evidence: `internal/api/router.go`)
- Routes → Reminder API: routes reminders (evidence: `internal/api/router.go`)
- Routes → Schedule cloning: routes cloning (evidence: `internal/api/router.go`)
- Routes → ICS export: routes export (evidence: `internal/api/router.go`)
- Routes → Internal services API: routes internal (evidence: `internal/api/router.go`)
- JWT and introspection → Auth service: checks account (evidence: `README.md`)
- Schedule handlers → Domain service: calls domain
- Extraction endpoint → Domain service: calls extraction
- Recurrence API → Domain service: calls domain (evidence: `internal/api/recurrence.go`)
- Reminder API → Domain service: calls domain (evidence: `internal/api/reminders.go`)
- Schedule cloning → Domain service: calls domain (evidence: `internal/api/clone.go`)
- ICS export → Domain service: reads schedules (evidence: `internal/api/ics.go`)
- Internal services API → Domain service: validates reminder (evidence: `internal/api/internal_services.go`)
- Domain service → Schedule logic: owns mutations (evidence: `internal/service/service.go`)
- Domain service → Extraction logic: owns extraction (evidence: `internal/service/service.go`)
- Domain service → Reminder logic: owns reminders (evidence: `internal/service/service.go`)
- Schedule logic → Schedule queries: queries schedules (evidence: `internal/service/schedules.go`)
- Schedule queries → MySQL database: reads and writes (evidence: `README.md`)
- Extraction logic → Gemini client: requests candidates (evidence: `internal/service/extract.go`)
- Gemini client → Gemini API: calls generateContent (evidence: `internal/ai/gemini.go`)
- Extraction logic → Schedule queries: stores extraction (evidence: `internal/service/extract.go`)
- Schedule logic → Transactional outbox: enqueues mutations (evidence: `README.md`)
- Transactional outbox → MySQL database: claims and updates (evidence: `internal/outbox/outbox.go`)
- Domain service → Transactional outbox: runs dispatcher (evidence: `internal/service/service.go`)
- Domain service → Event coordination: coordinates events (evidence: `internal/service/service.go`)
- Transactional outbox → JetStream publisher: publishes committed rows (evidence: `internal/outbox/outbox.go`)
- JetStream publisher → NATS JetStream: publishes events (evidence: `internal/events/publisher.go`)
- Account deletion consumer → Domain service: cleans deleted account
- Account deletion consumer → NATS JetStream: consumes deletion
- Internal services API → Auth service: checks account status (evidence: `internal/api/internal_services.go`)
- HTTP server → Runtime configuration: loads settings (evidence: `cmd/server/main.go`)
- HTTP server → Database connection and migrations: migrates and connects (evidence: `cmd/server/main.go`)
- Database connection and migrations → MySQL database: connects (evidence: `internal/db/db.go`)
- Routes → Health and metrics: routes health (evidence: `internal/api/router.go`)
- Routes → Metrics and tracing: installs metrics (evidence: `internal/api/router.go`)
- HTTP server → JetStream publisher: initializes stream (evidence: `cmd/server/main.go`)
