A full-stack application built with SvelteKit frontend and Spring Boot backend.
.
├── frontend/ # SvelteKit frontend application
│ ├── src/ # Source files
│ ├── static/ # Static assets
│ └── ...
│
└── backend/ # Spring Boot backend application
├── src/ # Source files
└── ...
The backend follows a domain-driven design (DDD) approach with clear separation of concerns and consistent use of design patterns:
- Entry point for all HTTP requests
- Handles request/response mapping
- Input validation
- Routes requests to appropriate services
- Key components:
OrderController: Handles order-related endpointsWebhookController: Processes incoming webhooks
- Orchestrates domain operations using command pattern
- Manages transactions and persistence
- Delegates business logic to domain layer
- Key services:
OrderService: Executes order commands and manages persistenceWebhookService: Converts webhooks to domain commandsItemService: Handles item operationsProductTypeService: Manages product typesOrderProgressService: Tracks order progress
- Handles object transformations between different layers
- Centralizes mapping logic for better maintainability
- Key mappers:
OrderMapper: Maps between domain Order and model Order/DTOsOrderDetailsMapper: Maps OrderDetails to various DTOsWebhookMapper: Maps webhook payloads to domain objects
- Contains core business logic and rules
- Implements command pattern for operations
- Uses factory pattern for object creation
- Enforces invariants through specifications
- Key components:
- Commands:
CreateOrderCommand: Creates new ordersCreateItemCommand: Creates new itemsCreateProductTypeCommand: Creates product typesCreateStatusDefinitionCommand: Creates status definitionsUpdateItemStatusCommand: Updates item statusUpdateProductTypeCommand: Changes product typesProcessWebhookCommand: Processes webhook payloadsSetupOrderDetailsCommand: Sets up order details
- Factory:
OrderFactory: Creates domain objects consistently
- Specifications:
OrderInvariantsSpecification: Validates business rules
- Entities:
Order: Rich domain model with behaviorOrderItem: Represents items in an order
- Value Objects:
OrderId: Encapsulates order identityCustomerInfo: Contains customer details
- Commands:
- Handles data persistence
- Maps domain objects to database entities
- Key components:
- Entities:
OrderEntity: Database representation of ordersOrderDetails: Stores order item details
- Repositories:
OrderRepository: Persists ordersItemRepository: Manages itemsProductTypeRepository: Handles product types
- Entities:
- Controllers receive requests and convert to DTOs
- Services use mappers to transform data between layers
- Services create appropriate commands
- Commands execute on domain objects
- Domain objects enforce business rules
- Services use mappers to transform domain objects for persistence
- Services handle persistence through repositories
- Service layer creates a command with necessary data
- Command executes on a domain object or performs a specific operation
- Domain object updates its state (if applicable)
- Service layer persists the changes
OrderFactorycreates consistent domain objects- Used by both
OrderServiceandWebhookService - Ensures domain objects are created with valid state
- Validates business rules
- Used before persisting changes
- Ensures domain invariants are maintained
- Centralizes transformation logic
- Provides clean separation between layers
- Makes data transformations maintainable and testable
- Reduces coupling between layers
The application has been optimized for fast dashboard loading times, achieving significant performance improvements:
- Initial Dashboard Loading: ~3680ms
- Optimized Dashboard Loading: ~565ms
- Performance Improvement: ~89% reduction in loading time
We maintain a simple but effective indexing strategy:
-- Primary indexes
CREATE INDEX IF NOT EXISTS idx_status_definitions_id ON status_definitions(id);
CREATE INDEX IF NOT EXISTS idx_status_definitions_name ON status_definitions(name);
CREATE INDEX IF NOT EXISTS idx_order_details_order_id ON order_details(order_id);These indexes were chosen after careful performance testing and provide the best balance between query performance and maintenance overhead.
The application uses Neon PostgreSQL as the database provider. Configuration is managed through environment variables:
NEON_DB_URL=jdbc:postgresql://<host>/gtrykdb?sslmode=require
NEON_DB_USERNAME=gtrykdb_ownerWe use Flyway for database migrations. Key commands:
# Run migrations
./mvnw flyway:migrate
# Repair migration history (if needed)
./mvnw flyway:repair- Spring Boot: 3.3.5
- Java: 22.0.2
- Database: PostgreSQL 16.5 (Neon)
- ORM: Hibernate 6.5.3
- Migration Tool: Flyway 10.10.0
-
Query Optimization
- Use appropriate indexes for frequently queried columns
- Keep indexes simple and focused
- Regular monitoring of query performance
-
Database Design
- Normalized schema design
- Appropriate use of foreign keys
- Regular database maintenance
-
Application Layer
- Efficient use of Hibernate
- Proper transaction management
- Regular performance monitoring
-
Performance Monitoring
- Regular dashboard loading time checks
- Database query performance analysis
- Resource utilization monitoring
-
Database Maintenance
- Regular index maintenance
- Periodic vacuum operations
- Query plan analysis
-
Troubleshooting
- Check slow query logs
- Monitor database connections
- Analyze application metrics
-
Navigate to the backend directory:
cd backend -
Run the Spring Boot application:
./mvnw spring-boot:run
The backend will start on http://localhost:8080
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the development server:
npm run dev
The frontend will start on http://localhost:5173
- Frontend development server:
http://localhost:5173 - Backend API:
http://localhost:8080
cd backend
./mvnw clean packagecd frontend
npm run buildWhen contributing to this project, please consider the following:
-
Performance Impact
- Test any changes against the performance baseline
- Document performance implications
- Consider index impact for schema changes
-
Database Changes
- Always use Flyway migrations for schema changes
- Test migrations in a staging environment
- Document any new indexes or constraints
-
Code Quality
- Follow existing architectural patterns
- Maintain separation of concerns
- Add appropriate tests
-
Slow Dashboard Loading
- Check database connection pool settings
- Verify index usage with EXPLAIN ANALYZE
- Monitor database resource utilization
-
Migration Issues
- Use
flyway:repairfor migration conflicts - Check migration versioning
- Verify database credentials
- Use
-
Performance Degradation
- Review recent changes
- Check database statistics
- Analyze query plans
[Add your license information here]