Skip to content

ashutosh-rath02/java-todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Todo App - Enterprise Edition

A comprehensive, enterprise-grade todo application built with proper separation of concerns, following SOLID principles and industrial best practices.

🏗️ Architecture Overview

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
└─────────────────┘

📦 Package Structure

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

✨ Features

Core Features

  • 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

Enterprise Features

  • 🏢 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

Interface Options

  • 🖥️ Console Interface: Command-line application
  • 🌐 Web Interface: Modern responsive web UI
  • 🔌 REST API: Full RESTful API endpoints

🚀 Quick Start

Prerequisites

  • Java 11 or higher
  • Maven 3.6+ (optional, for advanced features)

Option 1: Enterprise Build Script (Recommended)

# Windows
run-enterprise.bat

# Unix/Linux/Mac
chmod +x run-enterprise.sh
./run-enterprise.sh

Option 2: Maven Build

# Compile and run
mvn clean compile
mvn exec:java -Dexec.mainClass="com.todoapp.TodoWebServer"

# Run tests
mvn test

# Package application
mvn package

Option 3: Manual Compilation

# 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

🌐 Web Interface

Accessing the Web Interface

  1. Start the web server: java -cp target/classes com.todoapp.TodoWebServer
  2. Open browser: http://localhost:8080
  3. Enjoy the modern, responsive interface!

API Endpoints

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

🖥️ Console Interface

Available Commands

  • add [title:description] - Add a new todo
  • list [completed\|pending] - List todos (with optional filter)
  • complete <id> - Mark todo as completed
  • toggle <id> - Toggle completion status
  • edit <id> - Edit a todo
  • delete <id> - Delete a todo
  • search <query> - Search todos
  • clear [completed] - Clear completed todos
  • stats - Show statistics
  • help - Show help
  • quit/exit - Exit application

⚙️ Configuration

The application supports external configuration through:

Configuration Sources (in order of precedence):

  1. Environment Variables (e.g., TODOAPP_SERVER_PORT=8080)
  2. System Properties (e.g., -Dserver.port=8080)
  3. application.properties file
  4. Default values

Configuration Properties:

# 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

🧪 Testing

Running Tests

# 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

Test Coverage

  • Service Layer: Business logic testing with mocked dependencies
  • Repository Layer: Data access testing
  • Controller Layer: API endpoint testing
  • Domain Models: Entity behavior testing

📁 Project Structure

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

🔧 Development

Adding New Features

  1. Domain Layer: Add business entities and rules
  2. Repository Layer: Implement data access methods
  3. Service Layer: Add business logic and orchestration
  4. Controller Layer: Create API endpoints
  5. DTO Layer: Define data transfer objects
  6. Tests: Write comprehensive unit tests

Design Patterns Used

  • 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

🚀 Deployment

Building for Production

# Create executable JAR
mvn clean package

# Run with production profile
java -Dspring.profiles.active=prod -jar target/todo-app.jar

Environment Variables

export TODOAPP_SERVER_PORT=80
export TODOAPP_DATA_FILE=/var/lib/todoapp/todos.txt
export TODOAPP_LOGGING_LEVEL=WARN

📊 Performance Considerations

  • 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

🔒 Security Features

  • 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

📈 Monitoring & Logging

  • Structured Logging: Consistent log format
  • Performance Metrics: Built-in performance monitoring
  • Health Checks: Application health endpoints
  • Audit Trail: Complete operation logging

🤝 Contributing

  1. Follow the established package structure
  2. Write comprehensive unit tests
  3. Follow SOLID principles
  4. Use proper exception handling
  5. Document public APIs
  6. Maintain backward compatibility

📄 License

This project is open source and available under the MIT License.


Built with ❤️ using enterprise-grade Java architecture patterns

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published