How inwerejosic/bank_codes_api works
Purpose and Runtime
A Rust/Axum HTTP service exposing static Nigerian bank-code data as JSON. It runs as an async server locally or in a Docker container; no database or third-party runtime service is indicated. Core artifacts: Cargo.toml, src/main.rs, data.json.
Application Bootstrap and Routing
src/main.rs is the executable entry point. It initializes application state, constructs the Axum router, registers the health, full-data, and query endpoints, and binds the HTTP listener (documented on port 3000). Route-to-handler control flow is centered on src/main.rs and src/handlers.rs.
Static Data Boundary
data.json is the authoritative bank dataset, containing bank codes, names, and categories. The application loads and exposes this data rather than querying a remote system or persistent database. Data parsing/storage responsibilities are separated into src/db.rs, with data.json as the input boundary.
HTTP API Layer
Request handling belongs in src/handlers.rs. The public surface is:
• GET /: health response.
• GET /api/data: serialized complete dataset.
• POST /api/query: accepts a JSON path and returns the selected value.
Handlers translate Axum requests into service calls and JSON HTTP responses, keeping HTTP concerns separate from lookup behavior. Paths: src/handlers.rs, src/main.rs.
Query and Domain Services
src/services.rs contains application-level data access/query behavior, notably dot-notation traversal such as banks.0.name. The primary flow is request JSON → handler → service path resolution over loaded JSON → result/error response. This is the main semantic boundary between transport logic and dataset traversal. Paths: src/services.rs, src/handlers.rs, data.json.
Shared Utilities and Error/Value Handling
src/utils.rs supports reusable logic needed by the API, likely including JSON/path-oriented helper behavior. It should remain below handlers/services in the dependency direction: handlers orchestrate requests, services implement domain operations, utilities provide generic support. Paths: src/utils.rs, src/services.rs.
Deployment Boundary
The service is containerized for Alpine-oriented, non-root deployment. Dockerfile defines the image build/runtime contract, while docker-compose.yml provides local container orchestration and port exposure. The application remains self-contained: deployment supplies compute/networking, and the static dataset is packaged or made available to the process. Paths: Dockerfile, docker-compose.yml, .dockerignore.
Main entry points: handlers.rs Request handlers · main.rs Axum router · Dockerfile Container image · db.rs Loaded dataset
Components 14
Service Runtime
- Cargo package
Cargo.toml - Server bootstrap · Builds state and router, then binds the HTTP listener.
src/main.rs
HTTP API
- Axum router · Registers health, data, and query endpoints.
src/main.rs - GET /
src/handlers.rs - GET /api/data
src/handlers.rs - POST /api/query · Accepts a JSON path and returns its selected value.
src/handlers.rs - Request handlers · Translates requests into service calls and JSON responses.
src/handlers.rs
Data Access
- Query service · Resolves dot-notation paths over loaded JSON.
src/services.rs - Loaded dataset · Parses and retains the static bank dataset.
src/db.rs - Bank-code dataset · Authoritative Nigerian bank codes, names, and categories.
data.json - JSON utilities
src/utils.rs
Container Deployment
- Container image · Defines Alpine-oriented non-root runtime image.
Dockerfile - Local containers · Runs the service with port exposure.
docker-compose.yml - Build context filter
.dockerignore
Connections 18
- Cargo package → Server bootstrap: builds
- Server bootstrap → Axum router: constructs
- Server bootstrap → Loaded dataset: initializes state
- Axum router → GET /: GET /
- Axum router → GET /api/data: GET /api/data
- Axum router → POST /api/query: POST /api/query
- GET / → Request handlers: dispatches
- GET /api/data → Request handlers: dispatches
- POST /api/query → Request handlers: dispatches
- Request handlers → Query service: delegates lookup
- Request handlers → Loaded dataset: returns full data
- Query service → Loaded dataset: traverses
- Query service → JSON utilities: uses
- Loaded dataset → Bank-code dataset: loads
- Container image → Server bootstrap: runs
- Container image → Bank-code dataset: packages
- Local containers → Container image: builds and runs
- Build context filter → Container image: filters context