FireTurbo is a monorepo template that integrates Express.js, Next.js, and Firebase using Turborepo. It serves as a comprehensive example of setting up a scalable and maintainable codebase, demonstrating best practices in combining backend and frontend frameworks with shared configurations and components.
- Backend with Express.js: Structured for Firebase Functions, including endpoints for updating and fetching user data from Firestore, with authentication middleware.
- Frontend with Next.js: Utilizes React MUI for UI components, Redux for state management, and Firebase Authentication for user login.
- Shared Packages: Includes shared configurations for ESLint and TypeScript, as well as reusable UI components like a design system.
- Hot Reloading: Configured with Vite for hot reloading, allowing Express to reload concurrently with the Firebase emulator.
The monorepo is organized as follows:
fireturbo/
├── apps/
│ ├── backend-repo/
│ │ ├── src/
│ │ │ ├── config/
│ │ │ ├── controllers/
│ │ │ ├── middlewares/
│ │ │ ├── models/
│ │ │ ├── routes/
| │ ├── server.ts
│ │ ├── index.ts
│ │ ├── vite.config.js
│ │ ├── tsconfig.json
│ │ ├── .firebaserc
│ │ ├── firebase.json
│ ├── frontend-repo/
│ │ ├── src/
│ │ │ ├── apis/
│ │ │ ├── components/
│ │ │ ├── store/
│ │ │ ├── theme/
│ │ │ ├── app/
│ │ ├── next.config.js
│ │ ├── tsconfig.json
├── packages/
│ ├── config-eslint/
│ ├── config-typescript/
│ ├── logger/
│ ├── types/
│ ├── ui/
├── .vscode/
├── .gitignore
├── .npmrc
├── README.md
├── eslint.config.js
├── package.json
├── pnpm-lock.yaml
├── pnpm-workspace.yaml
└── turbo.json
apps/: Contains the main applications:backendandfrontend.packages/: Houses shared configurations and UI components.backend/: Structured with directories for configuration, controllers, core application setup, entities, middleware, repositories, services, and routes.frontend/: Organized with directories for APIs, theming, application-level components, atomic design components, and Redux store management.
To get started with FireTurbo, follow these steps:
-
Clone the Repository:
git clone https://github.com/agus08/fireturbo.git cd fireturbo -
Install Dependencies:
pnpm install
-
Set Up Environment Variables:
-
Backend Setup:
- Place the
service-account-key.jsonfile insideapps/backend-repo/. - You can obtain this file from your Firebase project settings under Service Accounts.
- Place the
-
Frontend Setup:
- Create an
.env.localfile insideapps/frontend-repo/based on.env.example. - The required Firebase configuration values can be retrieved from your Firebase project settings.
- Create an
-
-
Run the Project:
pnpm run dev
The command will start both backend and frontend applications with hot reloading enabled for efficient development.
-
Endpoints:
POST /update-user-data: Updates user data in the FirestoreUSERScollection.GET /fetch-user-data: Fetches user data from the FirestoreUSERScollection.
-
Middleware:
authMiddleware: Validates the request token to ensure authenticated access to endpoints.
-
State Management:
- Configured with Redux to manage application state, including user authentication status and data fetching states.
-
UI Components:
- Utilizes React MUI for responsive and accessible UI components.
- Includes a design system in the shared
uipackage for consistent styling across the application.
-
Routing:
- Employs Next.js App Router (Next.js 14+) for navigation between the login and main pages.
-
Firebase Authentication:
- Integrated for user login, with a responsive login form built using React MUI.