This document describes the architecture of the Circle Frontend.
The application is a Single Page Application (SPA) built with Vite and React. It utilizes a component-based architecture and robust state management to ensure scalability.
-
Vite Build Tool
- Provides extremely fast development server start-up and Hot Module Replacement (HMR).
- Optimized production builds using Rollup.
-
Component Structure
- Atoms/Molecules/Organisms: While not strictly enforced, components are generally broken down into smaller, reusable pieces.
- Pages: Top-level components that represent a full route (e.g.,
Home,Profile,Login). - Layouts: Wrapper components that define the common structure (Sidebar, Navbar) for pages.
-
State Management (Redux Toolkit)
- Store: Centralized state source.
- Slices: Modular state logic (e.g.,
authSlice,threadSlice). - Thunks: Async logic for API calls (e.g.,
loginUser,fetchThreads).
-
Routing (React Router)
- Manages navigation between views.
- Handles protected routes (redirecting unauthenticated users to Login).
src/
├── assets/ # Static assets (images, global css)
├── components/ # Reusable UI components
├── features/ # Feature-specific logic (Redux slices, specific components)
├── hooks/ # Custom React hooks
├── layout/ # Page layouts (MainLayout, AuthLayout)
├── pages/ # Route components
├── services/ # API integration (Axios instance, endpoints)
├── store/ # Redux store configuration
├── types/ # TypeScript definitions
├── utils/ # Helper functions
├── App.tsx # Main application component
└── main.tsx # Entry point
- User Action: User clicks a button (e.g., "Post Thread").
- Component: Event handler dispatches a Redux action (Thunk).
- Redux Thunk: Calls the API service using Axios.
- API Service: Sends HTTP request to Backend.
- Redux Slice: Updates state (
loading->success) with response data. - Component: React re-renders with new data from the Store.
We use a Hybrid Approach:
- Chakra UI: For base accessible components (Buttons, Modals, Inputs).
- Tailwind CSS: For layout primitives, spacing, and responsive design.
- Emotion: For complex dynamic styling (underlying Chakra).
- Framer Motion: Handles page transitions and micro-interactions.
- React Hook Form + Zod: manages complex form validation efficiently.