Skip to content

LukaszKwiatkowski94/Simply-news-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

117 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“° Simply News App

A modern, framework-free PHP news portal built with clean architecture, custom routing, and real-world functionality. Perfect for learning modern PHP development patterns or deploying as a lightweight news management system.

PHP Version License GitHub


🎯 About

Simply News App is a full-featured news management system built entirely in PHP without relying on any framework. This project demonstrates professional PHP development practices including MVC architecture, custom routing, exception handling, and database abstraction.

Whether you're a student learning PHP, a developer exploring framework-free architecture, or someone needing a lightweight news portalβ€”this application is designed to be simple, readable, and extensible.


✨ Features

  • πŸ“° Multi-Category News - Organize articles by topics and categories
  • πŸ‘€ User Authentication - Secure login/signup with session management
  • πŸ” Role-Based Access Control - Separate permissions for admins and regular users
  • ✏️ Content Management - Create, edit, and publish news articles
  • πŸ’¬ Comment System - Readers can engage with articles via comments
  • 🎨 Responsive UI - Modern, mobile-friendly design with vanilla CSS & JavaScript
  • πŸ›£οΈ Custom Router - Lightweight HTTP routing engine without framework overhead
  • πŸ—„οΈ Database Abstraction - Clean model layer with PDO for database operations
  • πŸš€ Docker Ready - Easily deployable with Docker containers
  • πŸ”§ Configuration Management - Environment-based settings via .env file

πŸ“¦ What's Included

Simply News App/
β”œβ”€β”€ πŸ“ src/                    # Core application logic
β”‚   β”œβ”€β”€ Controllers/           # Request handlers
β”‚   β”œβ”€β”€ Models/                # Database layer
β”‚   β”œβ”€β”€ Classes/               # Utility classes
β”‚   β”œβ”€β”€ Exception/             # Custom exceptions
β”‚   β”œβ”€β”€ Router.php             # Custom routing engine
β”‚   β”œβ”€β”€ Request.php            # HTTP request wrapper
β”‚   β”œβ”€β”€ Response.php           # HTTP response wrapper
β”‚   └── View.php               # Template renderer
β”œβ”€β”€ πŸ“ config/                 # Application configuration
β”‚   β”œβ”€β”€ routes.php             # Route definitions
β”‚   β”œβ”€β”€ configuration.php      # App settings
β”‚   β”œβ”€β”€ database.php           # DB configuration
β”‚   └── env.php                # Environment variables
β”œβ”€β”€ πŸ“ database/               # Database initialization
β”‚   β”œβ”€β”€ init.php               # Database setup script
β”‚   └── schema.sql             # Schema reference
β”œβ”€β”€ πŸ“ templates/              # View files (MVC templates)
β”‚   └── pages/                 # Page-specific templates
β”œβ”€β”€ πŸ“ public/                 # Frontend assets
β”‚   β”œβ”€β”€ css/                   # Stylesheets
β”‚   β”œβ”€β”€ js/                    # Client-side scripts
β”‚   β”œβ”€β”€ img/                   # Images
β”‚   └── icon/                  # Icons & favicons
β”œβ”€β”€ πŸ“„ docker-entrypoint.sh    # Docker startup script
β”œβ”€β”€ πŸ“„ Dockerfile              # Docker image definition
β”œβ”€β”€ πŸ“„ docker-compose.yml      # Multi-container setup
β”œβ”€β”€ πŸ“„ index.php               # Application entry point
└── πŸ“„ .env                    # Environment variables

πŸš€ Quick Start

Prerequisites

  • PHP 8.1 or higher
  • MySQL 8.0 or higher
  • Docker & Docker Compose (for Docker deployment)
  • Git

Installation & Setup

Option 1: Using Docker (Recommended)

  1. Clone the repository:

    git clone https://github.com/LukaszKwiatkowski94/Simply-news-app.git
    cd Simply-news-app
  2. Configure .env:

    cp example.env .env

    Edit .env and set:

    DB_HOST=mysql
    DB_NAME=simplyNewsDB
    DB_USER=root
    DB_PASS=password
    APP_ENV=docker
    ADMIN_DEFAULT_PASSWORD=ChangeMe123!
  3. Start Docker:

    docker-compose up -d

    The startup process handles everything automatically:

    • MySQL container starts and waits for readiness
    • Web container runs docker-entrypoint.sh
    • php database/init.php creates database, tables, and admin user
    • Apache starts and app is ready
  4. Access the application:

