Originally published byDev.to
Same architecture as before, adapted for TypeScript conventions โ .tsx/.ts extensions, a dedicated types/ system, strict config files, and typed everything.
my-app/
โโโ public/
โ โโโ favicon.ico
โ โโโ robots.txt
โ โโโ index.html
โ
โโโ src/
โ โโโ assets/
โ โ โโโ images/
โ โ โโโ fonts/
โ โ โโโ icons/
โ โ
โ โโโ components/
โ โ โโโ common/
โ โ โ โโโ Button/
โ โ โ โ โโโ Button.tsx
โ โ โ โ โโโ Button.module.css
โ โ โ โ โโโ Button.types.ts
โ โ โ โ โโโ Button.test.tsx
โ โ โ โ โโโ index.ts
โ โ โ โโโ Modal/
โ โ โโโ layout/
โ โ โโโ Header/
โ โ โโโ Footer/
โ โ
โ โโโ features/ # Feature-based modules
โ โ โโโ auth/
โ โ โ โโโ components/
โ โ โ โ โโโ LoginForm.tsx
โ โ โ โโโ hooks/
โ โ โ โ โโโ useAuth.ts
โ โ โ โโโ services/
โ โ โ โ โโโ authService.ts
โ โ โ โโโ types/
โ โ โ โ โโโ auth.types.ts
โ โ โ โโโ authSlice.ts # Redux Toolkit slice / Zustand store
โ โ โ โโโ index.ts
โ โ โโโ dashboard/
โ โ โโโ profile/
โ โ
โ โโโ pages/
โ โ โโโ Home/
โ โ โ โโโ Home.tsx
โ โ โ โโโ Home.module.css
โ โ โโโ About/
โ โ โโโ NotFound/
โ โ
โ โโโ routes/
โ โ โโโ AppRoutes.tsx
โ โ โโโ ProtectedRoute.tsx
โ โ โโโ routes.types.ts
โ โ
โ โโโ hooks/ # Global/shared custom hooks
โ โ โโโ useDebounce.ts
โ โ โโโ useFetch.ts
โ โ โโโ useLocalStorage.ts
โ โ
โ โโโ context/
โ โ โโโ ThemeContext.tsx
โ โ โโโ AuthContext.tsx
โ โ
โ โโโ store/ # Global state management
โ โ โโโ index.ts
โ โ โโโ hooks.ts # Typed useDispatch/useSelector
โ โ โโโ slices/
โ โ โโโ userSlice.ts
โ โ
โ โโโ services/ # API layer
โ โ โโโ api.ts # Axios instance/config (typed)
โ โ โโโ authService.ts
โ โ โโโ userService.ts
โ โ
โ โโโ utils/
โ โ โโโ formatDate.ts
โ โ โโโ validators.ts
โ โ โโโ constants.ts
โ โ
โ โโโ types/ # Global/shared TypeScript types
โ โ โโโ index.ts # Re-exports
โ โ โโโ user.types.ts
โ โ โโโ api.types.ts
โ โ โโโ env.d.ts # Typed process.env / import.meta.env
โ โ โโโ global.d.ts # Ambient/global declarations
โ โ
โ โโโ styles/
โ โ โโโ globals.css
โ โ โโโ variables.css
โ โ โโโ theme.ts # Typed theme object (MUI/styled-components)
โ โ
โ โโโ config/
โ โ โโโ env.ts # Typed env config
โ โ โโโ appConfig.ts
โ โ
โ โโโ App.tsx
โ โโโ App.css
โ โโโ main.tsx # Entry point (Vite) / index.tsx (CRA)
โ โโโ vite-env.d.ts # Vite's built-in type reference
โ
โโโ tests/
โ
โโโ .env
โโโ .env.example
โโโ .eslintrc.cjs
โโโ .prettierrc
โโโ .gitignore
โโโ tsconfig.json # TS compiler config
โโโ tsconfig.node.json # For vite.config.ts itself
โโโ package.json
โโโ vite.config.ts
โโโ README.md
What Changes vs. the JS Version
1. Every file gets typed extensions
.jsx โ .tsx (files with JSX), .js โ .ts (pure logic files like utils, services, hooks without JSX).
2. Dedicated types/ folders, at two levels
Global types (src/types/) โ shared across the app: API response shapes, User model, env typings.
Feature-local types (features/auth/types/) โ scoped to that domain only.
3. tsconfig.json is critical
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"]
}
4. Typed component pattern
// Button.types.ts
export interface ButtonProps {
label: string;
variant?: 'primary' | 'secondary';
onClick?: () => void;
disabled?: boolean;
}
// Button.tsx
import { FC } from 'react';
import { ButtonProps } from './Button.types';
const Button: FC<ButtonProps> = ({ label, variant = 'primary', onClick, disabled }) => {
return (
<button className={`btn btn-${variant}`} onClick={onClick} disabled={disabled}>
{label}
</button>
);
};
export default Button;
5. Typed API service layer
// services/api.ts
import axios, { AxiosInstance } from 'axios';
const api: AxiosInstance = axios.create({
baseURL: import.meta.env.VITE_API_URL,
timeout: 10000,
});
export default api;
// services/userService.ts
import api from './api';
import { User } from '@/types/user.types';
export const getUser = async (id: string): Promise<User> => {
const { data } = await api.get<User>(`/users/${id}`);
return data;
};
6. Typed Redux store (if using Redux Toolkit)
// store/index.ts
import { configureStore } from '@reduxjs/toolkit';
import authReducer from '@/features/auth/authSlice';
export const store = configureStore({
reducer: { auth: authReducer },
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
// store/hooks.ts โ typed versions of useDispatch/useSelector
import { useDispatch, useSelector, TypedUseSelectorHook } from 'react-redux';
import type { RootState, AppDispatch } from './index';
export const useAppDispatch: () => AppDispatch = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
Essential Packages for This Setup
npm install -D typescript @types/react @types/react-dom @types/node
npm install -D @typescript-eslint/parser @typescript-eslint/eslint-plugin
๐บ๐ธ
More news from United StatesUnited States
NORTH AMERICA
Related News
Secret Claude Tracker Shocks Users After Anthropic's Anti-Surveillance Stance
12h ago
EV Batteries Defy Expectations, Last Hundreds of Thousands of Miles
1d ago
GBase 8a Performance Anomaly Case Study: How a Single Parameter Change Sparked a Chain Reaction
1d ago
Who Else Has Inherited a Codebase With Zero Comments and a Prayer?
1d ago
ๅฎ็พ็ๅนณๅบธ
3h ago