# Scopes
As your application grows, managing routes at the top-level App becomes unwieldy. Scopes allow you to group related routes under a common path prefix and share state or middleware among them.
#Defining a Scope
You create a scope using web::scope("/prefix"). All routes added to this scope will be prefixed with /prefix.
code_blocksrust
use actix_web::{web, App};
// Routes will be /api/users and /api/posts
let scope = web::scope("/api")
.route("/users", web::get().to(get_users))
.route("/posts", web::get().to(get_posts));#Shared Resources
Scopes can have their own application state and middleware, which is only applied to routes within that scope. This is extremely useful for applying authentication middleware exclusively to an /admin scope.