# Sentinela 🇧🇷

Brazilian Financial Data API — serves market data from BCB and CVM public sources.

## Quick Start

```bash
# Build and run (seeds data automatically on first run)
make run

# Or directly
go run ./cmd/sentinela
```

The API starts on `http://localhost:3333`. On first run, it automatically fetches:
- **BCB**: Selic, CDI, IPCA, USD/BRL, EUR/BRL (last ~3 years)
- **CVM**: Company registry + IPE filings (current + previous year)

## API Documentation

Visit **`/docs`** for interactive Swagger UI with full endpoint documentation.

The OpenAPI 3.0 spec is also available at `/docs/openapi.yaml`.

## Endpoints

| Endpoint | Description |
|---|---|
| `GET /health` | Health check |
| `GET /api/v1/companies` | List companies |
| `GET /api/v1/companies/search?q=petrobras` | Search companies |
| `GET /api/v1/companies/:id` | Get company |
| `GET /api/v1/companies/:id/filings` | Company filings |
| `GET /api/v1/filings` | List filings |
| `GET /api/v1/filings/recent` | Recent filings |
| `GET /api/v1/filings/search?q=dividendo` | Search filings |
| `GET /api/v1/market/selic` | Selic history |
| `GET /api/v1/market/selic/current` | Current Selic |
| `GET /api/v1/market/cdi` | CDI history |
| `GET /api/v1/market/cdi/current` | Current CDI |
| `GET /api/v1/market/ipca` | IPCA history |
| `GET /api/v1/market/ipca/current` | Current IPCA |
| `GET /api/v1/market/fx` | FX rates |
| `GET /api/v1/market/fx/current` | Current FX |
| `GET /api/v1/market/overview` | Market dashboard |
| `GET /api/v1/search?q=vale` | Global search |

## Configuration

Set via environment variables (see `.env.example`):

- `PORT` — HTTP port (default: 3333)
- `DATABASE_PATH` — SQLite path (default: data/sentinela.db)
- `RATE_LIMIT` — Requests per minute per IP (default: 100)
- `API_KEY` — Optional API key (if set, all requests need it via `X-API-Key` header)
- `SYNC_INTERVAL` — Auto-refresh interval (default: 30m)
- `LOG_LEVEL` — info or debug

## Tech Stack

- Go 1.22+
- Fiber v2 (HTTP)
- SQLite via modernc.org/sqlite (pure Go, no CGO)
- FTS5 full-text search
