This project comprises a comprehensive full-stack application, named Focus Space, designed for blog list management, real-time communication, and integrated client-side productivity.
Focus Space follows a Decoupled Monorepo Architecture, clearly separating the Server (API) from the Client (SPA) but unifying management within a single structure.
| Layer | Technology | Primary Role | Communication |
|---|---|---|---|
| Client | React, Redux Toolkit, Socket.IO Client | User Interface, State Management, Real-time Rendering | REST (Axios) for CRUD, WebSockets (Socket.IO) for Real-time Updates |
| Server | Node.js, Express, MongoDB, Socket.IO Server | REST API, Data Persistence, Authentication, Real-time Broadcasting | Mongoose (ODM) for MongoDB, JWT for Security |
The core feature is instant synchronization:
-
Client Action (e.g., liking a blog) triggers a REST
$\text{PATCH}$ request to the server. -
Server updates the database, then uses the Socket.IO Server to instantly broadcast an event (e.g.,
blogUpdated) to all connected clients. -
Clients receive the event, and the
socketListeners.jsfile dispatches a Redux action, causing the UI to re-render immediately without polling.
The server is a highly modular Node.js application built on Express.
The server prioritizes Integration Testing using Node's native test runner and Supertest. This ensures API endpoints, database interactions, and middleware (authentication, error handling) function correctly as a single unit.
| Test Type | Tools Used | Focus/Goal |
|---|---|---|
| Integration Tests |
node:test, Supertest
|
Verifies the full request-response cycle for CRUD operations, checks |
-
Real-time Decoupling: The global
$\text{Socket.IO}$ registry allows for future horizontal scaling by integrating a$\text{Socket.IO}$ adapter (like Redis). -
Security: Authentication is handled by
$\text{JWT}$ . Routes are protected by dedicated middleware ($\text{tokenExtractor}$ /$\text{userExtractor}$). -
Data Integrity: Payloads are sanitized, and
$\text{Mongoose}$ schemas enforce consistent data structure, reducing vulnerability to unexpected input.
The client is a performant single-page application built on React, utilizing Redux for state management.
The client uses Vitest as the test runner and React Testing Library (RTL) for component testing, ensuring a user-centric verification process.
| Test Type | Tools Used | Focus/Goal |
|---|---|---|
| Component Tests | Vitest, RTL, user-event |
Verifies that individual UI components (e.g., <Blog />, <BlogForm />) render correctly, simulate user actions (clicks, typing), and correctly fire the associated event handlers/props. |
| Unit Tests | Vitest | Used for isolated testing of Redux reducers, thunks, and pure utility functions. |
-
Redux Toolkit: Manages all server-synced data (
blogs,users) with asynchronous logic handled by Thunks. -
Session Persistence: The user
$\text{JWT}$ is stored in$\text{localStorage}$ . A browser$\text{storage}$ event listener ensures login status synchronizes across multiple browser tabs without delays.
The Focus Space application includes dedicated tools that manage their state locally for speed and separation of concerns.
| Tool Name | Persistence Mechanism | Focus |
|---|---|---|
| Tasks Tool | localStorage (key: focus-space-tasks) |
Prioritization and management of to-do items (High, Medium, Low). |
| Pomodoro Timer Tool | localStorage (key: focus-space-pomodoro) |
Customizable focus/break time management and session tracking. |
| Journal Tool | localStorage (key: focus-space-journal) |
Quick logging of thoughts and notes with timestamps. |
- Node.js (v18 or higher)
- MongoDB instance (local or remote URI)
-
Install Dependencies: Run
npm install(in bothserver/andclient/directories if using distinct$\text{package.json}$ files). -
Environment Setup: Create a
.envfile in the server root directory:PORT=3003 MONGODB_URI=mongodb://localhost:27017/focus-space-dev SECRET=your_super_secret_jwt_key # Client variables (used in client build process) VITE_API_BASE=http://localhost:3003/api VITE_SOCKET_URL=http://localhost:3003
| Layer | Script | Command | Purpose |
|---|---|---|---|
| Server | npm start |
cross-env NODE_ENV=production node index.js |
Runs the server in production mode. |
| Server | npm run dev |
cross-env NODE_ENV=development nodemon index.js |
Starts the server with nodemon (auto-reloads). |
| Server | npm run test-jest |
cross-env NODE_ENV=test jest ... |
Runs Integration Tests against the test database. |
| Client | npm run dev |
vite |
Starts the client development server with HMR. |
| Client | npm run build |
vite build |
Builds the production static assets. |
| Client | npm run test |
vitest run |
Runs Component/Unit Tests using Vitest. |