r/learnprogramming • u/Electrical-Cap-9537 • 25d ago
Resource Need help with this!
Hi all, I'm 18 and I'm building a BI/analytics project on the Olist Brazilian e-commerce dataset. Right now I have PostgreSQL, Pandas and a bunch of analytical SQL queries (revenue, delivery times, customer retention and so on). The next step is to expose this data through an API with FastAPI, and a dashboard would consume it.
I understand what an API is and why FastAPI is popular, but when I try to build a mental model of a real app I get lost. Endpoints, HTTP methods, status codes, routers, Pydantic schemas, services, dependency injection with Depends, auth... each explanation is clear alone, but I can't see how the request goes through all these layers. For example I don't really get where validation ends and business logic starts, or where the DB session should live and why.
My second problem is how I learn. I'm very curious and I want to know how things work internally, like what FastAPI does between the request and my function, or why Pydantic validates in a certain way. It's a good habit long term, but I lose hours on one detail and the project doesn't move. I don't have unlimited time and I don't want months of theory before building.
Some questions:
If you never built an API, how would you learn it from scratch?
HTTP/REST fundamentals first, or start directly with FastAPI and learn along the way?
What is the best way to understand how the layers (router, schema, service, database access) fit together? Is it better to start with everything in one file and refactor later?
How deep should I go on a concept before moving on? Is "basics now, details later" a real strategy or just an excuse?
Any resources, open source repos to read or small projects you recommend? Something like a read-only analytics API sounds like a good first one to me, but tell me if I'm wrong.
I don't want to copy tutorials and have something that works without knowing why. I want a solid mental model so I can design my own backend later. If you learned backend with personal projects, I'd really like to hear what worked for you and what you wasted time on.
Thanks!
1
u/SwiftQuest 24d ago
For the mental model, trace one request by hand: the router matches the URL, the Pydantic schema checks the shape of the input (types, required fields), and your function then does whatever the data actually means, like "this date range makes sense" or "this customer exists". That split is basically where validation ends and business logic starts. The DB session is opened per request (that's what Depends is for) and closed when the request ends, so each request gets its own clean connection and nothing leaks between them. For a read-only analytics API I'd do exactly what you said, one endpoint per query, and only pull out a service layer once you notice you're copying the same logic around.
1
u/Available_Safe1818 24d ago
Just make one route for each query?
0
u/[deleted] 25d ago
[removed] — view removed comment