This is a project template for headless commerce using T3 stack for the storefront and Medusa.js for the backend.
- Clone this repository.
- Open terminal in local repository.
- Install NPM dependencies.
pnpm install
-
Open terminal in
apps/backend
folder. -
Run seed script
pnpm seed
-
Start server
pnpm start
-
Create test customer
curl --request POST \ --url http://localhost:9000/store/customers \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{"first_name":"John","last_name":"Doe","email":"john@medusa-test.com","password":"supersecret","phone":"+49 123 456789"}'
Hint: You can access Medusa.js Admin via http://localhost:9000/app and sign in with email "admin@medusa-test.com" and password "supersecret".
-
Open terminal in
apps/storefront
folder. -
Create
.env
file from template.cp .env.example .env
-
Generate secret key for Next-Auth.
openssl rand -base64 32
-
Open
.env
file and insert variable with secret key.# .env NEXTAUTH_SECRET="your_secret_key"
-
Start server
pnpm dev
- Visit http://localhost:3000/
- Sign in with test customer:
- Email: john@medusa-test.com
- Password: supersecret
The storefront app has been set up using Create T3 App. See its documentation for more details.
The storefront uses Next-Auth as authentication library. A custom provider is implemented to support sign in via Medusa.js API. See src/integrations/medusa/auth-provider.ts
Medusa.js session ID is stored inside the JWT managed by Next-Auth and is not exposed as part of client session data (e.g. useSession
). Therefore, it can only be access on the server-side, i.e. in getServerSideProps
or in API routes (including tRPC procedures). As a consequence, all queries and mutations requiring user authentication must be proxied to Medusa.js via tRPC procedures. See auth router for example: src/features/auth/server/api/auth-router.ts
The storefront supports English and German. Internationalization is implemented using next-i18next. Language files with translations are located in public/locales
folder.
Keep in mind that data coming from Medusa.js is not localized because there is no multi-language support yet.
The storefront has some basic styling using TailwindCSS and daisyUI.
To keep things simple, there are only two guidelines for modularization and abstraction in the storefront project.
- Feature-specific code belongs into the corresponding folder inside
src/features
(e.g. React components dedicated to the catalog insrc/features/catalog/components
) while shared code goes into the top-level directories (e.g. general React components insrc/components
) - Communication with vendor-specific backend APIs is performed via service functions which create a backend-agnostic facade. These functions build the bridge between the business domain model used in React components and the underlying vendor-specific APIs (like Medusa.js model). See cart services for example:
src/features/cart/services