|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Official Java SDK for FiscalAPI - a Mexican CFDI electronic invoicing service (SAT integration). Provides CFDI 4.0 invoicing, certificate management, mass downloads, payroll, and SAT catalog queries. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +mvn clean compile # Compile |
| 13 | +mvn test # Run tests |
| 14 | +mvn package # Create JAR |
| 15 | +mvn clean deploy -Prelease # Deploy to Maven Central (requires GPG) |
| 16 | +``` |
| 17 | + |
| 18 | +## Architecture |
| 19 | + |
| 20 | +### Entry Point |
| 21 | +`FiscalApiClient.create(FiscalApiSettings)` - Factory method creating the main client with all services. |
| 22 | + |
| 23 | +### Service Layer Pattern |
| 24 | +``` |
| 25 | +IFiscalApiClient (facade) |
| 26 | + ├── getInvoiceService() → IInvoiceService extends IFiscalApiService<Invoice> |
| 27 | + ├── getPersonService() → IPersonService extends IFiscalApiService<Person> |
| 28 | + ├── getProductService() → IProductService extends IFiscalApiService<Product> |
| 29 | + ├── getTaxFileService() → ITaxFileService extends IFiscalApiService<TaxFile> |
| 30 | + ├── getCatalogService() → ICatalogService extends IFiscalApiService<CatalogDto> |
| 31 | + └── ... (other services) |
| 32 | +``` |
| 33 | + |
| 34 | +### Generic CRUD Base |
| 35 | +All services extend `BaseFiscalApiService<T>` which implements standard CRUD: |
| 36 | +- `getList(pageNumber, pageSize)` → `ApiResponse<PagedList<T>>` |
| 37 | +- `getById(id, details)` → `ApiResponse<T>` |
| 38 | +- `create(model)` → `ApiResponse<T>` |
| 39 | +- `update(model)` → `ApiResponse<T>` |
| 40 | +- `delete(id)` → `ApiResponse<Boolean>` |
| 41 | + |
| 42 | +Subclasses must implement `getTypeParameterClass()` to return the entity type for Jackson deserialization. |
| 43 | + |
| 44 | +### DTO Hierarchy |
| 45 | +``` |
| 46 | +SerializableDto → AuditableDto (createdAt, updatedAt) → BaseDto (id) |
| 47 | +``` |
| 48 | +All models extend `BaseDto`. Responses wrapped in `ApiResponse<T>`. |
| 49 | + |
| 50 | +### HTTP Layer |
| 51 | +- `OkHttpClientFactory` - Creates/caches OkHttpClient instances with auth headers (X-API-KEY, X-TENANT-KEY, X-API-VERSION, X-TIMEZONE) |
| 52 | +- `FiscalApiHttpClient` - Wraps OkHttp with Jackson, handles request/response logging in debug mode |
| 53 | + |
| 54 | +### Key Packages |
| 55 | +- `abstractions/` - Service interfaces |
| 56 | +- `common/` - ApiResponse, PagedList, settings |
| 57 | +- `http/` - HTTP client implementation |
| 58 | +- `models/` - All DTOs (invoicing/, downloading/ subpackages) |
| 59 | +- `services/` - Service implementations |
| 60 | + |
| 61 | +## Configuration |
| 62 | + |
| 63 | +```java |
| 64 | +FiscalApiSettings settings = new FiscalApiSettings(); |
| 65 | +settings.setApiUrl("https://test.fiscalapi.com"); // or https://live.fiscalapi.com |
| 66 | +settings.setApiKey("sk_test_..."); |
| 67 | +settings.setTenant("..."); |
| 68 | +settings.setDebugMode(true); // Logs requests/responses |
| 69 | +FiscalApiClient client = FiscalApiClient.create(settings); |
| 70 | +``` |
| 71 | + |
| 72 | +## API Endpoint Pattern |
| 73 | + |
| 74 | +`{apiUrl}/api/{apiVersion}/{resource}/{id?}/{action?}` |
| 75 | + |
| 76 | +Example: `POST api/v4/invoices`, `GET api/v4/invoices/{id}?details=true` |
| 77 | + |
| 78 | +## Dependencies |
| 79 | + |
| 80 | +- OkHttp3 4.12.0 (HTTP) |
| 81 | +- Jackson 2.14.2 (JSON) |
| 82 | +- Java 8+ (source/target) |
0 commit comments