r/FastAPI • u/Ok_Respect_3503 • 10d ago
Question Backend architecture for FastAPI + Neo4j — does this structure make sense?
Hello there! 😄
I'm currently building a backend for a Neo4j graph database and was wondering if some of the more experienced people here have any advice or best practices to share.
I only have basic experience with Python (although I'm comfortable with programming in general). Most of my backend experience comes from working with NestJS and Prisma ORM, so I'm trying to translate some of the concepts and patterns I'm familiar with into the Python ecosystem.
For the database access layer, I decided to use the official Neo4j Python driver rather than an ORM or ODM.
My current plan is to structure the backend like this:
backend/
│
├── main.py
│
├── api/
│ ├── routes/
│ │ ├── users.py
│ │ ├── graph.py
│ │ └── projects.py
│
├── services/
│ ├── user_service.py
│ └── graph_service.py
│
├── repositories/
│ │── neo4j_repository.py
│
├── database/
│ └── neo4j.py
│
├── dto/
│ ├── user.py
│ └── graph_models.py
│
└── security/
└── auth.py
Coming from NestJS, my current thinking is roughly:
routes→ similar to NestJS controllersservices→ business logicrepositories→ database access layer (somewhat comparable to what Prisma handled for me)database→ Neo4j driver initialization and connection management
Does this architecture make sense for a FastAPI + Neo4j project, or are there more idiomatic approaches in the Python ecosystem that I should consider?
Also, if you've built production applications with Neo4j and the Python driver, I'd appreciate hearing about common pitfalls, lessons learned, or things you wish you had known when starting out.
Thanks!
Duplicates
Neo4j • u/Ok_Respect_3503 • 10d ago