• Stars
    star
    360
  • Rank 117,712 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿบ โ€Ž A minimalist MVC framework.

๐Ÿบ Laconia

License: MIT

An MVC framework from scratch in PHP.

View the demo

Installation

Install a local copy with the instructions below, or follow the Docker instructions.

Install Apache, MySQL, and PHP

It is assumed you already know how to install a LAMP stack. For macOS and Windows local development, I would recommend downloading MAMP for a sandboxed environment. You can set up virtual hosts as well.

If using MAMP, add MAMP to the PHP command line by adding this line to .bash_profile.

export PATH=/Applications/MAMP/bin/php/php7.2.1/bin:$PATH

Install Composer

Composer is the standard in PHP for dependency management, class autoloading, and much more.

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Set up server

Create a virtual host called laconia.server. The server should point to the /public directory. Your httpd-vhosts.conf will look like this:

<VirtualHost *:80>
    DocumentRoot "/Users/tania/hosts/laconia/public"
    ServerName laconia.server
</VirtualHost>

Run install script

  • Run php bin/install.php in the root directory to initialize the database.
  • Run composer install to autoload classes and configuration.
  • Run npm i to install depencencies to use Sass.
  • Run npm run sass to run sass.

Copy credentials example file to credentials.

cp credentials.example.php credentials.php

Laconia is all set up and ready to use!

Docker Instructions

  • Run make init to build all containers.
  • Run make install to run the install script.

npm and sass are not integrated in Docker at the moment.

  • Run npm i to install depencencies to use Sass.
  • Run npm run sass to run sass.

Autoload classes

If you change or add a class at anytime, you'll need to re-run the autoload script to re-load the new classes.

composer dump-autoload

Project Structure

The entire program flows through /public/index.php, and the rest of the project is a directory above public.

laconia/
  .git               # Git source directory
  assets/            # Uncompiled raw SCSS
  bin/               # Command line scripts
      install.php    # Database installation script
  config/            # Database credentials, utility helpers, and other configuration
  data/              # SQL database files
  node_modules/      # Node.js front end dependencies
  docker/            # Contains Docker environment variables
  public/            # Publicly accessible files
      css/           # Compiled, ready-to-use styles
      js/            # Compiled, ready-to-use scripts
      index.php      # Main entry point for the entire application
  src/               # PHP source code
      app            # Router code
      controllers/   # Controller classes
      models/        # Model classes
      views/         # Views
  tests/             # Unit tests
  vendor/            # Composer files and 3rd party packages
  .gitignore         # Files to be ignored in the repository
  composer.json      # Composer dependency file
  composer.lock      # Composer lockfile
  docker-compose.yml # Docker configuration
  Dockerfile         # Docker configuration
  LICENSE            # MIT License file
  Makefile           # Docker instructions
  package.json       # npm dependency file
  package-lock.json  # Dependency lockfile
  README.md          # Brief documentation

Usage

Laconia is a simple list-making website. You can register an account, log in, log out, reset your password, create and edit lists, and view public profiles.

  • / - Landing page
  • /register - Register a new user
  • /login - Log in to user account
  • /dashboard - Logged in dashboard screen
  • /logout - Log out of user session
  • /forgot-password - Get a password reset link
  • /create-password - Create a new password
  • /users - View all users
  • /settings - Edit user settings
  • /lists - View lists
  • /create - Create a new list
  • /edit/:list_id - Edit an existing list
  • /:username - View public profile
  • /404 - Any not found redirects to 404.

Testing

Laconia uses PHPUnit for unit testing. Tests will go in the /tests directory. For now, here is how to run a Hello, World! script.

./vendor/bin/phpunit ./tests/HelloWorldTest

Motivation

Laconia is a personal project created by Tania Rascia to learn the fundamentals of programming and modern web development from scratch. The main goals of the project are to learn MVC (Model View Controller) architecture, the OOP (Object-Oriented Programming) paradigm, routing, authentication, security, modern development practices, and how to tie it all together to make a functional web app.

Laconia runs on PHP 7.2 and MySQL. It uses Composer to autoload classes, configuration and utility files, as well as future tests through PHPUnit. Node.js is used to compile Sass to CSS via npm scripts. The CSS framework Primitive was used for the design.

Here are some of the concepts I learned while writing this program:

  • Authentication โ€“ logging in, logging out, resetting a password, having private content/dashboard hidden from anonymous users
  • Security and validation โ€“ encrypted passwords and hashing, parameter binding with SQL, making sure users cannot be overridden, making sure no spam or empty content can go through, making sure passwords and usernames have the proper characters
  • Routing โ€“ Redirecting to URLs based on incoming request method and URI path, creating public user profiles in the root directory, creating dynamic pages based on GET requests
  • Object-oriented programming โ€“ I had never used a class in a working application before writing this app, so I learned a lot about constructors, inheritance, and abstract classes
  • Composer โ€“ I had no prior experience using Composer, so I wanted to find out why it was the standard in modern PHP development. I used it for autoloading classes and configuration.
  • Database schema โ€“ how to structure a database to relate information easily between the tables, i.e. linking lists and list items, users and user comments, etc. Sessions and Users โ€“ how to easily deal with sessions, users, and authentication.

