# Refactor: Convert the Project into a Reusable Laravel Base Template

Refactor this project into a **clean, reusable Laravel base project** that can serve as the starting point for future applications.

The goal is **not only to delete project-specific code**, but to redesign the project so it becomes a maintainable, extensible, and production-ready Laravel boilerplate.

Follow the existing project coding standards:

- Service Layer
- Form Requests
- API Resources
- Spatie Media Library
- Spatie Translatable
- Spatie Permission
- Eloquent only (no Repository Pattern)

---

# 1. Remove Project-Specific Features

Completely remove all business modules related to the current fasting application.

Examples include (but are not limited to):

- Fasting Plans
- Fasting Sessions
- Meals
- Medical Tests
- Challenges
- Rewards
- Blogs
- Doctors
- Consultations
- Chats
- Sleep Tracking
- Water Tracking
- Health Index
- Daily Questions
- Suggestions
- Medications
- Advertisements
- Ramadan
- Country-specific business logic
- Any other application-specific feature

Remove:

- Models
- Migrations
- Seeders
- Controllers
- Services
- Requests
- Resources
- Routes
- Policies
- Events
- Listeners
- Notifications
- Commands
- Tests
- Config
- Enums
- Factories
- Media collections
- Translation keys


---

# 2. Keep One Reference Module

Keep only one complete module as an implementation example.

It should demonstrate the project's architecture, including:

- Model
- Migration
- Controller
- Service
- Form Requests
- API Resource
- Policies
- Routes
- Seeder
- Tests

This module will serve as the template for future development.

---

# 3. Keep Generic Core Modules

Preserve and improve only reusable modules that are useful in almost every project.

Examples:

## Authentication

- Login
- Logout
- Forgot Password
- Reset Password
- OTP (optional)
- Sanctum

---

## Users

Generic user management.

---

## Admins

Redesign admins to support multiple roles and permissions.

Avoid hardcoded admin types.

Use Spatie Permission properly.
 
Adding future roles should require no schema changes.

---

## Roles & Permissions

Fully reusable.

---

## Settings

Create a flexible settings system.

Support:

- grouped settings
- typed values
- cached values

Example categories:

- General
- Integrations
- Notifications
- Payments

---

## Countries

If generic enough.

---

## Pages

(Optional)

Privacy Policy

Terms

About

Contact

---

## Media Upload

Reusable upload service.

---

## API Response Helpers

Keep the existing standardized API response format.

---

# 4. Make Everything More Generic

Refactor generic utilities so they can be reused by any future project.

Examples:

- Base Service
- Base Controller
- Base Resource
- Traits
- Helper functions
- Response builders
- Exception handling
- Pagination helpers

Reduce duplicated code wherever possible.

---

# 5. Documentation

Create a `/docs` directory.

For every removed feature that may be useful in future projects, create a detailed Markdown document explaining how it was implemented.

Do **not** keep its code.

Instead, document the implementation thoroughly.

Examples:

- Realtime Chat using Laravel Reverb
- Notification System
- Wallet System
- Payment Integration
- Analytics Dashboard
- OTP Authentication

Each document should include:

- Feature overview
- Database schema
- Relationships
- Folder structure
- Routes
- Controllers
- Services
- Events
- Listeners
- Broadcast events
- Queues
- Jobs
- Policies
- Requests
- Resources
- Code snippets
- Common pitfalls

The documentation should be detailed enough to rebuild the feature quickly in a future project.

---

# 6. Improve Project Structure

Review the entire project structure.

Refactor anything that reduces maintainability.

Examples:

- Folder organization
- Naming conventions
- Namespaces
- Shared traits
- Enums
- Helpers
- Configuration
- Constants

Keep everything consistent.



---

# 8. Developer Experience

Improve developer productivity.

Examples:

- Better README
- Installation guide
- Environment setup
- Coding standards
- Project conventions
- Module creation guidelines
- Example request/response structures
- Seeder conventions

---

# 9. Code Quality

While refactoring:

- Remove dead code.
- Remove duplicated logic.
- Improve naming.
- Improve type hints.
- Add missing PHPDoc where useful.
- Use eager loading appropriately.
- Optimize queries.
- Remove unnecessary abstractions.
- Keep the codebase clean and easy to extend.

---

# Goal

The final result should be a **production-ready Laravel starter template** that can be reused across many different projects with minimal changes.

It should contain only reusable infrastructure and generic modules, while all removed business features are preserved as comprehensive documentation under `/docs`, allowing them to be reimplemented quickly when needed.