Option 2: Local Development (without Docker - with MySQL)

If you have MySQL installed locally:

  1. Clone the repository:

    git clone https://github.com/LukaszKwiatkowski94/Simply-news-app.git
    cd Simply-news-app
  2. Configure environment variables:

    cp example.env .env

    Edit .env:

    DB_HOST=localhost
    DB_PORT=3306
    DB_NAME=simplyNewsDB
    DB_USER=root
    DB_PASS=password
    APP_ENV=development
    ADMIN_DEFAULT_PASSWORD=ChangeMe123!
  3. Initialize database:

    php database/init.php

    This script will:

    • Create the database
    • Create all tables
    • Seed the default admin user with password from ADMIN_DEFAULT_PASSWORD
  4. Start the development server:

    php -S localhost:8000 index.php
  5. Access the application:

    • Open http://localhost:8000
    • Default login: admin / ChangeMe123!
    • ⚠️ Change password immediately!

πŸ”‘ First Login & Security

Default Admin Account

When you first start the application, a default admin user is automatically created:

  • Username: admin
  • Password: ChangeMe123! (from ADMIN_DEFAULT_PASSWORD env variable)

⚠️ Important Security Notes

  1. Change Default Password Immediately

    • The default password is ChangeMe123! from ADMIN_DEFAULT_PASSWORD env variable
    • TODO: Application should force password change on first login
    • Change it via user profile or database:
      php -r "echo password_hash('NewPassword', PASSWORD_DEFAULT);"
      # Then update in database via PHPMyAdmin or MySQL CLI
  2. Creating Additional Admin Users

    • Create regular users via signup page
    • Grant admin privileges via database:
      UPDATE SN_users SET is_admin = 1 WHERE username = 'username';
    • Or modify database/init.php before first run
  3. Production Deployment

    • Set APP_ENV=production to block init.php execution
    • Initialize database manually before deployment
    • Change ADMIN_DEFAULT_PASSWORD to a strong, unique password
    • Never commit .env to version control
    • Use environment-specific configurations

🐳 Docker Deployment

Using Docker Compose

The easiest way to run the entire application stack (Web + MySQL + PHPMyAdmin):

  1. Configure .env file:

    cp example.env .env

    Edit .env:

    DB_HOST=mysql
    DB_NAME=simplyNewsDB
    DB_USER=root
    DB_PASS=password
    APP_ENV=docker
    ADMIN_DEFAULT_PASSWORD=ChangeMe123!
  2. Start all services:

    docker-compose up -d

    What happens on startup:

    • MySQL container initializes
    • Web container runs docker-entrypoint.sh:
      • Waits for MySQL health check
      • Executes php database/init.php
      • Creates database and tables
      • Seeds admin user with ADMIN_DEFAULT_PASSWORD
      • Starts Apache
  3. Access the application:

  4. View initialization logs:

    docker-compose logs web

    Look for "πŸš€ Simply News App - Database Initialization" section.

  5. Stop services:

    docker-compose down
  6. Rebuild after changes:

    docker-compose up -d --build

See DOCKER.md for more detailed Docker documentation and commands.

πŸ”§ Configuration

All sensitive configuration is managed through environment variables in the .env file:

# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=simplyNewsDB
DB_USER=root
DB_PASS=your_password

# Application Settings
APP_ENV=development
ADMIN_DEFAULT_PASSWORD=ChangeMe123!

⚠️ Security Note: Never commit your .env file to version control. It's listed in .gitignore for your protection.


πŸ’‘ Technology Stack

Technology Purpose Why It's Great
PHP 8.1+ Backend logic Type hints, match expressions, nullsafe operators
MySQL/MariaDB Data persistence Reliable, scalable database
PDO Database abstraction Secure, parameterized queries prevent SQL injection
Vanilla JavaScript Frontend interactivity No heavy dependencies, lightweight
CSS3 Styling Modern, responsive design
Docker Containerization Consistent development & production environments

πŸ“ Architecture

This project follows the Model-View-Controller (MVC) pattern:

  • Models (src/Models/) - Database interactions and business logic
  • Views (templates/) - User interface templates
  • Controllers (src/Controllers/) - Request handling and logic orchestration
  • Router (src/Router.php) - Custom HTTP routing without external dependencies

🀝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs via GitHub Issues
  • Submit feature requests

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ”— Links & Resources


Happy coding! πŸŽ‰ If you found this project useful, please give it a ⭐ on GitHub!