How to refactor to create-t3-app?
I have the following setup. I have a Django backend and a Nextjs frontend. In Next, I replicate my Django models and have api functions for accessing the api endpoints from Django.
How would I refactor this setup to an app that's created with
create-t3-app
Product/index.ts
26 Replies
Product/api.ts
Product/types.ts
Any help or advice is appreciatedUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
Can/should I still use tRPC if I use Django's endpoints for fetching data
maybe if you need to hide an api key or something
otherwise probably not
Well currently we have an Axios client
How does it differ from trpc
trpc is for talking between your frontend and a typescript api that you own
if you're not doing that then you don't have a use for it
Yeah no it's a Python Django backend
What about Zod
Is that still viable?
In my stack
My current stack basically is:
Python Django backend
Next frontend with;
TypeScript
Axios as API client
NextAuth
React-query
Tailwind
can you generate openapi definitions for your python project?
that would allow you to import the api types in your frontend
otherwise you can use zod schema and infer types from that
Schemas - Django REST framework
Django, API, REST, Schemas
Not as of now no
Not sure if that's easily implemented
if you cant get that, then you basically just have to write types in the frontend manually
which isnt great but tbh a lot of boomer company apps still work like that
Yeah thats what im currently doing
I replicate my Django models one by one 💀
then there's not much this stack can give you tbh
you can use zod schema to validate forms etc but thats about it
Yeah thats what I thought
i dont really understand axios, its like 12kb and all it does is make fetch syntax a bit nicer, but if bundle size isn't a big concern then i think your stack is fine as it is
I'd like to start using t3 for myself tho dont get me wrong
Might look into Zod schemas and infering those into types then
Do you have any general tips about the 'replicating' tho?
Replace axios with a simple custom fetch wrapper
Axios can do a ton of stuff, but here's a simpler solution that can handle most use cases
I was thinking about refactoring my
api.ts
file to static methods for each replicated model
So I would just have e.g. Product.create() instead of a createProduct fni dont think that matters too much. if you prefer that syntax then go ahead
tbh i usually give this sort of stuff to team members to decide
Is there any good practice for types
so that i can put my foot down when theres a decision thats actually important to me
Hahah
Yeah I kinda rolled into Tech Lead for these 2 projects im on
At least for the Nextjs part
just read the "basic usage" part here https://github.com/colinhacks/zod
GitHub
GitHub - colinhacks/zod: TypeScript-first schema validation with st...
TypeScript-first schema validation with static type inference - GitHub - colinhacks/zod: TypeScript-first schema validation with static type inference
for input types
for the types of the API response theres not much you can do other than just write the type
Actually a nice read tho thanks
I keep struggling on where to store all my types
Kinda just all over the place rn
Rather wondering if it's a better practice to keep it in a basic src/types directory and organise that by context instead
It's personal preference in the end nonetheless
But still
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View