How psmri/common-api works
Project Type and Purpose
• This is a backend-only microservice (Spring Boot V2, JDK17) named “Common API” for the AMRIT ecosystem.
• It exposes a large set of REST endpoints (beneficiary registration, call handling, OTP, email/SMS, feedback, reporting, integration with external systems such as c-Zentrix, Everwell, OpenKM, etc.) and acts as a centralized gateway for AMRIT.
• It uses MySQL (primary and secondary schemas), Redis caching, Quartz for scheduled jobs, Swagger for API docs, and integrates with various third-party systems.
File Structure Analysis
• Top-level: Dockerfile, pom.xml, config/, src/main:
• src/main/java/com/iemr/common: Spring-Boot entrypoint + layered code (config, controller, service, repo, mapper, model, dto).
• src/main/resources: application.properties, logback config.
• src/main/environment: per-environment property stubs.
• config/: XML-based category configs.
• src/main/webapp: minimal deployment descriptors (jboss).
• Design patterns:
• Layered (Controller → Service → Repository → Database).
• Two DataSources (PrimaryDBConfig, SecondaryDBConfig).
• RedisConfig: for caching/session.
• QuartzConfig + multiple ScheduleJob classes: background syncing, unblocking, email/SMS dispatch, data pulls, etc.
• SwaggerConfig, CORS, Interceptor pattern.
README Insights
• Describes Common API as a microservice/gateway.
• Lists everything it does (beneficiary, user auth, call handling, device data, file management, appointments, etc.).
• References external Developer Guide & API Guide.
a. Main Components
• Clients: Web/Mobile front ends, other AMRIT microservices, external callers.
• API Layer: Common-API Spring-Boot application
• REST Controllers
• Interceptors (JWT, CORS)
• Swagger UI
• Service Layer: business logic (Java @Service classes)
• Data Layer:
• Repositories (Spring Data JPA)
• MySQL Primary DB (transactional data)
• MySQL Secondary DB (reporting read-only)
• Redis (caching, session, token blacklist)
• Scheduler: Quartz jobs for sync, notifications, unblocking, reports
• External Integrations:
• c-Zentrix CTI / SMS gateway
• Everwell API
• OpenKM file management
• Email SMTP or generic email gateway
• OTP provider
• Other gov/health APIs (ABDM facility, eSanjeevani, POCT devices)
b. Relationships & Interactions
• Client → HTTP(S) → REST Controllers
• Controllers → Service Layer → Repositories/Utilities
• Service Layer → DB writes/reads (Primary DB)
• Service Layer → Secondary DB for reporting (read)
• Service Layer ↔ RedisCache for session or frequently used masters
• Service Layer → External services via RestTemplate (OpenKMConnector, HttpUtils)
• QuartzScheduler → invokes ServiceLayer jobs on schedule
• Docker container runs the Spring-Boot JAR, environment props passed at startup
c. Architectural Patterns & Principles
• Layered architecture (strict separation of concerns)
• Microservice (single responsibility for common functionality)
• Two-data-source pattern (primary for writes, secondary for heavy reports)
• Caching (Redis) to relieve DB on master lookups
• Scheduler (Quartz) for asynchronous background tasks
• Dependency Injection (Spring) and configuration classes
d. Technologies/Frameworks
• Spring Boot 2.x (Web, Data JPA, Cache, Quartz)
• MySQL (primary & secondary)
• Redis
• Swagger/OpenAPI
• Maven, Docker
• Lombok (likely), Jackson (JSON)
• REST endpoints secured via JWT filters
Essential Details to Capture
• Two DataSources with different purposes.
• Redis usage for caching/session/token blacklist.
• Quartz scheduler and the fact that it triggers multiple jobs.
• All major external connectors (e.g., OpenKMConnector, RestTemplateUtil).