|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Build Commands |
| 8 | + |
| 9 | +**Always skip GPG signing locally:** |
| 10 | +```bash |
| 11 | +# Build everything |
| 12 | +mvn clean install -Dmaven.javadoc.skip=true -Dgpg.skip=true |
| 13 | + |
| 14 | +# Build a single module (run from the module directory) |
| 15 | +cd kernel/kernel-idgenerator-service |
| 16 | +mvn clean install -Dgpg.skip=true |
| 17 | + |
| 18 | +# Skip tests for faster builds |
| 19 | +mvn clean install -Dgpg.skip=true -DskipTests=true |
| 20 | + |
| 21 | +# Run a single test class |
| 22 | +mvn test -Dgpg.skip=true -Dtest=UinGeneratorServiceTest |
| 23 | + |
| 24 | +# Run with a specific Spring profile |
| 25 | +java -Dspring.profiles.active=local -jar target/<jar-name>.jar |
| 26 | + |
| 27 | +# Run with remote config server |
| 28 | +java -Dspring.profiles.active=env \ |
| 29 | + -Dspring.cloud.config.uri=<config-url> \ |
| 30 | + -Dspring.cloud.config.label=<branch> \ |
| 31 | + -jar target/<jar-name>.jar |
| 32 | +``` |
| 33 | + |
| 34 | +The root `pom.xml` only contains the `kernel` module. All service modules are under `kernel/`. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Repository Structure |
| 39 | + |
| 40 | +``` |
| 41 | +commons/ |
| 42 | +├── pom.xml # Root POM (io.mosip:commons:1.4.0-SNAPSHOT) |
| 43 | +├── kernel/ # All kernel modules — one Maven reactor |
| 44 | +│ ├── pom.xml # io.mosip.kernel:kernel-parent (Java 21, 39 submodules) |
| 45 | +│ ├── kernel-bom/ # Bill of Materials — all third-party version pins |
| 46 | +│ ├── kernel-core/ # Shared interfaces, exceptions, base DTOs, utilities |
| 47 | +│ ├── kernel-logger-logback/ # Logback wrapper implementing kernel-core logger SPI |
| 48 | +│ ├── kernel-dataaccess-hibernate/ # Hibernate JPA base classes |
| 49 | +│ ├── kernel-idgenerator-*/ # ID generator libraries (VID, PRID, RID, TokenID, MachineID, etc.) |
| 50 | +│ ├── kernel-idvalidator-*/ # Corresponding validators for each ID type |
| 51 | +│ ├── kernel-notification-service/ # Spring Boot: SMS + email via REST (port 8083) |
| 52 | +│ ├── kernel-ridgenerator-service/ # Spring Boot: RID generation REST service |
| 53 | +│ ├── kernel-idgenerator-service/ # Vert.x: UIN + VID generator service (NOT Spring MVC) |
| 54 | +│ ├── kernel-pridgenerator-service/ # Spring Boot: PRID generation REST service |
| 55 | +│ ├── kernel-salt-generator/ # Spring Boot: cryptographic salt generation |
| 56 | +│ └── kernel-config-server/ # Spring Cloud Config Server wrapper |
| 57 | +├── helm/ # Helm charts for Kubernetes deployment |
| 58 | +│ ├── idgenerator/ # chart version: 0.0.1-develop (image: mosipqa/kernel-idgenerator-service:develop) |
| 59 | +│ ├── notifier/ # chart version: 0.0.1-develop |
| 60 | +│ ├── ridgenerator/ # chart version: 0.0.1-develop |
| 61 | +│ ├── pridgenerator/ # chart version: 0.0.1-develop |
| 62 | +│ ├── config-server/ # chart version: 0.0.2-develop |
| 63 | +│ ├── conf-secrets/ # chart version: 0.0.1-develop |
| 64 | +│ └── regproc-salt/ # chart version: 0.0.1-develop |
| 65 | +├── db_scripts/ # PostgreSQL DDL + DML scripts (mosip_kernel schema) |
| 66 | +│ └── <db_name>/ddl/ dml/ # Tables + seed data; run via deploy.sh |
| 67 | +└── deploy/ # Shell-based Kubernetes install scripts |
| 68 | + ├── kernel/ |
| 69 | + ├── config-server/ |
| 70 | + └── conf-secrets/ |
| 71 | +``` |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Architecture: Two Service Patterns |
| 76 | + |
| 77 | +### Standard Spring Boot services |
| 78 | +`kernel-ridgenerator-service`, `kernel-pridgenerator-service`, `kernel-notification-service`, `kernel-salt-generator`, `kernel-config-server` — follow the conventional `@SpringBootApplication` pattern with Spring MVC controllers. Their `bootstrap.properties` points to the config server for all runtime config. |
| 79 | + |
| 80 | +### Vert.x + Spring hybrid (`kernel-idgenerator-service`) |
| 81 | +This is the most architecturally unusual module. It does **not** use Spring MVC for its HTTP layer. Instead: |
| 82 | +- `IDGeneratorVertxApplication.main()` first fetches config from Spring Config Server via the Vert.x config retriever, then bootstraps a `Vertx` instance manually. |
| 83 | +- **UIN subsystem**: `UinGeneratorVerticle` + `UinTransferVerticle` — worker verticles that pre-generate a pool of UINs in PostgreSQL (`kernel.uin` table) using `SecureRandom` + Verhoeff checksum + configurable filters. UINs are produced in batches and held in the DB until consumed by ID Repository. |
| 84 | +- **VID subsystem**: `VidPoolCheckerVerticle`, `VidPopulatorVerticle`, `VidExpiryVerticle`, `VidIsolatorVerticle` — worker verticles managing the VID pool lifecycle. VID generation reuses the `kernel-idgenerator-vid` library. |
| 85 | +- Spring context (`HibernateDaoConfig`) is initialised only for JPA (Hibernate/PostgreSQL), not for HTTP serving. |
| 86 | +- Verticles communicate via the Vert.x event bus (addresses defined in `UinGeneratorConstant`, `EventType`). |
| 87 | +- HTTP health checks are handled by Vert.x `HealthCheckHandler`, not Spring Actuator routes. |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## MOSIP ID Types (Domain Context) |
| 92 | + |
| 93 | +Understanding these is essential when working on any generator or validator module: |
| 94 | + |
| 95 | +| ID | Full Name | Nature | Key facts | |
| 96 | +|---|---|---|---| |
| 97 | +| **UIN** | Unique Identification Number | Permanent resident ID | Generated with SecureRandom + Verhoeff checksum; never reissued; filtered against pattern rules | |
| 98 | +| **VID** | Virtual ID | Temporary alias for UIN | Expirable, revocable, privacy-friendly; used for authentication instead of exposing UIN | |
| 99 | +| **RID / AID** | Registration / Application ID | Per-registration-event ID | Tracks each lifecycle event (enrolment, update, lost ID) at registration center | |
| 100 | +| **PRID** | Pre-Registration ID | Pre-registration phase ID | Assigned when resident books appointment before visiting registration center | |
| 101 | +| **Token ID (PSUT)** | Partner-Specific User Token | Per-partner pseudonym | Returned in auth response to relying party; prevents cross-partner linkage; not used for auth | |
| 102 | + |
| 103 | +Additional IDs generated by library modules (not services): MachineID, RegistrationCenterID, PartnerID, MISPID, LicenseKey. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Key Cross-Cutting Patterns |
| 108 | + |
| 109 | +### Dependency hierarchy |
| 110 | +All modules depend on `kernel-core` for interfaces and `kernel-bom` for version pinning. Do not declare third-party dependency versions in module POMs — they come from the BOM. |
| 111 | + |
| 112 | +### Lombok |
| 113 | +All entity classes and most DTOs use `@Data`, `@AllArgsConstructor`, `@NoArgsConstructor`. Lombok is declared as `<scope>compile</scope>` in `kernel-core/pom.xml` and inherited. **Important**: if a `.java` file is placed in the wrong package directory (package declaration doesn't match directory), the resulting "duplicate class" compile error will prevent Lombok annotation processing from completing, causing cascading "cannot find symbol" errors across the entire module — not just the offending file. |
| 114 | + |
| 115 | +### Configuration |
| 116 | +All services pull runtime configuration from the MOSIP Config Server at startup. Property files live in a separate repo: `https://github.com/mosip/mosip-config`. The relevant files are `application-default.properties` and `kernel-default.properties`. Local overrides go in `bootstrap.properties` (`spring.profiles.active=local`). |
| 117 | + |
| 118 | +### Database schemas |
| 119 | +Each service uses its own PostgreSQL schema (e.g., `kernel` for UIN/VID tables). DDL/DML bootstrap scripts are in `db_scripts/`. Tests use H2 in-memory with the same Hibernate configuration. |
| 120 | + |
| 121 | +### Versioning convention |
| 122 | +- `develop` branch: `*-SNAPSHOT` versions (currently `1.4.0-SNAPSHOT`) |
| 123 | +- Release candidates: `1.x.x-rc.y` |
| 124 | +- Production releases: `1.x.x` |
| 125 | +- Helm chart versions for develop stay at `0.0.x-develop`; Docker image `tag: develop`, repo `mosipqa/...` (not `mosipid/...` which is production) |
| 126 | + |
| 127 | +### Branch merge strategy |
| 128 | +When merging a release tag into develop (`PROMPT.md` pattern): |
| 129 | +- Default to release tag for all code changes |
| 130 | +- Keep develop's SNAPSHOT versions in all `pom.xml` |
| 131 | +- Keep develop's Helm chart versions (`0.0.x-develop`) and `mosipqa/` image repos in `values.yaml` |
| 132 | +- Take resource limits / javaOpts from the release tag |
| 133 | +- Version bump is done separately (`Snapshot.md` pattern): find-replace SNAPSHOT version strings in `pom.xml` files only |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## Runtime Prerequisites (Local Dev) |
| 138 | + |
| 139 | +1. **Config Server** running, pointed at a local clone of `mosip-config` |
| 140 | +2. **PostgreSQL 10+** with scripts from `db_scripts/` applied |
| 141 | +3. **Keycloak / auth server** (for services that validate auth tokens) |
| 142 | +4. `kernel-auth-adapter.jar` on classpath for auth-protected services |
| 143 | + |
| 144 | +Config server local start command: |
| 145 | +```bash |
| 146 | +java -jar kernel-config-server-<version>.jar \ |
| 147 | + -Dspring.profiles.active=native \ |
| 148 | + -Dspring.cloud.config.server.native.search-locations=file:<path-to-mosip-config>/config |
| 149 | +``` |
| 150 | + |
| 151 | +API docs (Swagger) for each service are at `http://localhost:<port>/v1/<service-name>/swagger-ui.html`. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## CI/CD |
| 156 | + |
| 157 | +CI runs on push via GitHub Actions (`.github/workflows/push-trigger.yml`). The workflow builds all modules, runs tests, and publishes SNAPSHOT artifacts to `https://central.sonatype.com/repository/maven-snapshots/`. GPG signing is required for publish but skipped locally with `-Dgpg.skip=true`. Sonar analysis runs under the `sonar` Maven profile. |
0 commit comments