Acknowledgements

I've used a combination of many tutorials and StackOverflow posts to create this project. These have been the most important.

Contributing

Please feel free to fork, comment, critique, or submit a pull request.

Author

License

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

More Repositories

1

takenote

๐Ÿ“ โ€Ž A web-based notes app for developers.
TypeScript
6,824
star
2

webpack-boilerplate

๐Ÿ“ฆ โ€Ž A sensible webpack 5 boilerplate.
JavaScript
2,399
star
3

taniarascia.com

๐Ÿ’พ โ€Ž Personal website running on Gatsby, React, and Node.js.
JavaScript
1,982
star
4

wp-functions

A compilation of function snippets for WordPress developers who create their own themes.
1,206
star
5

new-moon

๐ŸŒ™ โ€Ž The optimized dark theme for web development.
Less
1,205
star
6

primitive

โ›๏ธ โ€Ž A front-end design toolkit for developing web apps.
SCSS
920
star
7

react-tutorial

A walkthrough of basic React concepts.
CSS
738
star
8

mvc

A simple MVC application in plain JavaScript.
JavaScript
575
star
9

sandbox

Development sandbox for front end projects and tutorials.
JavaScript
531
star
10

chip8

๐ŸŽฎ โ€Ž A Chip-8 emulator written in JavaScript for web, CLI, and native UI.
JavaScript
413
star
11

react-hooks

Build a CRUD app in React with Hooks.
JavaScript
371
star
12

snek

๐Ÿ โ€Ž A terminal-based Snake implementation written in JavaScript.
JavaScript
272
star
13

pdo

Connecting to MySQL in PHP using PDO.
PHP
230
star
14

startwordpress

Learn how to develop a WordPress theme from scratch with this basic skeleton and accompanying tutorial.
PHP
208
star
15

chat

๐Ÿ’ฌ ๐Ÿ• โ€Ž very chat. such messages. so talking. wow. React/Redux, TypeScript, Socket.io chat app.
TypeScript
204
star
16

accordion

๐Ÿช— Play the accordion with your computer keyboard!
JavaScript
174
star
17

vue-tutorial

A walkthrough of basic Vue concepts.
Vue
149
star
18

react-advanced-form

An example of a schema-based form system for React.
JavaScript
128
star
19

oblate

Custom theme for my personal website and blog.
PHP
124
star
20

startjekyll

An example and guide to getting started with Jekyll and static site generators.
CSS
115
star
21

memory

โญ โ€Ž JavaScript Memory Game.
JavaScript
110
star
22

node-api-postgres

RESTful API with Node.js, Express, and Postgres.
JavaScript
103
star
23

upload

How to Upload a File to a Server in PHP
PHP
101
star
24

bootstrapblog

Build on the official Bootstrap blog starter template to learn how to make a WordPress theme.
HTML
97
star
25

sokoban

Sokoban.js ๐Ÿ“ฆ
JavaScript
91
star
26

new-moon-vscode

New Moon Theme for Visual Studio Code.
90
star
27

untheme

A blank WordPress theme for developers.
PHP
88
star
28

new-moon-chrome-devtools

New Moon Theme for Chrome Devtools.
CSS
58
star
29

card

A well-designed card element.
CSS
55
star
30

new-moon-sublime

New Moon Syntax Theme for Sublime Text
54
star
31

router-example

Use React Router DOM to create a Single Page Application (SPA).
JavaScript
52
star
32

tictactoe

#๏ธโƒฃ Tic Tac Toe in TypeScript.
TypeScript
42
star
33

baba

JavaScript
31
star
34

node-test

How to make your first Node.js project
JavaScript
26
star
35

new-moon-atom-syntax

New Moon Syntax Theme for Atom
CSS
25
star
36

new-moon-brackets

New Moon Theme for Brackets.
Less
22
star
37

calc

Unit Testing in JavaScript
JavaScript
20
star
38

graphql-fantasy-api

JavaScript
19
star
39

dotfiles

Dotfile configuration.
15
star
40

taniarascia

13
star
41

singularity

An online, text-based dystopian strategy game built in PHP. Modified from the original QMT Promisance code.
PHP
12
star
42

3d

3D printer projects.
10
star
43

coffee

Cafรฉtography
JavaScript
10
star
44

new-moon.vim

port of taniarascias newmoon colorscheme
Vim Script
10
star
45

startgrunt

Learn how to install Grunt and use it to create a Sass and JavaScript workflow.
JavaScript
10
star
46

comments

Comments
7
star
47

httpcast

HTML
5
star
48

signals

Signal test
JavaScript
3
star