My project is broken into two different code bases, a PHP api created with the Lumen framework and a static client website created with React and Semantic UI.
The api could almost be seen as a totally functioning version of the project, just without an interface. It provides all the real functionality to the client, the client is just making HTTP requests to the api whenever it wants to do something. The api knows absolutely nothing about the client and could be easily reused for a mobile app, for example.
The api uses a token based authentication system. Upon registering or logging in, the user is given a unique api token that is sent up with subsequent requests. This token allows the api to identify the user making the request and determine who is uploading a picture or trying to delete a comment (and whether or not they are allowed to). The api validates against any bad data and authorizes any actions being performed by the user.
The client uses React for templating and components and Semantic UI for stylized components like buttons, inputs, etc. React allowed me to easily put together pages as javascript classes that contained everything needed to show the page, including the pages state and how that state is rendered on the pages template.
The client is eventually built for production which results in a completely static collection of html, javascript, and css. This static website is simply served to the user, and all http requests to the api are made locally via ajax on the users machine.
The frameworks I used create a lot of files that you really don't need to look at. I recommend looking over the following files in the following order, the code should document itself well enough.
db/awp-pictures.sql
: has all of the sql to create the structure of the database + comments on the structure itself
api/bootstrap/app.php
: bootstraps the api framework, nothing super interestingapi/app/Http/Middleware/Authenticate.php
: middleware to authenticate user requestsapi/app/Providers/AuthServiceProvider.php
: service used by auth middlewareapi/routes/web.php
: defines the routes of all the endpoints in the apiapi/app/Http/Controllers/UserController.php
: controller that holds all the functionality for usersapi/app/Http/Controllers/PictureController.php
: controller that holds all the functionality for picturesapi/app/Libraries/Helpers.php
: collection of random helper functions
client/src/index.js
: initial javascript entry point of react appclient/src/App.js
: app component, holds all other components and displays with routerclient/src/App.css
: global css (not much, most comes from Semantic UI)client/src/Util.js
: util functions used by a lot of the page componentsclient/src/pages/LoginPage.js
: the login pageclient/src/pages/CreateAccountPage.js
: the create account pageclient/src/pages/VerifyEmailPage.js
: the verify email page, sent here upon clicking the link in the 'verify email' emailclient/src/pages/ForgotPasswordPage.js
: the forgot password page, allows you to create a forgot password request which sends the emailclient/src/pages/ChangePasswordPage.js
: the change password page, sent here upon clicking the link in the 'forgot password' email or when you click change password from the user dropdown menuclient/src/pages/BrowsePage.js
: the browse page, main page to look at paginated/sorted list of uploaded picturesclient/src/pages/PostPicturePage.js
: the post picture pageclient/src/pages/PicturePage.js
: the picture page, detail page for a single picture
You don't need to read this part Professor Provine, just here for my reference.
cd awp-pictures/api/
composer install
chmod 755 -R ../../awp-pictures
chmod 777 -R storage
cd ../
mysql -u richealp7 -p richealp7 < db/awp-pictures.sql
cd awp-pictures/client/
npm install
npm run build
- Add the following to a
.htaccess
file insideawp-pictures/client/build/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~richealp7/awp/awp-pictures/client/build/index.html [L]
</IfModule>
chmod 755 -R ../../awp-pictures
cd awp-pictures/api/
chmod 777 -R storage