How razanfawwaz/sirekap-api works
Purpose and principal workflow
This Go API exposes read-only election vote counts by polling station. An HTTP client initiates the main workflow with GET /api/v1/ppwp?limit=…&offset=…; Gin routes the request to a handler that parses pagination, requests records from PostgreSQL, and returns JSON in a standard response envelope. The README describes the records as data collected from the official KPU election site, but the sampled code shows database reads, not collection or ingestion.
Components
HTTP application and response
• Gin server and route registration — main.go: configures Gin, registers /ping and /api/v1/ppwp, connects the database, and starts the server on the configured port.
• PPWP HTTP handler — interfaces/ppwp_handler.go: reads limit and offset, validates that limit is present, calls the application operation, and serializes success or error responses.
• Response envelope and pagination type — config/base_response.go: defines the JSON response shape used by the handler, plus a page metadata type.
Election-data query and representation
• PPWP application operation — application/ppwp.go: obtains the configured database handle, constructs the repository, and delegates the paginated data request.
• PPWP PostgreSQL repository — repository/ppwp_repository.go: selects polling-station election fields from ppwp_tps, filters to rows with status_suara true, applies SQL limit and offset, and scans results into domain records.
• Election report domain models — domain/ppwp.go: defines the flat and nested structures for regional identifiers, candidate votes, voter counts, tally-image references, and status fields.
Runtime configuration and external systems
• Database and environment configuration — config/config.go: reads settings through Viper, opens a PostgreSQL database/sql connection, and exposes the database handle.
• HTTP client — null: External caller that sends the PPWP request; no repository path.
• PostgreSQL database — null: External state system queried by the repository; the configured database contains the ppwp_tps table.
• KPU election-data source — null: The README identifies the official KPU site as the upstream source for collected data, but no ingestion path is established by the sampled code.
Relationships
• HTTP client -> Gin server and route registration: sends the documented PPWP request; evidence: README.md.
• Gin server and route registration -> PPWP HTTP handler: registers the handler for GET /api/v1/ppwp; evidence: main.go.
• Gin server and route registration -> Database and environment configuration: connects the database before starting the server; evidence: main.go.
• PPWP HTTP handler -> PPWP application operation: passes parsed limit and offset to GetAllData; evidence: interfaces/ppwp_handler.go.
• PPWP HTTP handler -> Response envelope and pagination type: constructs the response envelope for validation, error, and success outcomes; evidence: interfaces/ppwp_handler.go.
• PPWP application operation -> Database and environment configuration: obtains the database handle with GetDB; evidence: application/ppwp.go.
• PPWP application operation -> PPWP PostgreSQL repository: constructs the repository and calls GetAllData; evidence: application/ppwp.go.
• PPWP PostgreSQL repository -> Election report domain models: scans query results into domain.ReportData; evidence: repository/ppwp_repository.go.
• PPWP PostgreSQL repository -> PostgreSQL database: queries ppwp_tps with a status filter and pagination; evidence: repository/ppwp_repository.go.
• PPWP HTTP handler -> HTTP client: returns the query result as JSON; evidence: interfaces/ppwp_handler.go.
• KPU election-data source -> PostgreSQL database: upstream collection is documented, but implementation and wiring are not shown; evidence: none (inferred).
Coverage limits
The sampled files establish the API’s read path and PostgreSQL query, but not how election data reaches the database, database schema, deployment topology, or behavior for malformed numeric pagination values. The source index identifies no additional substantial application modules beyond those represented here.
Main entry points: ppwp_handler.go PPWP handler · main.go Gin server and routes · ppwp.go PPWP operation · ppwp_repository.go PPWP repository
Components 10
HTTP API
- Gin server and routes
main.go - PPWP handler
interfaces/ppwp_handler.go - Response envelope
config/base_response.go
PPWP Read Path
- PPWP operation
application/ppwp.go - PPWP repository
repository/ppwp_repository.go - Election report models
domain/ppwp.go
Runtime Configuration
- Database configuration
config/config.go
Other components
- HTTP client
- PostgreSQL · Configured database containing the ppwp_tps table.
- KPU election-data source · Upstream source identified by the README; ingestion is not shown in sampled code.
Connections 11
- HTTP client → Gin server and routes: sends request
README.md - Gin server and routes → PPWP handler: routes request
main.go - Gin server and routes → Database configuration: connects database
main.go - PPWP handler → PPWP operation: passes pagination
interfaces/ppwp_handler.go - PPWP handler → Response envelope: builds response
interfaces/ppwp_handler.go - PPWP operation → Database configuration: gets database handle
application/ppwp.go - PPWP operation → PPWP repository: calls query
application/ppwp.go - PPWP repository → Election report models: scans results
repository/ppwp_repository.go - PPWP repository → PostgreSQL: queries records
repository/ppwp_repository.go - PPWP handler → HTTP client: returns JSON
interfaces/ppwp_handler.go - KPU election-data source → PostgreSQL: supplies data · Inferred; not shown in the code that was read.