A comprehensive, enterprise-grade todo application built with proper separation of concerns, following SOLID principles and industrial best practices.
This application follows a layered architecture with clear separation of concerns:
┌─────────────────┐
│ Presentation │ ← Controllers, DTOs
├─────────────────┤
│ Business │ ← Services, Domain Models
├─────────────────┤
│ Data Access │ ← Repository Pattern
├─────────────────┤
│ Infrastructure│ ← Configuration, DI Container
└─────────────────┘
src/main/java/com/todoapp/
├── domain/ # Domain entities and business objects
├── dto/ # Data Transfer Objects for API
├── repository/ # Data access layer (Repository pattern)
├── service/ # Business logic layer
├── controller/ # Presentation layer (REST API)
├── config/ # Configuration and dependency injection
└── exception/ # Custom exception hierarchy
- ✅ CRUD Operations: Complete Create, Read, Update, Delete functionality
- ✅ Business Logic: Proper validation and business rules
- ✅ Data Persistence: File-based storage with proper error handling
- ✅ Search & Filter: Advanced search and filtering capabilities
- ✅ Statistics: Real-time completion statistics
- 🏢 Separation of Concerns: Clean layered architecture
- 🔧 Dependency Injection: Manual DI container for loose coupling
- 📊 Configuration Management: Externalized configuration
- 🧪 Unit Testing: Comprehensive test coverage with JUnit 5
- 📝 Exception Handling: Proper exception hierarchy
- 🔄 Repository Pattern: Abstracted data access layer
- 📋 DTO Pattern: Clean API contracts
- 🎯 SOLID Principles: Following industry best practices
- 🖥️ Console Interface: Command-line application
- 🌐 Web Interface: Modern responsive web UI
- 🔌 REST API: Full RESTful API endpoints
- Java 11 or higher
- Maven 3.6+ (optional, for advanced features)
# Windows
run-enterprise.bat
# Unix/Linux/Mac
chmod +x run-enterprise.sh
./run-enterprise.sh
# Compile and run
mvn clean compile
mvn exec:java -Dexec.mainClass="com.todoapp.TodoWebServer"
# Run tests
mvn test
# Package application
mvn package
# Compile all classes
javac -cp . -d target/classes src/main/java/com/todoapp/**/*.java
# Run console app
java -cp target/classes com.todoapp.TodoConsoleApp
# Run web server
java -cp target/classes com.todoapp.TodoWebServer
- Start the web server:
java -cp target/classes com.todoapp.TodoWebServer
- Open browser:
http://localhost:8080
- Enjoy the modern, responsive interface!
Method | Endpoint | Description |
---|---|---|
GET | /api/todos |
Get all todos (with optional filter) |
GET | /api/todos?filter=completed |
Get completed todos |
GET | /api/todos?filter=pending |
Get pending todos |
POST | /api/todos/add |
Create new todo |
POST | /api/todos/toggle |
Toggle completion status |
POST | /api/todos/edit |
Update todo |
POST | /api/todos/delete |
Delete todo |
POST | /api/todos/clear-completed |
Clear completed todos |
GET | /api/stats |
Get statistics |
add [title:description]
- Add a new todolist [completed\|pending]
- List todos (with optional filter)complete <id>
- Mark todo as completedtoggle <id>
- Toggle completion statusedit <id>
- Edit a tododelete <id>
- Delete a todosearch <query>
- Search todosclear [completed]
- Clear completed todosstats
- Show statisticshelp
- Show helpquit/exit
- Exit application
The application supports external configuration through:
- Environment Variables (e.g.,
TODOAPP_SERVER_PORT=8080
) - System Properties (e.g.,
-Dserver.port=8080
) - application.properties file
- Default values
# Server Configuration
server.port=8080
server.host=localhost
# Data Configuration
data.file=todos.txt
# CORS Configuration
cors.enabled=true
cors.allowed.origins=*
# Logging Configuration
logging.level=INFO
# Cache Configuration
cache.enabled=true
cache.size=1000
# With Maven
mvn test
# Manual compilation and execution
javac -cp .:junit-platform-console-standalone.jar -d target/test-classes src/test/java/com/todoapp/**/*.java
java -jar junit-platform-console-standalone.jar --class-path target/test-classes
- Service Layer: Business logic testing with mocked dependencies
- Repository Layer: Data access testing
- Controller Layer: API endpoint testing
- Domain Models: Entity behavior testing
java-todo/
├── src/
│ ├── main/
│ │ ├── java/com/todoapp/
│ │ │ ├── domain/ # Domain entities
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ ├── repository/ # Data access layer
│ │ │ ├── service/ # Business logic layer
│ │ │ ├── controller/ # REST API controllers
│ │ │ ├── config/ # Configuration & DI
│ │ │ ├── exception/ # Custom exceptions
│ │ │ ├── TodoConsoleApp.java
│ │ │ └── TodoWebServer.java
│ │ └── resources/
│ │ └── application.properties
│ └── test/
│ └── java/com/todoapp/
│ └── service/ # Unit tests
├── pom.xml # Maven configuration
├── run-enterprise.bat # Windows build script
├── run-enterprise.sh # Unix build script
├── index.html # Web interface
└── README.md # This file
- Domain Layer: Add business entities and rules
- Repository Layer: Implement data access methods
- Service Layer: Add business logic and orchestration
- Controller Layer: Create API endpoints
- DTO Layer: Define data transfer objects
- Tests: Write comprehensive unit tests
- Repository Pattern: Abstract data access
- DTO Pattern: Clean API contracts
- Dependency Injection: Loose coupling
- Factory Pattern: Object creation
- Strategy Pattern: Different implementations
- Observer Pattern: Event handling
# Create executable JAR
mvn clean package
# Run with production profile
java -Dspring.profiles.active=prod -jar target/todo-app.jar
export TODOAPP_SERVER_PORT=80
export TODOAPP_DATA_FILE=/var/lib/todoapp/todos.txt
export TODOAPP_LOGGING_LEVEL=WARN
- Caching: In-memory caching for frequently accessed data
- Connection Pooling: Efficient resource management
- Lazy Loading: Load data only when needed
- Batch Operations: Efficient bulk operations
- Indexing: Optimized data access patterns
- Input Validation: Comprehensive validation at all layers
- SQL Injection Prevention: Parameterized queries
- XSS Protection: Proper output encoding
- CORS Configuration: Configurable cross-origin policies
- Error Handling: Secure error messages
- Structured Logging: Consistent log format
- Performance Metrics: Built-in performance monitoring
- Health Checks: Application health endpoints
- Audit Trail: Complete operation logging
- Follow the established package structure
- Write comprehensive unit tests
- Follow SOLID principles
- Use proper exception handling
- Document public APIs
- Maintain backward compatibility
This project is open source and available under the MIT License.
Built with ❤️ using enterprise-grade Java architecture patterns