The FARM Stack Book

FullStack FastAPI, React and MongoDB

Building Python web applications with the FARM stack

This book is a complete zero-to-hero guide to the FARM stack. The author took the time to break down React hooks, FastAPI routes and file structure, and MongoDB to the point that someone from a non-programming background can understand it and get up and running.

Eleke Great, Technical Reviewer

Probably the best way to start using a new technology, or a new stack - a blend of technologies - is by using it. I have written this book with a particular reader in mind: myself.

While this is by no means a comprehensive guide to MongoDB or React - two mainstream technologies that have been around for some time, the book has another protagonist - fastAPI, a relatively young, but already mature and battle tested Python-based asynchronous framework for building applications.

The book takes a practical approach and tries to introduce the parts of the stack in a simple and straightforward way, while gradually presenting features - MongoDB queries, drivers, simple React Hooks, the FastAPI way of performing standard and not-so-standard web development tasks.

This book is aimed at web developers and analysts who desire to include the power of a modern asynchronous Python framework, a flexible data store and a powerful UI library mixed with the combination of two of the most important programming languages today into their web developers toolkit. The book would also prove useful for various beginners in the field of information presentation. The book requires a beginner-level understanding of Python and JavaScript programming, HTML and CSS.

Packt Publishing Amazon

What's inside the book?

The book is aimed at giving the readers a basic, yet thorough understanding of the FARM stack components and of the possibilities offered by the framework.

Here is a brief rundown of the chapters.

Chapter 1: Web Development and the FARM Stack

We try to make a case for this partticular type of stack - comparing the FARM stack and its components to other, more popular, alternatives. And it makes sense!

Chapter 2: Setting Up the Document Store with MongoDB

A rather thourough look at MongoDB - what it is, why it is almost perfect for some types of solutions and why it might not be the best fit for others.

Chapter 3: Getting Started with FastAPI

It is time to meet FastAPI - the coolest and brightest Python framework of our time! FastAPI shouldn't be intimidating after this one!

Chapter 4: Setting Up a React Workflow

React is a the UI library - we go over what React achieves, the basic syntax, JSX and the creation of components and how to set up a new project, we talk a bit about two of the most popular and arguably most important Hooks - the useState and the useEffect.

Chapter 5: Building the Backend for Our Application

We begin building a very simple but full-fledged API: we start by setting up MongoDB, we create an instance of FastAPI and then we create our routes. Finally we deploy our app.

Chapter 6: Building the Frontend of the Application

Now that we have a backend, it is time to connect it to a frontend. A React application featuring Tailwind CSS (our CSS framework of choice) and the latest version of the React Router - version 6.

Chapter 7: Authentication and Authorization

JWT tokens are a very popular solution and although we develop a rather simple variation of a JWT-based authentication system the chapter should give you enough information so that in the future you can dive into JWT systems in other frameworks.

Chapter 8: Server-Side Rendering and Image Processing with FastAPI and Next.js

Here we tackle different real-life web development problems in a fun way!

  1. File uploads
  2. Image processing
  3. Server-side rendering (SSR)and static generation
  4. The worlds most feature-rich frontend framework - NextJS
  5. Next.js API routes and authentication with httpOnly cookies?
  6. Deployment on Vercel

Chapter 9: Building a Data Visualization App with the FARM Stack

This is probably my favourite chapter, and certainly the one I've had the most fun writing.

You will get to know SWR - a better way of fetching data, Chart.js, an excellent charting library that hits a sweet spot between ease of use and customizability. We also get to send some emails, create documents and other fun stuff!

Chapter 10: Caching with Redis and Deployment on Ubuntu (DigitalOcean) and Netlify

It's time to deploy our analytics app on an Ubuntu Server - Uvicorn, Nginx, Netlify, Redis.

Chapter 11: Useful Resources and Project Ideas

To close things off, the chapter includes some creative ideas for you (and me!) to test your FARM stack knowledge and creativity.

GitHub: Book Resources

The GitHub repo for the book is located at this link and it should be updated with some additional info. Please do not hesitate to let me know if you find errors, small ones, big ones or ways to make the code more illustrative or concise.

What is not inside

Writing really boils down to two things: what to write about and what to omit. This book is pretty opinionated and doesn't include some topics that you would maybe expect to find in a FastAPI book, so I think that it is only fair to mention what is not covered:

  1. SQL databases (because, you know... MongoDB)
  2. Jinja2 or any other Python templating system, because we use React
  3. Other User-Interface frameworks
  4. While we do embed a simple Random Forest regressor, machine learning is not covered
  5. Deployment on Docker containers (see above)
  6. Third-party authentication systems like Auth0, Cognito, Firebase
  7. There is no in-depth React coverage - there would simply be no space
  8. No basic Python or JavaScript tutorials or introductions
  9. Testing

Technologies used in the book

I have tried to use modern and up to date technologies that enable developers and alike to quickly get up and running. FastAPI is an excellent newcomer into the React / MongoDB stacks (MERN, MEAN, PERN) and I really believe that developers could benefit from the inclusion of the Python ecosystem through an async communication.

Where possible, I have tried to include simple and free or at least very cheap solutions, since I am a firm believer in the try-before-you-buy philosophy. I have intentionally ommited complex deployment solutions based on Docker containers and the "big" platforms (Azure, Google App Engine), since in most cases, especially if you are working with some smaller, in-house, application, you will want to deploy early and quickly, hopefully with minimal payment requirements. Unfortunately, in the brief weeks between the writing of the book and the publishing, Heroku seems to have ceased to provide its free service, but that should not be a game-changer or prevent you from diving into the stack.


The Author

Hello! My name is Marko Aleksendrić and I am the author of this book. I am a graduate of the University of Belgrade, Serbia, with a PhD and also a Master’s degree in Control Engineering. I am a self-taught full-stack developer and former scientist and I work as an analyst in a trade promotion agency.

I started my programming journey with Visual Basic and Fortran 77 for numeric simulations. Upon discovering Python (version 2.3), I started using it for all kinds of automation tasks: building reporting pipelines and exporting measurement data from instruments into Excel or similar user friendly or unfriendly reporting tools. Nowadays, I split my time between consulting and analytics, full-stack web development, and data visualization.

My interests include web development, data science, JAM stack technologies and data visualization and I have more than 20 years of experience with Python and the WWW.

I want and I have to thank the wonderful Packt Publishing team for giving me this opportunity and for being incredibly friendly, professional and kind along the journey. Thank you Aamir, Jane, Apeksha, Anamika!

Drop me a line