How chatok-jnr/legalaid-backend works
1. This repository is a backend-only Spring Boot 3.3 application written in Java 21. It is organized as a modular monolith: one deployable process, with business areas split into separate packages under com.legalaid.
2. The request entrypoint is the REST API layer. Each feature package has a *Controller that accepts HTTP requests, delegates to a *Service, and persists through Spring Data JPA repositories. DTOs are used at the boundary so API shapes stay separate from database entities.
3. Cross-cutting infrastructure lives in config/ and common/. SecurityConfig, JwtConfig, JwtAuthFilter, CorsConfig, and CloudinaryConfig define authentication, CORS, token handling, and external storage wiring. GlobalExceptionHandler and ApiResponse standardize error and success responses across all endpoints.
4. Authentication is centered in auth/. The flow supports Google OAuth token exchange, JWT issuance, token refresh, and logout. JwtAuthFilter protects private routes, while AuthService, GoogleOAuthService, and JwtService handle identity verification and token lifecycle. This is the main security boundary before requests reach domain services.
5. User identity and roles are modeled separately in user/. User, UserRole, and UserService represent platform accounts and role-based state. This package is the base layer that other domains build on, since lawyer, client, and admin behavior all depend on the current authenticated user.
6. Lawyer management is a distinct domain in lawyer/. It contains the core lawyer profile plus specialized sub-entities for availability, courts, languages, locations, practice areas, and verification documents. This package supports onboarding, verification, public profile viewing, and lawyer statistics.
7. Service listings are handled in service/. LegalService and related entities such as ServiceMedia, ServiceFeature, ServiceFaq, and ServiceHighlight represent the marketplace offering a lawyer publishes. The structure suggests a rich listing model with media and metadata rather than a simple title/description record.
8. Contracting is its own bounded context in contract/. Contract, ContractMilestone, status enums, and repositories model the hire flow between client and lawyer. The README’s state-machine behavior is reflected here: contracts move through pending, active, completed, cancelled, and escrow-related states, and milestones are tracked separately from the contract header.
9. Case management lives in case_/. LegalCase is the core case record, with supporting entities for access control, milestones, and tags. This package is important because it defines collaborative legal work: access grants, editor/owner rules, and case-level milestone tracking.
10. Documents are isolated in document/ and are backed by Cloudinary rather than stored locally. DocumentService and CloudinaryService handle upload and metadata persistence, while DocumentRepository stores references in PostgreSQL. This creates a clear split between binary storage in Cloudinary and structured metadata in the database.
11. Payments are modeled in payment/ with both client-side payments and lawyer payouts. Payment, Payout, their status enums, and related DTOs support escrow-like transaction handling, manual verification, release, and withdrawal flows. The backend is the source of truth for payment state; external bKash interaction is represented as submitted transaction IDs plus admin verification.
12. Notifications are a separate domain in notification/. The package includes paginated listing, unread counts, read state updates, and deletion. Architecturally, notifications act as a platform-side side effect of other business actions such as contract updates, payments, or case changes.
13. Persistence is PostgreSQL-centric throughout. Nearly every domain has a repository package using Spring Data JPA, which means the application keeps business rules in services and uses the database as the durable system of record for users, listings, contracts, cases, payments, and documents.
14. The most important runtime flow is: HTTP request → Spring Security/JWT filter → controller → service → repository → PostgreSQL or Cloudinary → DTO response. That flow is consistent across the modules, making the repo a good candidate for an architecture diagram with a shared infrastructure layer and multiple domain boxes beneath it.
15. Testing is lightweight and focused on core service behavior. The repository includes JUnit tests for auth, JWT, and user services, plus a Spring Boot context test. Build and execution are Maven-based via the wrapper scripts, and configuration is driven from application.yaml and test resources.
Main entry points: SecurityConfig.java Security · AuthService.java Auth service · DocumentService.java Document service · AuthController.java Auth API
Components 30
Bootstrap
Application entrypoint and startup wiring
- App · Main application bootstrap and component scan
src/main/java/com/legalaid/BackendApplication.java
Infrastructure
Security, shared responses, and external integrations
- Security · HTTP security, auth boundaries, and filter chain setup
src/main/java/com/legalaid/config/SecurityConfig.java - JWT filter · Authenticates protected requests before controllers run
src/main/java/com/legalaid/auth/JwtAuthFilter.java - JWT config · JWT token settings and signing parameters
src/main/java/com/legalaid/config/JwtConfig.java - CORS config · Cross-origin policy for the API
src/main/java/com/legalaid/config/CorsConfig.java - Errors · Centralized API exception mapping
src/main/java/com/legalaid/common/exception/GlobalExceptionHandler.java - Response · Shared success and error payload shape
src/main/java/com/legalaid/common/response/ApiResponse.java - Google OAuth · Verifies Google token exchange for sign-in
src/main/java/com/legalaid/auth/GoogleOAuthService.java - JWT service · Issues and validates JWTs
src/main/java/com/legalaid/auth/JwtService.java
Business domains
Feature packages exposed through REST controllers and services
- Auth API · Login, token refresh, logout, and OAuth exchange endpoints
src/main/java/com/legalaid/auth/AuthController.java - Auth service · Coordinates OAuth verification and JWT lifecycle
src/main/java/com/legalaid/auth/AuthService.java - User API · Current user and profile endpoints
src/main/java/com/legalaid/user/UserController.java - User service · Manages platform accounts and roles
src/main/java/com/legalaid/user/UserService.java - Lawyer API · Lawyer onboarding, profile, and verification endpoints
src/main/java/com/legalaid/lawyer/LawyerController.java - Lawyer service · Coordinates lawyer profiles, availability, and verification
src/main/java/com/legalaid/lawyer/LawyerService.java - Service API · Marketplace service listing endpoints
src/main/java/com/legalaid/service/ServiceController.java - Service service · Manages legal service listings and metadata
src/main/java/com/legalaid/service/ServiceService.java - Contract API · Contract creation and lifecycle endpoints
src/main/java/com/legalaid/contract/ContractController.java - Contract service · Handles hiring flow, contract states, and milestones
src/main/java/com/legalaid/contract/ContractService.java - Case API · Case management and access control endpoints
src/main/java/com/legalaid/case_/CaseController.java - Case service · Manages cases, access grants, tags, and milestones
src/main/java/com/legalaid/case_/CaseService.java - Document API · Document upload and management endpoints
src/main/java/com/legalaid/document/DocumentController.java - Document service · Persists document metadata and coordinates Cloudinary uploads
src/main/java/com/legalaid/document/DocumentService.java - Payment API · Payment recording, invoice, and payout endpoints
src/main/java/com/legalaid/payment/PaymentController.java - Payment service · Tracks payment and payout state
src/main/java/com/legalaid/payment/PaymentService.java - Notify API · Notification list and read-state endpoints
src/main/java/com/legalaid/notification/NotificationController.java - Notify service · Creates and manages user notifications
src/main/java/com/legalaid/notification/NotificationService.java
External systems
Durable storage and third-party services
- Cloudinary · Uploads and retrieves file assets from Cloudinary
src/main/java/com/legalaid/document/CloudinaryService.java - PostgreSQL · System of record for all domain entities
- Cloudinary · External binary storage for documents and media
Connections 28
- App → Security: boots · Application startup wires security and web infrastructure
- Security → JWT filter: uses · Security chain includes JWT authentication
- Security → JWT config: reads · Security depends on token settings
- Security → CORS config: applies · Security exposes configured cross-origin policy
- Auth API → Auth service: delegates · REST auth endpoints delegate to identity workflows
- Auth service → Google OAuth: verifies · Google OAuth token exchange and identity verification
- Auth service → JWT service: issues · Creates and refreshes JWTs
- JWT filter → JWT service: validates · Filter checks bearer tokens before routing
- Auth API → Response: returns · Auth endpoints use shared response shapes
- User API → User service: delegates · User endpoints delegate to account logic
- User service → PostgreSQL: persists · User accounts and roles are stored in the database
- Lawyer API → Lawyer service: delegates · Lawyer endpoints coordinate onboarding and profile reads
- Lawyer service → PostgreSQL: persists · Lawyer profile and verification data are stored in the database
- Service API → Service service: delegates · Service listing endpoints delegate to marketplace logic
- Service service → PostgreSQL: persists · Listing data and metadata are stored in the database
- Contract API → Contract service: delegates · Contract API routes enter the hiring workflow
- Contract service → PostgreSQL: persists · Contracts and milestones are stored in the database
- Case API → Case service: delegates · Case endpoints manage collaborative legal work
- Case service → PostgreSQL: persists · Cases, access grants, and tags are stored in the database
- Document API → Document service: delegates · Document endpoints handle upload and metadata operations
- Document service → Cloudinary: uploads · Binary files are sent to Cloudinary
- Document service → PostgreSQL: persists · Document metadata is stored in the database
- Cloudinary → Cloudinary: stores · Cloudinary is the external binary store
- Payment API → Payment service: delegates · Payment endpoints manage transactions and payouts
- Payment service → PostgreSQL: persists · Payment and payout state are stored in the database
- Notify API → Notify service: delegates · Notification endpoints handle inbox operations
- Notify service → PostgreSQL: persists · Notification state is stored in the database
- Errors → Response: standardizes · Exceptions are normalized into the shared response envelope