This project demonstrates a robust setup for a React application using Vite and TypeScript, containerized with Docker (using Bun and Nginx), and featuring granular routing management.
The application serves as a dashboard with authentication management. Key features include:
- Tech Stack: React 18, TypeScript, Vite.
- State Management: Zustand for global state (e.g., session management).
- Styling: Material UI (MUI) & Emotion.
- HTTP Client: Axios.
The project uses a multi-stage Docker build process optimized for performance and size:
- Build Stage: Uses
oven/bun:1.3.0-alpineto install dependencies and build the application. It utilizes specific cache layers (package.json,bun.lock) to speed up rebuilds. - Runtime Stage: Uses
nginx:1.27-alpineto serve the static assets.- Custom
nginx.conffor optimized caching and routing fallback (SPA support). - Environment variable injection at runtime using an entrypoint script (
env.sh) to support "build once, deploy anywhere" patterns.
- Custom
Key Files:
Containerfile: Defines the multi-stage build.compose.yml: Docker Compose configuration for local development.
Routing is handled by React Router v7, structured for scalability and security:
- Router Provider: Centrally managed in
src/router/ReactRouterProvider.tsx. - Middleware: Protected routes are wrapped in a
MiddlewareRoutecomponent that checks for authentication (viauseSessionStore) and redirects accordingly.PublicLayout: For public pages (Home, Access Denied).MainLayout: For authenticated dashboard pages.
- Lazy Loading: Routes are lazy-loaded (
lazy(() => import(...))) to optimize initial bundle size. Suspense checks are handled via awithSuspenseutility.
The project uses GitHub Actions for Continuous Integration and Continuous Deployment (CI/CD), automatically deploying to Cloudflare Pages.
- Triggers:
- Pushes to
develop. - Pull Requests to
develop,test,main(when closed and merged).
- Pushes to
- Build Process:
- Runs on
ubuntu-latest. - Sets up Bun (v1.3.0).
- Installs dependencies and builds the project using
bun run build.
- Runs on
- Deployment:
- Uses Wrangler to deploy the
distfolder to Cloudflare Pages. - Deploys to a specific branch environment based on the event (PR base ref or branch name).
- Secrets: Requires
CLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_IDsecrets in the GitHub repository.
- Uses Wrangler to deploy the