Difference between revisions of "Web Frameworks"
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | ''The following recommendations were last updated Fall 2024'' | |
− | Web Frameworks are an alternative method for writing web applications. Frameworks exist to make writing code more maintainable, scalable, as well as to introduce base functionality for the application you make. | + | So far in this class, you have been using PHP, HTML, and JS to run your website. You may have found that PHP can become burdensome for larger applications and difficult to use in collaboration. |
+ | |||
+ | Web Frameworks are an alternative method for writing web applications. Frameworks exist to make writing code more maintainable, and scalable, as well as to introduce base functionality for the application you make. | ||
There are ''hundreds'' of frameworks available. We've categorized and listed some of the more popular below to help you decide what's right for your application. | There are ''hundreds'' of frameworks available. We've categorized and listed some of the more popular below to help you decide what's right for your application. | ||
Line 9: | Line 11: | ||
=== Routing === | === Routing === | ||
− | A '''key difference''' between PHP and web frameworks is | + | A '''key difference''' between PHP and web frameworks is how routing occurs. |
In PHP, if you went to an address like http://www.example.com/welcome.php then Apache would run the script located at, for example, ''/var/www/html/welcome.php''. | In PHP, if you went to an address like http://www.example.com/welcome.php then Apache would run the script located at, for example, ''/var/www/html/welcome.php''. | ||
Line 17: | Line 19: | ||
=== Less Code === | === Less Code === | ||
− | Frameworks are designed to separate your application logic from your HTML and CSS. In fact, most web frameworks automatically generate all of the HTML and CSS that you need. So, you could write a fully functional (albeit bland-looking) | + | Frameworks are designed to separate your application logic from your HTML and CSS. In fact, most web frameworks automatically generate all of the HTML and CSS that you need. So, you could write a fully functional (albeit bland-looking) website in a Web Framework without writing a single line of HTML or CSS! |
=== MVC Architecture === | === MVC Architecture === | ||
Line 45: | Line 47: | ||
=== Front-end Frameworks === | === Front-end Frameworks === | ||
=====React===== | =====React===== | ||
− | Get started [https:// | + | Get started [https://react.dev/ Here] |
− | |||
− | |||
− | React is the most popular front end framework. React uses JS to create HTML (JSX), as opposed to updating HTML with JS. This makes manipulating the DOM more efficient and smoother. | + | React is the most popular front-end framework. React uses JS to create HTML (JSX), as opposed to updating HTML with JS. This makes manipulating the DOM more efficient and smoother. |
=====Vue===== | =====Vue===== | ||
Get started [https://vuejs.org/v2/guide/ Here] | Get started [https://vuejs.org/v2/guide/ Here] | ||
− | + | A really good happy medium between React and Angular. Not fully contained, but separates/organizes your code very nicely. Don't have to use JSX or Angular-specific methods. The code structure is better organized than React, but not as opinionated as in Angular. | |
Vue is partnered with PHP Laravel so a lot of the integrations are very code-friendly. | Vue is partnered with PHP Laravel so a lot of the integrations are very code-friendly. | ||
Line 61: | Line 61: | ||
Get started [https://angular.io/guide/quickstart Here] | Get started [https://angular.io/guide/quickstart Here] | ||
− | Not to be confused with Angular.js (the old version), Angular is the Google developed front-end framework that competes with React and Vue. Angular has | + | Not to be confused with Angular.js (the old version), Angular is the Google-developed front-end framework that competes with React and Vue. Angular has its own more opinionated code practices, making it easy for developers to understand but with a higher initial learning curve. |
=== Back-end Frameworks === | === Back-end Frameworks === | ||
Line 72: | Line 72: | ||
Get started [https://laravel.com/docs/5.8 Here] | Get started [https://laravel.com/docs/5.8 Here] | ||
− | Laravel is certainly the most popular PHP back-end option. If you aren't sure you want to venture over to a Node, Python, or | + | Laravel is certainly the most popular PHP back-end option. If you aren't sure you want to venture over to a Node, Python, or another back-end, I urge you to try Laravel instead of vanilla PHP. Super clean, super simple, and genuinely makes writing PHP enjoyable. As mentioned above, it's coupled extremely well with Vue.js, I would recommend searching for tutorials of the two together if that's the approach you'd like to take. |
=====Django (Python)===== | =====Django (Python)===== | ||
Line 117: | Line 117: | ||
</source> | </source> | ||
− | Depending on what frameworks you're using, it's easy to just place your full front-end framework in the client folder, all of your back-end files in the server folder, and all of your database and other configurations in the config folder. Your | + | Depending on what frameworks you're using, it's easy to just place your full front-end framework in the client folder, all of your back-end files in the server folder, and all of your database and other configurations in the config folder. Your entry point is just a file containing the command(s) to start everything. Whether this is a package.json file, or a python file that starts your Django server, it's nice to keep it in the root of your project. |
Have fun! | Have fun! | ||
[[Category:Module 5]] | [[Category:Module 5]] |
Latest revision as of 20:39, 6 June 2024
The following recommendations were last updated Fall 2024
So far in this class, you have been using PHP, HTML, and JS to run your website. You may have found that PHP can become burdensome for larger applications and difficult to use in collaboration.
Web Frameworks are an alternative method for writing web applications. Frameworks exist to make writing code more maintainable, and scalable, as well as to introduce base functionality for the application you make.
There are hundreds of frameworks available. We've categorized and listed some of the more popular below to help you decide what's right for your application.
Common Features of Frameworks
Routing
A key difference between PHP and web frameworks is how routing occurs.
In PHP, if you went to an address like http://www.example.com/welcome.php then Apache would run the script located at, for example, /var/www/html/welcome.php.
With routers, however, you can set arbitrary URLs to run different controller files.
Less Code
Frameworks are designed to separate your application logic from your HTML and CSS. In fact, most web frameworks automatically generate all of the HTML and CSS that you need. So, you could write a fully functional (albeit bland-looking) website in a Web Framework without writing a single line of HTML or CSS!
MVC Architecture
In PHP, your code probably ended up jumbled together in various disorganized places. This is part of the reason why many Web Frameworks choose to use a Model-View-Controller architecture.
You learned about the Model-View-Controller architecture in CSE 132. If you need a review, read the article on Wikipedia.
A directory structure for an MVC framework might look like the following:
- app (holds MVC components)
- models (contains models)
- controllers (contains controllers)
- views (contains views)
- config (holds global server configurations)
- lib (other assorted libraries)
With an MVC architecture, a request to the server typically follows the following path:
- The server routes the request to a certain controller.
- The controller interprets the request, loading requested information from the models.
- The controller passes the information from the models to a view.
- The final view is sent to the user.
So what do I do?
Front-end Frameworks
React
Get started Here
React is the most popular front-end framework. React uses JS to create HTML (JSX), as opposed to updating HTML with JS. This makes manipulating the DOM more efficient and smoother.
Vue
Get started Here
A really good happy medium between React and Angular. Not fully contained, but separates/organizes your code very nicely. Don't have to use JSX or Angular-specific methods. The code structure is better organized than React, but not as opinionated as in Angular.
Vue is partnered with PHP Laravel so a lot of the integrations are very code-friendly.
Angular
Get started Here
Not to be confused with Angular.js (the old version), Angular is the Google-developed front-end framework that competes with React and Vue. Angular has its own more opinionated code practices, making it easy for developers to understand but with a higher initial learning curve.
Back-end Frameworks
Express (NodeJS)
Get started Here
If you're planning on using a NodeJS backend, Express is a great option. Other options include Hapi.js or KOA if you're already familiar with Express and want to try something else.
Laravel (PHP)
Get started Here
Laravel is certainly the most popular PHP back-end option. If you aren't sure you want to venture over to a Node, Python, or another back-end, I urge you to try Laravel instead of vanilla PHP. Super clean, super simple, and genuinely makes writing PHP enjoyable. As mentioned above, it's coupled extremely well with Vue.js, I would recommend searching for tutorials of the two together if that's the approach you'd like to take.
Django (Python)
Get started Here
Django's tagline is "The Web framework for perfectionists with deadlines". Take that as you will.
Django is a fairly opinionated full-stack framework, meaning both your front-end and back-end will be written and handled by Django (as opposed to, say Express, which can integrate with whatever sort of front-end you'd like). This doesn't mean it's more difficult to learn, but it does kind of force you to learn how Django does its front-end and back-end which is why it counts for both in terms of points.
Flask (Python)
Get started Here
Flask is a micro back-end framework and is extremely easy to setup. Unlike Django, Flask won't handle your Front-end for you. This leaves you the option to use any of the recommended front-end frameworks or to just use regular HTML/JS.
Bottle (Python)
Get started Here
Same gist as Flask, just an alternative.
Other and Database Info
MongoDB
Get started Here
MongoDB is a very popular no-sql based database. It may seem like a hassle to learn another type of database querying, but as soon as you realize you don't have to mess with foreign keys and it's all essentially javascript objects, it becomes a pretty attractive option. They also have free cloud databases now which is awesome because you don't have to worry about hosting a database on your computer, but much of the security is handled on their end.
Firebase
Get started Here
Firebase is another cloud-based no-sql option. Firebase provides everything from the database itself to real-time crash reporting and analytics. Very easy to integrate into your app and get started with.
Other SQL
Structuring Your Project
Once you've outlined your project and have chosen what languages and frameworks you'd like to use, knowing where to start can be a bit daunting. We recommend a straightforward file structure similar to the following:
client/
server/
config/
entrypoint
Depending on what frameworks you're using, it's easy to just place your full front-end framework in the client folder, all of your back-end files in the server folder, and all of your database and other configurations in the config folder. Your entry point is just a file containing the command(s) to start everything. Whether this is a package.json file, or a python file that starts your Django server, it's nice to keep it in the root of your project.
Have fun!